Documentation
¶
Index ¶
- type MapBackData
- func (b *MapBackData[K, V]) Add(key K, value V) bool
- func (b *MapBackData[K, V]) Adjust(key K, f func(V) V) (value V, ok bool)
- func (b *MapBackData[K, V]) AdjustWithInit(key K, adjust func(V) V, init func() V) (V, bool)
- func (b *MapBackData[K, V]) All() map[K]V
- func (b *MapBackData[K, V]) Clear()
- func (b *MapBackData[K, V]) Get(key K) (value V, ok bool)
- func (b *MapBackData[K, V]) Has(key K) bool
- func (b *MapBackData[K, V]) Keys() []K
- func (b *MapBackData[K, V]) Remove(key K) (value V, ok bool)
- func (b *MapBackData[K, V]) Size() uint
- func (b *MapBackData[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MapBackData ¶
type MapBackData[K comparable, V any] struct { // contains filtered or unexported fields }
MapBackData implements a map-based generic memory BackData backed by a Go map. Note that this implementation is NOT thread-safe, and the higher-level Backend is responsible for concurrency management.
func NewMapBackData ¶
func NewMapBackData[K comparable, V any]() *MapBackData[K, V]
func (*MapBackData[K, V]) Add ¶
func (b *MapBackData[K, V]) Add(key K, value V) bool
Add attempts to add the given value to the backdata, without overwriting existing data. If a value is already stored under the input key, Add is a no-op and returns false. If no value is stored under the input key, Add adds the value and returns true.
func (*MapBackData[K, V]) Adjust ¶
func (b *MapBackData[K, V]) Adjust(key K, f func(V) V) (value V, ok bool)
Adjust adjusts the value using the given function if the given key can be found. Returns:
- the updated value for the key (if the key exists)
- a boolean indicating whether the key was found (and the update applied)
func (*MapBackData[K, V]) AdjustWithInit ¶ added in v0.33.1
func (b *MapBackData[K, V]) AdjustWithInit(key K, adjust func(V) V, init func() V) (V, bool)
AdjustWithInit adjusts the value using the provided function if the key is found. If the key is not found, it initializes the value using the given init function and then applies the adjustment.
Args: - key: The key for which the value should be adjusted. - adjust: the function that adjusts the value. - init: A function that initializes the value if the key is not present.
Returns: - the adjusted value. - a bool which indicates whether the value was adjusted (for MapBackData this is always true)
func (*MapBackData[K, V]) All ¶
func (b *MapBackData[K, V]) All() map[K]V
All returns all stored key-value pairs as a map.
func (*MapBackData[K, V]) Clear ¶
func (b *MapBackData[K, V]) Clear()
Clear removes all key-value pairs from the backdata.
func (*MapBackData[K, V]) Get ¶ added in v0.43.0
func (b *MapBackData[K, V]) Get(key K) (value V, ok bool)
Get returns the value for the given key. Returns true if the key-value pair exists, and false otherwise.
func (*MapBackData[K, V]) Has ¶
func (b *MapBackData[K, V]) Has(key K) bool
Has checks if a value is stored under the given key.
func (*MapBackData[K, V]) Keys ¶ added in v0.43.0
func (b *MapBackData[K, V]) Keys() []K
Keys returns an unordered list of keys stored in the backdata.
func (*MapBackData[K, V]) Remove ¶ added in v0.27.0
func (b *MapBackData[K, V]) Remove(key K) (value V, ok bool)
Remove removes the value with the given key. If the key-value pair exists, returns the value and true. Otherwise, returns the zero value for type V and false.
func (*MapBackData[K, V]) Size ¶
func (b *MapBackData[K, V]) Size() uint
Size returns the number of stored key-value pairs.
func (*MapBackData[K, V]) Values ¶ added in v0.43.0
func (b *MapBackData[K, V]) Values() []V
Values returns an unordered list of values stored in the backdata.