perfect-hash-generator 0.2.0.4 → 0.2.0.5
raw patch · 6 files changed
+57/−52 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.PerfectHash.TestUtils: eitherExit :: Either String b -> IO ()
- Data.PerfectHash.TestUtils: testLookups :: (Show b, Eq b, Show a, ToHashableChunks a, Unbox b) => LookupTable b -> [(a, b)] -> Either String ()
- Data.PerfectHash.TestUtils: wordsFromFile :: FilePath -> IO [(String, Int)]
Files
- demo/ints/Main.hs +1/−1
- demo/strings/Main.hs +1/−1
- perfect-hash-generator.cabal +8/−3
- src/Data/PerfectHash/TestUtils.hs +0/−46
- test-utils/Exercise.hs +46/−0
- test/Main.hs +1/−1
demo/ints/Main.hs view
@@ -6,8 +6,8 @@ import qualified Data.IntSet as IntSet import qualified Data.PerfectHash.Construction as Construction import qualified Data.PerfectHash.Lookup as Lookup-import qualified Data.PerfectHash.TestUtils as Exercise import qualified Data.Vector.Unboxed as Vector+import qualified Exercise valueCount = 250000
demo/strings/Main.hs view
@@ -4,7 +4,7 @@ import qualified Data.PerfectHash.Construction as Construction import qualified Data.PerfectHash.Lookup as Lookup-import qualified Data.PerfectHash.TestUtils as Exercise+import qualified Exercise enableDebug = False
perfect-hash-generator.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 3429fd1131c7e55998ad9391be6e8af0010ce07ec53e20ea840551bc47a942ac+-- hash: df669bc3ba741914da19be7e67c73565365e07ef3a7f13c93f2d9c51330f48bb name: perfect-hash-generator-version: 0.2.0.4+version: 0.2.0.5 synopsis: Perfect minimal hashing implementation in native Haskell description: A <https://en.wikipedia.org/wiki/Perfect_hash_function perfect hash function> for a set @S@ is a hash function that maps distinct elements in @S@ to a set of integers, with __no collisions__. A <https://en.wikipedia.org/wiki/Perfect_hash_function#Minimal_perfect_hash_function minimal perfect hash function> is a perfect hash function that maps @n@ keys to @n@ __consecutive__ integers, e.g. the numbers from @0@ to @n-1@. .@@ -70,7 +70,6 @@ Data.PerfectHash.Construction Data.PerfectHash.Hashing Data.PerfectHash.Lookup- Data.PerfectHash.TestUtils other-modules: Paths_perfect_hash_generator default-language: Haskell2010@@ -79,6 +78,7 @@ main-is: Main.hs hs-source-dirs: demo/ints+ test-utils ghc-options: -fwarn-tabs -W build-depends: base >=4.5 && <5@@ -93,6 +93,7 @@ , unordered-containers , vector other-modules:+ Exercise Paths_perfect_hash_generator default-language: Haskell2010 @@ -100,6 +101,7 @@ main-is: Main.hs hs-source-dirs: demo/strings+ test-utils ghc-options: -fwarn-tabs -W build-depends: base >=4.5 && <5@@ -113,6 +115,7 @@ , unordered-containers , vector other-modules:+ Exercise Paths_perfect_hash_generator default-language: Haskell2010 @@ -121,6 +124,7 @@ main-is: Main.hs hs-source-dirs: test+ test-utils ghc-options: -fwarn-tabs -W build-depends: HUnit@@ -136,5 +140,6 @@ , unordered-containers , vector other-modules:+ Exercise Paths_perfect_hash_generator default-language: Haskell2010
− src/Data/PerfectHash/TestUtils.hs
@@ -1,46 +0,0 @@--- | This module is not used by the main library for constructing perfect hashes;--- it just provides convenience functions for use by the tests and demonstration executables.-module Data.PerfectHash.TestUtils where--import Control.Monad (unless)-import Data.Foldable (traverse_)-import qualified Data.Vector.Unboxed as Vector--import qualified Data.PerfectHash.Hashing as Hashing-import qualified Data.PerfectHash.Lookup as Lookup---testLookups :: (Show b, Eq b, Show a, Hashing.ToHashableChunks a, Vector.Unbox b) =>- Lookup.LookupTable b- -> [(a, b)]- -> Either String ()-testLookups lookup_table =- traverse_ check_entry- where- check_entry (word, source_index) = unless (lookup_result == source_index) $- Left $ unwords [- "Result for key"- , show word- , "had incorrect index"- , show lookup_result- , "; should have been"- , show source_index- ]- where- lookup_result = Lookup.lookupPerfect lookup_table word----- | Generate a map of words from a file to their line numbers.------ Intended for use with @\"/usr/share/dict/words\"@.-wordsFromFile :: FilePath -> IO [(String, Int)]-wordsFromFile path = do- file_lines <- readFile path- let word_index_tuples = zip (lines file_lines) [1..]- return word_index_tuples---eitherExit :: Either String b -> IO ()-eitherExit x = case x of- Left err -> error err- Right _ -> return ()
+ test-utils/Exercise.hs view
@@ -0,0 +1,46 @@+-- | This module is not used by the main library for constructing perfect hashes;+-- it just provides convenience functions for use by the tests and demonstration executables.+module Exercise where++import Control.Monad (unless)+import Data.Foldable (traverse_)+import qualified Data.Vector.Unboxed as Vector++import qualified Data.PerfectHash.Hashing as Hashing+import qualified Data.PerfectHash.Lookup as Lookup+++testLookups :: (Show b, Eq b, Show a, Hashing.ToHashableChunks a, Vector.Unbox b) =>+ Lookup.LookupTable b+ -> [(a, b)]+ -> Either String ()+testLookups lookup_table =+ traverse_ check_entry+ where+ check_entry (word, source_index) = unless (lookup_result == source_index) $+ Left $ unwords [+ "Result for key"+ , show word+ , "had incorrect index"+ , show lookup_result+ , "; should have been"+ , show source_index+ ]+ where+ lookup_result = Lookup.lookupPerfect lookup_table word+++-- | Generate a map of words from a file to their line numbers.+--+-- Intended for use with @\"/usr/share/dict/words\"@.+wordsFromFile :: FilePath -> IO [(String, Int)]+wordsFromFile path = do+ file_lines <- readFile path+ let word_index_tuples = zip (lines file_lines) [1..]+ return word_index_tuples+++eitherExit :: Either String b -> IO ()+eitherExit x = case x of+ Left err -> error err+ Right _ -> return ()
test/Main.hs view
@@ -12,7 +12,7 @@ import qualified Data.PerfectHash.Construction as Construction import qualified Data.PerfectHash.Hashing as Hashing-import qualified Data.PerfectHash.TestUtils as Exercise+import qualified Exercise testHashComputation :: (Hashing.ToHashableChunks a, Show a) =>