Given an integer m, a hash function defined on T
is a map T -> {0, 1, 2, ..., m - 1}
. If k
is an element of T
and m
is a positive integer, we denote hash(k, m)
its hashed value.
For simplicity, most hash functions are of the form hash(k, m) = f(k) % m
where f
is a map from T
to the set of integers.
In the case where m = 2^p
(which is often used to the modulo m
operation is cheap) and T
is a set of integers, I have seen many people using f(k) = c * k
with c
being a prime number.
I understand if you want to choose a function of the form f(k) = c * k
, you need to have gcd(c, m) = 1
for every hash table size m
. Even though using a prime number fits the bill, c = 1
is also good.
So my question is the following: why do people still use f(k) = prime * k
as their hash function? What kind of nice property does it have?