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;
}
I am trying to double hash and I am confused on how to do it. I think I am on the right track but this is giving a NullPointerException
on table[index].value=value;
.
Any help would be great.