genh

package module
v0.0.0-...-b53f8ce Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: BSD-3-Clause Imports: 18 Imported by: 4

README

genh

PkgGoDev

A Random collection of helpers for Go generics.

License: BSD-style license (same as go)

Documentation

Overview

Package slices defines various functions useful with slices of any type. Unless otherwise specified, these functions all apply to the elements of a slice at index 0 <= i < len(s).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T Integer | Float](v T) T

func BinarySearch

func BinarySearch[E Ordered](x []E, target E) (int, bool)

BinarySearch searches for target in a sorted slice and returns the position where target is found, or the position where target would appear in the sort order; it also returns a bool saying whether the target is really found in the slice. The slice must be sorted in increasing order.

func BinarySearchFunc

func BinarySearchFunc[E any](x []E, cmp func(E) int) (int, bool)

BinarySearchFunc works like BinarySearch, but uses a custom comparison function. The slice must be sorted in increasing order, where "increasing" is defined by cmp. cmp(a, b) is expected to return an integer comparing the two parameters: 0 if a == b, a negative number if a < b and a positive number if a > b.

func ChanToSlice

func ChanToSlice[T any](s <-chan T, cap int) []T

func Clip

func Clip[S ~[]E, E any](s S) S

Clip removes unused capacity from the slice, returning s[:len(s):len(s)].

func Clone

func Clone[T any](v T, keepPrivateFields bool) (cp T)

func ClosedChan

func ClosedChan[T any]() chan T

func Compact

func Compact[S ~[]E, E comparable](s S) S

Compact replaces consecutive runs of equal elements with a single copy. This is like the uniq command found on Unix. Compact modifies the contents of the slice s; it does not create a new slice.

func CompactFunc

func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S

CompactFunc is like Compact but uses a comparison function.

func Compare

func Compare[S ~[]E, E Ordered](s1, s2 S) int

Compare compares the elements of s1 and s2. The elements are compared sequentially, starting at index 0, until one element is not equal to the other. The result of comparing the first non-matching elements is returned. If both slices are equal until one of them ends, the shorter slice is considered less than the longer one. The result is 0 if s1 == s2, -1 if s1 < s2, and +1 if s1 > s2. Comparisons involving floating point NaNs are ignored.

func CompareFunc

func CompareFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, cmp func(E1, E2) int) int

CompareFunc is like Compare but uses a comparison function on each pair of elements. The elements are compared in increasing index order, and the comparisons stop after the first time cmp returns non-zero. The result is the first non-zero result of cmp; if cmp always returns 0 the result is 0 if len(s1) == len(s2), -1 if len(s1) < len(s2), and +1 if len(s1) > len(s2).

func Contains

func Contains[S ~[]E, E comparable](s S, v E) bool

Contains reports whether v is present in s.

func ContainsFunc

func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool

ContainsFunc reports whether f(v) is present in s.

func Decode

func Decode[T any, DecT DecoderType](r io.Reader, fn func(r io.Reader) DecT) (v T, err error)

func DecodeFile

func DecodeFile[T any, DecT DecoderType](fp string, fn func(r io.Reader) DecT) (v T, err error)

func DecodeMsgpack

func DecodeMsgpack(r io.Reader, vs ...any) error

func Delete

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

Delete removes the elements s[i:j] from s, returning the modified slice. Delete panics if s[i:j] is not a valid slice of s. Delete modifies the contents of the slice s; it does not create a new slice. Delete is O(len(s)-(j-i)), so if many items must be deleted, it is better to make a single call deleting them all together than to delete one at a time.

func DieIf

func DieIf(tb testingTB, err error, args ...any)

func Encode

func Encode[EncT TypeEncoder](w io.Writer, v any, fn func(w io.Writer) EncT) (err error)

func EncodeFile

func EncodeFile[EncT TypeEncoder](fp string, v any, fn func(w io.Writer) EncT) (err error)

func EncodeMsgpack

func EncodeMsgpack(w io.Writer, vs ...any) error

func Equal

func Equal[S ~[]E, E comparable](s1, s2 S) bool

Equal reports whether two slices are equal: the same length and all elements equal. If the lengths are different, Equal returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first unequal pair. Floating point NaNs are not considered equal.

func EqualFunc

func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) bool) bool

EqualFunc reports whether two slices are equal using a comparison function on each pair of elements. If the lengths are different, EqualFunc returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first index for which eq returns false.

func ErrorIf

func ErrorIf(tb testingTB, err error, args ...any) bool

func Filter

