Hash functions for integers: H(K) = K mod M
-
For general integer keys and a table of size M, a prime number:
-
a good fast general purpose hash function is H(K) = K mod M
-
If table size is not a prime, this may not work well for some key distributions
-
for example, suppose table size is an even number; and keys happen to be all even, or all odd. Then only half the table locations will be hit by this hash function
-
So, use prime-sized tables with H(K) = K mod M
CONTENTS PREVIOUS NEXT