Documentation
¶
Overview ¶
Package safemap provides a generic, concurrency-safe map wrapper.
All operations are protected by a lockmetrics.RWMutex for concurrent access with full Prometheus instrumentation.
Index ¶
- func ClonePtrMap[K comparable, V any](m map[K]*V) map[K]*V
- func CloneRegionalPtrMap[R comparable, K comparable, V any](m map[R]map[K]*V) map[R]map[K]*V
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Clone() map[K]V
- func (m *Map[K, V]) Close()
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Get(key K) (V, bool)
- func (m *Map[K, V]) Keys() []K
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) Range(f func(K, V) bool)
- func (m *Map[K, V]) Set(key K, value V)
- func (m *Map[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClonePtrMap ¶
func ClonePtrMap[K comparable, V any](m map[K]*V) map[K]*V
ClonePtrMap returns a deep copy of a map whose values are pointers: the returned map has the same keys, but each value points to a freshly allocated copy of the pointed-to value (nil pointers are preserved as nil).
This differs from the standard library's maps.Clone, which copies the map structure but shares the underlying pointers — insufficient for a stable point-in-time snapshot, where the copy must not observe later mutations of the original values. Returns nil when m is nil.
func CloneRegionalPtrMap ¶
func CloneRegionalPtrMap[R comparable, K comparable, V any](m map[R]map[K]*V) map[R]map[K]*V
CloneRegionalPtrMap returns a deep copy of the region-nested pointer maps used pervasively by service backends (outer key = region, inner key = resource name, value = *T). Both map levels are reallocated and each value is value-copied via ClonePtrMap. Returns nil when m is nil.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a generic concurrency-safe map.
The zero value is not usable; always create via New.
func New ¶
func New[K comparable, V any](name string) *Map[K, V]
New creates a new Map. The name appears as the "lock" label in Prometheus metrics and should be a stable, human-readable identifier (e.g. "sqs.queue.my-queue.tags").
func (*Map[K, V]) Clone ¶
func (m *Map[K, V]) Clone() map[K]V
Clone returns a shallow copy of the underlying map.
func (*Map[K, V]) Close ¶
func (m *Map[K, V]) Close()
Close removes the Map's underlying lockmetrics.RWMutex from the global metrics registry. It should be called when the Map is no longer needed to prevent unbounded growth of the Prometheus collector. After Close is called, the Map must not be used.
func (*Map[K, V]) Keys ¶
func (m *Map[K, V]) Keys() []K
Keys returns all keys as a slice in unspecified order.