Long answer: here
Short answer:
A funnel occurs when 2+ keys get hashed to the same value because of an error with the underlying hashing function. Like this:
Map<String,Object> myMap = new HashMap<String,Object>();
Thing thing1, thing2;
thing1 = new Thing();
thing2 = new Thing();
myMap.put("ab", thing1);
myMap.put("ba", thing2);
If there is an inherent flaw in the hashing function used by HashMap<K,V>
, a "funnel" could occur where the keys ab
and ba
both map to, say, thing1
.
Think of a funnel as an actual funnel: multiple inputs get funneled into the same place.
Edit
If a hash function is flawed and does contain funnels, then a way to minimize their occurrence is to set the size of the table to being a prime number.
This is because, in terms of being a "class" (category) of numbers, prime numbers have the least amount of factors. According to that article, funnels occur when a given key is a factor or multiple of the size of the table. So if we set the table size to 100 (not a prime number), we introduce the possibility of funneling when the provided key is any factor of 100: 1, 2, 4, 5, 10, ..., 100, 200, 300, etc.
But if we make the size of the table to a prime, say, 101... then the only possibility of a funnel occurs at: 1, 101, 202, 302, etc. We've greatly reduced the possibility of a funnel.