util

package
v0.58.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinSearchInRange

func BinSearchInRange(from, to int, fn func(i int) bool) int

func ByteToStringUnsafe

func ByteToStringUnsafe(b []byte) string

func CollapseErrors

func CollapseErrors(errs []error) error

CollapseErrors combines errors and writes repeats of each.

func DeduplicateErrors

func DeduplicateErrors(errs []error) error

DeduplicateErrors deduplicates errors.

func DurationToUnit

func DurationToUnit(durationVal time.Duration, unit string) float64

DurationToUnit converts duration to unit and returns as float64.

func EnsureSliceSize

func EnsureSliceSize[T any](src []T, size int) []T

func Float64ToPrec

func Float64ToPrec(val float64, prec uint32) float64

Float64ToPrec formats float64 by removing numberics after prec digit.

func IdxFill

func IdxFill(n int) []int

func IdxShuffle

func IdxShuffle(n int) []int

func IsCancelled

func IsCancelled(ctx context.Context) bool

IsCancelled is a faster way to check if the context has been canceled, compared to ctx.Err() != nil

func IsRecoveredPanicError

func IsRecoveredPanicError(e error) bool

func MsTsToESFormat

func MsTsToESFormat(ts uint64) string

MsTsToESFormat converts timestamp in milliseconds to ES time format string.

func MustSyncPath

func MustSyncPath(path string)

func ParseDuration

func ParseDuration(esDuration string) (time.Duration, error)

func Recover

func Recover(metric prometheus.Counter, err error)

func RecoverToError

func RecoverToError(panicData any, metric prometheus.Counter) error

func RunEvery

func RunEvery(done <-chan struct{}, runInterval time.Duration, actionFn func())

func SizeStr

func SizeStr(bytes uint64) string

func SizeToUnit

func SizeToUnit(sizeVal uint64, unit string) float64

SizeToUnit converts size in bytes to unit and returns as float64.

func StringToByteUnsafe

func StringToByteUnsafe(str string) []byte

func ZapDurationWithPrec

func ZapDurationWithPrec(
	key string, dur time.Duration, unit string, prec uint32,
) zap.Field

ZapDurationWithPrec converts duration to unit and forms float64 zap.Field with removed numerics after prec digit.

func ZapFloat64WithPrec

func ZapFloat64WithPrec(key string, val float64, prec uint32) zap.Field

ZapFloat64WithPrec forms float64 zap.Field with removed numerics after prec digit.

func ZapMsTsAsESTimeStr

func ZapMsTsAsESTimeStr(key string, ts uint64) zap.Field

ZapMsTsAsESTimeStr converts timestamp in milliseconds to ES time format string and forms string zap.Field.

func ZapUint64AsSizeStr

func ZapUint64AsSizeStr(key string, val uint64) zap.Field

ZapUint64AsSizeStr forms string zap.Field with val converted to size string.

Types

type Bitmask

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

func LoadBitmask

func LoadBitmask(size int, data []byte) Bitmask

func NewBitmask

func NewBitmask(size int) Bitmask

func (*Bitmask) Get

func (b *Bitmask) Get(pos int) bool

func (*Bitmask) GetBitmaskBinary

func (b *Bitmask) GetBitmaskBinary() []byte

func (*Bitmask) GetSize

func (b *Bitmask) GetSize() int

func (*Bitmask) HasBitsIn

func (b *Bitmask) HasBitsIn(left, right int) bool

func (*Bitmask) Set

func (b *Bitmask) Set(pos int, state bool)

type ReallocSolver

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

func NewReallocSolver

func NewReallocSolver(opts ...ReallocSolverOpts) ReallocSolver

func (*ReallocSolver) ReallocParams

func (s *ReallocSolver) ReallocParams(curLen, curCap int) (int, bool)

type ReallocSolverOpts

type ReallocSolverOpts func(*ReallocSolver)

func ReallocSolverLabel

func ReallocSolverLabel(label string) ReallocSolverOpts

func ReallocSolverSize

func ReallocSolverSize(statSize int) ReallocSolverOpts

Jump to

Keyboard shortcuts

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