Why choosing a prime number is common practise in the size of a hash table?

• 本文约 61 字,阅读大致需要 1 分钟 | Development

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.