Copyright | (c) Edward Kmett 2013-2015 |
---|---|
License | BSD3 |
Maintainer | Edward Kmett <[email protected]> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Data.HyperLogLog
Contents
Description
See the original paper for details: http://algo.inria.fr/flajolet/Publications/FlFuGaMe07.pdf
Synopsis
- data HyperLogLog (p :: k)
- class HasHyperLogLog a (p :: k) | a -> p where
- hyperLogLog :: Lens' a (HyperLogLog p)
- size :: forall {k} (p :: k). Reifies p Integer => HyperLogLog p -> Approximate Int64
- intersectionSize :: forall {k} (p :: k). Reifies p Integer => [HyperLogLog p] -> Approximate Int64
- insert :: forall {k} (s :: k) a. (Reifies s Integer, Serial a) => a -> HyperLogLog s -> HyperLogLog s
- insertHash :: forall {k} (s :: k). Reifies s Integer => Word32 -> HyperLogLog s -> HyperLogLog s
- cast :: forall {k1} {k2} (p :: k1) (q :: k2). (Reifies p Integer, Reifies q Integer) => HyperLogLog p -> Maybe (HyperLogLog q)
- coerceConfig :: forall {k1} {k2} (p :: k1) (q :: k2). (Reifies p Integer, Reifies q Integer) => Maybe (Coercion (HyperLogLog p) (HyperLogLog q))
HyperLogLog
data HyperLogLog (p :: k) 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.
Instances
class HasHyperLogLog a (p :: k) | a -> p where Source #
Methods
hyperLogLog :: Lens' a (HyperLogLog p) Source #
Instances
HasHyperLogLog (HyperLogLog p) (p :: k) Source # | |
Defined in Data.HyperLogLog.Type Methods hyperLogLog :: Lens' (HyperLogLog p) (HyperLogLog p) Source # |
size :: forall {k} (p :: k). Reifies p Integer => HyperLogLog p -> Approximate Int64 Source #
Approximate size of our set
intersectionSize :: forall {k} (p :: k). Reifies p Integer => [HyperLogLog p] -> Approximate Int64 Source #
insert :: forall {k} (s :: k) a. (Reifies s Integer, Serial a) => a -> HyperLogLog s -> HyperLogLog s Source #
insertHash :: forall {k} (s :: k). 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.
cast :: forall {k1} {k2} (p :: k1) (q :: k2). (Reifies p Integer, Reifies q Integer) => HyperLogLog p -> Maybe (HyperLogLog q) Source #
coerceConfig :: forall {k1} {k2} (p :: k1) (q :: k2). (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
and HyperLogLog
p
. We do this by building
a hole in the HyperLogLog
qnominal
role for the configuration parameter.