func Filter[S ~[]E, E any](in S, f func(E) (keep bool), inplace bool) (out S)

Filter filters a slice optionally in place.

func FirstNonZero

func FirstNonZero[T any](args ...T) T

func FirstNonZeroCmp

func FirstNonZeroCmp[T comparable](args ...T) T

func FirstNonZeroPtr

func FirstNonZeroPtr[T any](args ...*T) *T

func GroupBy

func GroupBy[M ~map[MapKey]MapVal, GM map[MapKey][]MapVal, MapKey comparable, MapVal any](in M, fn func(k MapKey, v MapVal) MapKey) (out GM)

func Grow

func Grow[S ~[]E, E any](s S, n int) S

Grow increases the slice's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the slice without another allocation. Grow may modify elements of the slice between the length and the capacity. If n is negative or too large to allocate the memory, Grow panics.

func Iff

func Iff[T any](cond bool, a, b T) T

func IffFn

func IffFn[T any](cond bool, a, b func() T) T

func Index

func Index[S ~[]E, E comparable](s S, v E) int

Index returns the index of the first occurrence of v in s, or -1 if not present.

func IndexFunc

func IndexFunc[S ~[]E, E any](s S, f func(E) bool) int

IndexFunc returns the first index i satisfying f(s[i]), or -1 if none do.

func Insert

func Insert[S ~[]E, E any](s S, i int, v ...E) S

Insert inserts the values v... into s at index i, returning the modified slice. In the returned slice r, r[i] == v[0]. Insert panics if i is out of range. This function is O(len(s) + len(v)).

func IsSorted

func IsSorted[E Ordered](x []E) bool

IsSorted reports whether x is sorted in ascending order.

func IsSortedFunc

func IsSortedFunc[E any](x []E, less func(a, b E) bool) bool

IsSortedFunc reports whether x is sorted in ascending order, with less as the comparison function.

func ListToMap

func ListToMap[K comparable, V any](l List[V], keyFn func(v V) K) map[K]V

func MapClear

func MapClear[M ~map[K]V, K comparable, V any](m M)

MapClear removes all entries from m, leaving it empty.

func MapClone

func MapClone[M ~map[K]V, K comparable, V any](m M) M

Clone returns a copy of m. This is a shallow clone: the new keys and values are set using ordinary assignment.

func MapCopy

func MapCopy[M ~map[K]V, K comparable, V any](dst, src M)

MapCopy copies all key/value pairs in src adding them to dst. When a key in src is already present in dst, the value in dst will be overwritten by the value associated with the key in src.

func MapDeleteFunc

func MapDeleteFunc[M ~map[K]V, K comparable, V any](m M, del func(K, V) bool)

MapDeleteFunc deletes any key/value pairs from m for which del returns true.

func MapEqual

