atomicmap

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package atomicmap contains functions, methods and types for the AtomicMap type. AtomicMaps themselves are thread-safe map implementations.

Index

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

func (m *AtomicMap[K, V]) Delete(key K) bool

Delete Method for deleting value with a key. Returns bool, which reports if a delete went well or not.

func (*AtomicMap[K, V]) Get

func (m *AtomicMap[K, V]) Get(key K) (V, bool)

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]) Len added in v0.4.0

func (m *AtomicMap[K, V]) Len() int

Len method for getting the current length of the map.

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

func (m *AtomicMap[K, V]) SetIfNotExists(key K, value V) bool

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.

func (*AtomicMap[K, V]) Update

func (m *AtomicMap[K, V]) Update(key K, value V) bool

Update Method for updating a value with its key. This method is exclusively meant for explicitly modifying an existing key. If the key does not exist, it will not set the value either. It returns bool, which reports whether an update went well or not.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL