util

package
v9.18.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Atoi

func Atoi(b []byte) (int, error)

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string.

func Max added in v9.15.0

func Max(a, b int) int

Max returns the maximum of two integers

func Min added in v9.15.0

func Min(a, b int) int

Min returns the minimum of two integers

func MustParseFloat added in v9.9.0

func MustParseFloat(s string) float64

MustParseFloat is like ParseFloat but panics on parse errors.

func ParseFloat

func ParseFloat(b []byte, bitSize int) (float64, error)

func ParseInt

func ParseInt(b []byte, base int, bitSize int) (int64, error)

func ParseStringToFloat added in v9.9.0

func ParseStringToFloat(s string) (float64, error)

ParseFloat parses a Redis RESP3 float reply into a Go float64, handling "inf", "-inf", "nan" per Redis conventions.

func ParseUint

func ParseUint(b []byte, base int, bitSize int) (uint64, error)

func SafeIntToInt32 added in v9.15.0

func SafeIntToInt32(value int, fieldName string) (int32, error)

SafeIntToInt32 safely converts an int to int32, returning an error if overflow would occur.

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice.

func ToPtr added in v9.3.0

func ToPtr[T any](v T) *T

Types

type AtomicMax

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

AtomicMax is a thread-safe max container

  • hasValue indicator true if a value was equal to or greater than threshold
  • optional threshold for minimum accepted max value
  • if threshold is not used, initialization-free
  • wait-free CompareAndSwap mechanic

func NewAtomicMax

func NewAtomicMax() (atomicMax *AtomicMax)

NewAtomicMax returns a thread-safe max container

  • if threshold is not used, AtomicMax is initialization-free

func (*AtomicMax) Max

func (m *AtomicMax) Max() (value float64, hasValue bool)

Max returns current max and value-present flag

  • hasValue true indicates that value reflects a Value invocation
  • hasValue false: value is zero-value
  • Thread-safe

func (*AtomicMax) Max1

func (m *AtomicMax) Max1() (value float64)

Max1 returns current maximum whether zero-value or set by Value

  • threshold is ignored
  • Thread-safe

func (*AtomicMax) Value

func (m *AtomicMax) Value(value float64) (isNewMax bool)

Value updates the container with a possible max value

  • isNewMax is true if:
  • — value is equal to or greater than any threshold and
  • — invocation recorded the first 0 or
  • — a new max
  • upon return, Max and Max1 are guaranteed to reflect the invocation
  • the return order of concurrent Value invocations is not guaranteed
  • Thread-safe

type AtomicMin

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

AtomicMin is a thread-safe Min container

  • hasValue indicator true if a value was equal to or greater than threshold
  • optional threshold for minimum accepted Min value
  • wait-free CompareAndSwap mechanic

func NewAtomicMin

func NewAtomicMin() (atomicMin *AtomicMin)

NewAtomicMin returns a thread-safe Min container

  • if threshold is not used, AtomicMin is initialization-free

func (*AtomicMin) Min

func (m *AtomicMin) Min() (value float64, hasValue bool)

Min returns current min and value-present flag

  • hasValue true indicates that value reflects a Value invocation
  • hasValue false: value is zero-value
  • Thread-safe

func (*AtomicMin) Min1

func (m *AtomicMin) Min1() (value float64)

Min1 returns current Minimum whether zero-value or set by Value

  • threshold is ignored
  • Thread-safe

func (*AtomicMin) Value

func (m *AtomicMin) Value(value float64) (isNewMin bool)

Value updates the container with a possible Min value

  • isNewMin is true if:
  • — value is equal to or greater than any threshold and
  • — invocation recorded the first 0 or
  • — a new Min
  • upon return, Min and Min1 are guaranteed to reflect the invocation
  • the return order of concurrent Value invocations is not guaranteed
  • Thread-safe

Jump to

Keyboard shortcuts

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