func MapEqual[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool

Equal reports whether two maps contain the same key/value pairs. Values are compared using ==.

func MapEqualFunc

func MapEqualFunc[M1 ~map[K]V1, M2 ~map[K]V2, K comparable, V1, V2 any](m1 M1, m2 M2, eq func(V1, V2) bool) bool

EqualFunc is like Equal, but compares values using eq. Keys are still compared with ==.

func MapFilter

func MapFilter[M ~map[K]V, K comparable, V any](m M, fn func(K, V) bool, inplace bool) (out M)

MapFilter

func MapKeys

func MapKeys[M ~map[K]V, K comparable, V any](m M) []K

Keys returns the keys of the map m. The keys will be in an indeterminate order.

func MapValues

func MapValues[M ~map[K]V, K comparable, V any](m M) []V

MapValues returns the values of the map m. The values will be in an indeterminate order.

func MarshalMsgpack

func MarshalMsgpack(v any) ([]byte, error)

func Max

func Max[T Ordered](a, b T) T

func Min

func Min[T Ordered](a, b T) T

func PanicIf

func PanicIf(lg *log.Logger, err error, args ...any)

func Ptr

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

func PtrVal

func PtrVal[T any](v *T) (_ T)

func PtrsToValues

func PtrsToValues[T any](vals []*T) []T

func PutMsgpackDecoder

func PutMsgpackDecoder(dec *MsgpackDecoder)

func PutMsgpackEncoder

func PutMsgpackEncoder(enc *MsgpackEncoder)

func ReflectClone

func ReflectClone(dst, src reflect.Value, keepPrivateFields bool)

func SafeChan

func SafeChan[T any](cap int) (ch <-chan T, pushFn func(T) bool, closeFn func())
func Search(n int, f func(int) bool) int

func SliceClone

func SliceClone[S ~[]E, E any](s S) S

SliceClone returns a copy of the slice. The elements are copied using assignment, so this is a shallow clone.

func SliceMap

func SliceMap[S ~[]E, E, T any](in S, fn func(E) T) []T

SliceMap takes a slice of type E, calls fn on each value of `in` and returns the results as a slice of type `T`

func SliceMapFilter

func SliceMapFilter[S ~[]E, E, T any](in S, fn func(E) (val T, ignore bool)) []T

SliceMapFilter merged SliceMap and Filter

func SliceMapFilterSameType

func SliceMapFilterSameType[S ~[]E, E any](in S, fn func(E) (val E, ignore bool), inplace bool) (out S)

SliceMapFilter merged SliceMapSameType and Filter

func SliceMapSameType

func SliceMapSameType[S ~[]E, E any](in S, fn func(E) E, inplace bool) (out S)

SliceMap takes a slice of type E, calls fn on each value of `in` and returns the modified in or a copy of it

func SliceToChan

func SliceToChan[T any](s []T, cap int) <-chan T

func Sort

func Sort[E Ordered](x []E)

Sort sorts a slice of any ordered type in ascending order. Sort may fail to sort correctly when sorting slices of floating-point numbers containing Not-a-number (NaN) values. Use slices.SortFunc(x, func(a, b float64) bool {return a < b || (math.IsNaN(a) && !math.IsNaN(b))}) instead if the input may contain NaNs.

func SortFunc

func SortFunc[E any](x []E, less func(a, b E) bool)

SortFunc sorts the slice x in ascending order as determined by the less function. This sort is not guaranteed to be stable.

SortFunc requires that less is a strict weak ordering. See https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings.

func SortStableFunc

func SortStableFunc[E any](x []E, less func(a, b E) bool)

SortStable sorts the slice x while keeping the original order of equal elements, using less to compare elements.

func UnmarshalMsgpack

func UnmarshalMsgpack(b []byte, v any) error

func ValuesToPtrs

func ValuesToPtrs[T any](vals []T, copy bool) []*T

ValuesToPtrs converts a slice of values to a slice of pointers optionally copying the values instead of pointing to them in the original slice.

func Zero

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

Types

type AtomicBool

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

func (*AtomicBool) CompareAndSwap

func (v *AtomicBool) CompareAndSwap(old, new bool) bool

func (*AtomicBool) Load

func (v *AtomicBool) Load() bool

func (*AtomicBool) MarshalBinary

func (v *AtomicBool) MarshalBinary() ([]byte, error)

func (*AtomicBool) MarshalJSON

func (v *AtomicBool) MarshalJSON() ([]byte, error)

func (*AtomicBool) Store

func (v *AtomicBool) Store(val bool)

func (*AtomicBool) Swap

func (v *AtomicBool) Swap(val bool) (old bool)

func (*AtomicBool) UnmarshalBinary

func (v *AtomicBool) UnmarshalBinary(b []byte) error

func (*AtomicBool) UnmarshalJSON

func (v *AtomicBool) UnmarshalJSON(b []byte) error

type AtomicFloat64

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

func (*AtomicFloat64) Add

func (v *AtomicFloat64) Add(val float64) float64

func (*AtomicFloat64) CompareAndSwap

func (v *AtomicFloat64) CompareAndSwap(old, new float64) bool

func (*AtomicFloat64) Load

func (v *AtomicFloat64) Load() float64

func (*AtomicFloat64) MarshalBinary

func (v *AtomicFloat64) MarshalBinary() ([]byte, error)

func (*AtomicFloat64) MarshalJSON

func (v *AtomicFloat64) MarshalJSON() ([]byte, error)

func (*AtomicFloat64) Store

func (v *AtomicFloat64) Store(val float64)

func (*AtomicFloat64) Swap

func (v *AtomicFloat64) Swap(val float64) (old float64)

func (*AtomicFloat64) UnmarshalBinary

func (v *AtomicFloat64) UnmarshalBinary(b []byte) error

func (*AtomicFloat64) UnmarshalJSON

func (v *AtomicFloat64) UnmarshalJSON(b []byte) error

type AtomicInt

type AtomicInt = signedValue64[int]

type AtomicInt16

type AtomicInt16 = signedValue32[int16]

type AtomicInt32

type AtomicInt32 = signedValue32[int32]

type AtomicInt64

type AtomicInt64 = signedValue64[int64]

type AtomicInt8

type AtomicInt8 = signedValue32[int8]

type AtomicUint

type AtomicUint = unsignedValue64[uint]

type AtomicUint16

type AtomicUint16 = unsignedValue32[uint16]

type AtomicUint32

type AtomicUint32 = unsignedValue32[uint32]

type AtomicUint64

type AtomicUint64 = unsignedValue64[uint64]

type AtomicUint8

type AtomicUint8 = unsignedValue32[uint8]

type AtomicUintptr

type AtomicUintptr = unsignedValue64[uintptr]

type Cloner

type Cloner[T any] interface {
	Clone() T
}

type Complex

type Complex = internal.Complex

type DecoderType

type DecoderType = internal.DecoderType

type EncoderType

type EncoderType = internal.EncoderType

type Float

type Float = internal.Float

type Float64List

type Float64List = List[float64]

type Int64List

type Int64List = List[int64]

type Integer

type Integer = internal.Integer

type LList

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

func (*LList[T]) Append

func (l *LList[T]) Append(vs ...T) *LList[T]

func (*LList[T]) Clear

func (l *LList[T]) Clear()

func (*LList[T]) ForEach

func (l *LList[T]) ForEach(fn func(v T) bool)

func (*LList[T]) Len

func (l *LList[T]) Len() int

func (*LList[T]) Push

func (l *LList[T]) Push(vs ...T)

func (*LList[T]) Raw

func (l *LList[T]) Raw() List[T]

type LMap

type LMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func LMapOf

func LMapOf[K comparable, V any](m map[K]V) *LMap[K, V]

func NewLMap

func NewLMap[K comparable, V any](sz int) *LMap[K, V]

func (*LMap[K, V]) Clear

func (lm *LMap[K, V]) Clear()

func (*LMap[K, V]) Clone

func (lm *LMap[K, V]) Clone() (m map[K]V)

func (*LMap[K, V]) Delete

func (lm *LMap[K, V]) Delete(k K)

func (*LMap[K, V]) DeleteGet

func (lm *LMap[K, V]) DeleteGet(k K) V

func (*LMap[K, V]) ForEach

func (lm *LMap[K, V]) ForEach(fn func(k K, v V) bool)

func (*LMap[K, V]) Get

func (lm *LMap[K, V]) Get(k K) (v V)

func (*LMap[K, V]) Keys

func (lm *LMap[K, V]) Keys() (keys []K)

func (*LMap[K, V]) Len

func (lm *LMap[K, V]) Len() (v int)

func (*LMap[K, V]) MarshalBinary

func (lm *LMap[K, V]) MarshalBinary() ([]byte, error)

func (*LMap[K, V]) MarshalJSON

func (lm *LMap[K, V]) MarshalJSON() ([]byte, error)

func (*LMap[K, V]) MustGet

func (lm *LMap[K, V]) MustGet(k K, fn func() V) V

func (*LMap[K, V]) Raw

func (lm *LMap[K, V]) Raw() map[K]V

func (*LMap[K, V]) Read

func (lm *LMap[K, V]) Read(fn func(m map[K]V))

func (*LMap[K, V]) Set

func (lm *LMap[K, V]) Set(k K, v V)

func (*LMap[K, V]) SetMap

func (lm *LMap[K, V]) SetMap(m map[K]V) (old map[K]V)

func (*LMap[K, V]) Swap

func (lm *LMap[K, V]) Swap(k K, v V) V

func (*LMap[K, V]) UnmarshalBinary

func (lm *LMap[K, V]) UnmarshalBinary(p []byte) error

func (*LMap[K, V]) UnmarshalJSON

func (lm *LMap[K, V]) UnmarshalJSON(p []byte) error

func (*LMap[K, V]) Update

func (lm *LMap[K, V]) Update(fn func(m map[K]V))

func (*LMap[K, V]) UpdateKey

func (lm *LMap[K, V]) UpdateKey(k K, fn func(V) V)

func (*LMap[K, V]) Values

func (lm *LMap[K, V]) Values() (values []V)

type LMultiMap

type LMultiMap[K1, K2 comparable, V any] struct {
	// contains filtered or unexported fields
}

LMultiMap is a locked multimap

func NewLMultiMap

func NewLMultiMap[K1, K2 comparable, V any](sz int) *LMultiMap[K1, K2, V]

func (*LMultiMap[K1, K2, V]) Clear

func (lm *LMultiMap[K1, K2, V]) Clear()

func (*LMultiMap[K1, K2, V]) ClearChild

func (lm *LMultiMap[K1, K2, V]) ClearChild(k1 K1)

func (*LMultiMap[K1, K2, V]) Clone

func (lm *LMultiMap[K1, K2, V]) Clone() (m map[K1]map[K2]V)

func (*LMultiMap[K1, K2, V]) Delete

func (lm *LMultiMap[K1, K2, V]) Delete(k1 K1)

func (*LMultiMap[K1, K2, V]) DeleteChild

func (lm *LMultiMap[K1, K2, V]) DeleteChild(k1 K1, k2 K2)

func (*LMultiMap[K1, K2, V]) DeleteGet

func (lm *LMultiMap[K1, K2, V]) DeleteGet(k1 K1) map[K2]V

func (*LMultiMap[K1, K2, V]) DeleteGetChild

func (lm *LMultiMap[K1, K2, V]) DeleteGetChild(k1 K1, k2 K2) V

func (*LMultiMap[K1, K2, V]) ForEach

func (lm *LMultiMap[K1, K2, V]) ForEach(fn func(k1 K1, m map[K2]V) bool, rw bool)

func (*LMultiMap[K1, K2, V]) ForEachChild

func (lm *LMultiMap[K1, K2, V]) ForEachChild(k1 K1, fn func(k2 K2, v V) bool)

func (*LMultiMap[K1, K2, V]) Get

func (lm *LMultiMap[K1, K2, V]) Get(k1 K1, k2 K2) (v V)

func (*LMultiMap[K1, K2, V]) GetChild

func (lm *LMultiMap[K1, K2, V]) GetChild(k1 K1, copy bool) map[K2]V

func (*LMultiMap[K1, K2, V]) Keys

func (lm *LMultiMap[K1, K2, V]) Keys() (keys []K1)

func (*LMultiMap[K1, K2, V]) KeysChild

func (lm *LMultiMap[K1, K2, V]) KeysChild(k1 K1) (keys []K2)

func (*LMultiMap[K1, K2, V]) Len

func (lm *LMultiMap[K1, K2, V]) Len() (v int)

func (*LMultiMap[K1, K2, V]) LenChild

func (lm *LMultiMap[K1, K2, V]) LenChild(k K1) (v int)

func (*LMultiMap[K1, K2, V]) MarshalBinary

func (lm *LMultiMap[K1, K2, V]) MarshalBinary() ([]byte, error)

func (*LMultiMap[K1, K2, V]) MarshalJSON

func (lm *LMultiMap[K1, K2, V]) MarshalJSON() ([]byte, error)

func (*LMultiMap[K1, K2, V]) MustGet

func (lm *LMultiMap[K1, K2, V]) MustGet(k1 K1, k2 K2, fn func() V) V

func (*LMultiMap[K1, K2, V]) Raw

func (lm *LMultiMap[K1, K2, V]) Raw() map[K1]map[K2]V

func (*LMultiMap[K1, K2, V]) Read

func (lm *LMultiMap[K1, K2, V]) Read(fn func(m map[K1]map[K2]V))

func (*LMultiMap[K1, K2, V]) ReadChild

func (lm *LMultiMap[K1, K2, V]) ReadChild(k K1, fn func(m map[K2]V))

func (*LMultiMap[K1, K2, V]) Set

func (lm *LMultiMap[K1, K2, V]) Set(k1 K1, k2 K2, v V)

func (*LMultiMap[K1, K2, V]) SetChild

func (lm *LMultiMap[K1, K2, V]) SetChild(k1 K1, v map[K2]V)

func (*LMultiMap[K1, K2, V]) SetMap

func (lm *LMultiMap[K1, K2, V]) SetMap(m map[K1]map[K2]V) (old map[K1]map[K2]V)

func (*LMultiMap[K1, K2, V]) UnmarshalBinary

func (lm *LMultiMap[K1, K2, V]) UnmarshalBinary(p []byte) error

func (*LMultiMap[K1, K2, V]) UnmarshalJSON

func (lm *LMultiMap[K1, K2, V]) UnmarshalJSON(p []byte) error

func (*LMultiMap[K1, K2, V]) Update

func (lm *LMultiMap[K1, K2, V]) Update(k1 K1, fn func(m map[K2]V) map[K2]V)

func (*LMultiMap[K1, K2, V]) Values

func (lm *LMultiMap[K1, K2, V]) Values(copy bool) (values []map[K2]V)

func (*LMultiMap[K1, K2, V]) ValuesChild

func (lm *LMultiMap[K1, K2, V]) ValuesChild(k1 K1) (values []V)

type LSlice

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

func (*LSlice[T]) Append

func (ls *LSlice[T]) Append(vs ...T)

func (*LSlice[T]) Cap

func (ls *LSlice[T]) Cap() int

func (*LSlice[T]) Clip

func (ls *LSlice[T]) Clip()

func (*LSlice[T]) ClipTo

func (ls *LSlice[T]) ClipTo(len_, cap_ int)

func (*LSlice[T]) Clone

func (ls *LSlice[T]) Clone() []T

func (*LSlice[T]) Delete

func (ls *LSlice[T]) Delete(i, j int)

func (*LSlice[T]) Filter

func (ls *LSlice[T]) Filter(fn func(T) bool, inplace bool) *LSlice[T]

func (*LSlice[T]) ForEach

func (ls *LSlice[T]) ForEach(fn func(i int, v T) bool)

func (*LSlice[T]) Get

func (ls *LSlice[T]) Get(i int) T

func (*LSlice[T]) Grow

func (ls *LSlice[T]) Grow(sz int)

func (*LSlice[T]) Insert

func (ls *LSlice[T]) Insert(i int, vs ...T)

func (*LSlice[T]) LClone

func (ls *LSlice[T]) LClone() *LSlice[T]

func (*LSlice[T]) Len

func (ls *LSlice[T]) Len() int

func (*LSlice[T]) Map

func (ls *LSlice[T]) Map(fn func(T) T, inplace bool) *LSlice[T]

func (*LSlice[T]) MarshalBinary

func (ls *LSlice[T]) MarshalBinary() ([]byte, error)

func (*LSlice[T]) MarshalJSON

func (ls *LSlice[T]) MarshalJSON() ([]byte, error)

func (*LSlice[T]) Raw

func (ls *LSlice[T]) Raw() []T

func (*LSlice[T]) Search

func (ls *LSlice[T]) Search(cmpFn func(v T) int) (v T, found bool)

func (*LSlice[T]) Set

func (ls *LSlice[T]) Set(i int, v T)

func (*LSlice[T]) SetSlice

func (ls *LSlice[T]) SetSlice(v []T)

func (*LSlice[T]) Sort

func (ls *LSlice[T]) Sort(lessFn func(a, b T) bool)

func (*LSlice[T]) Swap

func (ls *LSlice[T]) Swap(i int, v T) (old T)

func (*LSlice[T]) UnmarshalBinary

func (ls *LSlice[T]) UnmarshalBinary(p []byte) error

func (*LSlice[T]) UnmarshalJSON

func (ls *LSlice[T]) UnmarshalJSON(p []byte) error

func (*LSlice[T]) Update

func (ls *LSlice[T]) Update(fn func(v []T) []T)

type LValue

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

LValue wraps a sync.RWMutex to allow simple and safe operation on the mutex.

func (*LValue[T]) CompareAndSwap

func (m *LValue[T]) CompareAndSwap(old, new T, eq func(a, b T) bool) (ok bool)

func (*LValue[T]) Get

func (m *LValue[T]) Get() T

func (*LValue[T]) MarshalBinary

func (m *LValue[T]) MarshalBinary() ([]byte, error)

func (*LValue[T]) MarshalJSON

func (m *LValue[T]) MarshalJSON() ([]byte, error)

func (*LValue[T]) Read

func (m *LValue[T]) Read(fn func(v T))

Read executes fn while the mutex is read-locked and guarantees the mutex is released even in the case of a panic.

func (*LValue[T]) Set

func (m *LValue[T]) Set(v T)

func (*LValue[T]) Swap

func (m *LValue[T]) Swap(v T) (old T)

func (*LValue[T]) UnmarshalBinary

func (m *LValue[T]) UnmarshalBinary(b []byte) error

func (*LValue[T]) UnmarshalJSON

func (m *LValue[T]) UnmarshalJSON(b []byte) error

func (*LValue[T]) Update

func (m *LValue[T]) Update(fn func(old T) T)

Update executes fn while the mutex is write-locked and guarantees the mutex is released even in the case of a panic.

type List

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

func ListOf

func ListOf[T any](vs ...T) (l List[T])

func (List[T]) Append

func (l List[T]) Append(vs ...T) List[T]

func (List[T]) AppendList

func (l List[T]) AppendList(ol List[T]) List[T]

func (*List[T]) Clear

func (l *List[T]) Clear()

func (List[T]) Clip

func (l List[T]) Clip() List[T]

func (List[T]) Clone

func (l List[T]) Clone() (out List[T])

func (*List[T]) DecodeMsgpack

func (l *List[T]) DecodeMsgpack(dec *msgpack.Decoder) (err error)

func (List[T]) EncodeMsgpack

func (l List[T]) EncodeMsgpack(enc *msgpack.Encoder) (err error)

func (List[T]) ForEach

func (l List[T]) ForEach(fn func(v T) bool)

func (List[T]) ForEachPtr

func (l List[T]) ForEachPtr(fn func(v *T) bool)

func (List[T]) Get

func (l List[T]) Get(idx int) T

func (List[T]) GetPtr

func (l List[T]) GetPtr(idx int) *T

func (List[T]) Head

func (l List[T]) Head() (v T)

func (*List[T]) Iter

func (l *List[T]) Iter() *ListIterator[T]

Iter is a c++-style iterator: it := l.Iter() for v := it.Value(); it.Next(); v = it.Value()) {}

