perfect-hash-generator 0.1.0.0 → 0.1.0.1
raw patch · 4 files changed
+21/−11 lines, 4 files
Files
- demo/IntsDemo.hs +5/−4
- demo/StringsDemo.hs +3/−3
- perfect-hash-generator.cabal +9/−3
- src/Data/PerfectHash/Hashing.hs +4/−1
demo/IntsDemo.hs view
@@ -1,8 +1,11 @@+module IntsDemo where+ import System.Random (RandomGen, mkStdGen, randomR) import Data.IntSet (IntSet) import qualified Data.IntSet as IntSet import qualified Data.PerfectHash.Construction as Construction+import qualified Data.PerfectHash.Hashing as Hashing import qualified Data.PerfectHash.Lookup as Lookup import qualified Data.Vector.Unboxed as Vector import Exercise (Atom (Atom))@@ -11,8 +14,7 @@ valueCount = 500000 -upperBound = 2^32 - 1-randomRange = (0, upperBound)+randomRange = (0, Hashing.mask32bits) data RandIntAccum t = RandIntAccum@@ -66,5 +68,4 @@ , "lookup entries with direct mappings." ] - let test_result_either = Exercise.testLookups lookup_table intMapTuples- Exercise.eitherExit test_result_either+ Exercise.eitherExit $ Exercise.testLookups lookup_table intMapTuples
demo/StringsDemo.hs view
@@ -1,3 +1,5 @@+module StringsDemo where+ import Control.Monad (when) import qualified Data.PerfectHash.Construction as Construction@@ -28,6 +30,4 @@ putStrLn $ unwords ["Vector G:", show $ Lookup.nonces lookup_table] putStrLn $ unwords ["Vector V:", show $ Lookup.values lookup_table] -- let test_result_either = Exercise.testLookups lookup_table word_index_tuples- Exercise.eitherExit test_result_either+ Exercise.eitherExit $ Exercise.testLookups lookup_table word_index_tuples
perfect-hash-generator.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: perfect-hash-generator-version: 0.1.0.0+version: 0.1.0.1 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@. .@@ -38,12 +38,18 @@ = Caveats Only integer keys of at most __32-bits__ have been demonstrated to work properly. Since the hash function masks to 32 bits, colliding 64-bit integers can hang the lookup table construction. category: Data Structures, Embedded-author: Karl Ostmo-maintainer: kostmo@gmail.com+homepage: https://github.com/kostmo/perfect-hash-generator#readme+bug-reports: https://github.com/kostmo/perfect-hash-generator/issues+author: Karl Ostmo <kostmo@gmail.com>+maintainer: Karl Ostmo <kostmo@gmail.com> license: Apache-2.0 license-file: LICENSE build-type: Simple cabal-version: >= 1.10++source-repository head+ type: git+ location: https://github.com/kostmo/perfect-hash-generator library hs-source-dirs:
src/Data/PerfectHash/Hashing.hs view
@@ -13,6 +13,9 @@ primeFNV = 0x01000193 +mask32bits = 0xffffffff++ -- | A Foldable of any data type may be hashed, so long as it implements -- an instance of this class. class ToNumeric a where@@ -47,4 +50,4 @@ then primeFNV else nonce - combine acc = (.&. 0xffffffff) . (* primeFNV) . xor acc . toNum+ combine acc = (.&. mask32bits) . (* primeFNV) . xor acc . toNum