hll

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package hll provides a HyperLogLog probabilistic cardinality estimator.

NOT safe for concurrent use. Callers must synchronize access externally.

Index

Constants

View Source
const (
	DefaultLog2m    = 31
	DefaultRegwidth = 8
)

HyperLogLog configuration constants.

Variables

View Source
var DefaultSettings = hll.Settings{
	Log2m:             DefaultLog2m,
	Regwidth:          DefaultRegwidth,
	ExplicitThreshold: hll.AutoExplicitThreshold,
	SparseEnabled:     true,
}

DefaultSettings is the default HyperLogLog configuration used by New.

Functions

func GetBytes

func GetBytes(key interface{}) ([]byte, error)

GetBytes encodes the given value into a byte slice using gob encoding.

Types

type HyperLogLog

type HyperLogLog struct {
	HLL hll.Hll
}

HyperLogLog is a probabilistic cardinality estimator.

func FromBytes

func FromBytes(raw []byte) (*HyperLogLog, error)

FromBytes deserializes a HyperLogLog from its binary representation.

func New

func New() (*HyperLogLog, error)

New creates a new HyperLogLog with DefaultSettings.

func (*HyperLogLog) Add

func (h *HyperLogLog) Add(data []byte)

Add hashes the given byte slice and adds it to the HyperLogLog.

func (*HyperLogLog) AddAny

func (h *HyperLogLog) AddAny(data any) error

AddAny gob-encodes the given value and adds it to the HyperLogLog.

func (*HyperLogLog) Clear

func (h *HyperLogLog) Clear() error

Clear resets the HyperLogLog to an empty state.

func (*HyperLogLog) Count

func (h *HyperLogLog) Count() uint64

Count returns the estimated number of distinct items as a uint64.

func (*HyperLogLog) IntersectionCount

func (h *HyperLogLog) IntersectionCount(h2 *HyperLogLog) (uint64, error)

IntersectionCount estimates the number of distinct items common to h and h2 using inclusion-exclusion.

func (*HyperLogLog) Len

func (h *HyperLogLog) Len() int

Len returns the estimated number of distinct items in the set.

func (*HyperLogLog) MarshalBinary

func (h *HyperLogLog) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*HyperLogLog) ToBytes

func (h *HyperLogLog) ToBytes() []byte

ToBytes serializes the HyperLogLog into its binary representation.

func (*HyperLogLog) Union

func (h *HyperLogLog) Union(h2 *HyperLogLog) (*HyperLogLog, error)

Union returns a new HyperLogLog that is the union of h and h2.

func (*HyperLogLog) UnionCount

func (h *HyperLogLog) UnionCount(h2 *HyperLogLog) (uint64, error)

UnionCount returns the estimated cardinality of the union of h and h2.

func (*HyperLogLog) UnmarshalBinary

func (h *HyperLogLog) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

Jump to

Keyboard shortcuts

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