func (List[T]) IterChan

func (l List[T]) IterChan(cap int) <-chan T

func (List[T]) Len

func (l List[T]) Len() int

func (List[T]) ListAt

func (l List[T]) ListAt(start, end int) List[T]

func (List[T]) MarshalBinary

func (l List[T]) MarshalBinary() ([]byte, error)

func (List[T]) MarshalJSON

func (l List[T]) MarshalJSON() ([]byte, error)

func (*List[T]) Merge

func (l *List[T]) Merge(ol *List[T])

Merge can cause an infinitate loop if ol is a part of l

func (*List[T]) Prepend

func (l *List[T]) Prepend(v T)

func (*List[T]) Push

func (l *List[T]) Push(vs ...T)

func (*List[T]) PushSort

func (l *List[T]) PushSort(v T, lessFn func(a, b T) bool)

PushSort pushes the item in the order returned by lessFn PushSort does *not* work with Clip, use Clone if you really have to.

func (List[T]) Safe

func (l List[T]) Safe() *LList[T]

func (*List[T]) Set

func (l *List[T]) Set(idx int, v T)

func (List[T]) Slice

func (l List[T]) Slice() (out []T)

func (List[T]) Tail

func (l List[T]) Tail() (v T)

func (*List[T]) UnmarshalBinary

