Constructing a hash table/hash function.

Posted by nn on Stack Overflow See other posts from Stack Overflow or by nn
Published on 2010-06-02T22:58:03Z Indexed on 2010/06/02 23:04 UTC
Read the original article Hit count: 530

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c

    Related posts about string