Ticket #1137: HashBug.hs

File HashBug.hs, 740 bytes (added by j.russell@…, 7 years ago)

Test case

Line 
1module Main 
2where
3
4import Data.Char
5import Data.HashTable
6import Data.Int (Int32)
7
8--old version (6.4.2) for comparison
9oldHashString :: String -> Int32
10oldHashString = fromIntegral . foldl f 0
11  where f m c = ord c + (m * 128) `rem` fromIntegral oldprime
12
13-- | A prime larger than the maximum hash table size
14oldprime :: Int32
15oldprime = 1500007
16
17
18strings :: [String]
19strings = strings' [] ['a'..'z']
20  where
21  strings' last [] = []
22  strings' last (c:cs) = let this = c : (take 1 last) ++ reverse (drop 1 last)
23                         in this:(strings' this cs)
24
25
26hashed :: [(Int32,String)]
27hashed = [(hashString s,s) | s <- strings]
28
29--for comparison
30oldhashed :: [(Int32,String)]
31oldhashed = [(oldHashString s,s) | s <- strings]
32
33
34
35
36