func (l *List[T]) UnmarshalBinary(p []byte) error

func (*List[T]) UnmarshalJSON

func (l *List[T]) UnmarshalJSON(p []byte) error

type ListIterator

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

func (*ListIterator[T]) Delete

func (it *ListIterator[T]) Delete()

func (*ListIterator[T]) Next

func (it *ListIterator[T]) Next() (v T, ok bool)

func (*ListIterator[T]) Set

func (it *ListIterator[T]) Set(v T)

type MsgpackDecoder

type MsgpackDecoder = msgpack.Decoder

func NewMsgpackDecoder

func NewMsgpackDecoder(r io.Reader) *MsgpackDecoder

NewMsgpackDecoder returns a new Decoder that reads from r. uses json CustomStructTag, and loose interface decoding.

type MsgpackEncoder

type MsgpackEncoder = msgpack.Encoder

func NewMsgpackEncoder

func NewMsgpackEncoder(w io.Writer) *MsgpackEncoder

NewMsgpackDecoder returns a new Decoder that writes to w. uses json CustomStructTag, compact floats and ints.

type Once

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

func (*Once[T]) Do

func (o *Once[T]) Do(fn func() (T, error)) (v T, err error)

type Ordered

type Ordered = internal.Ordered

type Pool

type Pool[T any] struct {
	New   func() *T
	Reset func(*T)
	// contains filtered or unexported fields
}

