hyperloglog-0.4.0.3: An approximate streaming (constant space) unique object counter

Copyright(c) Edward Kmett 2013-2015
LicenseBSD3
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell98

Data.HyperLogLog

Contents

Description

Synopsis

HyperLogLog

data HyperLogLog p Source

Initialize a new counter:

>>> runHyperLogLog (mempty :: HyperLogLog 3) == V.fromList [0,0,0,0,0,0,0,0]
True

Please note how you specify a counter size with the n invocation. Sizes of up to 16 are valid, with 7 being a likely good minimum for decent accuracy.

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 = 9, _hi = 17}

Note how insert can be used to add new observations to the approximate counter.

class HasHyperLogLog a p | a -> p where Source

Instances

size :: Reifies p Integer => HyperLogLog p -> Approximate Int64 Source

Approximate size of our set

insertHash :: Reifies s Integer => Word32 -> HyperLogLog s -> HyperLogLog s Source

Insert a value that has already been hashed by whatever user defined hash function you want.

coerceConfig :: forall p q. (Reifies p Integer, Reifies q Integer) => Maybe (Coercion (HyperLogLog p) (HyperLogLog q)) Source

If two types p and q reify the same configuration, then we can coerce between HyperLogLog p and HyperLogLog q. We do this by building a hole in the nominal role for the configuration parameter.