What integer hash function are good that accepts an integer hash key?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Knuth’s multiplicative method:
In general, you should pick a multiplier that is in the order of your hash size (
2^32in the example) and has no common factors with it. This way the hash function covers all your hash space uniformly.Edit: The biggest disadvantage of this hash function is that it preserves divisibility, so if your integers are all divisible by 2 or by 4 (which is not uncommon), their hashes will be too. This is a problem in hash tables – you can end up with only 1/2 or 1/4 of the buckets being used.