func (*Pool[T]) Get

func (p *Pool[T]) Get() *T

func (*Pool[T]) Put

func (p *Pool[T]) Put(v *T)

type PtrTo

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

func (*PtrTo[T]) IsSet

func (p *PtrTo[T]) IsSet() bool

func (PtrTo[T]) MarshalBinary

func (p PtrTo[T]) MarshalBinary() ([]byte, error)

func (PtrTo[T]) MarshalJSON

func (p PtrTo[T]) MarshalJSON() ([]byte, error)

func (*PtrTo[T]) Set

func (p *PtrTo[T]) Set(v T)

func (*PtrTo[T]) UnmarshalBinary

func (p *PtrTo[T]) UnmarshalBinary(b []byte) error

func (*PtrTo[T]) UnmarshalJSON

func (p *PtrTo[T]) UnmarshalJSON(b []byte) error

func (*PtrTo[T]) Unset

func (p *PtrTo[T]) Unset()

func (*PtrTo[T]) Val

func (p *PtrTo[T]) Val() T

type SLMap

type SLMap[V any] struct {
	// contains filtered or unexported fields
}

func NewSLMap

func NewSLMap[V any](ln int) *SLMap[V]

func (*SLMap[V]) Clear

func (lm *SLMap[V]) Clear()

func (*SLMap[V]) Clone

