Documentation
¶
Index ¶
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Clone() *Map[K, V]
- func (m *Map[K, V]) CompareAndDelete(key K, value V) (deleted bool)
- func (m *Map[K, V]) CompareAndSwap(key, old, new any) (swapped bool)
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Load(key K) (V, bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *Map[K, V]) LoadOrStore(key K, value V) (V, bool)
- func (m *Map[K, V]) MarshalJSON() ([]byte, error)
- func (m *Map[K, V]) Range(f func(key K, value V) bool)
- func (m *Map[K, V]) Store(key K, value V)
- func (m *Map[K, V]) Swap(key, value any) (previous any, loaded bool)
- func (m *Map[K, V]) ToKeys() []K
- func (m *Map[K, V]) ToMap() map[K]V
- func (m *Map[K, V]) ToValues() []V
- func (m *Map[K, V]) UnmarshalJSON(data []byte) error
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]) CompareAndDelete ¶
CompareAndDelete deletes the entry for a key only if it is currently mapped to a given value.
func (*Map[K, V]) CompareAndSwap ¶
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]) LoadAndDelete ¶
LoadAndDelete retrieves and deletes the value for a given key.
func (*Map[K, V]) LoadOrStore ¶
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 ¶
MarshalJSON implements the json.Marshaler interface for the Map type.
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 ¶
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 ¶
UnmarshalJSON implements the json.Unmarshaler interface for the Map type.