Documentation ¶
Index ¶
- func MaxHeap[T constraints.Ordered](a, b T) bool
- func MinHeap[T constraints.Ordered](a, b T) bool
- type Heap
- 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)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaxHeap ¶
func MaxHeap[T constraints.Ordered](a, b T) bool
MaxHeap is a comparator function to implement max-heap for any type that supports ordering.
func MinHeap ¶
func MinHeap[T constraints.Ordered](a, b T) bool
MinHeap is a comparator function to implement min-heap for any type that supports ordering.
Types ¶
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
Heap is a generic port of container.Heap. Not safe to use concurrently.
func (*Heap[T]) Peek ¶
func (h *Heap[T]) Peek() T
Peek returns the top value without removing it from the heap. Will panic if the heap is empty.
func (*Heap[T]) Pop ¶
func (h *Heap[T]) Pop() T
Pop returns and removes the top element from the heap. Panics if there are no elements.
type SyncMap ¶
type SyncMap[K comparable, V any] struct { // contains filtered or unexported fields }
SyncMap is a generic wrapper around sync.Map that allows you to specify the key and value types to avoid type assertions and casting.
func (*SyncMap[K, V]) Delete ¶
func (m *SyncMap[K, V]) Delete(key K)
Delete deletes the value for a key.
func (*SyncMap[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 (*SyncMap[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 (*SyncMap[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.