util

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package util

Package util

Package util

Package util

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MinInt

func MinInt(a, b int) int

MinInt returns the smaller one of a and b.

func Now

func Now() time.Duration

Now returns a relative time duration since initTime, which is not important. The caller only needs to care about the relative value.

func Pid

func Pid() int

Pid returns pid of current process.

func ProcessName

func ProcessName() string

ProcessName returns the processname, same as the command name.

func Rand

func Rand() string

Rand returns a random string.

func RandId

func RandId() string

RandId returns a random id string.

func Randn

func Randn(n int) string

Randn returns a random string with length n.

func Seed

func Seed(seed int64)

Seed sets the seed to seed.

func Since

func Since(d time.Duration) time.Duration

Since returns a diff since given d.

Types

type Bucket

type Bucket struct {
	Sum   float64
	Count int64
}

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

type Proba

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

A Proba is used to test if true on given probability.

func NewProba

func NewProba() *Proba

NewProba returns a Proba.

func (*Proba) TrueOnProba

func (p *Proba) TrueOnProba(proba float64) (truth bool)

TrueOnProba checks if true on given probability.

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