The constant factor should be prime, and if I remember correctly it should be relatively prime w.r.t. the modulus. This is all discussed at great length in Knuth Volume III.
Hash functions multiplying key with constant
-
30-06-2022 - |
Question
How does a constant before the key in the formula:
h(k) = (const * key) % m,
affect the distribution of the hash values in the table?
Are there any rules on how to choose such a constant to minimize collisions and get an even distribution of the keys in the hash table?
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow