Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: hashCode

Reply
Thread Tools

Re: hashCode

 
 
Arne Vajh°j
Guest
Posts: n/a
 
      08-13-2012
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 <(E-Mail Removed)>

On 8/11/2012 7:54 AM, Roedy Green wrote:
> On Fri, 10 Aug 2012 12:45:07 -0700 (PDT), Lew <(E-Mail Removed)>
> 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/3
-+- 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/3
-+- 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/3
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hashcode of primitive types Dimitri Pissarenko Java 5 01-29-2004 11:05 PM
Improving hashCode() to match equals() Marco Java 10 01-17-2004 09:55 PM
Designing hashCode() methods kelvSYC Java 1 12-24-2003 02:56 AM
equals and hashCode Gregory A. Swarthout Java 2 12-20-2003 12:34 AM
hashCode for byte[] Roedy Green Java 1 08-22-2003 02:08 AM



Advertisments