PerfectHash 0.1.2 → 0.1.3
raw patch · 4 files changed
+1/−120 lines, 4 filesdep −HUnitdep −QuickCheckdep −bytestring-triePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: HUnit, QuickCheck, bytestring-trie
API changes (from Hackage documentation)
- Data.PerfectHash: fromList :: (Show a) => [(ByteString, a)] -> PerfectHash a
+ Data.PerfectHash: fromList :: Show a => [(ByteString, a)] -> PerfectHash a
- HackedMicrobench: microbench :: (Microbenchable a) => String -> a -> IO ()
+ HackedMicrobench: microbench :: Microbenchable a => String -> a -> IO ()
Files
- PerfectHash.cabal +1/−25
- benchmark.hs +0/−22
- benchmark_trie.hs +0/−24
- t/00_correctness.hs +0/−49
PerfectHash.cabal view
@@ -1,5 +1,5 @@ Name: PerfectHash-Version: 0.1.2+Version: 0.1.3 Cabal-Version: >= 1.2 License: BSD3 License-File: LICENSE@@ -25,28 +25,4 @@ extra-libraries: cmph build-depends: base, haskell98, containers, bytestring, digest,array, time, binary -Executable benchmark- Executable: benchmark- Main-Is: benchmark.hs- extra-lib-dirs: /usr/local/lib/- extra-libraries: cmph- c-sources: stub.c- includes: stub.h -Executable benchmark_trie- Executable: benchmark_trie- Main-Is: benchmark_trie.hs- extra-lib-dirs: /usr/local/lib/- extra-libraries: cmph- c-sources: stub.c- includes: stub.h- build-depends: bytestring-trie--Executable test- Executable: test- Main-Is: t/00_correctness.hs- extra-lib-dirs: /usr/local/lib/- extra-libraries: cmph- c-sources: stub.c- includes: stub.h- build-depends: QuickCheck, HUnit
− benchmark.hs
@@ -1,22 +0,0 @@--{-# LANGUAGE ScopedTypeVariables #-}--import Random-import HackedMicrobench -- small bugfix - use Integer rather than Int. original author unavailable for reports-import Control.Exception-import Data.List as List-import Data.PerfectHash as PerfectHash-import Maybe-import qualified Data.ByteString.Char8 as S---perfect_lookup :: PerfectHash Integer -> [S.ByteString] -> Integer -> Integer-perfect_lookup m words size = sum $ mapMaybe (PerfectHash.lookup m) targets- where targets :: [S.ByteString] = genericTake size $ cycle words--main = do- str <- S.readFile "/usr/share/dict/words"- words <- evaluate $ S.lines str- source :: [(S.ByteString, Integer)] <- evaluate $ zip words [1..]- perfect <- evaluate $ PerfectHash.fromList source- {-# SCC "mb_lookup" #-} microbench "perfect lookup" (perfect_lookup perfect words)
− benchmark_trie.hs
@@ -1,24 +0,0 @@--{-# LANGUAGE ScopedTypeVariables #-}--import Random-import HackedMicrobench -- small bugfix - use Integer rather than Int. original author unavailable for reports-import Control.Exception-import Data.List as List-import Data.Trie as Trie-import Maybe-import qualified Data.ByteString.Char8 as S---trie_lookup :: Trie.Trie Integer -> [S.ByteString] -> Integer -> Integer-trie_lookup m words size = sum $ mapMaybe (tl m) targets- where targets :: [S.ByteString] = genericTake size $ cycle words--tl string trie = {-# SCC "trie" #-} Trie.lookup trie string--main = do- str <- S.readFile "/usr/share/dict/words"- words <- evaluate $ S.lines str- source :: [(S.ByteString, Integer)] <- evaluate $ zip words [1..]- trie <- evaluate $ Trie.fromList source- {-# SCC "mb_lookup" #-} microbench "trie lookup" (trie_lookup trie words)
− t/00_correctness.hs
@@ -1,49 +0,0 @@-{-# LANGUAGE ScopedTypeVariables, FlexibleInstances, IncoherentInstances, OverlappingInstances #-}--import qualified Data.ByteString.Char8 as S-import qualified Data.Map as Map-import qualified Data.PerfectHash as PerfectHash-import Debug.Trace-import Test.HUnit-import List -import Maybe-import Test.QuickCheck---newtype Blub = Blub ([S.ByteString],[S.ByteString])- deriving (Show, Read)--newtype Bar = Bar [S.ByteString]- deriving (Show, Read)----- would be nice to have a reasonable way of generating random strings, then i could --- move this to quickcheck and get rid of the dependence on /usr/share/dict/words--halves :: [a] -> ([a], [a])-halves ls = List.splitAt ((length ls) `div` 2) ls--big_test ws = TestList [TestLabel "Successful lookup" $ TestList successTests, - TestLabel "Faithful report of absence" $ TestList absenceTests]- where hash = PerfectHash.fromList al- datamap = Map.fromList al- al = zip source [0..]- (source, orphans) = halves $ sortedNub ws- absenceTests = map (\w -> TestCase $- assertEqual "shouldn't find it"- (PerfectHash.lookup hash w)- Nothing- ) orphans- successTests = map (\w -> TestCase $- assertEqual "should find it: same result as Data.Map"- (Map.lookup w datamap )- (PerfectHash.lookup hash w)-- ) source- -sortedNub xs = map head $ group $ sort xs--main = do- l <- S.readFile "/usr/share/dict/words";- runTestTT (big_test $ take 10000 $ S.lines l)-