utilities

package
v0.0.0-...-3439542 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenerateUniqueId func() uint64 = func() func() uint64 {
	var nextConnectionId uint64 = 0
	return func() uint64 {
		return atomic.AddUint64(&nextConnectionId, 1)
	}
}()
View Source
var GitVersion = "dev"

GitVersion is the Git revision hash

Functions

func AbsPercentDifference

func AbsPercentDifference(
	current float64,
	previous float64,
) (difference float64)

func AllSequentialIncreasesLessThan

func AllSequentialIncreasesLessThan[T Number](elements []T, limit float64) (bool, float64)

func ApproximatelyEqual

func ApproximatelyEqual[T float32 | float64](truth T, maybe T, fudge T) bool

func CalculateAverage

func CalculateAverage[T Number](elements []T) float64

func CalculatePercentile

func CalculatePercentile[T Number](
	elements []T,
	p uint,
) (result T)

func CalculateStandardDeviation

func CalculateStandardDeviation[T constraints.Float | constraints.Integer](elements []T) float64

func ChannelToSlice

func ChannelToSlice[S any](channel <-chan S) (slice []S)

func Conditional

func Conditional[T any](condition bool, t T, f T) T

func ContextSignaler

func ContextSignaler(ctxt context.Context, st time.Duration, condition *func() bool, c *sync.Cond)

func FilenameAppend

func FilenameAppend(filename, appendage string) string

func Filter

func Filter[S any](elements []S, filterer func(S) bool) []S

func Fmap

func Fmap[S any, F any](elements []S, mapper func(S) F) []F

func GetSome

func GetSome[S any](optional Optional[S]) S

func IndentOutput

func IndentOutput(output string, depth uint, character string) string

func Iota

func Iota(low int, high int) (made []int)

func IsInterfaceNil

func IsInterfaceNil(ifc interface{}) bool

func IsNone

func IsNone[S any](optional Optional[S]) bool

func IsSome

func IsSome[S any](optional Optional[S]) bool

func Max

func Max(x, y uint64) uint64

func OrTimeout

func OrTimeout(f func(), timeout time.Duration)

func OverrideHostTransport

func OverrideHostTransport(transport *http.Transport, connectToAddr string)

func PerSecondToInterval

func PerSecondToInterval(rate int64) time.Duration

func RandBetween

func RandBetween(max int) int

func Reverse

func Reverse[T any](elements []T) []T

func SeekForAppend

func SeekForAppend(file *os.File) (err error)

func SignedPercentDifference

func SignedPercentDifference[T constraints.Float | constraints.Integer](
	current T,
	previous T,
) (difference float64)

func ToMBps

func ToMBps(bytes float64) float64

func ToMbps

func ToMbps(bytes float64) float64

func TrimBy

func TrimBy[T Number](elements []T, trim int) []T

elements must already be sorted!

func TrimmedMean

func TrimmedMean[T Number](elements []T, trim int) (float64, []T)

func UserAgent

func UserAgent() string

func WaitWithContext

func WaitWithContext(ctxt context.Context, condition *func() bool, mu *sync.Mutex, c *sync.Cond) bool

Types

type MeasurementResult

type MeasurementResult struct {
	Delay            time.Duration
	MeasurementCount uint16
	Err              error
}

type Number

type Number interface {
	constraints.Float | constraints.Integer
}

type Optional

type Optional[S any] struct {
	// contains filtered or unexported fields
}

func None

func None[S any]() Optional[S]

func Some

func Some[S any](value S) Optional[S]

func (Optional[S]) String

func (optional Optional[S]) String() string

type Pair

type Pair[T1, T2 any] struct {
	First  T1
	Second T2
}

Jump to

Keyboard shortcuts

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