counter

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package counter implements linear counter estimator

Index

Constants

View Source
const (
	// DefaultCap max capacity for the counter
	DefaultCap = 1 << 19
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	Bits *bitset.BitSet `json:"bits"`
}

Counter implements a simple probabilistic counter estimator with 1% estimation accuracy as described in https://www.waitingforcode.com/big-data-algorithms/cardinality-estimation-linear-probabilistic-counting/read

func FromBinary

func FromBinary(data []byte) (*Counter, error)

FromBinary unmarshals counter state

func New

func New(cap uint) *Counter

New creates a counter for the maximum amount unique elements provided

func (*Counter) Count

func (c *Counter) Count() uint

Count returns an estimate of distinct elements in the set

func (*Counter) Mark

func (c *Counter) Mark(key string)

Mark marks key as present in the set

func (*Counter) Reset

func (c *Counter) Reset()

Reset the counter

func (*Counter) ToBinary

func (c *Counter) ToBinary() ([]byte, error)

ToBinary marshals counter state

Jump to

Keyboard shortcuts

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