Re: Hash support for arrays

Поиск
Список
Период
Сортировка
От hernan gonzalez
Тема Re: Hash support for arrays
Дата
Msg-id AANLkTimurNWF2Wq_g0G2jiceZjdT_Y5-Qk=qZwCNfPDm@mail.gmail.com
обсуждение исходный текст
Ответ на Hash support for arrays  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Hiroshi Inoue
Дата:
Сообщение: Re: Complier warnings on mingw gcc 4.5.0
Следующее
От: Alex Hunsaker
Дата:
Сообщение: Re: why does plperl cache functions using just a bool for is_trigger