packages feed

murmur3 1.0.0 → 1.0.1

raw patch · 2 files changed

+34/−41 lines, 2 filesdep +cerealdep −binaryPVP ok

version bump matches the API change (PVP)

Dependencies added: cereal

Dependencies removed: binary

API changes (from Hackage documentation)

Files

Data/Hash/Murmur.hs view
@@ -1,13 +1,11 @@+{-# LANGUAGE BangPatterns #-}+ module Data.Hash.Murmur (murmur3) where  import Control.Monad (replicateM )-import Data.Binary -    ( Binary-    , Word32 -    )-import Data.Binary.Get -    ( Get-    , runGet++import Data.Serialize.Get +    ( runGet     , getWord32le     ) import Data.Bits @@ -22,8 +20,8 @@     , append     , replicate     )-import qualified Data.ByteString.Lazy as BL-    ( fromStrict )+import Data.List (foldl')+import Data.Word (Word32)  -- | MurmurHash3 (x86_32). For more details, see -- <http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp>@@ -34,40 +32,35 @@     h8   where     -- Block and tail sizes-    nBlocks = BS.length bs `div` 4-    nTail   = BS.length bs `mod` 4+    !nBlocks = BS.length bs `quot` 4+    !nTail   = BS.length bs `rem` 4     -- Data objects-    blocks  = runGet' (replicateM nBlocks getWord32le) bs+    Right blocks  = runGet (replicateM nBlocks getWord32le) bs     bsTail  = BS.drop (nBlocks*4) bs `BS.append` BS.replicate (4-nTail) 0     -- Body-    h1   = foldl mix nHashSeed blocks+    !h1   = foldl' mix nHashSeed blocks     -- Tail-    t1   = runGet' getWord32le bsTail-    t2   = t1 * c1-    t3   = t2 `rotateL` 15-    t4   = t3 * c2-    h2   = h1 `xor` t4+    Right !t1   = runGet getWord32le bsTail+    !t2   = t1 * c1+    !t3   = t2 `rotateL` 15+    !t4   = t3 * c2+    !h2   = h1 `xor` t4     -- Finalization-    h3   = h2 `xor` (fromIntegral $ BS.length bs)-    h4   = h3 `xor` (h3 `shiftR` 16) -    h5   = h4 * 0x85ebca6b-    h6   = h5 `xor` (h5 `shiftR` 13)-    h7   = h6 * 0xc2b2ae35-    h8   = h7 `xor` (h7 `shiftR` 16)+    !h3   = h2 `xor` fromIntegral (BS.length bs)+    !h4   = h3 `xor` (h3 `shiftR` 16) +    !h5   = h4 * 0x85ebca6b+    !h6   = h5 `xor` (h5 `shiftR` 13)+    !h7   = h6 * 0xc2b2ae35+    !h8   = h7 `xor` (h7 `shiftR` 16)     -- Mix function-    mix r1 k1 = r4+    mix !r1 !k1 = r4       where-        k2 = k1 * c1-        k3 = k2 `rotateL` 15-        k4 = k3 * c2-        r2 = r1 `xor` k4-        r3 = r2 `rotateL` 13-        r4 = r3*5 + 0xe6546b64+        !k2 = k1 * c1+        !k3 = k2 `rotateL` 15+        !k4 = k3 * c2+        !r2 = r1 `xor` k4+        !r3 = r2 `rotateL` 13+        !r4 = r3*5 + 0xe6546b64     -- Constants     c1 = 0xcc9e2d51      c2 = 0x1b873593 ---- Strict version of @Data.Binary.runGet@-runGet' :: Binary a => Get a -> BS.ByteString -> a-runGet' m = (runGet m) . BL.fromStrict-
murmur3.cabal view
@@ -1,5 +1,5 @@ name:                  murmur3-version:               1.0.0+version:               1.0.1 synopsis:                   Pure Haskell implementation of the MurmurHash3 x86_32 algorithm. description:@@ -25,11 +25,11 @@ library     exposed-modules:   Data.Hash.Murmur -    build-depends: base                     >= 4.6          && < 5 -                 , bytestring                     >= 0.10       && < 0.11 -                 , binary                   >= 0.7          && < 0.8 +    build-depends: base                     >= 4.6        && < 5 +                 , bytestring               >= 0.10       && < 0.11 +                 , cereal                   >= 0.5.1      && < 0.5.2  -    ghc-options:       -Wall +    ghc-options: -Wall  test-suite test-murmur3     type:              exitcode-stdio-1.0