From: Simon Marlow Date: Thu, 15 Feb 2007 09:43:04 +0000 (+0000) Subject: fix for hashString, from Jan-Willem Maessen (see #1137) X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=49d9807b876a0d4debaa0c23a9dcebefe5372069;p=ghc-base.git fix for hashString, from Jan-Willem Maessen (see #1137) --- diff --git a/Data/HashTable.hs b/Data/HashTable.hs index 8ea7909..0cee737 100644 --- a/Data/HashTable.hs +++ b/Data/HashTable.hs @@ -207,14 +207,14 @@ mulHi a b = fromIntegral (r `shiftR` 32) -- golden ratio and adding. The implementation is: -- -- > hashString = foldl' f 0 --- > where f m c = fromIntegral (ord c) + mulHi m golden --- +-- > 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. hashString :: String -> Int32 hashString = foldl' f 0 - where f m c = fromIntegral (ord c) + mulHi m golden + where f m c = fromIntegral (ord c + 1) * golden + mulHi m golden -- | A prime larger than the maximum hash table size prime :: Int32