Hello,
I'm having some problems with filling a hash table using the following hash functions:
Code:
int h1(int k, int m){
int h1 = mod(k,m);
return h1;
}
int h2(int k, int m){
int h2probe = mod(2*k+1,m);
return h2probe;
}
int h(int k,int i, int m){
int h1a = h1(k,m);
int h2a = h2(k,m);
int h = mod(h1a + i*h2a, m);
return h;
int insert(int H[], int m, int key){
if (isFull(H, m) == -1) return -1;
int i=0;
int key2 = key*2+1;
if(key2 < 0) key /= 2;
int probe = h(key,i,m); // 0 <= probe < m;
while (H[probe] != 0) // we know there is room, so will terminate if the hashing function is able to map at each spot.
probe = h(key,++i,m);
H[probe] = key;
return probe;
}
The problem is that when I try to fill an 18 slots table slot 14 never gets a change to be filled. Similar deadlocks occur with other sizes. While a table of 10 elements fills correctly. The literature found about double hashing seem not to answer my problem. The insertion code simply tries again increasing i. However deadlocks occur. Any suggestions on how to solve it still using double hashing and the h functions specified above(so only play with the insertion method). Mod(a,m) return the module > 0.