Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Hash Functions

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hash Functions

    Hi

    Do you guys know about Hash functions?

    Is there a library for this?

    Thanks a lot


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Hash Functions

    Hash functions is a very general term. What exactly do you need? A typical hash function uses multiplcation, addition, with a prime number in there somewhere to generate the hash. For example, a simple hash function for a class containing two values would be
    public class Test{
    	int var1;
    	int var2;
     
    	 @Override
    	public int hashCode() {
    		final int prime = 31;
    		int result = 1;
    		result = prime * result + var1;
    		result = prime * result + var2;
    		return result;
    	}
    }

    Eclipse can generate these for you.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Hash Functions

    A hash function is simply a way to take the data inside an object and reduce it down to 1 number. This can be done any many ways. The important thing is that for the exact same object, this number must always be the same. The hash function should also attempt to be as "random" as possible between different objects, but it's near impossible to guarantee that a hash function will have no collisions.

    See: Hash function - Wikipedia, the free encyclopedia

  4. #4
    Junior Member
    Join Date
    Jun 2012
    Location
    Long Island, NY
    Posts
    11
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Hash Functions

    Hello i just stumbled upon this thread and i think that my library can help you. You can find its thread at http://www.javaprogrammingforums.com...ndcentral.html and its project at http://code.google.com/p/grandcentral/

Similar Threads

  1. Constructors, Hash Tables, & Linked Lists
    By illusion887 in forum Collections and Generics
    Replies: 2
    Last Post: December 3rd, 2009, 03:46 AM
  2. callback functions? non-blocking socket help
    By Tomas in forum Java Networking
    Replies: 0
    Last Post: September 12th, 2009, 06:46 PM
  3. convert arraylist to a hash map
    By nadman123 in forum Collections and Generics
    Replies: 1
    Last Post: July 29th, 2009, 04:24 AM
  4. Comparing hash functions and collision resolutions
    By dansongarcia in forum Collections and Generics
    Replies: 0
    Last Post: November 11th, 2008, 10:50 AM