As pointed out in
http://www.haskell.org/pipermail/glasgow-haskell-bugs/2007-August/009545.html
the old behaviour was
Prelude Data.HashTable> map hashInt [0..10]
[0,-1,-1,-2,-2,-2,-3,-3,-4,-4,-4]
Fixed according to the "Fibonacci Hashing" algorithm described in
http://www.brpreiss.com/books/opus4/html/page213.html
http://www.brpreiss.com/books/opus4/html/page214.html
golden = -1640531527
-- | A sample (and useful) hash function for Int and Int32,
golden = -1640531527
-- | A sample (and useful) hash function for Int and Int32,
--- implemented by extracting the uppermost 32 bits of the 64-bit
+-- implemented by extracting the lowermost 32 bits of the
-- result of multiplying by a 32-bit constant. The constant is from
-- Knuth, derived from the golden ratio:
--
-- > golden = round ((sqrt 5 - 1) * 2^31) :: Int
hashInt :: Int -> Int32
-- result of multiplying by a 32-bit constant. The constant is from
-- Knuth, derived from the golden ratio:
--
-- > golden = round ((sqrt 5 - 1) * 2^31) :: Int
hashInt :: Int -> Int32
-hashInt x = mulHi (fromIntegral x) golden
+hashInt x = fromIntegral x * golden
-- hi 32 bits of a x-bit * 32 bit -> 64-bit multiply
mulHi :: Int32 -> Int32 -> Int32
-- hi 32 bits of a x-bit * 32 bit -> 64-bit multiply
mulHi :: Int32 -> Int32 -> Int32
--
-- > hashString = foldl' f 0
-- > where f m c = fromIntegral (fromEnum c + 1) * golden + mulHi m golden
--
-- > hashString = foldl' f 0
-- > where f m c = fromIntegral (fromEnum c + 1) * golden + mulHi m golden
-- Note that this has not been extensively tested for reasonability,
-- but Knuth argues that repeated multiplication by the golden ratio
-- will minimize gaps in the hash space.
-- Note that this has not been extensively tested for reasonability,
-- but Knuth argues that repeated multiplication by the golden ratio
-- will minimize gaps in the hash space.