collection

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 2 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 {
	// contains filtered or unexported fields
}

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

func (*Bucket) Count

func (b *Bucket) Count() int64

func (*Bucket) Sum

func (b *Bucket) Sum() float64

type SlidingWindow

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

SlidingWindow defines a Sliding window to calculate the events in buckets with time interval.

func NewSlidingWindow

func NewSlidingWindow(size int, interval time.Duration, opts ...SlidingWindowOption) *SlidingWindow

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

func (*SlidingWindow) Add

func (s *SlidingWindow) Add(v float64) *SlidingWindow

Add adds value to current bucket.

func (*SlidingWindow) Reduce

func (s *SlidingWindow) Reduce(fn func(b *Bucket))

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

type SlidingWindowOption

type SlidingWindowOption func(*SlidingWindow)

SlidingWindowOption customize the SlidingWindow.

func IgnoreCurrentBucket

func IgnoreCurrentBucket() SlidingWindowOption

IgnoreCurrentBucket ignore current bucket.

Jump to

Keyboard shortcuts

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