Documentation
¶
Index ¶
- type Map
- func (m *Map[Key, Value]) Delete(key Key)
- func (m *Map[Key, Value]) Empty() bool
- func (m *Map[Key, Value]) Load(key Key) (Value, bool)
- func (m *Map[Key, Value]) LoadAndDelete(key Key) (Value, bool)
- func (m *Map[Key, Value]) LoadOrStore(key Key, newValue Value) (Value, bool)
- func (m *Map[Key, Value]) LoadOrStoreNew(key Key, valueFactory func() Value) (Value, bool)
- func (m *Map[Key, Value]) Range(f func(key Key, value Value) bool)
- func (m *Map[Key, Value]) Store(key Key, value Value)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[Key comparable, Value any] sync.Map
func (*Map[Key, Value]) Delete ¶
func (m *Map[Key, Value]) Delete(key Key)
Deletes the value for the passed key. If the key has no corresponding value, the map is unchanged.
func (*Map[Key, Value]) Empty ¶
Returns true if the map is empty. Note that this is point-in-time check, and the map might be modified immediately after this method returns.
func (*Map[Key, Value]) Load ¶
Returns the value stored in the map (if found), and a boolean indicating whether the value was found.
func (*Map[Key, Value]) LoadAndDelete ¶
Loads and deletes the value for the passed key. If the key has no corresponding value, the map is unchanged and the returned boolean is false.
func (*Map[Key, Value]) LoadOrStore ¶
Loads and returns the value for for the passed key. If the key has no corresponding value, the newValue is stored and returned. The returned boolean is true if the value was already in the map, and false if the new value was stored.
func (*Map[Key, Value]) LoadOrStoreNew ¶
Loads and returns the value for for the passed key. If the key has no corresponding value, a new value is created using the passed valueFactory, then stored and returned. The returned boolean is true if the value was already in the map, and false if the new value was stored.
Note: in high-contention conditions the value factory function might be called even if the key is already in the map. If this happens, the existing value is returned and the new value is discarded.