alg

package
v0.0.0-...-a78daf7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	Hll *HyperLogLog
	// Now - artifical now of the incoming data reprents the first timestamp of the open interval.
	Now int
}

Counter that stors unique users per minute. The main structure is a HyperLogLog counter and the starting epoh time - The first incoming message. This implementation assumes messages are ordered.

func (*Counter) Count

func (c *Counter) Count(uid string, ts int) (bool, int)

Count unique uids from one minute timeframe.

type HyperLogLog

type HyperLogLog struct {
	// contains filtered or unexported fields
}

A HyperLogLog cardinality estimator. See http://algo.inria.fr/flajolet/Publications/FlFuGaMe07.pdf for details about the algorithm.

func NewHyperLogLog

func NewHyperLogLog(stdErr float64) *HyperLogLog

NewHyperLogLog returns an estimator for counting cardinality to within the given stderr.

Smaller values require more space, but provide more accurate results. For a good time, try 0.001 or so.

func (*HyperLogLog) Add

func (h *HyperLogLog) Add(hash uint32)

Add an item by its hash.

func (*HyperLogLog) Count

func (h *HyperLogLog) Count() uint64

Count returns the current estimate of the number of distinct items seen.

func (*HyperLogLog) Merge

func (h *HyperLogLog) Merge(from *HyperLogLog)

Merge another HyperLogLog into this one.

type LpCounter

type LpCounter struct {
	Bits *bitarray.BitArray
}

LpCounter - Linear Probabilistic counter

func NewLpCounter

func NewLpCounter(maxKb int) *LpCounter

NewLpCounter - Creates new LpCounter

func (*LpCounter) Count

func (lp *LpCounter) Count() int

Count - Gets the current value of the bitmap: -size * ln(unset_bits/size)

func (*LpCounter) Inc

func (lp *LpCounter) Inc(item string) error

Inc - Increment the counter for the item

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL