histogram

package
v0.0.0-...-64560cf Latest Latest
Warning

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

Go to latest
Published: May 31, 2018 License: MIT Imports: 3 Imported by: 29

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoShardFn      = errors.New("no shard function provided in constructor")
	ErrZeroShardCount = errors.New("can't create histogram with zero shards")
)

Errors returned by New.

Functions

This section is empty.

Types

type Histogram

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

Histogram is a generic histogram implementation intended for use in concurrent environment. All methods are goroutine-safe. Zero value and nil are not valid Histograms.

func Default

func Default() *Histogram

Default creates histogram with reasonable defaults.

func New

func New(
	shardsCount uint32, shardFn func(uint64) uint32,
) (*Histogram, error)

New creates a new histogram. It can panic if the shardsCount is more than runtime can handle (i.e. slice size limit).

func WithDefaultHash

func WithDefaultHash(shardsCount uint32) (*Histogram, error)

WithDefaultHash creates histogram with specified shardCount and reasonable sharding function.

func (*Histogram) Add

func (h *Histogram) Add(key uint64, amount uint64)

Add increments counter associated with the specified key by the amount specified.

func (*Histogram) Count

func (h *Histogram) Count() uint64

Count calculates the number of elements in histogram in a more efficient way that can be implemented with VisitAll

func (*Histogram) Get

func (h *Histogram) Get(key uint64) uint64

Get returns current value for the given key.

func (*Histogram) Increment

func (h *Histogram) Increment(key uint64)

Increment increments counter associated with the specified key by 1.

func (*Histogram) VisitAll

func (h *Histogram) VisitAll(fn func(uint64, uint64) bool)

VisitAll function applies function to each key-value pair in histogram. If function returns false iteration stops. Locks the entire histogram.

Jump to

Keyboard shortcuts

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