packages feed

hyperloglog 0.1 → 0.2

raw patch · 3 files changed

+21/−22 lines, 3 filesdep ~approximatedep ~comonaddep ~lens

Dependency ranges changed: approximate, comonad, lens, semigroupoids

Files

CHANGELOG.markdown view
@@ -1,3 +1,7 @@+0.2+---+* Made compatible with `lens` 4+ 0.1 --- * Ported `Data.Analytics.Approximate.HyperLogLog` from [analytics](http://github.com/analytics) into a separate package.
hyperloglog.cabal view
@@ -1,6 +1,6 @@ name:          hyperloglog category:      Numeric-version:       0.1+version:       0.2 license:       BSD3 cabal-version: >= 1.8 license-file:  LICENSE@@ -48,22 +48,22 @@  library   build-depends:-    approximate               >= 0.1      && < 1,+    approximate               >= 0.2.1    && < 1,     base                      >= 4.3      && < 5,     binary                    >= 0.5      && < 0.8,     bits                      >= 0.2      && < 1,     bytes                     >= 0.7      && < 1,     cereal                    >= 0.3.5    && < 0.4,     cereal-vector             >= 0.2      && < 0.3,-    comonad                   >= 3        && < 4,+    comonad                   >= 4        && < 5,     deepseq                   >= 1.3      && < 1.5,     distributive              >= 0.3      && < 1,     generic-deriving          >= 1.4      && < 1.6,     hashable                  >= 1.1.2.3  && < 1.3,     hashable-extras           >= 0.1      && < 1,-    lens                      >= 3.9      && < 4,+    lens                      >= 4        && < 5,     reflection                >= 1.3      && < 2,-    semigroupoids             >= 3.0.2    && < 4,+    semigroupoids             >= 4        && < 5,     semigroups                >= 0.8.4    && < 1,     safecopy                  >= 0.8.1    && < 0.9,     tagged                    >= 0.4.5    && < 1,
src/Data/HyperLogLog/Type.hs view
@@ -37,6 +37,7 @@     HyperLogLog(..)   , HasHyperLogLog(..)   , size+  , insert   , intersectionSize   , cast   ) where@@ -81,10 +82,10 @@ -- -- Let's count a list of unique items and get the latest estimate: ----- >>> size (foldr cons mempty [1..10] :: HyperLogLog $(4))+-- >>> size (foldr insert mempty [1..10] :: HyperLogLog $(4)) -- Approximate {_confidence = 0.9972, _lo = 2, _estimate = 11, _hi = 20} ----- Note how 'cons' can be used to add new observations to the+-- Note how 'insert' can be used to add new observations to the -- approximate counter. newtype HyperLogLog p = HyperLogLog { runHyperLogLog :: V.Vector Rank }     deriving (Eq, Show, Generic)@@ -113,21 +114,15 @@   mappend = (<>)   {-# INLINE mappend #-} -instance (Profunctor p, Bifunctor p, Functor f, ReifiesConfig s, Hashable a, s ~ t, a ~ b) => Cons p f (HyperLogLog s) (HyperLogLog t) a b where-  _Cons = unto go where-    go (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)-      !bk = calcBucket m h-      !rnk = calcRank m h-  {-# INLINE _Cons #-}--instance (Profunctor p, Bifunctor p, Functor f, ReifiesConfig s, Hashable a, s ~ t, a ~ b) => Snoc p f (HyperLogLog s) (HyperLogLog t) a b where-  _Snoc = unto go where-    go (m@(HyperLogLog v), a) = HyperLogLog $ V.modify (\x -> do old <- MV.read x bk; when (rnk > old) $ MV.write x bk rnk) v where-      !h = w32 (hash a)-      !bk = calcBucket m h-      !rnk = calcRank m h-  {-# INLINE _Snoc #-}+insert :: (ReifiesConfig s, Hashable 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)+  !bk = calcBucket m h+  !rnk = calcRank m h+{-# INLINE insert #-}  -- | Approximate size of our set size :: ReifiesConfig p => HyperLogLog p -> Approximate Int64