maps

package
v0.0.0-...-4e0b803 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 2 Imported by: 2

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
}

Map is a concurrent map with generic key and value types.

func New

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

New creates and returns a new Map instance.

func (*Map[K, V]) Clear

func (m *Map[K, V]) Clear()

Clear removes all entries from the map.

func (*Map[K, V]) Clone

func (m *Map[K, V]) Clone() *Map[K, V]

Clone creates and returns a shallow copy of the Map.

func (*Map[K, V]) CompareAndDelete

func (m *Map[K, V]) CompareAndDelete(key K, value V) (deleted bool)

CompareAndDelete deletes the entry for a key only if it is currently mapped to a given value.

func (*Map[K, V]) CompareAndSwap

func (m *Map[K, V]) CompareAndSwap(key, old, new any) (swapped bool)

CompareAndSwap swaps the entry for a key only if it is currently mapped to a given value.

func (*Map[K, V]) Delete

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

Delete removes the value for a given key.

func (*Map[K, V]) Load

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

Load retrieves the value for a given key.

func (*Map[K, V]) LoadAndDelete

func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)

LoadAndDelete retrieves and deletes the value for a given key.

func (*Map[K, V]) LoadOrStore

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

LoadOrStore retrieves the existing value for a key or stores and returns the given value if the key is not present.

func (*Map[K, V]) MarshalJSON

func (m *Map[K, V]) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for the Map type.

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(f func(key K, value V) bool)

Range iterates over all key-value pairs in the map.

func (*Map[K, V]) Store

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

Store sets the value for a given key.

func (*Map[K, V]) Swap

func (m *Map[K, V]) Swap(key, value any) (previous any, loaded bool)

Swap sets the value for a key and returns the previous value and whether it was present.

func (*Map[K, V]) ToKeys

func (m *Map[K, V]) ToKeys() []K

ToKeys returns a slice of all keys in the map.

func (*Map[K, V]) ToMap

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

Clone creates and returns a shallow copy of the map as a standard map.

func (*Map[K, V]) ToValues

func (m *Map[K, V]) ToValues() []V

ToValues returns a slice of all values in the map.

func (*Map[K, V]) UnmarshalJSON

func (m *Map[K, V]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for the Map type.

Jump to

Keyboard shortcuts

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