For some reason, it's hashing to a very large number like
1241200051for an index (i.e. bucket). I'm building a simple hash table via open addressing w/ linear probing and it's phonebooks where the keys are string names, with 7-digit phone nums as values.
here is the tested-and-tried string hash function FNV I found @:
Eternally Confuzzled - The Art of Hashing
Code:
unsigned fnv_hash ( void *key, int len )//Q: how do I use generic ptr key?
{
unsigned char* p = (unsigned char*)key;
unsigned h = 2166136261U;
int i;
for ( i = 0; i < len; i++ )
h = ( h * 16777619 ) ^ p[i];
return h;
}
Code:
int main()
{
int phonebook_1[10] = {0,0,0,0,0,0,0,0,0,0};//always initialize size since specific compilers say its ok so don't get comfy w/ bad practices
size_t size_1 = 10;
string nam_1 = "Cooke";
void* p_to_nam_1 = &nam_1;
unsigned int bucket= fnv_hash( p_to_nam_1, size_1 );
cout << bucket << endl;
return 0;
}
EDIT: actually I found the official website on how to set the params and values @ FNV Hash, so I'lll take a look first before posting further...