Error in Double hashing for linear probing
qiuhaha opened this issue · 1 comments
qiuhaha commented
Your first and secondary hash function are like this:
protected int hash(Key key)
{
int hash = key.hashCode() & 0x7fffffff;
if (lgM < 26)
hash = hash % PRIMES[lgM + 5];
return hash % size;
}
protected int secondaryHash(Key key)
{
int hash2 = (key.hashCode() % size) & 0x7fffffff;
hash2 = hash2 != 0 ? hash2 : size + 1;
return hash2;
}
The problem here is that the keys with the same hashCode values still end up with the same exact probe sequence. You should compute a new hashCode for the secondary hash function.
reneargento commented
The issue is that ideally the hash functions should generate different hashes, right?
If that is the case, I updated the exercise here: ffeb38d
Thanks for the suggestion!