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]) 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 wrapper for sync.Map that supports type-safe operations. 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 provided value and deletes the entry if they match. CompareAndDelete 比较存在的值与提供的值,如果匹配,则删除条目。
func (*Map[K, V]) CompareAndSwap ¶
CompareAndSwap compares the existing value with the old value and swaps it with the new value if they match. CompareAndSwap 将存在的值与旧值比较,如果匹配,则替换为新值。
func (*Map[K, V]) Count ¶
Count returns the count num of key-value pairs in the Map. Count 返回 Map 中的键值对数量。
func (*Map[K, V]) Debug ¶
func (m *Map[K, V]) Debug()
Debug prints all key-value pairs for debugging purposes. Debug 打印所有键值对,主要用于调试逻辑。
func (*Map[K, V]) Delete ¶
func (m *Map[K, V]) Delete(key K)
Delete removes the value associated with the specified key. Delete 删除指定键相关的值。
func (*Map[K, V]) GetMap ¶
func (m *Map[K, V]) GetMap() map[K]V
GetMap returns all key-value pairs as a standard Go map. GetMap 返回所有键值对,格式为标准的 Go map。
func (*Map[K, V]) Keys ¶
func (m *Map[K, V]) Keys() (keys []K)
Keys retrieves all keys from the Map. Keys 返回 Map 中的所有键。
func (*Map[K, V]) Load ¶
Load retrieves the value associated with the specified key. Load 获取与指定键相关的值。
func (*Map[K, V]) LoadAndDelete ¶
LoadAndDelete retrieves and removes the value associated with the specified key. LoadAndDelete 获取并删除与指定键相关的值。
func (*Map[K, V]) LoadOrStore ¶
LoadOrStore retrieves the value associated with the key or stores and returns the new value if the key does not exist. LoadOrStore 获取指定键相关的值,如果键不存在,则存储并返回新值。
func (*Map[K, V]) SetMap ¶
func (m *Map[K, V]) SetMap(mp map[K]V)
SetMap adds or updates key-value pairs from a standard Go map. SetMap 将标准 Go map 中的键值对添加或更新到 Map。
func (*Map[K, V]) SetSyncMap ¶
SetSyncMap copies all key-value pairs from a Map. SetSyncMap 复制一个 Map 中的所有键值对到当前 Map。
func (*Map[K, V]) SetSyncMaps ¶
SetSyncMaps copies all key-value pairs 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 for the specified key. Store 为指定的键设置值。