Hashes 17 resize

preview_player
Показать описание
Dr. Rob Edwards from San Diego State University shows how to resize a chained hash when it gets full
Рекомендации по теме
Комментарии
Автор

Just a little correction: LinkedList<HashElement<K, V>>[] new_array = (LinkedList<HashElement<K, V>>[]) new LinkedList[newSize];

diegocruzalves
Автор

From my modest point of view, I would opt for declaring this method with private visibility, given that it is called by other public methods from the class.

yusefbm
Автор

minor fix forgotten new: LinkedList<HashElement<K, V>> [] new_array =
(LinkedList<HashElement<K, V>>[]) new LinkedList[newSize];

pavelgorbatyuk
Автор

With big respect:
1. Need to change numElements amount as well.
2. Also I didn't get the idea of "for(K key: this)" Because you are in Hash class. I did this instead
for (LinkedList<HashElement<K, V>> linkedList : harray) {
for (HashElement<K, V> el : linkedList) {

int hashVal = el.key.hashCode();
hashVal = hashVal &
hashVal = hashVal % newSize;

newArray[hashVal].add(el);
newNumOfElements++;
}
}

giorgi
welcome to shbcf.ru