X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FHashTable.hs;h=0cee737d924ac376ef3fc2e5d8f224177891da76;hb=48b5ddb3fc2d52d172230da3916e1b06bf36eafa;hp=8ea79099f0b37726efbb247c59103cdcfdaf8e7f;hpb=1a3710614eec1bba6f241f44e9bf84249d43b58d;p=ghc-base.git 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