Data.HashTable.hashInt seems somewhat sub-optimal

Simon.Frankau at barclayscapital.com Simon.Frankau at barclayscapital.com
Thu Aug 16 12:06:53 EDT 2007


I tried submitting this bug through the tracker, but it seemed to give
me permissions errors - probably a firewall issue here. :( Apologies.
Anyway...

Prelude> Data.HashTable.hashInt 0
0
Prelude> Data.HashTable.hashInt 1
-1
Prelude> Data.HashTable.hashInt 2
-1
Prelude> Data.HashTable.hashInt 3
-2
Prelude> Data.HashTable.hashInt 4
-2
Prelude> Data.HashTable.hashInt 5
-2
Prelude> Data.HashTable.hashInt 6
-3
Prelude> Data.HashTable.hashInt 7
-3
Prelude> Data.HashTable.hashInt 8
-4
Prelude> Data.HashTable.hashInt 9
-4
Prelude> Data.HashTable.hashInt 10
-4
Prelude> Data.HashTable.hashInt 200
-77
Prelude> Data.HashTable.hashInt 201
-77
Prelude> Data.HashTable.hashInt 202
-78

I prefer to use hashing to decrease the likelihood of collisions, not
increase them. ;)

I think the original algorithm was quite possibly supposed to use the
bottom 32 bits of the result, although this means that changes in higher
bits of the input do not affect lower bits of the hash. It should
probably also use unsigned multiplication. Perhaps a better solution
would be to xor or add together the high and low 32 bits? (I'm not sure
as I haven't read the literature).

Simon Frankau (sgf at arbitrary.name)
------------------------------------------------------------------------
For important statutory and regulatory disclosures and more information about Barclays Capital, please visit our web site at http://www.barcap.com.

Internet communications are not secure and therefore the Barclays Group does not accept legal responsibility for the contents of this message.  Although the Barclays Group operates anti-virus programmes, it does not accept responsibility for any damage whatsoever that is caused by viruses being passed.  Any views or opinions presented are solely those of the author and do not necessarily represent those of the Barclays Group.  Replies to this email may be monitored by the Barclays Group for operational or business reasons.

Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group.
------------------------------------------------------------------------


More information about the Glasgow-haskell-bugs mailing list