Can any one suggest just to get me started, how I can implement
a hash function that takes a string and returns a fixed length of that string ? just a big picture ....
Printable View
Can any one suggest just to get me started, how I can implement
a hash function that takes a string and returns a fixed length of that string ? just a big picture ....
>just a big picture ....
Big picture, huh? Well then, here's a decent hash function that works well for minimizing collisions. :)
-PreludeCode:int hash ( char *hashStr, int tableSize )
{
int hashValue = 0, index,
x = 31415, y = 27183;
for ( index = 0; hashStr[index] != '\0'; index++ ) {
hashValue = ( x * hashValue + (int)hashStr[index] ) % tableSize;
x = x * y % ( tableSize - 1 );
}
return hashValue;
}
Wouldn't it be x = 31416?