Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Do we have a concept(?) called 'Hashfunction' in 'Hashtable' in Java?

  1. Dec 15, 2011 #1
    I know what Hashtable is. I have seen the methods that it contains and used these methods. I know the differences between the implementation classes. But I have not come across anything called 'Hashfunction' during the time when I was studying Collections framework. Is this 'Hashfuntion' has something to do with 'Hashtable'?
    I saw some videos and the guys were talking about 'Hashcode'(I know little bit about this), 'Compression function', 'Collision handling' and 'Separate chaining', 'Open addressing' and 'Linear probing', 'Double hashing', and they also talk about the performance of hashing..and 'associative arrays'. I am wondering if these concepts have something to do with 'Hashing technique'. I only know that there is something called Hashing technique which helps in making the searches faster. And there are "buckets" in which objects are stored in Hashing technique.
    If all of these concepts belongs to Hashtable in Java, is it important to know all of these concepts to create Hashtable?
    Thanks for your time.
     
    Last edited: Dec 15, 2011
  2. jcsd
  3. Dec 15, 2011 #2
    The Java Object has a hashcode() method which does some kinda default calculation -- I think it produces the value printed for objects that don't implement toString(). When you stuff Objects into a hash table the hashcode() method is called to figure out what hash bucket to use. There is some probability that two objects will have the same code, so hash stores need to be able to rummage through each bucket in order to find the actual object, but the hash code gets you to the right bucket with (usually) one integer compare. All those other concepts are optimizations. You actually don't need to know nutthin bout hashing to use the Java HashMap classes, they just (usually) work...
     
  4. Dec 15, 2011 #3
    All of these words you are using are important for implementing a hashtable. The point of something like Hashtable in java is it should be a black box. You don't need to know what's going on inside. You just need to know it works.

    The only thing you might need to care about is when you implement hashcode(), like schip666 said.

    http://www.javapractices.com/topic/TopicAction.do?Id=28

    But this is only if you are using custom classes as keys I think.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Do we have a concept(?) called 'Hashfunction' in 'Hashtable' in Java?
  1. Hashtable for booleans? (Replies: 18)

Loading...