cardinal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package cardinal implements efficient cardinality estimation datastructures.

Package cardinal implements efficient cardinality estimation datastructures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Weight

func Weight(numCounters uint32) float64

Weight computes the weight for the cardinality estimators based on the counters.

Types

type HyperLogLog

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

HyperLogLog data structure does cardinality estimation by ranking items according to the LSB bits index.

func NewHyperLogLog

func NewHyperLogLog(precision int) (*HyperLogLog, error)

NewHyperLogLog creates a new instance of hyperloglog precision takes values in (4..16).

func (*HyperLogLog) Add

func (h *HyperLogLog) Add(item int32)

Add indexes an element into the counter.

func (*HyperLogLog) Cardinal

func (h *HyperLogLog) Cardinal() int

Cardinal approximately counts the number of unique elements indexed by the HyperLogLog counter.

func (*HyperLogLog) Rank

func (h *HyperLogLog) Rank(value uint32) int

Rank which is the least significant bit position.

type LinearCounter

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

LinearCounter is a simple map(hash(value) => bit) and cardinality can be estimated using n = ~m*ln(V) where m is a parameter chosen based on how much entires we expect and V is the number of 0-set bits.

func NewLinearCounter

func NewLinearCounter(m int) LinearCounter

NewLinearCounter creates a new linear counter.

func (*LinearCounter) Add

func (lc *LinearCounter) Add(item int) error

Add an item to the linear counter

func (*LinearCounter) Cardinal

func (lc *LinearCounter) Cardinal() float64

Cardinal returns the estimated cardinal of the dataset

Jump to

Keyboard shortcuts

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