Re: hashCode

Discussion in 'Java' started by Arne Vajhøj, Aug 13, 2012.

  1. Arne Vajhøj

    Arne Vajhøj Guest

    To: Roedy Green
    From: "Arne Vajhoj" <arne.vajhoj@1:261/38.remove-m2z-this>

    To: Roedy Green
    From: Arne Vajhoj <>

    On 8/11/2012 7:54 AM, Roedy Green wrote:
    > On Fri, 10 Aug 2012 12:45:07 -0700 (PDT), Lew <>
    > wrote, quoted or indirectly quoted someone who said :
    >
    >> h =3D 31 * h + attribute.hashCode();
    >> }

    > In my essay I recommend XOR which is an inherentely faster operation
    > than multiply. I wonder which actually works out better.


    Multiply.

    XOR has several problems:
    - many small values give small result
    - same values in different fields give same result
    - two identical values give result zero
    + all those I did not think of.

    > If you had a
    > large number of fields, the multiply effect could fall off the left
    > hand end. It is the algorithm used for String which could have very
    > long strings, so Sun must have thought of that.


    The multiply effect does not fall off the left with a value like 31 (it would
    with 32).

    Arne

    -+- BBBS/Li6 v4.10 Dada-1
    + Origin: Prism bbs (1:261/38)
    -+- Synchronet 3.16a-Win32 NewsLink 1.98
    Time Warp of the Future BBS - telnet://time.synchro.net:24

    --- BBBS/Li6 v4.10 Dada-1
    * Origin: Prism bbs (1:261/38)
    --- Synchronet 3.16a-Win32 NewsLink 1.98
    Time Warp of the Future BBS - telnet://time.synchro.net:24
    Arne Vajhøj, Aug 13, 2012
    #1
    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. Roedy Green

    hashCode for byte[]

    Roedy Green, Aug 22, 2003, in forum: Java
    Replies:
    1
    Views:
    413
    Dale King
    Aug 22, 2003
  2. Marco
    Replies:
    10
    Views:
    756
  3. Gregory A. Swarthout

    equals and hashCode

    Gregory A. Swarthout, Dec 19, 2003, in forum: Java
    Replies:
    2
    Views:
    341
    Silvio Bierman
    Dec 20, 2003
  4. kelvSYC

    Designing hashCode() methods

    kelvSYC, Dec 23, 2003, in forum: Java
    Replies:
    1
    Views:
    360
    Ulrich Stern
    Dec 24, 2003
  5. Dimitri Pissarenko

    Hashcode of primitive types

    Dimitri Pissarenko, Jan 29, 2004, in forum: Java
    Replies:
    5
    Views:
    5,814
    Hylander
    Jan 29, 2004
Loading...

Share This Page