mathutil

package
v1.1.0-beta.0...-d02d48a Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxInt  = 1<<(IntBits-1) - 1
	MinInt  = -MaxInt - 1
	MaxUint = 1<<IntBits - 1
	IntBits = 1 << (^uint(0)>>32&1 + ^uint(0)>>16&1 + ^uint(0)>>8&1 + 3)
)

Architecture and/or implementation specific integer limits and bit widths.

Variables

This section is empty.

Functions

func Abs

func Abs(n int64) int64

Abs implement the abs function according to http://cavaliercoder.com/blog/optimized-abs-for-int64-in-go.html

func Clamp

func Clamp[T constraints.Ordered](n, minv, maxv T) T

Clamp restrict a value to a certain interval.

func Divide2Batches

func Divide2Batches(total, batches int) []int

Divide2Batches divides 'total' into 'batches', and returns the size of each batch. Σ(batchSizes) = 'total'. if 'total' < 'batches', we return 'total' batches with size 1. 'total' is allowed to be 0.

func IsFinite

func IsFinite(f float64) bool

IsFinite reports whether f is neither NaN nor an infinity.

func NextPowerOfTwo

func NextPowerOfTwo(i int64) int64

NextPowerOfTwo returns the smallest power of two greater than or equal to `i` Caller should guarantee that i > 0 and the return value is not overflow.

func StrLenOfInt64Fast

func StrLenOfInt64Fast(x int64) int

StrLenOfInt64Fast efficiently calculate the string character lengths of an int64 as input

func StrLenOfUint64Fast

func StrLenOfUint64Fast(x uint64) int

StrLenOfUint64Fast efficiently calculate the string character lengths of an uint64 as input

Types

type ExponentialMovingAverage

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

ExponentialMovingAverage is an exponential moving average measurement implementation. It is not thread-safe.

func NewExponentialMovingAverage

func NewExponentialMovingAverage(
	factor float64,
	warmupWindow int,
) *ExponentialMovingAverage

NewExponentialMovingAverage will create a new ExponentialMovingAverage.

func (*ExponentialMovingAverage) Add

func (m *ExponentialMovingAverage) Add(value float64)

Add a single sample and update the internal state.

func (*ExponentialMovingAverage) Get

Get the current value.

type MysqlRng

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

MysqlRng is random number generator and this implementation is ported from MySQL. See https://github.com/tikv/tikv/pull/6117#issuecomment-562489078.

func NewWithSeed

func NewWithSeed(seed int64) *MysqlRng

NewWithSeed create a rng with random seed.

func NewWithTime

func NewWithTime() *MysqlRng

NewWithTime create a rng with time stamp.

func (*MysqlRng) Gen

func (rng *MysqlRng) Gen() float64

Gen will generate random number.

func (*MysqlRng) GetSeed1

func (rng *MysqlRng) GetSeed1() uint32

GetSeed1 is an interface to get seed1. It's only used for getting session states.

func (*MysqlRng) GetSeed2

func (rng *MysqlRng) GetSeed2() uint32

GetSeed2 is an interface to get seed2. It's only used for getting session states.

func (*MysqlRng) SetSeed1

func (rng *MysqlRng) SetSeed1(seed uint32)

SetSeed1 is a interface to set seed1

func (*MysqlRng) SetSeed2

func (rng *MysqlRng) SetSeed2(seed uint32)

SetSeed2 is a interface to set seed2

Jump to

Keyboard shortcuts

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