Re: Hash support for arrays - Mailing list pgsql-hackers

From hernan gonzalez
Subject Re: Hash support for arrays
Date
Msg-id AANLkTimurNWF2Wq_g0G2jiceZjdT_Y5-Qk=qZwCNfPDm@mail.gmail.com
Whole thread Raw
In response to Hash support for arrays  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
>Hmm.  I am reminded of Knuth's famous dictum: "never generate random
numbers with a method chosen at random".  Is there any actual theory
behind that algorithm, and if so what is it?  The combination of
shifting with addition (not xor) seems more likely to lead to weird
cancellations than any improvement in the hash behavior.

For what's worth: the standard way in Java is multiplying by 31.  Which 31 amounts to a 5 bit shift and a substraction. 
In general, a prime number is recommended though one would like that Knuth made some analysis here... it all seems mostly empirical.

Perhaps the 5 bit shift is related to the spread of ascii charpoints, as that hashcode() implementation was mainly tested and implemented for a String. But now it's also suggested for general objects, and it's even specified for standard collections: for example 
http://download.oracle.com/javase/6/docs/api/java/util/List.html#hashCode()


Hernán J. González

pgsql-hackers by date:

Previous
From: Hiroshi Inoue
Date:
Subject: Re: Complier warnings on mingw gcc 4.5.0
Next
From: Alex Hunsaker
Date:
Subject: Re: why does plperl cache functions using just a bool for is_trigger