Implement a hash table

后端 未结 3 1997
挽巷
挽巷 2020-12-28 10:42

I\'m trying to create an efficient look-up table in C.

I have an integer as a key and a variable length char* as the value.

I\'

3条回答
  •  佛祖请我去吃肉
    2020-12-28 11:09

    It really depends on the distribution of your key field. For example, if it's a unique value always between 0 and 255 inclusive, just use key % 256 to select the bucket and you have a perfect hash.

    If it's equally distributed across all possible int values, any function which gives you an equally distributed hash value will do (such as the afore-mentioned key % 256) albeit with multiple values in each bucket.

    Without knowing the distribution, it's a little hard to talk about efficient hashes.

提交回复
热议问题