Documentation
¶
Index ¶
- type ConcurrentMap
- func (m *ConcurrentMap[K, T]) All() iter.Seq2[K, T]
- func (m *ConcurrentMap[K, T]) Delete(key K) bool
- func (m *ConcurrentMap[K, T]) Get(key K) T
- func (m *ConcurrentMap[K, T]) GetOrCreate(key K, create func() (T, error)) (T, error)
- func (m *ConcurrentMap[K, T]) Lookup(key K) (T, bool)
- func (m *ConcurrentMap[K, T]) Set(key K, value T)
- func (m *ConcurrentMap[K, T]) WithWriteLock(f func(m map[K]T) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentMap ¶
type ConcurrentMap[K comparable, T any] struct { // contains filtered or unexported fields }
ConcurrentMap is a thread safe map backed by a Go map.
func NewConcurrentMap ¶
func NewConcurrentMap[K comparable, T any]() *ConcurrentMap[K, T]
NewConcurrentMap creates a new ConcurrentMap.
func (*ConcurrentMap[K, T]) All ¶
func (m *ConcurrentMap[K, T]) All() iter.Seq2[K, T]
All returns an iterator over all key/value pairs in the map. A read lock is held during the iteration.
func (*ConcurrentMap[K, T]) Delete ¶
func (m *ConcurrentMap[K, T]) Delete(key K) bool
Delete deletes the given key from the map. It returns true if the key was found and deleted, false otherwise.
func (*ConcurrentMap[K, T]) Get ¶
func (m *ConcurrentMap[K, T]) Get(key K) T
Get gets the value for the given key. It returns the zero value of T if the key is not found.
func (*ConcurrentMap[K, T]) GetOrCreate ¶
func (m *ConcurrentMap[K, T]) GetOrCreate(key K, create func() (T, error)) (T, error)
GetOrCreate gets the value for the given key if it exists, or creates it if not.
func (*ConcurrentMap[K, T]) Lookup ¶
func (m *ConcurrentMap[K, T]) Lookup(key K) (T, bool)
Lookup looks up the given key in the map. It returns the value and a boolean indicating whether the key was found.
func (*ConcurrentMap[K, T]) Set ¶
func (m *ConcurrentMap[K, T]) Set(key K, value T)
Set sets the given key to the given value.
func (*ConcurrentMap[K, T]) WithWriteLock ¶
func (m *ConcurrentMap[K, T]) WithWriteLock(f func(m map[K]T) error) error
WithWriteLock executes the given function with a write lock on the map. Note that the map m should only be accessed within the function f.