On Sun, 03 Jun 2012 08:40:22 -0700, Knute Johnson
<nospam@knutejohnson.com> wrote, quoted or indirectly quoted someone
who said :
One of the problems is HashMaps, even in 64-bit JVMs, can still only
hold 1<< 30 elements.
What does that mean?
see http://www.mathe-online.at/JavaCalc/jcintro.html
it will evaluate it for you to :
1,073,741,824
Note it is smaller than
Integer.MAX_VALUE
+2,147,483,647 [2^31-1] aka 2 gig, roughly 2 billion
I "cheated" and looked inside HashMap source. The docs lie. The max
value is controlled by a constant
MAX_CAPACITY = 1<< 30;
Internally it needs an array sized a power of 2 with some breathing
room to track when the various hash chains start. The power of two
restriction allows it to convert a hashCode to an array index with
just a shift rather than a divide/modulus.
number of entries.