util

package
v0.0.0-...-53ff736 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Index

Constants

View Source
const (
	ID_LENGTH = 16
)

Variables

View Source
var (
	MaxInt4       = LongToInt4(math.MaxInt32)
	NumFreeValues = 255 - MaxInt4
)

Functions

func Byte4ToInt

func Byte4ToInt(b byte) int

func BytesDifference

func BytesDifference(priorTerm, currentTerm []byte) (int, error)

func Int4ToLong

func Int4ToLong(i int) int64

func IntToByte4

func IntToByte4(i int) byte

func Log

func Log(x, base int) int

func LongToInt4

func LongToInt4(i int64) int

func NextUp

func NextUp(f float64) float64

func RandomId

func RandomId() []byte

RandomId Generates a non-cryptographic globally unique id.

func SelectK

func SelectK(k int, data sort.Interface)

func SelectorCheckArgs

func SelectorCheckArgs(from, to, k int)

func SumRelativeErrorBound

func SumRelativeErrorBound(numValues int) float64

SumRelativeErrorBound Return a relative error bound for a sum of numValues positive doubles, computed using recursive summation, ie. sum = x1 + ... + xn. NOTE: This only works if all values are POSITIVE so that Σ |xi| == |Σ xi|. This uses formula 3.5 from Higham, Nicholas J. (1993), "The accuracy of floating point summation", SIAM Journal on Scientific Computing.

Types

type Bits

type Bits interface {

	// Test Returns the value of the bit with the specified index.
	// Params: 	index – index, should be non-negative and < length(). The result of passing negative or out of
	// 			bounds values is undefined by this interface, just don't do it!
	// Returns: true if the bit is set, false otherwise.
	Test(index uint) bool

	// Len Returns the number of bits in this set
	Len() uint
}

Bits Interface for Bitset-like structures.

type IntroSelector

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

func NewIntroSelector

func NewIntroSelector(cfg *IntroSelectorConfig) *IntroSelector

func (*IntroSelector) Select

func (r *IntroSelector) Select(from, to, k int)

func (*IntroSelector) Swap

func (r *IntroSelector) Swap(i, j int)

type IntroSelectorConfig

type IntroSelectorConfig struct {
	FnSwap         func(i, j int)
	FnSetPivot     func(i int)
	FnComparePivot func(i int) int
	FnCompare      func(i, j int) int
}

type RefCount

type RefCount[T io.Closer] struct {
	// contains filtered or unexported fields
}

func NewRefCount

func NewRefCount[T io.Closer](object T, release func(r *RefCount[T]) error) *RefCount[T]

func (*RefCount[T]) DecRef

func (r *RefCount[T]) DecRef() error

DecRef Decrements the reference counting of this object. When reference counting hits 0, calls release().

func (*RefCount[T]) Get

func (r *RefCount[T]) Get() T

func (*RefCount[T]) GetRefCount

func (r *RefCount[T]) GetRefCount() int

GetRefCount Returns the current reference count.

func (*RefCount[T]) IncRef

func (r *RefCount[T]) IncRef()

IncRef Increments the reference count. Calls to this method must be matched with calls to decRef().

type Selector

type Selector interface {
	// Select Reorder elements so that the element at position k is the same as if all elements were
	// sorted and all other elements are partitioned around it: [from, k) only contains elements that
	// are less than or equal to k and (k, to) only contains elements that are greater than or equal to k.
	Select(from, to, k int)

	// Swap values at slots i and j.
	Swap(i, j int)
}

Selector An implementation of a selection algorithm, ie. computing the k-th greatest value from a collection.

Jump to

Keyboard shortcuts

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