packages feed

hyperloglog 0.2.3.3 → 0.3

raw patch · 3 files changed

+22/−5 lines, 3 filesdep +siphashdep ~lensPVP ok

version bump matches the API change (PVP)

Dependencies added: siphash

Dependency ranges changed: lens

API changes (from Hackage documentation)

- Data.HyperLogLog: insert :: (ReifiesConfig s, Hashable a) => a -> HyperLogLog s -> HyperLogLog s
+ Data.HyperLogLog: insert :: (ReifiesConfig s, Serial a) => a -> HyperLogLog s -> HyperLogLog s
- Data.HyperLogLog.Type: insert :: (ReifiesConfig s, Hashable a) => a -> HyperLogLog s -> HyperLogLog s
+ Data.HyperLogLog.Type: insert :: (ReifiesConfig s, Serial a) => a -> HyperLogLog s -> HyperLogLog s

Files

CHANGELOG.markdown view
@@ -1,3 +1,7 @@+0.3+---+* Switched to `SipHash`, so the package actually works.+ 0.2.3.2 ------- * More `#ifdef` bugfixes
hyperloglog.cabal view
@@ -1,6 +1,6 @@ name:          hyperloglog category:      Numeric-version:       0.2.3.3+version:       0.3 license:       BSD3 cabal-version: >= 1.8 license-file:  LICENSE@@ -66,6 +66,7 @@     semigroupoids             >= 4        && < 5,     semigroups                >= 0.8.4    && < 1,     safecopy                  >= 0.8.1    && < 0.9,+    siphash                   >= 1.0.3    && < 2,     tagged                    >= 0.4.5    && < 1,     vector                    >= 0.9      && < 0.11 
src/Data/HyperLogLog/Type.hs view
@@ -52,16 +52,19 @@ import           Control.Applicative import           Control.Lens import           Control.Monad+import           Crypto.MAC.SipHash import           Data.Approximate.Type import           Data.Bits import           Data.Bits.Extras-import           Data.Hashable+import           Data.Bytes.Put (runPutS)+import           Data.Bytes.Serial import           Data.HyperLogLog.Config import           Data.Proxy import           Data.Semigroup import           Data.Serialize import qualified Data.Vector.Unboxed                           as V import qualified Data.Vector.Unboxed.Mutable                   as MV+import           Data.Word import           Generics.Deriving                             hiding (D, to) import           GHC.Int @@ -90,7 +93,7 @@ -- Let's count a list of unique items and get the latest estimate: -- -- >>> size (foldr insert mempty [1..10] :: HyperLogLog $(4))--- Approximate {_confidence = 0.9972, _lo = 2, _estimate = 11, _hi = 20}+-- Approximate {_confidence = 0.9972, _lo = 2, _estimate = 9, _hi = 17} -- -- Note how 'insert' can be used to add new observations to the -- approximate counter.@@ -129,12 +132,21 @@   mappend = (<>)   {-# INLINE mappend #-} -insert :: (ReifiesConfig s, Hashable a) => a -> HyperLogLog s -> HyperLogLog s+sipKey :: SipKey+sipKey = SipKey 4 7++siphash :: (Serial a) => a -> Word64+siphash a = h+  where !bs = runPutS (serialize a)+        (SipHash !h) = hash sipKey bs+{-# INLINE siphash #-}++insert :: (ReifiesConfig s, Serial a) => a -> HyperLogLog s -> HyperLogLog s insert a m@(HyperLogLog v) = HyperLogLog $ V.modify (\x -> do     old <- MV.read x bk     when (rnk > old) $ MV.write x bk rnk   ) v where-  !h = w32 (hash a)+  !h = w32 (siphash a)   !bk = calcBucket m h   !rnk = calcRank m h {-# INLINE insert #-}