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 ¶
- func Abs[T Integer | Float](v T) T
- func BinarySearch[E Ordered](x []E, target E) (int, bool)
- func BinarySearchFunc[E any](x []E, cmp func(E) int) (int, bool)
- func ChanToSlice[T any](s <-chan T, cap int) []T
- func Clip[S ~[]E, E any](s S) S
- func Clone[T any](v T, keepPrivateFields bool) (cp T)
- func ClosedChan[T any]() chan T
- func Compact[S ~[]E, E comparable](s S) S
- func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S
- func Compare[S ~[]E, E Ordered](s1, s2 S) int
- func CompareFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, cmp func(E1, E2) int) int
- func Contains[S ~[]E, E comparable](s S, v E) bool
- func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool
- func Decode[T any, DecT DecoderType](r io.Reader, fn func(r io.Reader) DecT) (v T, err error)
- func DecodeFile[T any, DecT DecoderType](fp string, fn func(r io.Reader) DecT) (v T, err error)
- func DecodeMsgpack(r io.Reader, vs ...any) error
- func Delete[S ~[]E, E any](s S, i, j int) S
- func DieIf(tb testingTB, err error, args ...any)
- func Encode[EncT TypeEncoder](w io.Writer, v any, fn func(w io.Writer) EncT) (err error)
- func EncodeFile[EncT TypeEncoder](fp string, v any, fn func(w io.Writer) EncT) (err error)
- func EncodeMsgpack(w io.Writer, vs ...any) error
- func Equal[S ~[]E, E comparable](s1, s2 S) bool
- func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) bool) bool
- func ErrorIf(tb testingTB, err error, args ...any) bool
- func Filter[S ~[]E, E any](in S, f func(E) (keep bool), inplace bool) (out S)
- func FirstNonZero[T any](args ...T) T
- func FirstNonZeroCmp[T comparable](args ...T) T
- func FirstNonZeroPtr[T any](args ...*T) *T
- 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[S ~[]E, E any](s S, n int) S
- func Iff[T any](cond bool, a, b T) T
- func IffFn[T any](cond bool, a, b func() T) T
- func Index[S ~[]E, E comparable](s S, v E) int
- func IndexFunc[S ~[]E, E any](s S, f func(E) bool) int
- func Insert[S ~[]E, E any](s S, i int, v ...E) S
- func IsSorted[E Ordered](x []E) bool
- func IsSortedFunc[E any](x []E, less func(a, b E) bool) bool
- func ListToMap[K comparable, V any](l List[V], keyFn func(v V) K) map[K]V
- func MapClear[M ~map[K]V, K comparable, V any](m M)
- func MapClone[M ~map[K]V, K comparable, V any](m M) M
- func MapCopy[M ~map[K]V, K comparable, V any](dst, src M)
- func MapDeleteFunc[M ~map[K]V, K comparable, V any](m M, del func(K, V) bool)
- func MapEqual[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool
- 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
- func MapFilter[M ~map[K]V, K comparable, V any](m M, fn func(K, V) bool, inplace bool) (out M)
- func MapKeys[M ~map[K]V, K comparable, V any](m M) []K
- func MapValues[M ~map[K]V, K comparable, V any](m M) []V
- func MarshalMsgpack(v any) ([]byte, error)
- func Max[T Ordered](a, b T) T
- func Min[T Ordered](a, b T) T
- func PanicIf(lg *log.Logger, err error, args ...any)
- func Ptr[T any](v T) *T
- func PtrVal[T any](v *T) (_ T)
- func PtrsToValues[T any](vals []*T) []T
- func PutMsgpackDecoder(dec *MsgpackDecoder)
- func PutMsgpackEncoder(enc *MsgpackEncoder)
- func ReflectClone(dst, src reflect.Value, keepPrivateFields bool)
- 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[S ~[]E, E any](s S) S
- func SliceMap[S ~[]E, E, T any](in S, fn func(E) T) []T
- func SliceMapFilter[S ~[]E, E, T any](in S, fn func(E) (val T, ignore bool)) []T
- func SliceMapFilterSameType[S ~[]E, E any](in S, fn func(E) (val E, ignore bool), inplace bool) (out S)
- func SliceMapSameType[S ~[]E, E any](in S, fn func(E) E, inplace bool) (out S)
- func SliceToChan[T any](s []T, cap int) <-chan T
- func Sort[E Ordered](x []E)
- func SortFunc[E any](x []E, less func(a, b E) bool)
- func SortStableFunc[E any](x []E, less func(a, b E) bool)
- func UnmarshalMsgpack(b []byte, v any) error
- func ValuesToPtrs[T any](vals []T, copy bool) []*T
- func Zero[T any]() (_ T)
- type AtomicBool
- func (v *AtomicBool) CompareAndSwap(old, new bool) bool
- func (v *AtomicBool) Load() bool
- func (v *AtomicBool) MarshalBinary() ([]byte, error)
- func (v *AtomicBool) MarshalJSON() ([]byte, error)
- func (v *AtomicBool) Store(val bool)
- func (v *AtomicBool) Swap(val bool) (old bool)
- func (v *AtomicBool) UnmarshalBinary(b []byte) error
- func (v *AtomicBool) UnmarshalJSON(b []byte) error
- type AtomicFloat64
- func (v *AtomicFloat64) Add(val float64) float64
- func (v *AtomicFloat64) CompareAndSwap(old, new float64) bool
- func (v *AtomicFloat64) Load() float64
- func (v *AtomicFloat64) MarshalBinary() ([]byte, error)
- func (v *AtomicFloat64) MarshalJSON() ([]byte, error)
- func (v *AtomicFloat64) Store(val float64)
- func (v *AtomicFloat64) Swap(val float64) (old float64)
- func (v *AtomicFloat64) UnmarshalBinary(b []byte) error
- func (v *AtomicFloat64) UnmarshalJSON(b []byte) error
- type AtomicInt
- type AtomicInt16
- type AtomicInt32
- type AtomicInt64
- type AtomicInt8
- type AtomicUint
- type AtomicUint16
- type AtomicUint32
- type AtomicUint64
- type AtomicUint8
- type AtomicUintptr
- type Cloner
- type Complex
- type DecoderType
- type EncoderType
- type Float
- type Float64List
- type Int64List
- type Integer
- type LList
- type LMap
- func (lm *LMap[K, V]) Clear()
- func (lm *LMap[K, V]) Clone() (m map[K]V)
- func (lm *LMap[K, V]) Delete(k K)
- func (lm *LMap[K, V]) DeleteGet(k K) V
- func (lm *LMap[K, V]) ForEach(fn func(k K, v V) bool)
- func (lm *LMap[K, V]) Get(k K) (v V)
- func (lm *LMap[K, V]) Keys() (keys []K)
- func (lm *LMap[K, V]) Len() (v int)
- func (lm *LMap[K, V]) MarshalBinary() ([]byte, error)
- func (lm *LMap[K, V]) MarshalJSON() ([]byte, error)
- func (lm *LMap[K, V]) MustGet(k K, fn func() V) V
- func (lm *LMap[K, V]) Raw() map[K]V
- func (lm *LMap[K, V]) Read(fn func(m map[K]V))
- func (lm *LMap[K, V]) Set(k K, v V)
- func (lm *LMap[K, V]) SetMap(m map[K]V) (old map[K]V)
- func (lm *LMap[K, V]) Swap(k K, v V) V
- func (lm *LMap[K, V]) UnmarshalBinary(p []byte) error
- func (lm *LMap[K, V]) UnmarshalJSON(p []byte) error
- func (lm *LMap[K, V]) Update(fn func(m map[K]V))
- func (lm *LMap[K, V]) UpdateKey(k K, fn func(V) V)
- func (lm *LMap[K, V]) Values() (values []V)
- type LMultiMap
- func (lm *LMultiMap[K1, K2, V]) Clear()
- func (lm *LMultiMap[K1, K2, V]) ClearChild(k1 K1)
- func (lm *LMultiMap[K1, K2, V]) Clone() (m map[K1]map[K2]V)
- func (lm *LMultiMap[K1, K2, V]) Delete(k1 K1)
- func (lm *LMultiMap[K1, K2, V]) DeleteChild(k1 K1, k2 K2)
- func (lm *LMultiMap[K1, K2, V]) DeleteGet(k1 K1) map[K2]V
- func (lm *LMultiMap[K1, K2, V]) DeleteGetChild(k1 K1, k2 K2) V
- func (lm *LMultiMap[K1, K2, V]) ForEach(fn func(k1 K1, m map[K2]V) bool, rw bool)
- func (lm *LMultiMap[K1, K2, V]) ForEachChild(k1 K1, fn func(k2 K2, v V) bool)
- func (lm *LMultiMap[K1, K2, V]) Get(k1 K1, k2 K2) (v V)
- func (lm *LMultiMap[K1, K2, V]) GetChild(k1 K1, copy bool) map[K2]V
- func (lm *LMultiMap[K1, K2, V]) Keys() (keys []K1)
- func (lm *LMultiMap[K1, K2, V]) KeysChild(k1 K1) (keys []K2)
- func (lm *LMultiMap[K1, K2, V]) Len() (v int)
- func (lm *LMultiMap[K1, K2, V]) LenChild(k K1) (v int)
- func (lm *LMultiMap[K1, K2, V]) MarshalBinary() ([]byte, error)
- func (lm *LMultiMap[K1, K2, V]) MarshalJSON() ([]byte, error)
- func (lm *LMultiMap[K1, K2, V]) MustGet(k1 K1, k2 K2, fn func() V) V
- func (lm *LMultiMap[K1, K2, V]) Raw() map[K1]map[K2]V
- func (lm *LMultiMap[K1, K2, V]) Read(fn func(m map[K1]map[K2]V))
- func (lm *LMultiMap[K1, K2, V]) ReadChild(k K1, fn func(m map[K2]V))
- func (lm *LMultiMap[K1, K2, V]) Set(k1 K1, k2 K2, v V)
- func (lm *LMultiMap[K1, K2, V]) SetChild(k1 K1, v map[K2]V)
- func (lm *LMultiMap[K1, K2, V]) SetMap(m map[K1]map[K2]V) (old map[K1]map[K2]V)
- func (lm *LMultiMap[K1, K2, V]) UnmarshalBinary(p []byte) error
- func (lm *LMultiMap[K1, K2, V]) UnmarshalJSON(p []byte) error
- func (lm *LMultiMap[K1, K2, V]) Update(k1 K1, fn func(m map[K2]V) map[K2]V)
- func (lm *LMultiMap[K1, K2, V]) Values(copy bool) (values []map[K2]V)
- func (lm *LMultiMap[K1, K2, V]) ValuesChild(k1 K1) (values []V)
- type LSlice
- func (ls *LSlice[T]) Append(vs ...T)
- func (ls *LSlice[T]) Cap() int
- func (ls *LSlice[T]) Clip()
- func (ls *LSlice[T]) ClipTo(len_, cap_ int)
- func (ls *LSlice[T]) Clone() []T
- func (ls *LSlice[T]) Delete(i, j int)
- func (ls *LSlice[T]) Filter(fn func(T) bool, inplace bool) *LSlice[T]
- func (ls *LSlice[T]) ForEach(fn func(i int, v T) bool)
- func (ls *LSlice[T]) Get(i int) T
- func (ls *LSlice[T]) Grow(sz int)
- func (ls *LSlice[T]) Insert(i int, vs ...T)
- func (ls *LSlice[T]) LClone() *LSlice[T]
- func (ls *LSlice[T]) Len() int
- func (ls *LSlice[T]) Map(fn func(T) T, inplace bool) *LSlice[T]
- func (ls *LSlice[T]) MarshalBinary() ([]byte, error)
- func (ls *LSlice[T]) MarshalJSON() ([]byte, error)
- func (ls *LSlice[T]) Raw() []T
- func (ls *LSlice[T]) Search(cmpFn func(v T) int) (v T, found bool)
- func (ls *LSlice[T]) Set(i int, v T)
- func (ls *LSlice[T]) SetSlice(v []T)
- func (ls *LSlice[T]) Sort(lessFn func(a, b T) bool)
- func (ls *LSlice[T]) Swap(i int, v T) (old T)
- func (ls *LSlice[T]) UnmarshalBinary(p []byte) error
- func (ls *LSlice[T]) UnmarshalJSON(p []byte) error
- func (ls *LSlice[T]) Update(fn func(v []T) []T)
- type LValue
- func (m *LValue[T]) CompareAndSwap(old, new T, eq func(a, b T) bool) (ok bool)
- func (m *LValue[T]) Get() T
- func (m *LValue[T]) MarshalBinary() ([]byte, error)
- func (m *LValue[T]) MarshalJSON() ([]byte, error)
- func (m *LValue[T]) Read(fn func(v T))
- func (m *LValue[T]) Set(v T)
- func (m *LValue[T]) Swap(v T) (old T)
- func (m *LValue[T]) UnmarshalBinary(b []byte) error
- func (m *LValue[T]) UnmarshalJSON(b []byte) error
- func (m *LValue[T]) Update(fn func(old T) T)
- type List
- func (l List[T]) Append(vs ...T) List[T]
- func (l List[T]) AppendList(ol List[T]) List[T]
- func (l *List[T]) Clear()
- func (l List[T]) Clip() List[T]
- func (l List[T]) Clone() (out List[T])
- func (l *List[T]) DecodeMsgpack(dec *msgpack.Decoder) (err error)
- func (l List[T]) EncodeMsgpack(enc *msgpack.Encoder) (err error)
- func (l List[T]) ForEach(fn func(v T) bool)
- func (l List[T]) ForEachPtr(fn func(v *T) bool)
- func (l List[T]) Get(idx int) T
- func (l List[T]) GetPtr(idx int) *T
- func (l List[T]) Head() (v T)
- func (l *List[T]) Iter() *ListIterator[T]
- func (l List[T]) IterChan(cap int) <-chan T
- func (l List[T]) Len() int
- func (l List[T]) ListAt(start, end int) List[T]
- func (l List[T]) MarshalBinary() ([]byte, error)
- func (l List[T]) MarshalJSON() ([]byte, error)
- func (l *List[T]) Merge(ol *List[T])
- func (l *List[T]) Prepend(v T)
- func (l *List[T]) Push(vs ...T)
- func (l *List[T]) PushSort(v T, lessFn func(a, b T) bool)
- func (l List[T]) Safe() *LList[T]
- func (l *List[T]) Set(idx int, v T)
- func (l List[T]) Slice() (out []T)
- func (l List[T]) Tail() (v T)
- func (l *List[T]) UnmarshalBinary(p []byte) error
- func (l *List[T]) UnmarshalJSON(p []byte) error
- type ListIterator
- type MsgpackDecoder
- type MsgpackEncoder
- type Once
- type Ordered
- type Pool
- type PtrTo
- func (p *PtrTo[T]) IsSet() bool
- func (p PtrTo[T]) MarshalBinary() ([]byte, error)
- func (p PtrTo[T]) MarshalJSON() ([]byte, error)
- func (p *PtrTo[T]) Set(v T)
- func (p *PtrTo[T]) UnmarshalBinary(b []byte) error
- func (p *PtrTo[T]) UnmarshalJSON(b []byte) error
- func (p *PtrTo[T]) Unset()
- func (p *PtrTo[T]) Val() T
- type SLMap
- func (lm *SLMap[V]) Clear()
- func (lm *SLMap[V]) Clone() (out map[string]V)
- func (lm *SLMap[V]) Delete(k string)
- func (lm *SLMap[V]) DeleteGet(k string) V
- func (lm *SLMap[V]) ForEach(fn func(k string, v V) bool)
- func (lm *SLMap[V]) Get(k string) (v V)
- func (lm *SLMap[V]) Keys() (keys []string)
- func (lm *SLMap[V]) Len() (ln int)
- func (lm *SLMap[V]) MarshalBinary() (_ []byte, err error)
- func (lm *SLMap[V]) MarshalJSON() (_ []byte, err error)
- func (lm *SLMap[V]) MustGet(k string, fn func() V) V
- func (lm *SLMap[V]) Read(fn func(m map[string]V))
- func (lm *SLMap[V]) Set(k string, v V)
- func (lm *SLMap[V]) Swap(k string, v V) V
- func (lm *SLMap[V]) UnmarshalBinary(p []byte) error
- func (lm *SLMap[V]) UnmarshalJSON(p []byte) (err error)
- func (lm *SLMap[V]) Update(fn func(m map[string]V))
- func (lm *SLMap[V]) UpdateKey(k string, fn func(V) V)
- func (lm *SLMap[V]) Values() (values []V)
- type SLMultiMap
- type Signed
- type StringList
- type TimedMap
- func (tm *TimedMap[K, V]) Delete(k K)
- func (tm *TimedMap[K, V]) DeleteGet(k K) (v V, ok bool)
- func (tm *TimedMap[K, V]) Get(k K) (v V)
- func (tm *TimedMap[K, V]) GetOk(k K) (v V, ok bool)
- func (tm *TimedMap[K, V]) Set(k K, v V, timeout time.Duration)
- func (tm *TimedMap[K, V]) SetUpdateExpireFn(k K, vfn func() V, updateEvery, expireIfNotAccessedFor time.Duration)
- func (tm *TimedMap[K, V]) SetUpdateFn(k K, vfn func() V, updateEvery time.Duration)
- type TypeDecoder
- type TypeEncoder
- type Uint64List
- type Unsigned
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinarySearch ¶
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 ¶
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 Clip ¶
func Clip[S ~[]E, E any](s S) S
Clip removes unused capacity from the slice, returning s[:len(s):len(s)].
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 ¶
CompactFunc is like Compact but uses a comparison function.
func Compare ¶
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 ¶
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 ¶
ContainsFunc reports whether f(v) is present in s.
func DecodeFile ¶
func Delete ¶
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 EncodeFile ¶
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 ¶
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 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 ¶
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 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 Insert ¶
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 IsSortedFunc ¶
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 PtrsToValues ¶
func PtrsToValues[T any](vals []*T) []T
func PutMsgpackDecoder ¶
func PutMsgpackDecoder(dec *MsgpackDecoder)
func PutMsgpackEncoder ¶
func PutMsgpackEncoder(enc *MsgpackEncoder)
func ReflectClone ¶
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 ¶
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 ¶
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 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 ¶
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 ¶
SortStable sorts the slice x while keeping the original order of equal elements, using less to compare elements.
func UnmarshalMsgpack ¶
func ValuesToPtrs ¶
ValuesToPtrs converts a slice of values to a slice of pointers optionally copying the values instead of pointing to them in the original slice.
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 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 DecoderType ¶
type DecoderType = internal.DecoderType
type EncoderType ¶
type EncoderType = internal.EncoderType
type Float64List ¶
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 (*LMap[K, V]) MarshalBinary ¶
func (*LMap[K, V]) MarshalJSON ¶
func (*LMap[K, V]) UnmarshalBinary ¶
func (*LMap[K, V]) UnmarshalJSON ¶
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]) ClearChild ¶
func (lm *LMultiMap[K1, K2, V]) ClearChild(k1 K1)
func (*LMultiMap[K1, K2, V]) DeleteChild ¶
func (lm *LMultiMap[K1, K2, V]) DeleteChild(k1 K1, k2 K2)
func (*LMultiMap[K1, K2, V]) DeleteGetChild ¶
func (lm *LMultiMap[K1, K2, V]) DeleteGetChild(k1 K1, k2 K2) V
func (*LMultiMap[K1, K2, V]) ForEachChild ¶
func (*LMultiMap[K1, K2, V]) KeysChild ¶
func (lm *LMultiMap[K1, K2, V]) KeysChild(k1 K1) (keys []K2)
func (*LMultiMap[K1, K2, V]) MarshalBinary ¶
func (*LMultiMap[K1, K2, V]) MarshalJSON ¶
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]) 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]) 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 (*LMultiMap[K1, K2, V]) UnmarshalJSON ¶
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]) 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]) MarshalBinary ¶
func (*LSlice[T]) MarshalJSON ¶
func (*LSlice[T]) UnmarshalBinary ¶
func (*LSlice[T]) UnmarshalJSON ¶
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 (*LValue[T]) MarshalBinary ¶
func (*LValue[T]) MarshalJSON ¶
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]) UnmarshalBinary ¶
func (*LValue[T]) UnmarshalJSON ¶
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
func (List[T]) AppendList ¶
func (*List[T]) DecodeMsgpack ¶
func (List[T]) EncodeMsgpack ¶
func (List[T]) ForEachPtr ¶
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]) MarshalBinary ¶
func (List[T]) MarshalJSON ¶
func (*List[T]) PushSort ¶
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]) UnmarshalBinary ¶
func (*List[T]) UnmarshalJSON ¶
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 Pool ¶
type Pool[T any] struct { New func() *T Reset func(*T) // contains filtered or unexported fields }
type PtrTo ¶
type PtrTo[T any] struct { // contains filtered or unexported fields }
func (PtrTo[T]) MarshalBinary ¶
func (PtrTo[T]) MarshalJSON ¶
func (*PtrTo[T]) UnmarshalBinary ¶
func (*PtrTo[T]) UnmarshalJSON ¶
type SLMap ¶
type SLMap[V any] struct { // contains filtered or unexported fields }
func (*SLMap[V]) MarshalBinary ¶
func (*SLMap[V]) MarshalJSON ¶
func (*SLMap[V]) UnmarshalBinary ¶
func (*SLMap[V]) UnmarshalJSON ¶
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 StringList ¶
type TimedMap ¶
type TimedMap[K comparable, V any] struct { // contains filtered or unexported fields }