Documentation
¶
Index ¶
- type RWMap
- func (m *RWMap[K, V]) Clear()
- func (m *RWMap[K, V]) CreateIfMissing(key K, fn func() V) (changed bool)
- func (m *RWMap[K, V]) Delete(key K)
- func (m *RWMap[K, V]) Get(key K) (value V, ok bool)
- func (m *RWMap[K, V]) Has(key K) (ok bool)
- func (m *RWMap[K, V]) Keys() (out []K)
- func (m *RWMap[K, V]) Len() int
- func (m *RWMap[K, V]) Range(f func(key K, value V) bool)
- func (m *RWMap[K, V]) Set(key K, value V)
- func (m *RWMap[K, V]) SetIfMissing(key K, v V) (changed bool)
- func (m *RWMap[K, V]) Values() (out []V)
- type RWValue
- type Watch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RWMap ¶
type RWMap[K comparable, V any] struct { // contains filtered or unexported fields }
RWMap is a simple wrapper around a map, with global Read-Write protection. For many concurrent reads/writes a sync.Map may be more performant, although it does not utilize Go generics. The RWMap does not have to be initialized, it is immediately ready for reads/writes.
func RWMapFromMap ¶ added in v1.12.0
func RWMapFromMap[K comparable, V any](m map[K]V) *RWMap[K, V]
RWMapFromMap creates a RWMap from the given map. This shallow-copies the map, changes to the original map will not affect the new RWMap.
func (*RWMap[K, V]) Clear ¶
func (m *RWMap[K, V]) Clear()
Clear removes all key-value pairs from the map.
func (*RWMap[K, V]) CreateIfMissing ¶ added in v1.12.0
CreateIfMissing creates a value at the given key, if the key is not set yet.
func (*RWMap[K, V]) Keys ¶ added in v1.12.0
func (m *RWMap[K, V]) Keys() (out []K)
Keys returns an unsorted list of keys of the map.
func (*RWMap[K, V]) Range ¶
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
func (*RWMap[K, V]) SetIfMissing ¶ added in v1.12.0
SetIfMissing is a convenience function to set a missing value if it does not already exist. To lazy-init the value, see CreateIfMissing.
type RWValue ¶
RWValue is a simple container struct, to deconflict reads/writes of the value, without locking up a bigger structure in the caller. It exposes the underlying RWLock and Value for direct access where needed.
type Watch ¶ added in v1.11.0
type Watch[E any] struct { // contains filtered or unexported fields }
Watch makes a value watch-able: every change will be notified to those watching.