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