I would like to build a hash table that looks for keys in sequences (strings) of bytes in the range of 1 to 15 bytes.
I would like to keep the integer value, so I assume that the array for hashing will be sufficient. It’s hard for me to understand how to construct a hash function in such a way that the given key returns an index to the array.
Any help would be greatly improved.
The maximum number of entries in the hash: 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];
}
What are some good options for a hash function, or how can I build it?
Thank.
source
share