From 49d9807b876a0d4debaa0c23a9dcebefe5372069 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Thu, 15 Feb 2007 09:43:04 +0000 Subject: [PATCH] fix for hashString, from Jan-Willem Maessen (see #1137) --- Data/HashTable.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 -- 1.7.10.4