Dish 0.0.0.3 → 0.0.0.4
raw patch · 2 files changed
+46/−31 lines, 2 files
Files
- Dish.cabal +3/−1
- src/Data/Dish/Murmur3.hs +43/−30
Dish.cabal view
@@ -1,5 +1,5 @@ name: Dish-version: 0.0.0.3+version: 0.0.0.4 homepage: http://github.com/zcourts/Dish license: BSD3 license-file: LICENSE@@ -11,6 +11,8 @@ description: A group of Hash related utilities (currently wraps MurmurHash3 C implementation) synopsis: Hash modules (currently Murmur3) extra-source-files: cbits/murmur3.c, cbits/murmur3.h+stability: Stable+copyright: Courtney Robinson source-repository head type: git
src/Data/Dish/Murmur3.hs view
@@ -12,21 +12,21 @@ -- * Default/Direct Map -- $default murmur3,+ murmur3', -- * X86 32 bits -- $32 murmur3Int,+ murmur3Int', -- * X86 128 bits -- $x128 murmur3IntegerX86,+ murmur3IntegerX86', -- * X64 128 bits -- $64_128 murmur3IntegerX64,+ murmur3IntegerX64', -- * FFI murmur3Raw,- -- * Unsafe- unsafeMurmur3Int,- unsafeMurmur3IntegerX86,- unsafeMurmur3IntegerX64, -- * Murmur3 Hash Version MHV(..) ) where@@ -45,11 +45,17 @@ Simple, verbose interface for generating hashes -} -- | Base function, which allows you to choose which 'MHV' to use -murmur3 :: String -- ^ The string to be hashed- -> Int -- ^ A seed value for the hash function- -> MHV -- ^ Which Murmur Hash version to use 'X86_32', 'X86_128' or 'X64_128'+murmur3 :: String -- ^ The string to be hashed+ -> Int -- ^ A seed value for the hash function+ -> MHV -- ^ Which Murmur Hash version to use 'X86_32', 'X86_128' or 'X64_128'+ -> [Int] -- ^ returns 4, 32 bit ints, if 'X86_32' is used only the first has a value and the other 3 are 0+murmur3 v s ver = US.unsafePerformIO $ murmur3' v s ver++murmur3' :: String -- ^ The string to be hashed+ -> Int -- ^ A seed value for the hash function+ -> MHV -- ^ Which Murmur Hash version to use 'X86_32', 'X86_128' or 'X64_128' -> IO [Int] -- ^ returns 4, 32 bit ints, if 'X86_32' is used only the first has a value and the other 3 are 0-murmur3 v s ver = do m <- murmur3Raw v s ver; toArr m+murmur3' v s ver = do m <- murmur3Raw v s ver; toArr m where toArr :: [CUInt] -> IO [Int] toArr [] = return []@@ -62,41 +68,57 @@ {-$32 Generate 32 bit hash values -} +murmur3Int' :: String -- ^ The string to be hashed+ -> Int -- ^ A seed value for the hash function+ -> IO Int -- ^ 32 bit number generated from the string+murmur3Int' val seed = do v <- murmur3Raw val seed X86_32 + -- safe to use L.head, list is never empty even if all vals are 0+ return $ fromIntegral (L.head v)+ {- | has the lowest throughput, but also the lowest latency. If you're making a hash table that usually has small keys, this is probably the one you want to use on 32-bit machines. It has a 32-bit output. -} murmur3Int :: String -- ^ The string to be hashed -> Int -- ^ A seed value for the hash function- -> IO Int -- ^ 32 bit number generated from the string-murmur3Int val seed = do v <- murmur3Raw val seed X86_32; - -- safe to use L.head, list is never empty even if all vals are 0- return $ fromIntegral (L.head v)+ -> Int -- ^ 32 bit number generated from the string+murmur3Int val seed = US.unsafePerformIO $ murmur3Int' val seed + {-$x128 Generate 128 bit hash values, optimized for 32 bit systems -}+murmur3IntegerX86' :: String -- ^ The string to be hashed+ -> Int -- ^ A seed value for the hash function+ -> IO Integer -- ^ 128 bit number generated from the string+murmur3IntegerX86' val seed = x128 val seed X86_128+ {- | Generate a 128 bit hash from the given value, this function's implementation is optimized for 32 bit architectures but works on any. Has about 30% higher throughput than 'murmur3Int'. Be warned, though, that its latency for a single 16-byte key is about 86% longer! -}-murmur3IntegerX86 :: String -- ^ The string to be hashed- -> Int -- ^ A seed value for the hash function- -> IO Integer -- ^ 128 bit number generated from the string-murmur3IntegerX86 val seed = x128 val seed X86_128- +murmur3IntegerX86 :: String -- ^ The string to be hashed+ -> Int -- ^ A seed value for the hash function+ -> Integer -- ^ 128 bit number generated from the string+murmur3IntegerX86 val seed = US.unsafePerformIO $ murmur3IntegerX86' val seed+ {-$64_128 Generate 128 bit hash values, optimized for 64 bit systems -}+murmur3IntegerX64' :: String -- ^ The string to be hashed+ -> Int -- ^ A seed value for the hash function+ -> IO Integer -- ^ 128 bit number generated from the string+murmur3IntegerX64' val seed = x128 val seed X64_128+ {- | Generate a 128 bit hash from the given value, this function's implementation is optimized for x64 architectures but works on any. Its throughput is 250% higher than 'murmur3IntegerX86', but it has roughly the same latency. -}-murmur3IntegerX64 :: String -- ^ The string to be hashed- -> Int -- ^ A seed value for the hash function- -> IO Integer -- ^ 128 bit number generated from the string-murmur3IntegerX64 val seed = x128 val seed X64_128+murmur3IntegerX64 :: String -- ^ The string to be hashed+ -> Int -- ^ A seed value for the hash function+ -> Integer -- ^ 128 bit number generated from the string+murmur3IntegerX64 val seed = US.unsafePerformIO $ murmur3IntegerX64' val seed foreign import ccall "MurmurHash3_x86_32" c_x86_32 :: CString -> CInt -> CUInt -> Ptr CUInt -> IO ()@@ -126,15 +148,6 @@ doHash X86_32 v s se o = c_x86_32 v s se o doHash X86_128 v s se o = c_x86_128 v s se o doHash X64_128 v s se o = c_x64_128 v s se o--unsafeMurmur3Int :: String -> Int -> Int-unsafeMurmur3Int val seed = US.unsafePerformIO $ murmur3Int val seed--unsafeMurmur3IntegerX86 :: String -> Int -> Integer-unsafeMurmur3IntegerX86 val seed = US.unsafePerformIO $ murmur3IntegerX86 val seed--unsafeMurmur3IntegerX64 :: String -> Int -> Integer-unsafeMurmur3IntegerX64 val seed = US.unsafePerformIO $ murmur3IntegerX64 val seed x128 :: String -> Int -> MHV -> IO Integer x128 val seed ver= do