Hey, I have been working on a program that is supposed to implement double hashing, but I have problems falling into an infinite loop, and Im not sure when to give the program the signal to say "hey, your in an infinite loop, break out of it"
Right now, I keep exiting way to early. I would really appreciate some help, I have been putting many hours into this program, and im stuck at this part and this was needing to be finished yesterday in all reality.
Given:
Primary Hash Function: XOR
Secondary Hash Function: Last7
table size = size of table(most likely not prime)
loop = variable used to see how many times i go through the while loop, I've tried setting it to 1 and 0
step = It should be the hash2 % table size;
nkeys = variable used to check the number of successful adds
My Code:
Code:
// XOR and Double
else if(Fxn == 2 && Coll == 2){
i = 1; // should it be 0 or 1?
index = XOR(key) % table_size;
if(keys[index] == ""){
keys[index] = key;
vals[index] = val;
nkeys++;
}
else{
step = Last7(key)%table_size;
if(step == 0){
step = 1;
}
while(keys[index] != ""){
index = (XOR(key) + (i*step)) % table_size;
if(keys[index] == ""){
keys[index] = key;
vals[index] = val;
nkeys++;
}
dbl_test = (XOR(key)+step)%table_size;
loop++;
if(loop >= table_size){ //not sure if this is right
cerr <<"Couldn't put " <<key<<" into the table"<<endl;
exit(1);
}
i++;
}
}
}
Look guys, I really appreciate your help in advance!