concurrent

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashMap

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

HashMap is a synchronized wrapper around hashmap.Map.

func NewHashMap

func NewHashMap[K, V any](hasher internalmaphash.Hasher[K]) *HashMap[K, V]

NewHashMap returns a new map that uses the specified hash function and key-equivalence relation.

func (*HashMap[K, V]) All

func (m *HashMap[K, V]) All() iter.Seq2[K, V]

All returns an iterator over the key/value entries of the map in undefined order.

func (*HashMap[K, V]) Clear

func (m *HashMap[K, V]) Clear()

func (*HashMap[K, V]) Delete

func (m *HashMap[K, V]) Delete(key K) (V, bool)

Delete removes the entry with the given key, if present. It reports whether the map changed, and returns the previous value, if any.

func (*HashMap[K, V]) Get

func (m *HashMap[K, V]) Get(key K) (V, bool)

Get reports whether the map contains the specified key, and returns the corresponding value if found, or the zero value if not.

func (*HashMap[K, V]) Keys

func (m *HashMap[K, V]) Keys() iter.Seq[K]

Keys returns an iterator over the map keys in unspecified order.

func (*HashMap[K, V]) LoadOrStore

func (m *HashMap[K, V]) LoadOrStore(key K, newValue func() V) (actual V, loaded bool)

LoadOrStore returns the existing value for key if present. Otherwise, it calls newValue to construct a value, stores it, and returns it. newValue is only called on a miss, so callers don't pay the cost of constructing a value when the key is already present. The loaded result is true if the value was loaded, false if stored. Unlike a separate Get followed by Set, this check-and-set is performed atomically under a single lock, so concurrent callers racing to initialize the same key never lose an update.

func (*HashMap[K, V]) Set

func (m *HashMap[K, V]) Set(key K, value V) (prev V, changed bool)

Set updates the map entry for key to value and returns the previous entry, if any. It reports whether the map size increased.

func (*HashMap[K, V]) String

func (m *HashMap[K, V]) String() string

String returns a string representation of the map's entries in an unspecified but deterministic order. Keys and values are printed as if by fmt.Sprint.

func (*HashMap[K, V]) Values

func (m *HashMap[K, V]) Values() iter.Seq[V]

Values returns an iterator over the map values in unspecified order.

type Map

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

func (*Map[K, V]) All

func (m *Map[K, V]) All() iter.Seq2[K, V]

All returns an iterator over the key-value pairs in the map. The iteration order is not specified and is not guaranteed to be the same from one iteration to the next.

All 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, All may reflect any mapping for that key from any point during the All call.

func (*Map[K, V]) Clear

func (m *Map[K, V]) Clear()

Clear deletes all the entries, resulting in an empty Map.

func (*Map[K, V]) CompareAndDelete

func (m *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool)

CompareAndDelete deletes the entry for key if its value is equal to old. The old value must be of a comparable type.

If there is no current value for key in the map, CompareAndDelete returns false (even if the old value is the nil interface value).

func (*Map[K, V]) CompareAndSwap

func (m *Map[K, V]) CompareAndSwap(key K, old, newVal V) (swapped bool)

CompareAndSwap swaps the old and new values for key if the value stored in the map is equal to old. The old value must be of a comparable type.

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

Delete deletes the value for a key. If the key is not in the map, Delete does nothing.

func (*Map[K, V]) Keys

func (m *Map[K, V]) Keys() iter.Seq[K]

func (*Map[K, V]) Load

func (m *Map[K, V]) Load(key K) (V, bool)

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

func (m *Map[K, V]) LoadAndDelete(key K) (V, 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[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, value V) (V, 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[K, V]) Store

func (m *Map[K, V]) Store(key K, value V)

Store sets the value for a key.

func (*Map[K, V]) Swap

func (m *Map[K, V]) Swap(key K, value V) (V, bool)

Swap swaps the value for a key and returns the previous value if any. The loaded result reports whether the key was present.

func (*Map[K, V]) Values

func (m *Map[K, V]) Values() iter.Seq[V]

type Queue

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

func (*Queue[T]) All

func (q *Queue[T]) All() iter.Seq[T]

All returns an iterator over the items in the queue. The iteration order is first-to-last.

All corresponds to a consistent snapshot of the Queue's contents at the time iteration starts.

func (*Queue[T]) Dequeue

func (q *Queue[T]) Dequeue() (T, bool)

func (*Queue[T]) Enqueue

func (q *Queue[T]) Enqueue(item T)

func (*Queue[T]) IsEmpty

func (q *Queue[T]) IsEmpty() bool

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

Jump to

Keyboard shortcuts

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