Documentation
ΒΆ
Index ΒΆ
- type Map
- func (m *Map) Clear()
- func (m *Map[K, V]) Clone() Map[K, V]
- func (m *Map) Delete(key K)
- func (m *Map) Has(key K) bool
- func (m *Map) Iter() iter.Seq2[K, V]
- func (m *Map) Keys() []K
- func (m *Map) Len() int
- func (m *Map) Load(key K) (V, bool)
- func (m *Map) LoadAndDelete(key K) (cur V, ok bool)
- func (m *Map) LoadOrStore(key K, val V) (cur V, ok bool)
- func (m *Map) Snapshot() map[K]V
- func (m *Map) Store(key K, value V)
- func (m *Map) Swap(key K, val V) (V, bool)
- func (m *Map) Values() []V
- type MapCmp
- func (m *MapCmp) Clear()
- func (m *MapCmp[K, V]) Clone() MapCmp[K, V]
- func (m *MapCmp) Delete(key K)
- func (m *MapCmp[K, V]) DeleteIfEqual(key K, expected V) bool
- func (m *MapCmp) Has(key K) bool
- func (m *MapCmp) Iter() iter.Seq2[K, V]
- func (m *MapCmp) Keys() []K
- func (m *MapCmp) Len() int
- func (m *MapCmp) Load(key K) (V, bool)
- func (m *MapCmp) LoadAndDelete(key K) (cur V, ok bool)
- func (m *MapCmp) LoadOrStore(key K, val V) (cur V, ok bool)
- func (m *MapCmp) Snapshot() map[K]V
- func (m *MapCmp) Store(key K, value V)
- func (m *MapCmp) Swap(key K, val V) (V, bool)
- func (m *MapCmp[K, V]) SwapIfEqual(key K, expected, val V) bool
- func (m *MapCmp) Values() []V
- type Slice
- func (s *Slice[E]) Append(items ...E)
- func (s *Slice[E]) At(i int) E
- func (s *Slice[E]) Cap() int
- func (s *Slice[E]) Clear() int
- func (s *Slice[E]) Clip() int
- func (s *Slice[E]) Concat(other ...[]E) (int, int)
- func (s *Slice[E]) Delete(i, j int) (int, int)
- func (s *Slice[E]) DeleteFunc(del func(E) bool) (int, int)
- func (s *Slice[E]) Grow(n int) int
- func (s *Slice[E]) Insert(i int, v ...E) (int, int)
- func (s *Slice[E]) Iter() iter.Seq2[int, E]
- func (s *Slice[E]) Len() int
- func (s *Slice[E]) Replace(i, j int, v ...E) (int, int)
- func (s *Slice[E]) Snapshot() []E
- func (s *Slice[E]) Store(i int, val E)
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type Map ΒΆ
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a plain simple thread-safe map implementation, using a mutex for synchronization
func NewMap ΒΆ
func NewMap[K comparable, V any](size ...int) *Map[K, V]
NewMap creates a new thread-safe map of type K, V An empty map is allocated with enough space to hold the specified number of elements. The size may be omitted, in which case a small starting size is allocated.
func (*Map) Iter ΒΆ
Iter returns an iterator for the map
Iter does not necessarily correspond to any consistent snapshot of the map's contents: no key will be visited more than once. Iter does not block other methods on the receiver
func (*Map) Load ΒΆ
func (m *Map) Load(key K) (V, bool)
Load returns the value for the key and a boolean indicating if the key was found
func (*Map) LoadAndDelete ΒΆ
func (m *Map) LoadAndDelete(key K) (cur V, ok bool)
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.
func (*Map) LoadOrStore ΒΆ
func (m *Map) LoadOrStore(key K, val V) (cur V, ok bool)
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) Snapshot ΒΆ
func (m *Map) Snapshot() map[K]V
Snapshot returns a snapshot copy of the underlying map
type MapCmp ΒΆ
type MapCmp[K, V comparable] struct { // contains filtered or unexported fields }
MapCmp is a thread-safe map implementation with comparable values It extends the Map with additional methods for conditionally deleting or swapping values
func NewMapCmp ΒΆ
func NewMapCmp[K, V comparable](size ...int) *MapCmp[K, V]
NewMapCmp creates a new thread-safe map of type with comparable values An empty map is allocated with enough space to hold the specified number of elements. The size may be omitted, in which case a small starting size is allocated.
func (*MapCmp[K, V]) DeleteIfEqual ΒΆ
DeleteIfEqual removes the key from the map when the value is equal to the expected value It returns true if the key was found and removed
func (*MapCmp) Iter ΒΆ
Iter returns an iterator for the map
Iter does not necessarily correspond to any consistent snapshot of the map's contents: no key will be visited more than once. Iter does not block other methods on the receiver
func (*MapCmp) Load ΒΆ
func (m *MapCmp) Load(key K) (V, bool)
Load returns the value for the key and a boolean indicating if the key was found
func (*MapCmp) LoadAndDelete ΒΆ
func (m *MapCmp) LoadAndDelete(key K) (cur V, ok bool)
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.
func (*MapCmp) LoadOrStore ΒΆ
func (m *MapCmp) LoadOrStore(key K, val V) (cur V, ok bool)
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 (*MapCmp) Snapshot ΒΆ
func (m *MapCmp) Snapshot() map[K]V
Snapshot returns a snapshot copy of the underlying map
func (*MapCmp) Store ΒΆ
func (m *MapCmp) Store(key K, value V)
Store sets a new key-value pair to the map
func (*MapCmp) Swap ΒΆ
func (m *MapCmp) Swap(key K, val V) (V, bool)
Swap replaces the value for the given key and returns the old value and a boolean indicating if the key was found
func (*MapCmp[K, V]) SwapIfEqual ΒΆ
SwapIfEqual removes the key from the map when the value is equal to the expected value
type Slice ΒΆ
type Slice[E any] struct { // contains filtered or unexported fields }
Slice is a thread-safe slice implementation
func NewSlice ΒΆ
NewSlice creates a new thread-safe slice of type E The size specifies the length. The capacity of the slice is equal to its length. A second integer argument may be provided to specify a different capacity; it must be no smaller than the length. For example, make([] int, 0, 10) allocates an underlying array of size 10 and returns a slice of length 0 and capacity 10 that is backed by this underlying array.
func NewSliceFrom ΒΆ
NewSliceFrom creates a new thread-safe slice of type E from the given elements The size of the slice is equal to the length of the elements, as well as the capacity The elements are copied into the resulting Slice
func (*Slice[E]) Append ΒΆ
func (s *Slice[E]) Append(items ...E)
Append appends new items to the slice. The new items are added to the end of the slice.
func (*Slice[E]) At ΒΆ
At returns the element at the given index. If the index is out of range, At panics.
func (*Slice[E]) Clear ΒΆ
Clear removes all elements from the slice but maintains the current capacity, returning the capacity of the slice.
func (*Slice[E]) Concat ΒΆ
Concat concatenates the passed in slices to the current one, returning the new length and capacity of the slice.
func (*Slice[E]) Delete ΒΆ
Delete removes the elements s[i:j] from s, returning the new length and capacity of the slice. Delete panics if j > len(s) or s[i:j] is not a valid slice of s. Delete is O(len(s)-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. Delete zeroes the elements s[len(s)-(j-i):len(s)].
func (*Slice[E]) DeleteFunc ΒΆ
DeleteFunc removes any elements from s for which del returns true, returning the new length and capacity of the slice. DeleteFunc zeroes the elements between the new length and the original length.
func (*Slice[E]) 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. If n is negative or too large to allocate the memory, Grow panics. It returns the new capacity of the slice.
func (*Slice[E]) Insert ΒΆ
Insert inserts the values v... into s at index i, and returns the new length and capacity of the slice. The elements at s[i:] are shifted up to make room. In the resulting slice r, r[i] == v[0], and r[i+len(v)] == value originally at r[i]. Insert panics if i is out of range. This function is O(len(s) + len(v)).
func (*Slice[E]) Iter ΒΆ
Iter returns an iterator for the slice
Iter does not necessarily correspond to any consistent snapshot of the slice's contents: no key will be visited more than once. Iter does not block other methods on the receiver