HashCodes and HashMaps

Discussion in 'Java' started by Roedy Green, Sep 20, 2005.

  1. Roedy Green

    Roedy Green Guest

    Think about the HashMap inside serialisation writes. It has to keep
    track of which objects it has already put into the stream and the
    offset where it put them.

    You would think it would work with a simple HashMap using the objects
    themselves as keys and an Integer or Long offset object.

    But the catch is the objects may have equals methods that are not
    equivalent to == anymore. That equals could conflate objects that
    were different.

    I suppose there are two ways it could be implemented -- cannibalise
    the code from HashMap using == instead of equals, or using little
    pointer objects that point to the object and whose equals method
    compares references.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 20, 2005
    #1
    1. Advertising

  2. Roedy Green

    Murray Guest

    "Roedy Green" <> wrote in message
    news:...
    > Think about the HashMap inside serialisation writes. It has to keep
    > track of which objects it has already put into the stream and the
    > offset where it put them.
    >
    > You would think it would work with a simple HashMap using the objects
    > themselves as keys and an Integer or Long offset object.
    >
    > But the catch is the objects may have equals methods that are not
    > equivalent to == anymore. That equals could conflate objects that
    > were different.
    >
    > I suppose there are two ways it could be implemented -- cannibalise
    > the code from HashMap using == instead of equals, or using little
    > pointer objects that point to the object and whose equals method
    > compares references.
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Again taking new Java programming contracts.


    Would IdentityHashMap do the job?
    Murray, Sep 20, 2005
    #2
    1. Advertising

  3. Roedy Green

    Roedy Green Guest

    On Tue, 20 Sep 2005 20:30:38 +1000, "Murray"
    <> wrote or quoted :

    >Would IdentityHashMap do the job?


    That looks exactly like my hypothetical cannibalised HashMap
    It would also use the original Object.hashCode, not the overridden
    one, with System.identityHashCode(Object x)
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 20, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maps and Hashmaps

    , May 25, 2004, in forum: Java
    Replies:
    2
    Views:
    2,424
    jAnO!
    May 25, 2004
  2. Marilyn Hart

    Help on Hashmaps

    Marilyn Hart, Jan 22, 2005, in forum: Java
    Replies:
    5
    Views:
    589
    Bjorn Abelli
    Jan 23, 2005
  3. Siam
    Replies:
    4
    Views:
    1,151
    Eric Sosman
    Dec 30, 2006
  4. Replies:
    5
    Views:
    408
  5. Replies:
    1
    Views:
    469
    Tom Hawtin
    Mar 11, 2007
Loading...

Share This Page