syncmap

package
v5.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

A Map is a map of a string to a generified value which is locked for safe access from multiple threads. It is effectively a generic version of Golang's standard library sync.Map. Admittedly, that has optimizations for multithreading performance that we do not here; thus, Map should not be used in truly performance sensitive areas, but places where code cleanliness is more important than raw performance. Map must always be passed by reference, not by value, to ensure thread safety is maintained.

func New

func New[K comparable, V any]() *Map[K, V]

New generates a new, empty Map

func (*Map[K, V]) Delete

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

Delete removes an entry from the map.

func (*Map[K, V]) Exists

func (m *Map[K, V]) Exists(key K) bool

Exists returns true if a key exists in the map.

func (*Map[K, V]) Get

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

Get retrieves an entry from the map. Semantic match Golang map semantics - the bool represents whether the key exists, and the empty value of T will be returned if the key does not exist.

func (*Map[K, V]) Put

func (m *Map[K, V]) Put(key K, value V)

Put adds an entry into the map

func (*Map[K, V]) ToMap

func (m *Map[K, V]) ToMap() map[K]V

ToMap returns a shallow copy of the underlying data of the Map.

func (*Map[K, V]) Underlying

func (m *Map[K, V]) Underlying() map[K]V

Underlying returns a reference to the underlying storage of the Map. Once Underlying has been called, the Map is NO LONGER THREAD SAFE. If thread safety is still required, the shallow-copy offered by ToMap() should be used instead.

Jump to

Keyboard shortcuts

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