collection

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Sum   float64
	Count int64
}

Bucket defines the bucket that holds sum and num of additions.

type RollingWindow

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

RollingWindow defines a rolling window to calculate the events in buckets with time interval.

func NewRollingWindow

func NewRollingWindow(size int, interval time.Duration, opts ...RollingWindowOption) *RollingWindow

NewRollingWindow returns a RollingWindow that with size buckets and time interval, use opts to customize the RollingWindow.

func (*RollingWindow) Add

func (rw *RollingWindow) Add(v float64)

Add adds value to current bucket.

func (*RollingWindow) Reduce

func (rw *RollingWindow) Reduce(fn func(b *Bucket))

Reduce runs fn on all buckets, ignore current bucket if ignoreCurrent was set.

type RollingWindowOption

type RollingWindowOption func(rollingWindow *RollingWindow)

RollingWindowOption let callers customize the RollingWindow.

func IgnoreCurrentBucket

func IgnoreCurrentBucket() RollingWindowOption

IgnoreCurrentBucket lets the Reduce call ignore current bucket.

Jump to

Keyboard shortcuts

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