Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
chris brat - 16 May 2006 11:19 GMT
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
Thomas Hawtin - 16 May 2006 12:20 GMT
> 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
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Jeffrey Schwab - 16 May 2006 22:27 GMT
>> 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.

So for the best performance, start with a capacity of two. ;)
Roedy Green - 21 May 2006 19:20 GMT
>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.

Hashtables do, but HashMaps round up to a power of two.

See http://mindprod.com/jgloss/hashtable.html
http://mindprod.com/jgloss/hashmap.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.