hyperloglog

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 3 Imported by: 0

README

go-hyperloglog

The Golang HyperLogLog implementation from the original paper

HyperLogLog is an algorithm for the count-distinct problem, approximating the number of distinct elements in a multiset

Example

The usage is quite simple:

    var someData []string
    // fill or obtain someData

    hll, err := hyperloglog.New(.001)
    if err != nil {
        log.Fatalln(err)
    }

    for _, x := range someData {
        hll.Add(x)
    }

    fmt.Println("Estimated cardinality:", hll.Count())
Quick start
$ go get github.com/ikashilov/go-hyperloglog
$ cd $GOPATH/src/github.com/ikashilov/go-hyperloglog
$ go test -test.v
$ go test -bench=.

Documentation

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
}

HyperLogLog is a cardinality estimator

func New

func New(err float64) (*HyperLogLog, error)

New creates a new HLL estimator with a given precision (error). The `good` value for error is (0.01 - 0.0001) Smaller values will case more memory usage

func (*HyperLogLog) Add

func (h *HyperLogLog) Add(val string)

Add adds a new []byte value to the HLL

func (*HyperLogLog) Count

func (h *HyperLogLog) Count() uint64

Count estimates the cardinality

Jump to

Keyboard shortcuts

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