counter

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCounterParams = CounterParams{
	MapLimit: 100,
	CMS: CMSketchParams{
		W: 100,
		D: 5,
		Grow: CMSGrowParams{
			SkipRateDecay: 10_000,
			Threshold:     0.35,
			Ratio:         1.5,
			MaxW:          10_000,
		},
	},
}

Functions

func NewCMSketchCounter

func NewCMSketchCounter(params CMSketchParams, src rand.Source, topKProvider topKFunc) *cmSketch

func NewHybridCounter

func NewHybridCounter(params CounterParams, src rand.Source) *hybridCounter

func NewMapCounter

func NewMapCounter(limit int) *mapCounter

NewMapCounter creates a mapCounter that also tracks the top K entries.

Types

type CMSGrowParams

type CMSGrowParams struct {
	SkipRateDecay int     // how often (in calls to Inc) the skip rate is halved (this makes it an exponential moving average)
	Threshold     float64 // at what skip ratio should we grow W
	Ratio         float64 // how much to grow W each time
	MaxW          int     // cap for W
}

type CMSketchParams

type CMSketchParams struct {
	W    int // width of sketch
	D    int // depth of sketch
	Grow CMSGrowParams
}

type Counter

type Counter interface {
	// GetPass tracks a value per key, which may be lossy or approximate. It increments the
	// value by inc and returns the new value. The value returned must be >= base.
	GetPass(key string, base, inc int64) int64
	// EstimateDistinctKeys returns an estimate of the number of distinct keys in the counter.
	EstimateDistinctKeys() int
	// Get the counts for a small number of top keys (the maximum keys returned will be limited
	// by the Counter's configuration). Not guaranteed to return the exact top.
	TopK() []TopKEntry
}

type CounterParams

type CounterParams struct {
	MapLimit int
	CMS      CMSketchParams
}

type TopKEntry

type TopKEntry struct {
	Key   string
	Count int64
}

TopKEntry is a count for a value with high count.

Jump to

Keyboard shortcuts

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