delphij's Chaos

选择chaos这个词是因为~~实在很难找到一个更合适的词来形容这儿了……

18 Mar 2004

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.