util

package
v0.0.0-...-bda8275 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutOfBounds = errors.New("index out of bounds")

Functions

func ByteCountSI

func ByteCountSI(b int64) string

func CopySlice

func CopySlice[T any](dst []T, src []T) []T

func ExtendSlice

func ExtendSlice[T any](xs []T, need int) []T

func GetMonoTimeNanos

func GetMonoTimeNanos() int64

func PinTo

func PinTo(cpus ...int) error

func PrependSlice

func PrependSlice[T any](x T, xs []T) []T

Types

type FenwickTree

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

func NewFenwickTree

func NewFenwickTree(n int) *FenwickTree

func NewFenwickTreeFrom

func NewFenwickTreeFrom(xs []int) *FenwickTree

func (*FenwickTree) Add

func (t *FenwickTree) Add(index, delta int)

func (*FenwickTree) At

func (t *FenwickTree) At(index int) int

func (*FenwickTree) Clear

func (t *FenwickTree) Clear(index int) int

func (*FenwickTree) Reset

func (t *FenwickTree) Reset()

func (*FenwickTree) Size

func (t *FenwickTree) Size() int

func (*FenwickTree) Sum

func (t *FenwickTree) Sum() int

func (*FenwickTree) SumFrom

func (t *FenwickTree) SumFrom(index int) int

func (*FenwickTree) SumRange

func (t *FenwickTree) SumRange(left, right int) int

func (*FenwickTree) SumUntil

func (t *FenwickTree) SumUntil(index int) (sum int)

type List

type List[T comparable] struct {
	// contains filtered or unexported fields
}

List of singly-linked nodes.

func NewList

func NewList[T comparable]() *List[T]

func (*List[T]) Add

func (l *List[T]) Add(v T)

func (*List[T]) At

func (l *List[T]) At(ix int) T

func (*List[T]) Exists

func (l *List[T]) Exists(v T) bool

func (*List[T]) Iterate

func (l *List[T]) Iterate(fn func(v *T))

func (*List[T]) RemoveIndex

func (l *List[T]) RemoveIndex(ix int) (v T)

func (*List[T]) RemoveValue

func (l *List[T]) RemoveValue(v T) bool

func (*List[T]) Size

func (l *List[T]) Size() int

type OnlineStats

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

OnlineStats gives you min/avg/max/stddev in O(1) time and space.

Note that stddev is less accurate than the one reported by Stats.

func NewOnlineStats

func NewOnlineStats() *OnlineStats

func (*OnlineStats) Add

func (s *OnlineStats) Add(xs ...float64)

func (*OnlineStats) Len

func (s *OnlineStats) Len() int

func (*OnlineStats) Reset

func (s *OnlineStats) Reset()

func (*OnlineStats) Result

func (s *OnlineStats) Result() *Result

type Result

type Result struct {
	Min    float64
	Max    float64
	Avg    float64
	StdDev float64
}

func (*Result) Reset

func (r *Result) Reset()

type Stats

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

Stats gives you min/avg/max/stddev in O(1) time O(n) space.

func NewStats

func NewStats(n int, cb func(*Result)) *Stats

func (*Stats) Add

func (s *Stats) Add(xs ...float64)

func (*Stats) Len

func (s *Stats) Len() int

func (*Stats) Reset

func (s *Stats) Reset()

func (*Stats) Result

func (s *Stats) Result() *Result

type Tracker

type Tracker struct {
	N int
	// contains filtered or unexported fields
}

func NewTracker

func NewTracker() *Tracker

func NewTrackerWithSamples

func NewTrackerWithSamples(n int) *Tracker

func (*Tracker) Record

func (t *Tracker) Record(sample int64) *TrackerStats

type TrackerStats

type TrackerStats struct {
	Min    float64
	Avg    float64
	Max    float64
	StdDev float64
	Var    float64
}

func (*TrackerStats) Reset

func (s *TrackerStats) Reset()

func (*TrackerStats) String

func (s *TrackerStats) String() string

type TtyHist

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

func NewTtyHist

func NewTtyHist(opts TtyHistOpts) *TtyHist

func (*TtyHist) Add

func (h *TtyHist) Add(xs ...int64)

func (*TtyHist) Reported

func (h *TtyHist) Reported() int

type TtyHistOpts

type TtyHistOpts struct {
	Name      string
	Scale     string
	N         int64
	MinPct    float64
	Min       int64
	Max       int64
	Precision int
	Writer    io.Writer
}

Jump to

Keyboard shortcuts

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