Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #17847

Re: hashCode

From "Arne Vajhøj" <arne.vajhøj@1:261/38.remove-odu-this>
Subject Re: hashCode
Message-ID <50294F02.56795.calajapr@time.synchro.net> (permalink)
Newsgroups comp.lang.java.programmer
Date 2012-08-13 19:38 +0000
Organization tds.net

Show all headers | View raw


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

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

  To: Roedy Green
From: Arne Vajhoj <arne@vajhoej.dk>

On 8/11/2012 7:54 AM, Roedy Green wrote:
> On Fri, 10 Aug 2012 12:45:07 -0700 (PDT), Lew <lewbloch@gmail.com>
> 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

--- 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

Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread


Thread

Re: hashCode "Arne Vajhøj" <arne.vajhøj@1:261/38.remove-odu-this> - 2012-08-13 19:38 +0000

csiph-web