Documentation
¶
Overview ¶
Package atomicmap contains functions, methods and types for the AtomicMap type. AtomicMaps themselves are thread-safe map implementations.
Index ¶
- type AtomicMap
- func (m *AtomicMap[K, V]) Clear()
- func (m *AtomicMap[K, V]) Clone() map[K]V
- func (m *AtomicMap[K, V]) Delete(key K) bool
- func (m *AtomicMap[K, V]) Get(key K) (V, bool)
- func (m *AtomicMap[K, V]) Len() int
- func (m *AtomicMap[K, V]) Set(key K, value V)
- func (m *AtomicMap[K, V]) SetIfNotExists(key K, value V) bool
- func (m *AtomicMap[K, V]) Update(key K, value V) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtomicMap ¶
type AtomicMap[K comparable, V any] struct { // contains filtered or unexported fields }
AtomicMap is a thread-safe map-wrapper. Internally it works by wrapping a map and a mutex and offering methods for interacting with the data.
func From ¶
func From[K comparable, V any](m map[K]V) *AtomicMap[K, V]
From Creates a new thread-safe map from an existing map. The supplied parameter will be shallowly cloned, as such, storing pointers is not recommended. If you must store pointers, it is recommended to use AtomicBox
func New ¶
func New[K comparable, V any]() *AtomicMap[K, V]
New creates a new empty, thread-safe map. It returns a pointer to the AtomicMap-object in the heap.
func (*AtomicMap[K, V]) Clear ¶ added in v0.4.0
func (m *AtomicMap[K, V]) Clear()
Clear is a method for Clearing the Map, deleting all entries.
func (*AtomicMap[K, V]) Clone ¶
func (m *AtomicMap[K, V]) Clone() map[K]V
Clone Method for cloning the internal map. It will return the internal map, which the struct stores. The map is copied-by-value, not by reference. Since the clone is shallow, storing pointers is not recommended as those will still point to the same object.
func (*AtomicMap[K, V]) Delete ¶
Delete Method for deleting value with a key. Returns bool, which reports if a delete went well or not.
func (*AtomicMap[K, V]) Get ¶
Get method for getting a value with a key. Returns V and bool, where V is the value of the key and bool represents if access was successful or not.
func (*AtomicMap[K, V]) Set ¶
func (m *AtomicMap[K, V]) Set(key K, value V)
Set Method for setting a value with a key. The value of the key is not immutable and overwriting data may happen. If overwrites are not allowed to happen, consider using SetIfNotExists instead.
func (*AtomicMap[K, V]) SetIfNotExists ¶
SetIfNotExists Method for setting value with a key if it does not exist. Similar to the regular Set method, but keys are treated as immutable. Returns a bool. True if the key was set, else false.