File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes writing efficient hashcode implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "writing efficient hashcode implementation" Watch "writing efficient hashcode implementation" New topic
Author

writing efficient hashcode implementation

anish jain
Ranch Hand

Joined: Feb 03, 2010
Posts: 129
How to write an efficient hashcode implementation so that tha hashcodes are uniformly distributed?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
There is a nice example in Effective Java by Joshua Bloch. The same technique is copied into Bruce Eckel's Thinking in Java, which you may be able to find a copy of the 3rd edition on the net (legally).
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Hi

Please check apache commons lang

org.apache.commons.lang.builder.HashCodeBuilder ( to build HashCode ...)

org.apache.commons.lang.builder.EqualsBuilder ( to generate Equsl() based on fields of class )


Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Thank you. Those Apache Commons methods might give effective hash and equals methods, but using such tools does not help one learn the algorithm, I am afraid.
 
 
subject: writing efficient hashcode implementation
 
Similar Threads
Clarification needed on K&B use of "legal" and "appropriate" regarding hashCode() implementations
Entity bean with composite key
identical hashcode values
appropriate, legal and efficient hashCode()
variables in hashCode( ) and equals( )