Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top