I am trying to create a function that generates a hash key based upon where in the hash table I want the value to go.
My hash function is (a + b * (key) ) % c = hash value
. I've seen a similar question to this on SO, and what I tried is replacing b * (key)
with d
and just doing:
private int ReverseModulus(int a, int b, int c, int hashValue)
{
if(hashValue >= c)
return -1;
if(a < hashValue)
return (hashValue - a) / b;
return (c + hashValue - a) / b;
}
but it seems that most of the time hashValue != Hash(ReverseModulus(a,b,c, hashValue))
.
I was wondering if the approach is wrong or if there is just an error in the code.