util

package
v0.73.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SizeOfString  = int(unsafe.Sizeof(""))
	SizeOfUint32  = int(unsafe.Sizeof(uint32(0)))
	SizeOfUint64  = int(unsafe.Sizeof(uint64(0)))
	SizeOfPointer = int(unsafe.Sizeof(int(0)))
	SizeOfFloat64 = int(unsafe.Sizeof(float64(0.0)))
)

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 CopyFile added in v0.71.0

func CopyFile(src, dst string) error

CopyFile copies a file (overwrites if already exists)

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 MsTsToESFormat

func MsTsToESFormat(ts uint64) string

MsTsToESFormat converts timestamp in milliseconds to ES time format string.

func MustCreateDir added in v0.70.0

func MustCreateDir(dirPath string)

MustCreateDir creates directory at dirPath. Handles the case when directory already exists.

func MustFsyncFile added in v0.70.0

func MustFsyncFile(fpath string)

func MustRemoveFileByPath added in v0.60.0

func MustRemoveFileByPath(fpath string)

func MustSyncPath

func MustSyncPath(dirPath string)

func MustWriteFileAtomic added in v0.70.0

func MustWriteFileAtomic(fpath string, data []byte, perm os.FileMode, tmpFileExt string)

func NsTsToESFormat added in v0.64.0

func NsTsToESFormat(ts uint64) string

NsTsToESFormat converts timestamp in nanoseconds to ES time format string. Nanosecond part will not be printed.

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 RemoveFile added in v0.62.3

func RemoveFile(file string)

RemoveFile safely removes a file with logging Handles cases where the file already doesn't exist

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 SyncPath added in v0.62.0

func SyncPath(dirPath string) error

func VisitFilesWithExt added in v0.70.0

func VisitFilesWithExt(des []os.DirEntry, ext string, cb func(name string) error) error

VisitFilesWithExt traverses all the files with `ext` extension in `des` directory and calls a `cb` func for each of files.

func WriteFileAtomic added in v0.70.0

func WriteFileAtomic(fpath string, data []byte, perm os.FileMode, tmpFileExt string) error

atomicWrite safely writes data to file using atomic replacement pattern

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 BufferPool added in v0.59.0

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

func (*BufferPool) Get added in v0.59.0

func (q *BufferPool) Get() *bytespool.Buffer

func (*BufferPool) Put added in v0.59.0

func (q *BufferPool) Put(b *bytespool.Buffer)

type MinHeap added in v0.73.0

type MinHeap[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

MinHeap is a min‑heap for any comparable type. Maintains both a heap structure and a map for fast lookup of items.

func NewMinHeap added in v0.73.0

func NewMinHeap[T cmp.Ordered]() *MinHeap[T]

NewMinHeap creates and initializes a new MinHeap instance.

func (*MinHeap[T]) Len added in v0.73.0

func (h *MinHeap[T]) Len() int

Len returns the current number of elements in the heap.

func (*MinHeap[T]) Min added in v0.73.0

func (h *MinHeap[T]) Min() (T, bool)

Min returns the minimum value in the heap without removing it. Returns (zero value, false) if the heap is empty.

func (*MinHeap[T]) PopMin added in v0.73.0

func (h *MinHeap[T]) PopMin() (T, bool)

PopMin removes and returns the minimum value from the heap. Returns (zero value, false) if the heap is empty.

func (*MinHeap[T]) Push added in v0.73.0

func (h *MinHeap[T]) Push(value T)

Push adds a value to the heap if it doesn't already exist (no duplicates).

func (*MinHeap[T]) Remove added in v0.73.0

func (h *MinHeap[T]) Remove(value T)

Remove deletes one occurrence of the specified value from the heap. Does nothing if the value doesn't exist.

type Pair added in v0.71.0

type Pair[F, S any] struct {
	First  F
	Second S
}

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

Jump to

Keyboard shortcuts

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