hll

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package hll provides an implementation of the HyperLogLog algorithm.

A HyperLogLog counter can approximate the cardinality of a set with high accuracy and little memory.

Accuracy

Average error for 1,000,000,000 elements for different values of logSize:

logSize    average error %
4          21
5          12
6          10
7          8.1
8          4.8
9          3.6
10         1.9
11         1.2
12         1.0
13         0.7
14         0.5
15         0.33
16         0.25

Citation

Flajolet, Philippe; Fusy, Éric; Gandouet, Olivier; Meunier, Frédéric (2007). "Hyperloglog: The analysis of a near-optimal cardinality estimation algorithm". Discrete Mathematics and Theoretical Computer Science Proceedings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HLL

type HLL[T any] struct {
	// contains filtered or unexported fields
}

An HLL is a HyperLogLog counter for arbitrary values.

func New

func New[T any](logSize int, h func(T) uint64) *HLL[T]

New creates a new HyperLogLog counter. The counter will use 2^logSize bytes. h is the hash function to use for added values.

func (*HLL[T]) Add

func (h *HLL[T]) Add(t T)

Add adds v to the counter. Calls hash once.

func (*HLL[T]) AddHLL

func (h *HLL[T]) AddHLL(other *HLL[T])

AddHLL adds the state of another counter to h, assuming they use the same hash function. The result is equivalent to adding all the values of other to h.

func (*HLL[T]) ApproxCount

func (h *HLL[T]) ApproxCount() int

ApproxCount returns the current approximate count. Does not alter the state of the counter.

func (*HLL[T]) LogSize added in v1.0.0

func (h *HLL[T]) LogSize() int

LogSize returns the logSize parameter that was used to create this counter.

Jump to

Keyboard shortcuts

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