Documentation
¶
Overview ¶
Package containers provides generic, concurrency-safe data structures.
Bag is a lock-free, append-only collection backed by an atomic linked list. AtomicMap is a mutex-protected map that avoids the per-element allocation overhead of sync.Map. The [mpsc] subpackage provides a lock-free multiple-producer, single-consumer queue.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtomicMap ¶
type AtomicMap[K comparable, V any] struct { // contains filtered or unexported fields }
AtomicMap is a mutex-protected map safe for concurrent use. It serves as a lighter alternative to sync.Map for workloads where the extra per-element allocation that sync.Map requires is undesirable.
The zero value is ready to use; the underlying map is allocated lazily on the first call to AtomicMap.LoadOrStore.
func (*AtomicMap[K, V]) Clear ¶
func (m *AtomicMap[K, V]) Clear()
Clear removes all elements from the map.
func (*AtomicMap[K, V]) LoadOrStore ¶
LoadOrStore returns the existing value for key if present. Otherwise, it stores and returns the given value. The boolean result is true if the value was loaded, false if stored.
func (*AtomicMap[K, V]) Store ¶ added in v1.14.0
func (m *AtomicMap[K, V]) Store(key K, value V)
Store writes value at key within the internal map. If the key already exists, its value is overwritten with the new value. If the key does not exist, it is created and value is assigned.
func (*AtomicMap[K, V]) Unwrap ¶ added in v1.14.0
func (m *AtomicMap[K, V]) Unwrap() map[K]V
Unwrap returns the internal map that backs the AtomicMap. A nil value may be returned if the AtomicMap has not yet been initialized, or Unwrap is called after a Clear call.
Once the internal map has been unwrapped, methods on the AtomicMap instance are no longer safe.
type Bag ¶
type Bag[T any] struct { // contains filtered or unexported fields }
Bag is a lock-free, append-only collection. Values can be added concurrently via Bag.Add and drained via Bag.Seq, but individual elements cannot be indexed or removed.
Bag uses an atomic linked list internally, so all methods are safe for concurrent use. The zero value is ready to use.