add System.Posix.Types to default nhc98 build
[haskell-directory.git] / Data / HashTable.hs
index ddbc24b..0cee737 100644 (file)
@@ -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
@@ -360,20 +360,20 @@ expandHashTable hash table@HT{ buckets=bkts, bmask=mask } = do
       then return table
       else do
    --
-   newbkts' <- newMutArray (0,newmask) []
+    newbkts' <- newMutArray (0,newmask) []
 
-   let
-    splitBucket oldindex = do
-      bucket <- readHTArray bkts oldindex
-      let (oldb,newb) =
+    let
+     splitBucket oldindex = do
+       bucket <- readHTArray bkts oldindex
+       let (oldb,newb) =
               partition ((oldindex==). bucketIndex newmask . hash . fst) bucket
-      writeMutArray newbkts' oldindex oldb
-      writeMutArray newbkts' (oldindex + oldsize) newb
-   mapM_ splitBucket [0..mask]
+       writeMutArray newbkts' oldindex oldb
+       writeMutArray newbkts' (oldindex + oldsize) newb
+    mapM_ splitBucket [0..mask]
 
-   newbkts <- freezeArray newbkts'
+    newbkts <- freezeArray newbkts'
 
-   return ( table{ buckets=newbkts, bmask=newmask } )
+    return ( table{ buckets=newbkts, bmask=newmask } )
 
 -- -----------------------------------------------------------------------------
 -- Deleting a mapping from the hash table