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


Groups > comp.lang.java.programmer > #17803 > unrolled thread

Re: hashCode

Started by"Arne Vajhøj" <arne.vajhøj@1:261/38.remove-nlb-this>
First post2012-08-13 18:36 +0000
Last post2012-08-13 18:36 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.java.programmer


Contents

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

#17803 — Re: hashCode

From"Arne Vajhøj" <arne.vajhøj@1:261/38.remove-nlb-this>
Date2012-08-13 18:36 +0000
SubjectRe: hashCode
Message-ID<502943B2.56751.calajapr@time.synchro.net>
  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

[toc] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web