utils

package
v1.12.0-initial-poc.8 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: BSD-3-Clause Imports: 9 Imported by: 236

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteIndex added in v1.11.13

func DeleteIndex[S ~[]E, E any](s S, i int) S

DeleteIndex moves the last element in the slice to index [i] and shrinks the size of the slice by 1.

This is an O(1) operation that allows the removal of an element from a slice when the order of the slice is not important.

If [i] is out of bounds, this function will panic.

func GetStacktrace added in v1.7.17

func GetStacktrace(all bool) string

func IsSortedAndUnique

func IsSortedAndUnique[T Sortable[T]](s []T) bool

Returns true iff the elements in [s] are unique and sorted.

func IsSortedAndUniqueByHash added in v1.9.4

func IsSortedAndUniqueByHash[T ~[]byte](s []T) bool

Returns true iff the elements in [s] are unique and sorted based by their hashes.

func IsSortedAndUniqueOrdered added in v1.9.4

func IsSortedAndUniqueOrdered[T cmp.Ordered](s []T) bool

Returns true iff the elements in [s] are unique and sorted.

func IsSortedBytes added in v1.10.3

func IsSortedBytes[T ~[]byte](s []T) bool

Returns true iff the elements in [s] are sorted.

func RandomBytes added in v1.3.2

func RandomBytes(n int) []byte

RandomBytes returns a slice of n random bytes Intended for use in testing

func Sort added in v1.9.4

func Sort[T Sortable[T]](s []T)

Sorts the elements of [s].

func SortByHash added in v1.9.4

func SortByHash[T ~[]byte](s []T)

Sorts the elements of [s] based on their hashes.

func Zero added in v1.8.0

func Zero[T any]() (_ T)

Returns a new instance of a T.

Types

type Atomic added in v1.9.8

type Atomic[T any] struct {
	// contains filtered or unexported fields
}

func NewAtomic added in v1.11.8

func NewAtomic[T any](value T) *Atomic[T]

func (*Atomic[T]) Get added in v1.9.8

func (a *Atomic[T]) Get() T

func (*Atomic[T]) MarshalJSON added in v1.11.8

func (a *Atomic[T]) MarshalJSON() ([]byte, error)

func (*Atomic[T]) Set added in v1.9.8

func (a *Atomic[T]) Set(value T)

func (*Atomic[T]) UnmarshalJSON added in v1.11.8

func (a *Atomic[T]) UnmarshalJSON(b []byte) error

type BytesPool added in v1.11.4

type BytesPool [intSize]sync.Pool

BytesPool tracks buckets of available buffers to be allocated. Each bucket allocates buffers of the following length:

0 1 3 7 15 31 63 127 ... MaxInt

In order to allocate a buffer of length 19 (for example), we calculate the number of bits required to represent 19 (5). And therefore allocate a slice from bucket 5, which has length 31. This is the bucket which produces the smallest slices that are at least length 19.

When replacing a buffer of length 19, we calculate the number of bits required to represent 20 (5). And therefore place the slice into bucket 4, which has length 15. This is the bucket which produces the largest slices that a length 19 slice can be used for.

func NewBytesPool added in v1.11.4

func NewBytesPool() *BytesPool

func (*BytesPool) Get added in v1.11.4

func (p *BytesPool) Get(length int) *[]byte

Get returns a non-nil pointer to a slice with the requested length.

It is not guaranteed for the returned bytes to have been zeroed.

func (*BytesPool) Put added in v1.11.4

func (p *BytesPool) Put(bytes *[]byte)

Put takes ownership of a non-nil pointer to a slice of bytes.

Note: this function takes ownership of the underlying array. So, the length of the provided slice is ignored and only its capacity is used.

type Sortable added in v1.9.4

type Sortable[T any] interface {
	Compare(T) int
}

Directories

Path Synopsis
crypto
bls
keychain/keychainmock
Package keychainmock is a generated GoMock package.
Package keychainmock is a generated GoMock package.
filesystemmock
Package filesystemmock is a generated GoMock package.
Package filesystemmock is a generated GoMock package.
hashingmock
Package hashingmock is a generated GoMock package.
Package hashingmock is a generated GoMock package.
resourcemock
Package resourcemock is a generated GoMock package.
Package resourcemock is a generated GoMock package.

Jump to

Keyboard shortcuts

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