Why is choosing a prime number common practice for the size of a hash table?
It’s a common practice to choose a prime number as the hash table size. This article analyzes Java’s implementation.
To make it short, it is important to avoid collisions in a hash table in order to maximize its search benefits. A funnel will occur only if the keys are multiples of the prime number; this will help prevent collisions.
在线阅读本文并参与讨论 delphij's Chaos blog.delphij.net/posts/2004/03/why-choosing-a/