Documentation
¶
Overview ¶
Package safemap provides a concurrency-safe generic map.
Index ¶
- func ToSlice[K comparable, V any, T any](sm *SafeMap[K, V], mapFn func(K, V) T) []T
- type SafeMap
- func (s *SafeMap[K, V]) Clear()
- func (s *SafeMap[K, V]) Compute(key K, fn func(prev V, ok bool) (next V, delete bool)) (V, bool)
- func (s *SafeMap[K, V]) Delete(key K)
- func (s *SafeMap[K, V]) Get(key K) (V, bool)
- func (s *SafeMap[K, V]) Has(key K) bool
- func (s *SafeMap[K, V]) Keys() []K
- func (s *SafeMap[K, V]) Len() int
- func (s *SafeMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (s *SafeMap[K, V]) Range(fn func(K, V) bool)
- func (s *SafeMap[K, V]) Set(key K, value V)
- func (s *SafeMap[K, V]) ToMap() map[K]V
- func (s *SafeMap[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type SafeMap ¶
type SafeMap[K comparable, V any] struct { // contains filtered or unexported fields }
SafeMap is a threadsafe map[K]V.
func NewFrom ¶
func NewFrom[K comparable, V any](src map[K]V) *SafeMap[K, V]
NewFrom initializes the map from an existing map (copied).
func (*SafeMap[K, V]) Compute ¶
Compute atomically updates the value for key using fn. If fn returns delete=true, the entry is removed.
func (*SafeMap[K, V]) LoadOrStore ¶
LoadOrStore returns the existing value if present; otherwise stores and returns the given value.
Click to show internal directories.
Click to hide internal directories.