public class HashTable <K, V> implements Table<K, V>{
PairHolder table[];
int idx;
public HashTable(int size){
table=new PairHolder[size];
}
public void put(K key, V value) {
int hVal = key.hashCode();
int index = hashFunc1(hVal);
int temp = hashFunc2(hVal);
int col = index +=temp;
while(table[index]!=null){
index += temp;
index %=table.length;
}
table[index].value=value;
}
}
public int hashFunc1(int key){
int abs = Math.abs(key%table.length);
return abs;
}
public int hashFunc2(int key){
int abs = Math.abs(5-key%5);
return abs;
}
我想加倍哈希,我很困惑如何做到這一點。我認爲我在正確的軌道上,但這是給NullPointerException
在table[index].value=value;
。試圖雙散列
任何幫助將是偉大的。
'table [0]'的值是什麼? –