func (lm *SLMap[V]) Clone() (out map[string]V)

func (*SLMap[V]) Delete

func (lm *SLMap[V]) Delete(k string)

func (*SLMap[V]) DeleteGet

func (lm *SLMap[V]) DeleteGet(k string) V

func (*SLMap[V]) ForEach

func (lm *SLMap[V]) ForEach(fn func(k string, v V) bool)

func (*SLMap[V]) Get

func (lm *SLMap[V]) Get(k string) (v V)

func (*SLMap[V]) Keys

func (lm *SLMap[V]) Keys() (keys []string)

func (*SLMap[V]) Len

func (lm *SLMap[V]) Len() (ln int)

func (*SLMap[V]) MarshalBinary

func (lm *SLMap[V]) MarshalBinary() (_ []byte, err error)

func (*SLMap[V]) MarshalJSON

func (lm *SLMap[V]) MarshalJSON() (_ []byte, err error)

func (*SLMap[V]) MustGet

func (lm *SLMap[V]) MustGet(k string, fn func() V) V

func (*SLMap[V]) Read

func (lm *SLMap[V]) Read(fn func(m map[string]V))

func (*SLMap[V]) Set

func (lm *SLMap[V]) Set(k string, v V)

func (*SLMap[V]) Swap

func (lm *SLMap[V]) Swap(k string, v V) V

