Documentation ¶
Index ¶
- type AtomicComparable
- type AtomicValue
- type CompareMap
- type Heap
- type PQItem
- type PQItemEmbed
- type PriorityQueue
- type SyncMap
- func (m *SyncMap[K, V]) Delete(key K)
- func (m *SyncMap[K, V]) Load(key K) (value V, ok bool)
- func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *SyncMap[K, V]) Range(f func(key K, value V) bool)
- func (m *SyncMap[K, V]) Store(key K, value V)
- func (m *SyncMap[K, V]) Swap(key K, value V) (previous V, loaded bool)
- type SyncPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtomicComparable ¶ added in v0.1.0
type AtomicComparable[T comparable] struct { AtomicValue[T] }
func (*AtomicComparable[T]) CompareAndSwap ¶ added in v0.1.0
func (av *AtomicComparable[T]) CompareAndSwap(old T, new T) (swapped bool)
CompareAndSwap exchanges values if the current value matches the passed in old value.
type AtomicValue ¶ added in v0.1.0
Atomic value is a wrapper around sync/atomic.Value. AtomicValues should not be copied after first use
func (*AtomicValue[T]) Load ¶ added in v0.1.0
func (av *AtomicValue[T]) Load() T
Load fetches a value
func (*AtomicValue[T]) Store ¶ added in v0.1.0
func (av *AtomicValue[T]) Store(v T)
Store stores a value
func (*AtomicValue[T]) Swap ¶ added in v0.1.0
func (av *AtomicValue[T]) Swap(new T) T
Swap exchanges a value for the current value. If there is no current value, the zero value of T is returned. Unlike sync/atomic.Value_Swap, the nil value is allowed if T is a pointer type.
type CompareMap ¶
type CompareMap[K comparable, V comparable] struct { SyncMap[K, V] }
CompareMap is a wrapper of sync.Map. It uses generics so that casting is not required. All methods directly correspond to sync.Map methods. Do not copy a SyncMap after you start using it.
CompareMap is only available when compiling with go 1.20 and above.
CompareMap requires that values be comparable which is not true of SyncMap.
func (*CompareMap[K, V]) CompareAndDelete ¶
func (m *CompareMap[K, V]) CompareAndDelete(key K, old V) (deleted bool)
CompareAndDelete will delete a value from the map if the current value matches the provided value.
func (*CompareMap[K, V]) CompareAndSwap ¶
func (m *CompareMap[K, V]) CompareAndSwap(key K, old V, new V) bool
CompareAndSwap will replace a value in the map if the current value matches the provided "old" value.
type Heap ¶ added in v0.3.0
type Heap[T any] struct { // contains filtered or unexported fields }
Heap is implemented with container/heap and is not thread-safe
type PQItem ¶ added in v0.3.0
type PQItem[P constraints.Ordered] interface { PQItem() *PQItemEmbed[P] }
PQItem is the interface that items in PriorityQueue must implement. Embedding PQItemEmbed is enough to satisfy the interface.
type PQItemEmbed ¶ added in v0.3.0
type PQItemEmbed[P constraints.Ordered] struct { // contains filtered or unexported fields }
PQItemEmbed may be embeded in the priority queue item's data structure, or the data structure can have a PQItemEmbed that it returns when the PQItem() method is called.
func (*PQItemEmbed[P]) PQItem ¶ added in v0.3.0
func (pqe *PQItemEmbed[P]) PQItem() *PQItemEmbed[P]
type PriorityQueue ¶ added in v0.3.0
type PriorityQueue[P constraints.Ordered, T PQItem[P]] struct { // contains filtered or unexported fields }
PriorityQueue is implemented with container/heap and is not thread-safe.
func NewPriorityQueue ¶ added in v0.3.0
func NewPriorityQueue[P constraints.Ordered, T PQItem[P]]() *PriorityQueue[P, T]
NewPriorityQueue creates a PriorityQueue from a comparison function.
func (*PriorityQueue[P, T]) Dequeue ¶ added in v0.3.0
func (h *PriorityQueue[P, T]) Dequeue() T
Dequeue is O(log n)
func (*PriorityQueue[P, T]) Enqueue ¶ added in v0.3.0
func (h *PriorityQueue[P, T]) Enqueue(x T, priority P)
Push is O(log n)
func (PriorityQueue[P, T]) Len ¶ added in v0.3.0
func (h PriorityQueue[P, T]) Len() int
func (*PriorityQueue[P, T]) Remove ¶ added in v0.3.0
func (h *PriorityQueue[P, T]) Remove(x T)
Remove takes an item out of the priority queue
type SyncMap ¶
type SyncMap[K comparable, V any] struct { sync.Map }
SyncMap is a wrapper of sync.Map. It uses generics so that casting is not required. All methods directly correspond to sync.Map methods. Do not copy a SyncMap after you start using it.
func (*SyncMap[K, V]) Delete ¶
func (m *SyncMap[K, V]) Delete(key K)
Delete removes an item from the map
func (*SyncMap[K, V]) Load ¶
Load looks up an item in the map. The bool is true if the value was found in the map.
func (*SyncMap[K, V]) LoadAndDelete ¶
LoadAndDelete looks up an item in the map, removes it from the map, and returns it. The boolean is true if the item was present in the map.
func (*SyncMap[K, V]) LoadOrStore ¶
LoadOrStore looks up an item in the map. If present, it returns it and the returned boolean is true. If not present, the provided value is stored in the map and also returned.
func (*SyncMap[K, V]) Range ¶
Range iterates over the values in the map. Iteration stops if the provided function returns false. The provided value is not safe to use because it can be already overwritten at the time it is received. (Or at least that's my reading of the sync.Map documentation).