Documentation
¶
Index ¶
- type Atomic
- type AtomicComparable
- type AtomicNumeric
- type HashMap
- type Map
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Has(key K) bool
- func (m *Map[K, V]) Keys() []K
- func (m *Map[K, V]) Length() (length int)
- func (m *Map[K, V]) Load(key K) (value V, ok bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (value V, ok bool)
- func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *Map[K, V]) Range(f func(key K, value V) bool)
- func (m *Map[K, V]) Store(key K, value V)
- func (m *Map[K, V]) ToMap() map[K]V
- func (m *Map[K, V]) Values() []V
- type MultiLock
- type Once
- type RingSlice
- type Slice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtomicComparable ¶
type AtomicComparable[T comparable] Atomic[T]
func NewAtomicComparable ¶
func NewAtomicComparable[T comparable](val T) AtomicComparable[T]
func (*AtomicComparable[T]) CompareAndSwap ¶
func (a *AtomicComparable[T]) CompareAndSwap(old T, new T) (swapped bool)
type AtomicNumeric ¶
type AtomicNumeric[T constraints.Numeric] AtomicComparable[T]
func NewAtomicNumeric ¶
func NewAtomicNumeric[T constraints.Numeric](val T) AtomicNumeric[T]
func (*AtomicNumeric[T]) Add ¶
func (a *AtomicNumeric[T]) Add(delta T) (new T)
func (*AtomicNumeric[T]) Subtract ¶
func (a *AtomicNumeric[T]) Subtract(delta T) (new T)
type HashMap ¶
type HashMap[T comparable] interface { Store(key T) Delete(key T) Has(key T) bool Length() int Keys() []T }
func NewHashMap ¶
func NewHashMap[T comparable](initial []T) HashMap[T]
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
This is a generically typed version of the built-in sync.Map
func NewMap ¶
func NewMap[K comparable, V any](initial map[K]V) *Map[K, V]
NewMap creates a new map with initial values
func (*Map[K, V]) Keys ¶
func (m *Map[K, V]) Keys() []K
Keys will get all keys in the map. It is subject to the same conditions/restrictions as Range.
func (*Map[K, V]) Length ¶
Length will get the number of elements in the map. It is subject to the same conditions/restrictions as Range.
func (*Map[K, V]) Load ¶
Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.
func (*Map[K, V]) LoadAndDelete ¶
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.
func (*Map[K, V]) LoadOrStore ¶
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (*Map[K, V]) Range ¶
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently (including by f), Range may reflect any mapping for that key from any point during the Range call. Range does not block other methods on the receiver; even f itself may call any method on m.
Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.
type MultiLock ¶
type MultiLock[T comparable] interface { LockAll(excluded ...T) UnlockAll(excluded ...T) Lock(key T) Unlock(key T) }
func NewMultiLock ¶
func NewMultiLock[T comparable](keys []T) MultiLock[T]
type Once ¶
gensync.Once is a form of sync.Once that captures and returns stack errors
func (*Once) Do ¶
func (o *Once) Do(f func() stackerr.Error) stackerr.Error
Do calls the function f if and only if Do is being called for the first time for this instance of Once. In other words, given
var once Once
if once.Do(f) is called multiple times, only the first call will invoke f, even if f has a different value in each invocation. A new instance of Once is required for each function to execute.
Do is intended for initialization that must be run exactly once. Since f is niladic, it may be necessary to use a function literal to capture the arguments to a function to be invoked by Do:
config.once.Do(func() { config.init(filename) })
Because no call to Do returns until the one call to f returns, if f causes Do to be called, it will deadlock.
If f panics, Do considers it to have returned; future calls of Do return without calling f.
type RingSlice ¶
type RingSlice[T any] interface { // Next will get the next value in the slice Next() T // Set will set new values for the slice Set(values []T) // Values will get a copy of the current values // (not the actual internal slice, just a copy of it) Values() []T }
A RingSlice is a slice that can be accessed by multiple routines to always return the next value in the slice, resetting at the first value once the last value is reached.
func NewRingSlice ¶
type Slice ¶
type Slice[V any] interface { // Load returns a COPY of the slice. Load() (slice []V) // SubSlice returns a COPY of the subslice in the form s[start:end]. SubSlice(start int, end int) (subslice []V) // StoreIndex will store a value in the slice at the given index. StoreIndex(index int, value V) // LoadIndex will load the value in the slice at the given index. LoadIndex(index int) (value V) // Concat will concatenate c to the end of the slice. Concat(c []V) // Append will append the value a to the end of the slice. Append(a V) // Length will get the number of elements in the slice Length() int }