utils

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package utils provides various utilities and helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClampFloat64

func ClampFloat64(value, minValue, maxValue float64) float64

ClampFloat64 limits the provided value according to the given range. Origin: https://docs.unity3d.com/ScriptReference/Mathf.Clamp.html.

Types

type Counter

type Counter[T CounterValue] interface {
	// Inc increments the counter by the given value.
	Inc(i T)
	// Dec decrements the counter by the given value.
	Dec(i T)
	// Count returns the current value of the counter.
	Count() T
}

Counter is a thread-safe metrics counter.

func NewInt64Counter added in v0.0.5

func NewInt64Counter(parent Counter[int64]) Counter[int64]

NewInt64Counter creates an int64 counter referring to a parent counter. If parent is nil, the root in the hierarchy is created.

func NewUint64Counter added in v0.0.5

func NewUint64Counter(parent Counter[uint64]) Counter[uint64]

NewUint64Counter creates a uint64 counter referring to a parent counter. If parent is nil, the root in the hierarchy is created.

type CounterValue added in v0.0.5

type CounterValue interface {
	~int64 | ~uint64
}

CounterValue is a supported counter numeric type. constraints.Integer is too wide here, we should use the narrowest constraint matching real implementation.

type EMASmoother added in v0.0.5

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

EMASmoother is a concurrency-safe exponential moving average calculator.

It helps stabilize noisy measurements (for example, memory utilization) so control logic reacts to trend changes instead of short spikes.

func NewEMASmoother added in v0.0.5

func NewEMASmoother(alpha float64) *EMASmoother

NewEMASmoother creates a new exponential moving average calculator.

The smoothing coefficient alpha is usually in (0; 1]: smaller alpha -> smoother but slower reaction, larger alpha -> faster reaction but noisier output.

func (*EMASmoother) Update added in v0.0.5

func (e *EMASmoother) Update(value float64) float64

Update adds a new sample and returns the current smoothed value.

Formula:

S_t = alpha*X_t + (1-alpha)*S_{t-1}

Directories

Path Synopsis
Package breaker contains useful thread-safe abstraction the helps to control lifetime of actors, background tasks, pools etc.
Package breaker contains useful thread-safe abstraction the helps to control lifetime of actors, background tasks, pools etc.
config
bytes
Package bytes helps to represent human-readable size values in JSON.
Package bytes helps to represent human-readable size values in JSON.
duration
Package duration helps to represent human-readable duration values in JSON.
Package duration helps to represent human-readable duration values in JSON.
prepare
Package prepare provides a function to validate configuration recursively.
Package prepare provides a function to validate configuration recursively.

Jump to

Keyboard shortcuts

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