Why hashing?

This is a discussion on Why hashing? within the Tech Board forums, part of the Community Boards category; Why .NET, Ruby and Java compare structures by its hash code? How about recursive structure comparison? Anyone know this?...

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    Question Why hashing?

    Why .NET, Ruby and Java compare structures by its hash code?

    How about recursive structure comparison?

    Anyone know this?
    Just GET it OFF out my mind!!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,312
    Quote Originally Posted by audinue
    Why .NET, Ruby and Java compare structures by its hash code?
    You can implement hash tables in pretty much any programming language, so there is nothing special about Ruby and Java in that regard. Hash tables can come in handy when you want constant time insertion, deletion and search of elements, but do not care about the order of elements.

    Quote Originally Posted by audinue
    How about recursive structure comparison?
    Comparing objects by comparing their components is useful too. It is all a matter of what are your requirements.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Quote Originally Posted by laserlight
    Comparing objects by comparing their components is useful too. It is all a matter of what are your requirements.
    Is it slower than comparing object hash codes so they aren't using it instead?
    Just GET it OFF out my mind!!

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    What are you talking about? I don't know about Ruby, but neither .Net nor Java "compare structures by its hash code". For one, Java doesn't even have structures. For another, the default equals()/Equals() compares references, so unless you override the method with your specific method of comparison (which depends heavily on context, but will probably be element-wise recursive comparison for value types), object identity is what you get.

    Same for hash code computation. The default hashCode()/whatever it's called in .Net uses the reference value with perhaps a simple bit shuffling for better distribution, so hashing happens based on object identity.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    What are you talking about? I don't know about Ruby, but neither .Net nor Java "compare structures by its hash code". For one, Java doesn't even have structures.
    A class is a structure called schema and it can contains data.
    Just GET it OFF out my mind!!

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,312
    Quote Originally Posted by audinue
    Is it slower than comparing object hash codes so they aren't using it instead?
    Who are "they"?

    Quote Originally Posted by audinue
    A class is a structure called schema and it can contains data.
    That does not really make sense to me, but then I do not know Ruby either. I took your use of "structure" to mean any kind of data structure, and in that sense I regard CornedBee's objection as being too pedantic concerning jargon.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    True, that was unnecessarily pedantic. But then, C# does make a big difference between structures and classes (value types and ref types in CLR jargon), and Java doesn't have structures in the C# sense.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating Linked List Using Hashing and Stack
    By m0ntana in forum C Programming
    Replies: 2
    Last Post: 04-07-2007, 08:11 AM
  2. Hashing, indexing and phonetic normalization for approximate str matching...
    By biterman in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 11-21-2006, 09:42 AM
  3. Replies: 8
    Last Post: 09-11-2006, 12:26 PM
  4. Doubt about Hashing
    By louis_mine in forum C Programming
    Replies: 1
    Last Post: 11-11-2005, 12:00 AM
  5. Double Hashing
    By carrja99 in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2003, 08:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21