Documentation ¶
Index ¶
- func Abs[T constraints.Integer | constraints.Float](val T) T
- func AdvanceReader(reader *Reader, n uint64) []byte
- func GenerateUniqueAlias() string
- func GetMapKeys[K comparable, V any](m map[K]V) []K
- func GetMapKeysSorted[K cmp.Ordered, V any](m map[K]V) []K
- func GetMapKeysSortedDescending[K cmp.Ordered, V any](m map[K]V) []K
- func GetMapValues[K comparable, V any](m map[K]V) []V
- func IsGeneratedAlias(alias string) bool
- func Max[T constraints.Ordered](vals ...T) (maximum T)
- func Min[T constraints.Ordered](vals ...T) (minimum T)
- func SliceToMapKeys[T comparable](slice []T) map[T]struct{}
- func SliceToMapValues[K comparable, V any](slice []V, getKey func(V) K) map[K]V
- func StartProfiling(options ProfilingOptions)
- func StopProfiling()
- type KeyValue
- type ProfilingOptions
- type Reader
- func (reader *Reader) Bool() bool
- func (reader *Reader) BoolSlice() []bool
- func (reader *Reader) Byte() byte
- func (reader *Reader) ByteSlice() []byte
- func (reader *Reader) BytesRead() uint64
- func (reader *Reader) Float32() float32
- func (reader *Reader) Float32Slice() []float32
- func (reader *Reader) Float64() float64
- func (reader *Reader) Float64Slice() []float64
- func (reader *Reader) Int16() int16
- func (reader *Reader) Int16Slice() []int16
- func (reader *Reader) Int32() int32
- func (reader *Reader) Int32Slice() []int32
- func (reader *Reader) Int64() int64
- func (reader *Reader) Int64Slice() []int64
- func (reader *Reader) Int8() int8
- func (reader *Reader) Int8Slice() []int8
- func (reader *Reader) Internal() id.Internal
- func (reader *Reader) IsEmpty() bool
- func (reader *Reader) RemainingBytes() uint64
- func (reader *Reader) String() string
- func (reader *Reader) StringSlice() []string
- func (reader *Reader) Uint16() uint16
- func (reader *Reader) Uint16Slice() []uint16
- func (reader *Reader) Uint32() uint32
- func (reader *Reader) Uint32Slice() []uint32
- func (reader *Reader) Uint64() uint64
- func (reader *Reader) Uint64Slice() []uint64
- func (reader *Reader) Uint8() uint8
- func (reader *Reader) Uint8Slice() []uint8
- func (reader *Reader) VariableInt() int64
- func (reader *Reader) VariableIntSlice() []int64
- func (reader *Reader) VariableUint() uint64
- func (reader *Reader) VariableUintSlice() []uint64
- type Stack
- type Writer
- func (writer *Writer) Bool(val bool)
- func (writer *Writer) BoolSlice(vals []bool)
- func (writer *Writer) Byte(val byte)
- func (writer *Writer) ByteSlice(vals []byte)
- func (writer *Writer) Data() []byte
- func (writer *Writer) Float32(val float32)
- func (writer *Writer) Float32Slice(vals []float32)
- func (writer *Writer) Float64(val float64)
- func (writer *Writer) Float64Slice(vals []float64)
- func (writer *Writer) Int16(val int16)
- func (writer *Writer) Int16Slice(vals []int16)
- func (writer *Writer) Int32(val int32)
- func (writer *Writer) Int32Slice(vals []int32)
- func (writer *Writer) Int64(val int64)
- func (writer *Writer) Int64Slice(vals []int64)
- func (writer *Writer) Int8(val int8)
- func (writer *Writer) Int8Slice(vals []int8)
- func (writer *Writer) Internal(val id.Internal)
- func (writer *Writer) Reset()
- func (writer *Writer) String(val string)
- func (writer *Writer) StringSlice(vals []string)
- func (writer *Writer) Uint16(val uint16)
- func (writer *Writer) Uint16Slice(vals []uint16)
- func (writer *Writer) Uint32(val uint32)
- func (writer *Writer) Uint32Slice(vals []uint32)
- func (writer *Writer) Uint64(val uint64)
- func (writer *Writer) Uint64Slice(vals []uint64)
- func (writer *Writer) Uint8(val uint8)
- func (writer *Writer) Uint8Slice(vals []uint8)
- func (writer *Writer) VariableInt(val int64)
- func (writer *Writer) VariableIntSlice(vals []int64)
- func (writer *Writer) VariableUint(val uint64)
- func (writer *Writer) VariableUintSlice(vals []uint64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶ added in v0.4.0
func Abs[T constraints.Integer | constraints.Float](val T) T
Abs returns the absolute value of the given number.
func AdvanceReader ¶ added in v0.13.0
AdvanceReader reads the next N bytes from the given Reader. This is only available for specific, performance-oriented circumstances, and should never be used otherwise. This is a standalone function to discourage its use, as it will not show up as a function of the Reader object in most IDEs. This uses a branchless comparison to limit the size of n to the end of the reader, and it does not allocate a new byte slice (returns a portion from the original byte slice).
func GenerateUniqueAlias ¶ added in v0.2.0
func GenerateUniqueAlias() string
GenerateUniqueAlias generates a unique alias. This is thread-safe.
func GetMapKeys ¶ added in v0.2.0
func GetMapKeys[K comparable, V any](m map[K]V) []K
GetMapKeys returns the map's keys as an unsorted slice.
func GetMapKeysSorted ¶ added in v0.2.0
GetMapKeysSorted returns the map's keys as a sorted slice. The keys are sorted in ascending order. For descending order, use GetMapKeysSortedDescending.
func GetMapKeysSortedDescending ¶ added in v0.2.0
GetMapKeysSortedDescending returns the map's keys as a sorted slice. The keys are sorted in descending order. For ascending order, use GetMapKeysSorted.
func GetMapValues ¶ added in v0.2.0
func GetMapValues[K comparable, V any](m map[K]V) []V
GetMapValues returns the map's values as a slice. Due to Go's map iteration, the values will be in a non-deterministic order.
func IsGeneratedAlias ¶ added in v0.2.0
IsGeneratedAlias returns whether the given alias was generated using GenerateUniqueAlias.
func Max ¶ added in v0.4.0
func Max[T constraints.Ordered](vals ...T) (maximum T)
Max returns the largest value of the given parameters. If no parameters are given, then returns the default value for the type.
func Min ¶ added in v0.4.0
func Min[T constraints.Ordered](vals ...T) (minimum T)
Min returns the smallest value of the given parameters.
func SliceToMapKeys ¶ added in v0.2.0
func SliceToMapKeys[T comparable](slice []T) map[T]struct{}
SliceToMapKeys converts the given slice into a map where all of the keys are represented by all of the slice's values.
func SliceToMapValues ¶ added in v0.2.0
func SliceToMapValues[K comparable, V any](slice []V, getKey func(V) K) map[K]V
SliceToMapValues converts the given slice into a map where all of the slice's values are keyed by the output of the `getKey` function, which takes a value and returns a key. It is up to the caller to return a unique key.
func StartProfiling ¶ added in v0.10.0
func StartProfiling(options ProfilingOptions)
StartProfiling starts profiling the CPU.
Types ¶
type KeyValue ¶ added in v0.12.0
type KeyValue[K comparable, V any] struct { Key K Value V }
KeyValue represents an entry in a map.
func GetMapKVs ¶ added in v0.12.0
func GetMapKVs[K comparable, V any](m map[K]V) []KeyValue[K, V]
GetMapKVs returns the map's KeyValue entries as an unsorted slice.
func GetMapKVsSorted ¶ added in v0.12.0
GetMapKVsSorted returns the map's KeyValue entries as a sorted slice. The keys are sorted in ascending order. For descending order, use GetMapKVsSortedDescending.
type ProfilingOptions ¶ added in v0.10.0
ProfilingOptions contains all options for starting the profiler.
func (ProfilingOptions) HasOptions ¶ added in v0.10.0
func (options ProfilingOptions) HasOptions() bool
HasOptions returns true when at least one profiler target has been selected.
type Reader ¶ added in v0.7.5
type Reader struct {
// contains filtered or unexported fields
}
Reader handles type-safe reading from a byte slice, which was created by a Writer. This is not safe for concurrent use.
func (*Reader) Byte ¶ added in v0.7.5
Byte reads a byte. This is equivalent to Uint8, but is included since it is more common to refer to a byte rather than a uint8.
func (*Reader) ByteSlice ¶ added in v0.7.5
ByteSlice reads a byte slice. This is equivalent to Uint8Slice, but is included since it is more common to refer to byte slices than uint8 slices.
func (*Reader) BytesRead ¶ added in v0.14.0
BytesRead returns the number of bytes that have been read.
func (*Reader) Float32Slice ¶ added in v0.7.5
Float32Slice reads a float32 slice.
func (*Reader) Float64Slice ¶ added in v0.7.5
Float64Slice reads a float64 slice.
func (*Reader) Int16Slice ¶ added in v0.7.5
Int16Slice reads an int16 slice.
func (*Reader) Int32Slice ¶ added in v0.7.5
Int32Slice reads an int32 slice.
func (*Reader) Int64Slice ¶ added in v0.7.5
Int64Slice reads an int64 slice.
func (*Reader) RemainingBytes ¶ added in v0.7.5
RemainingBytes returns the number of bytes that have not yet been read.
func (*Reader) StringSlice ¶ added in v0.7.5
StringSlice reads a string slice.
func (*Reader) Uint16Slice ¶ added in v0.7.5
Uint16Slice reads a uint16 slice.
func (*Reader) Uint32Slice ¶ added in v0.7.5
Uint32Slice reads a uint32 slice.
func (*Reader) Uint64Slice ¶ added in v0.7.5
Uint64Slice reads a uint64 slice.
func (*Reader) Uint8Slice ¶ added in v0.7.5
Uint8Slice reads a uint8 slice.
func (*Reader) VariableInt ¶ added in v0.7.5
VariableInt reads an int64 that was written using variable-length encoding.
func (*Reader) VariableIntSlice ¶ added in v0.7.5
VariableIntSlice reads an int64 slice that was written using variable-length encoding.
func (*Reader) VariableUint ¶ added in v0.7.5
VariableUint reads a uint64 that was written using variable-length encoding.
func (*Reader) VariableUintSlice ¶ added in v0.7.5
VariableUintSlice reads a uint64 slice that was written using variable-length encoding.
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack is a generic stack.
func (*Stack[T]) Peek ¶
func (s *Stack[T]) Peek() (value T)
Peek returns the top value on the stack without removing it.
func (*Stack[T]) PeekDepth ¶
PeekDepth returns the n-th value from the top. PeekDepth(0) is equivalent to the standard Peek().
func (*Stack[T]) PeekReference ¶
func (s *Stack[T]) PeekReference() *T
PeekReference returns a reference to the top value on the stack without removing it.
type Writer ¶ added in v0.7.5
type Writer struct {
// contains filtered or unexported fields
}
Writer handles type-safe writing into a byte buffer, which may later be read from using Reader. The Writer will automatically grow as it is written to. The serialized forms of booleans, ints, uints, and floats are byte-comparable, meaning it is valid to use bytes.Compare() without needing to deserialize them. Variable-length encoded values, strings, and slices are not byte-comparable. This is not safe for concurrent use.
func NewWriter ¶ added in v0.7.5
NewWriter creates a new Writer with the given starting capacity. A larger starting capacity reduces reallocations at the cost of potentially wasted memory.
func (*Writer) Byte ¶ added in v0.7.5
Byte writes a byte. This is equivalent to Uint8, but is included since it is more common to refer to a byte rather than a uint8.
func (*Writer) ByteSlice ¶ added in v0.7.5
ByteSlice writes a byte slice. This is equivalent to Uint8Slice, but is included since it is more common to refer to byte slices than uint8 slices.
func (*Writer) Float32Slice ¶ added in v0.7.5
Float32Slice writes a float32 slice.
func (*Writer) Float64Slice ¶ added in v0.7.5
Float64Slice writes a float64 slice.
func (*Writer) Int16Slice ¶ added in v0.7.5
Int16Slice writes an int16 slice.
func (*Writer) Int32Slice ¶ added in v0.7.5
Int32Slice writes an int32 slice.
func (*Writer) Int64Slice ¶ added in v0.7.5
Int64Slice writes an int64 slice.
func (*Writer) Reset ¶ added in v0.8.0
func (writer *Writer) Reset()
Reset resets the Writer to be empty, but it retains the underlying storage for use by future writes.
func (*Writer) StringSlice ¶ added in v0.7.5
StringSlice writes a string slice.
func (*Writer) Uint16Slice ¶ added in v0.7.5
Uint16Slice writes a uint16 slice.
func (*Writer) Uint32Slice ¶ added in v0.7.5
Uint32Slice writes a uint32 slice.
func (*Writer) Uint64Slice ¶ added in v0.7.5
Uint64Slice writes a uint64 slice.
func (*Writer) Uint8Slice ¶ added in v0.7.5
Uint8Slice writes a uint8 slice.
func (*Writer) VariableInt ¶ added in v0.7.5
VariableInt writes an int64 using variable-length encoding. Smaller values use less space at the cost of larger values using more bytes, but this is generally more space-efficient. This does carry a small computational hit when reading.
func (*Writer) VariableIntSlice ¶ added in v0.7.5
VariableIntSlice writes an int64 slice using variable-length encoding. Smaller values use less space at the cost of larger values using more space, but this is generally more space-efficient. This does carry a computational hit when reading.
func (*Writer) VariableUint ¶ added in v0.7.5
VariableUint writes a uint64 using variable-length encoding. Smaller values use less space at the cost of larger values using more bytes, but this is generally more space-efficient. This does carry a small computational hit when reading.
func (*Writer) VariableUintSlice ¶ added in v0.7.5
VariableUintSlice writes a uint64 slice using variable-length encoding. Smaller values use less space at the cost of larger values using more space, but this is generally more space-efficient. This does carry a computational hit when reading.