BigDecimal nextProbablePrime() method performance (to set initial capacity of HashMap to a prime num

C

chris brat

Hi,

Where can I find information about the performance of the
nextProbablePrime() method in the java.math.BigInteger class? The
relates to the initial capacity of a HashMap.

The HashMap that can hold data of at least size X and at most Y,
and I want to set the initial capacity to the next possible prime
between X and Y.

By the way Y = X * 2.

At the moment I am setting the capacity to X but I've read that
HashMaps perform better if the initial capacity is a prime number - I
want to test this.

Thanks,
Chris
 
T

Thomas Hawtin

chris said:
At the moment I am setting the capacity to X but I've read that
HashMaps perform better if the initial capacity is a prime number - I
want to test this.

The current implementation of java.util.HashMap (in Sun JREs) always
rounds up to a power of two.

Tom Hawtin
 
J

Jeffrey Schwab

Thomas said:
The current implementation of java.util.HashMap (in Sun JREs) always
rounds up to a power of two.

So for the best performance, start with a capacity of two. ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top