hyperloglog

package module
v0.0.0-...-0b4f1d4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2014 License: MIT Imports: 2 Imported by: 1

README

hyperloglog

Package hyperloglog implements the HyperLogLog algorithm for cardinality estimation. In English: it counts things. It counts things using very small amounts of memory compared to the number of objects it is counting.

For a full description of the algorithm, see the paper HyperLogLog: the analysis of a near-optimal cardinality estimation algorithm by Flajolet, et. al. at http://algo.inria.fr/flajolet/Publications/FlFuGaMe07.pdf

For documentation see http://godoc.org/github.com/eclesh/hyperloglog

Quick start

$ go get github.com/eclesh/hyperloglog
$ cd $GOPATH/src/github.com/eclesh/hyperloglog
$ go test -test.v
$ go test -bench=.

License

hyperloglog is licensed under the MIT license.

Documentation

Overview

Package hyperloglog implements the HyperLogLog algorithm for cardinality estimation. In English: it counts things. It counts things using very small amounts of memory compared to the number of objects it is counting.

For a full description of the algorithm, see the paper HyperLogLog: the analysis of a near-optimal cardinality estimation algorithm by Flajolet, et. al.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HyperLogLog

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

func New

func New(registers uint) (*HyperLogLog, error)

Return a new HyperLogLog with the given number of registers. More registers leads to lower error in your estimated count, at the expense of memory.

Choose a power of two number of registers, depending on the amount of memory you're willing to use and the error you're willing to tolerate. Each register uses one byte of memory.

Approximate error will be:

1.04 / sqrt(registers)

func (*HyperLogLog) Add

func (h *HyperLogLog) Add(val uint32)

Add to the count. val should be a 32 bit unsigned integer from a good hash function.

func (*HyperLogLog) Count

func (h *HyperLogLog) Count() uint64

Get the estimated count.

func (*HyperLogLog) Merge

func (h1 *HyperLogLog) Merge(h2 *HyperLogLog) error

Merge another HyperLogLog into this one. The number of registers in each must be the same.

func (*HyperLogLog) Reset

func (h *HyperLogLog) Reset()

Reset all internal variables and set the count to zero.

Jump to

Keyboard shortcuts

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