Documentation
¶
Index ¶
- type Map
- func (m *Map[K, V]) CompareAndDelete(key K, value V) bool
- func (m *Map[K, V]) CompareAndSwap(key K, old, new V) bool
- func (m *Map[K, V]) Count() (size int)
- func (m *Map[K, V]) Debug()
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) GetMap() map[K]V
- func (m *Map[K, V]) Has(key K) bool
- func (m *Map[K, V]) Keys() (keys []K)
- func (m *Map[K, V]) Load(key K) (res V, ok bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (res V, ok bool)
- func (m *Map[K, V]) LoadOrStore(key K, new V) (V, bool)
- func (m *Map[K, V]) Range(run func(key K, value V) bool)
- func (m *Map[K, V]) SetMap(mp map[K]V)
- func (m *Map[K, V]) SetSyncMap(mp *Map[K, V])
- func (m *Map[K, V]) SetSyncMaps(mps ...*Map[K, V])
- func (m *Map[K, V]) Store(key K, value V)
- func (m *Map[K, V]) Swap(key K, value V) (pre V, ok bool)
- func (m *Map[K, V]) Values() (values []V)
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 generic type-safe interface to sync.Map. Map 是 sync.Map 的泛型类型安全接口。
func New ¶ added in v1.0.16
func New[K comparable, V any]() *Map[K, V]
New creates a new instance of Map. New 创建一个新的 Map 实例。
func NewMap ¶
func NewMap[K comparable, V any]() *Map[K, V]
NewMap creates a new instance of Map. NewMap 创建一个新的 Map 实例。
func (*Map[K, V]) CompareAndDelete ¶
CompareAndDelete compares the existing value with the given value and deletes the item when both match. CompareAndDelete 比较已存在的值与给定的值,当两者匹配时删除该项。
func (*Map[K, V]) CompareAndSwap ¶
CompareAndSwap compares the existing value with the old value and swaps to the new value when both match. CompareAndSwap 将已存在的值与旧值比较,当两者匹配时替换成新值。
func (*Map[K, V]) Debug ¶
func (m *Map[K, V]) Debug()
Debug prints each item to help with debugging. Debug 打印每一项,用于调试。
func (*Map[K, V]) Delete ¶
func (m *Map[K, V]) Delete(key K)
Delete removes the value associated with the given item. Delete 删除与给定项关联的值。
func (*Map[K, V]) GetMap ¶
func (m *Map[K, V]) GetMap() map[K]V
GetMap returns each item as a standard Go map. GetMap 将每一项作为标准 Go map 返回。
func (*Map[K, V]) Has ¶ added in v1.0.17
Has checks if an item exists in the Map. Has 检查项是否存在于 Map 中。
func (*Map[K, V]) Keys ¶
func (m *Map[K, V]) Keys() (keys []K)
Keys gets each item's name from the Map. Keys 获取 Map 中每项的名称。
func (*Map[K, V]) LoadAndDelete ¶
LoadAndDelete retrieves and removes the value associated with the given item. LoadAndDelete 获取并删除与给定项关联的值。
func (*Map[K, V]) LoadOrStore ¶
LoadOrStore retrieves the value associated with the item, and when the item does not exist, stores and returns the new value. LoadOrStore 获取与项关联的值,当该项不存在时,存储并返回新值。
func (*Map[K, V]) SetMap ¶
func (m *Map[K, V]) SetMap(mp map[K]V)
SetMap adds and updates items from a standard Go map. SetMap 从标准 Go map 添加和更新项到 Map。
func (*Map[K, V]) SetSyncMap ¶
SetSyncMap copies each item from a Map. SetSyncMap 从一个 Map 复制每一项到当前 Map。
func (*Map[K, V]) SetSyncMaps ¶
SetSyncMaps copies each item from multiple Maps. SetSyncMaps 从多个 Map 复制每一项到当前 Map。
func (*Map[K, V]) Store ¶
func (m *Map[K, V]) Store(key K, value V)
Store sets the value of the given item. Store 设置给定项的值。