hll

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hll implements a HyperLogLog sketch over uniformly distributed 64-bit hashes.

Index

Constants

View Source
const Precision = 14

Precision is the number of leading hash bits that select a register.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sketch

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

Sketch is a HyperLogLog sketch. Add calls may run concurrently with each other and with Estimate. Reset may run concurrently with Add, but then it does not guarantee that the Add is kept: callers that need a value added during a Reset to be counted must serialize the two.

func New

func New() *Sketch

New returns an empty sketch.

func (*Sketch) Add

func (s *Sketch) Add(x uint64)

Add records x. The registers are chosen by the bits of x, so x must be a uniformly distributed 64-bit hash, such as a series ID; raw sequential values skew the estimate.

func (*Sketch) Estimate

func (s *Sketch) Estimate() uint64

Estimate returns the estimated number of distinct values added since creation or the last Reset. An estimate that does not fit in a uint64 is capped at math.MaxUint64. It uses the improved raw estimator of Ertl (https://arxiv.org/abs/1702.01284), which has no bias over the whole cardinality range and needs no linear counting switch or bias table.

func (*Sketch) Reset

func (s *Sketch) Reset()

Reset clears every register.

Jump to

Keyboard shortcuts

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