Constructing a hash table/hash function.
- by nn
Hi, I would like to construct a hash table that looks up keys in sequences (strings) of bytes ranging from 1 to 15 bytes.
I would like to store an integer value, so I imagine an array for hashing would suffice. I'm having difficulty conceptualizing how to construct a hash function such that given the key would give an index into the array.
Any assistance would be much appreiated.
The maximum number of entries in the hash is: 4081*15 + 4081*14 + ... 4081 = 4081((15*(16))/2) = 489720.
So for example:
int table[489720];
int lookup(unsigned char *key)
{
int index = hash(key);
return table[index];
}
How can I compute hash(key). I'd preferably like to get a perfect hash function.
Thanks.