packages feed

murmur-hash 0.1.0.2 → 0.1.0.4

raw patch · 3 files changed

+39/−16 lines, 3 filesdep +bytestringdep ~basePVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependencies added: bytestring

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Data.Digest.Murmur32: instance Hashable32 ByteString
+ Data.Digest.Murmur64: instance Hashable64 ByteString

Files

Data/Digest/Murmur32.hs view
@@ -10,9 +10,9 @@  Type class and primitives for constructing 32 bit hashes using the MurmurHash2 algorithm.  See <http://murmurhash.googlepages.com> for-details on MurmurHash2.                                             +details on MurmurHash2. -}-module Data.Digest.Murmur32 +module Data.Digest.Murmur32   ( Hash32, asWord32,     Hashable32(..),     hash32AddWord32, hash32AddInt, hash32, hash32WithSeed@@ -22,6 +22,8 @@ import Data.Word import Numeric ( showHex ) import Data.Bits+import qualified Data.ByteString as B+import qualified Data.ByteString.Lazy as L import Data.Char ( ord ) import Data.Foldable import Data.List ( unfoldr )@@ -37,7 +39,7 @@ asWord32 :: Hash32 -> Word32 asWord32 (Hash32 w) = w --- | Instance for +-- | Instance for class Hashable32 a where   hash32Add :: a -> Hash32 -> Hash32 @@ -57,7 +59,7 @@   in Hash32 h2  hash32AddInt :: Int -> Hash32 -> Hash32-hash32AddInt !k0 +hash32AddInt !k0   | bitSize (undefined :: Int) <= 32     -- Int is 32 bits     = hash32AddWord32 (fromIntegral k0)   | otherwise                            -- Int is 64 bits@@ -81,7 +83,7 @@ hash32 = hash32WithSeed defaultSeed  -- | Combine two hash generators.  E.g.,--- +-- -- @ --   hashFoo (Foo a) = hash32AddInt 1 `combine` hash32Add a -- @@@ -134,7 +136,7 @@ -- Instances  instance Hashable32 Char where-  hash32Add c = hash32AddInt (ord c) +  hash32Add c = hash32AddInt (ord c)  instance Hashable32 Int where   hash32Add = hash32AddInt@@ -153,11 +155,11 @@    = hash32AddInt (fromIntegral i0)    | otherwise    -- Prefix by sign, then hash the raw data words, starting with LSB-   = hash32Add (signum i0 > 0) `combine` +   = hash32Add (signum i0 > 0) `combine`      hash32AddFoldable (unfoldr f (abs i0) :: [Word32])     where       f i | i == 0 = Nothing-      f i = +      f i =         let (i', a) = quotRem i maxWord in         Just (fromIntegral a, i')       maxWord = fromIntegral (maxBound :: Word32) + 1 :: Integer@@ -191,3 +193,10 @@     hash32Add a `combine` hash32Add b `combine`     hash32Add c `combine` hash32Add d +instance Hashable32 B.ByteString where+  hash32Add = B.foldl go (hash32AddWord32 8)+    where go acc b = acc `combine` hash32AddWord32 (fromIntegral b)++instance Hashable32 L.ByteString where+  hash32Add = L.foldl go (hash32AddWord32 9)+    where go acc b = acc `combine` hash32AddWord32 (fromIntegral b)
Data/Digest/Murmur64.hs view
@@ -10,9 +10,9 @@  Type class and primitives for constructing 64 bit hashes using the MurmurHash2 algorithm.  See <http://murmurhash.googlepages.com> for-details on MurmurHash2.                                             +details on MurmurHash2. -}-module Data.Digest.Murmur64 +module Data.Digest.Murmur64   ( Hash64, asWord64,     Hashable64(..),     hash64AddWord64, hash64AddInt, hash64, hash64WithSeed, combine,@@ -22,6 +22,8 @@ import Data.Word import Numeric ( showHex ) import Data.Bits+import qualified Data.ByteString as B+import qualified Data.ByteString.Lazy as L import Data.Char ( ord ) import Data.Foldable import Data.List ( unfoldr )@@ -76,7 +78,7 @@ hash64 = hash64WithSeed defaultSeed  -- | Combine two hash generators.  E.g.,--- +-- -- @ --   hashFoo (Foo a) = hash64AddInt 1 `combine` hash64Add a -- @@@ -129,7 +131,7 @@ -- Instances  instance Hashable64 Char where-  hash64Add c = hash64AddInt (ord c) +  hash64Add c = hash64AddInt (ord c)  instance Hashable64 Int where   hash64Add = hash64AddInt@@ -148,11 +150,11 @@    = hash64AddInt (fromIntegral i0)    | otherwise    -- Prefix by sign, then hash the raw data words, starting with LSB-   = hash64Add (signum i0 > 0) `combine` +   = hash64Add (signum i0 > 0) `combine`      hash64AddFoldable (unfoldr f (abs i0) :: [Word64])     where       f i | i == 0 = Nothing-      f i = +      f i =         let (i', a) = quotRem i maxWord in         Just (fromIntegral a, i')       maxWord = fromIntegral (maxBound :: Word64) + 1 :: Integer@@ -186,3 +188,10 @@     hash64Add a `combine` hash64Add b `combine`     hash64Add c `combine` hash64Add d +instance Hashable64 B.ByteString where+  hash64Add = B.foldl go (hash64AddWord64 8)+    where go acc b = acc `combine` hash64AddWord64 (fromIntegral b)++instance Hashable64 L.ByteString where+  hash64Add = L.foldl go (hash64AddWord64 9)+    where go acc b = acc `combine` hash64AddWord64 (fromIntegral b)
murmur-hash.cabal view
@@ -1,5 +1,5 @@ Name:            murmur-hash-Version:         0.1.0.2+Version:         0.1.0.4 License:         BSD3 License-File:    LICENSE Author:          Thomas Schilling@@ -21,8 +21,13 @@  Library   Build-Depends:-    base          >= 3.0 && < 4.4+    base          >= 3.0 && < 4.5,+    bytestring    == 0.9.*    exposed-modules:     Data.Digest.Murmur32     Data.Digest.Murmur64++Source-repository head+  Type:       git+  Location:   git://github.com/nominolo/murmur-hash.git