func (*SLMap[V]) UnmarshalBinary

func (lm *SLMap[V]) UnmarshalBinary(p []byte) error

func (*SLMap[V]) UnmarshalJSON

func (lm *SLMap[V]) UnmarshalJSON(p []byte) (err error)

func (*SLMap[V]) Update

func (lm *SLMap[V]) Update(fn func(m map[string]V))

func (*SLMap[V]) UpdateKey

func (lm *SLMap[V]) UpdateKey(k string, fn func(V) V)

func (*SLMap[V]) Values

func (lm *SLMap[V]) Values() (values []V)

type SLMultiMap

type SLMultiMap[V any] struct {
	// contains filtered or unexported fields
}

func (*SLMultiMap[V]) Clear

func (lm *SLMultiMap[V]) Clear()

func (*SLMultiMap[V]) Delete

func (lm *SLMultiMap[V]) Delete(k1, k2 string)

func (*SLMultiMap[V]) Get

func (lm *SLMultiMap[V]) Get(k1, k2 string) V

func (*SLMultiMap[V]) MustGet

func (lm *SLMultiMap[V]) MustGet(k1, k2 string, fn func() V) V

func (*SLMultiMap[V]) Set

func (lm *SLMultiMap[V]) Set(k1, k2 string, v V)

type Signed

type Signed = internal.Signed

type StringList

type StringList = List[string]

type TimedMap

type TimedMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*TimedMap[K, V]) Delete

func (tm *TimedMap[K, V]) Delete(k K)

func (*TimedMap[K, V]) DeleteGet

func (tm *TimedMap[K, V]) DeleteGet(k K) (v V, ok bool)

func (*TimedMap[K, V]) Get

func (tm *TimedMap[K, V]) Get(k K) (v V)

func (*TimedMap[K, V]) GetOk

func (tm *TimedMap[K, V]) GetOk(k K) (v V, ok bool)

func (*TimedMap[K, V]) Set

func (tm *TimedMap[K, V]) Set(k K, v V, timeout time.Duration)

func (*TimedMap[K, V]) SetUpdateExpireFn

func (tm *TimedMap[K, V]) SetUpdateExpireFn(k K, vfn func() V, updateEvery, expireIfNotAccessedFor time.Duration)

func (*TimedMap[K, V]) SetUpdateFn

func (tm *TimedMap[K, V]) SetUpdateFn(k K, vfn func() V, updateEvery time.Duration)

type TypeDecoder

type TypeDecoder interface {
	Decode(v any) error
}

type TypeEncoder

type TypeEncoder interface {
	Encode(v any) error
}

type Uint64List

type Uint64List = List[uint64]

type Unsigned

type Unsigned = internal.Unsigned

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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