Documentation
¶
Index ¶
- type ListOrderedMap
- func (p *ListOrderedMap[K, V]) Add(key K, value V)
- func (p *ListOrderedMap[K, V]) Clear()
- func (p *ListOrderedMap[K, V]) Del(key K)
- func (p *ListOrderedMap[K, V]) Find(key K) (V, bool)
- func (p *ListOrderedMap[K, V]) First() (K, V, bool)
- func (p *ListOrderedMap[K, V]) Foreach(f func(key K, value V) (isContinue bool))
- func (p *ListOrderedMap[K, V]) Last() (K, V, bool)
- func (p *ListOrderedMap[K, V]) Len() int
- func (p *ListOrderedMap[K, V]) ReverseForeach(f func(key K, value V) (isContinue bool))
- func (p *ListOrderedMap[K, V]) Shrink()
- type MapMgr
- func (p *MapMgr[TKey, TVal]) Add(key TKey, value TVal)
- func (p *MapMgr[TKey, TVal]) AddIfNotExist(key TKey, value TVal) bool
- func (p *MapMgr[TKey, TVal]) Clear()
- func (p *MapMgr[TKey, TVal]) Del(key ...TKey)
- func (p *MapMgr[TKey, TVal]) Find(key TKey) (TVal, bool)
- func (p *MapMgr[TKey, TVal]) Foreach(f func(key TKey, value TVal) (isContinue bool))
- func (p *MapMgr[TKey, TVal]) Get(key TKey) TVal
- func (p *MapMgr[TKey, TVal]) IsExist(key TKey) bool
- func (p *MapMgr[TKey, TVal]) Len() int
- func (p *MapMgr[TKey, TVal]) RadomGet() (TKey, TVal, bool)
- func (p *MapMgr[TKey, TVal]) Shrink()
- type MapMutexMgr
- func (p *MapMutexMgr[TKey, TVal]) Add(key TKey, value TVal)
- func (p *MapMutexMgr[TKey, TVal]) AddIfNotExist(key TKey, value TVal) bool
- func (p *MapMutexMgr[TKey, TVal]) Clear()
- func (p *MapMutexMgr[TKey, TVal]) Del(key ...TKey)
- func (p *MapMutexMgr[TKey, TVal]) Find(key TKey) (TVal, bool)
- func (p *MapMutexMgr[TKey, TVal]) Foreach(f func(key TKey, value TVal) (isContinue bool))
- func (p *MapMutexMgr[TKey, TVal]) Get(key TKey) TVal
- func (p *MapMutexMgr[TKey, TVal]) Len() int
- func (p *MapMutexMgr[TKey, TVal]) RadomGet() (TKey, TVal, bool)
- func (p *MapMutexMgr[TKey, TVal]) Shrink()
- type SliceOrderedMapdeprecated
- func (p *SliceOrderedMap[K, V]) Add(key K, value V)
- func (p *SliceOrderedMap[K, V]) Clear()
- func (p *SliceOrderedMap[K, V]) Del(key K)
- func (p *SliceOrderedMap[K, V]) Find(key K) (V, bool)
- func (p *SliceOrderedMap[K, V]) Foreach(f func(key K, value V) (isContinue bool))
- func (p *SliceOrderedMap[K, V]) Len() int
- func (p *SliceOrderedMap[K, V]) ReverseForeach(f func(key K, value V) (isContinue bool))
- func (p *SliceOrderedMap[K, V]) Shrink()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ListOrderedMap ¶
type ListOrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
ListOrderedMap 使用双向链表实现的有序映射
func NewListOrderedMap ¶
func NewListOrderedMap[K comparable, V any]() *ListOrderedMap[K, V]
NewListOrderedMap 创建新的实例
func (*ListOrderedMap[K, V]) First ¶
func (p *ListOrderedMap[K, V]) First() (K, V, bool)
First 获取第一个元素
func (*ListOrderedMap[K, V]) Foreach ¶
func (p *ListOrderedMap[K, V]) Foreach(f func(key K, value V) (isContinue bool))
Foreach 遍历元素
f 返回 false 时停止遍历 [⚠️] Foreach 中调用增加或移除元素的方法,可能会影响遍历结果.
func (*ListOrderedMap[K, V]) Last ¶
func (p *ListOrderedMap[K, V]) Last() (K, V, bool)
Last 获取最后一个元素
func (*ListOrderedMap[K, V]) ReverseForeach ¶
func (p *ListOrderedMap[K, V]) ReverseForeach(f func(key K, value V) (isContinue bool))
ReverseForeach 反向遍历元素
f 返回 false 时停止遍历 [⚠️] ReverseForeach 中调用增加或移除元素的方法,可能会影响遍历结果.
type MapMgr ¶
type MapMgr[TKey comparable, TVal any] struct { // contains filtered or unexported fields }
func NewMapMgr ¶
func NewMapMgr[TKey comparable, TVal any]() *MapMgr[TKey, TVal]
NewMapMgr 创建 Mgr 实例
func (*MapMgr[TKey, TVal]) AddIfNotExist ¶
AddIfNotExist 添加元素, 如果不存在则-添加-返回true, 如果存在则-不添加-返回false
func (*MapMgr[TKey, TVal]) Foreach ¶
Foreach 遍历所有元素
如果 f 返回 false,则停止遍历 [⚠️] Foreach 中调用增加或移除元素的方法,可能会影响遍历结果
type MapMutexMgr ¶
type MapMutexMgr[TKey comparable, TVal any] struct { // contains filtered or unexported fields }
func NewMapMutexMgr ¶
func NewMapMutexMgr[TKey comparable, TVal any]() *MapMutexMgr[TKey, TVal]
NewMapMutexMgr 创建 Mgr 实例
func (*MapMutexMgr[TKey, TVal]) Add ¶
func (p *MapMutexMgr[TKey, TVal]) Add(key TKey, value TVal)
Add 添加元素
func (*MapMutexMgr[TKey, TVal]) AddIfNotExist ¶
func (p *MapMutexMgr[TKey, TVal]) AddIfNotExist(key TKey, value TVal) bool
AddIfNotExist 添加元素,如果不存在则添加
func (*MapMutexMgr[TKey, TVal]) Find ¶
func (p *MapMutexMgr[TKey, TVal]) Find(key TKey) (TVal, bool)
Find 查找元素
func (*MapMutexMgr[TKey, TVal]) Foreach ¶
func (p *MapMutexMgr[TKey, TVal]) Foreach(f func(key TKey, value TVal) (isContinue bool))
Foreach 遍历所有元素
如果 f 返回 false, 则停止遍历 [⚠️] f 中不要再次调用含有互斥锁的方法 [⚠️] Foreach 中调用增加或移除元素的方法,可能会影响遍历结果
func (*MapMutexMgr[TKey, TVal]) RadomGet ¶
func (p *MapMutexMgr[TKey, TVal]) RadomGet() (TKey, TVal, bool)
RadomGet 随机获取
func (*MapMutexMgr[TKey, TVal]) Shrink ¶
func (p *MapMutexMgr[TKey, TVal]) Shrink()
Shrink 优化内存使用
通过创建新的 map 并复制数据来释放多余内存
type SliceOrderedMap
deprecated
type SliceOrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
SliceOrderedMap 是一个泛型结构体,它使用 slice (保持元素插入顺序) 和 map 来保持元素
Deprecated: 使用 ListOrderedMap 代替 [❕] 这个操作在切片较大时可能效率不高 但在大多数情况下是可以接受的. 如果需要频繁地删除元素 并且关心性能 需要考虑使用其他数据结构, 如链表或双向队列, 来维护键的顺序
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *SliceOrderedMap[K, V]
NewOrderedMap 创建一个新的实例
func (*SliceOrderedMap[K, V]) Find ¶
func (p *SliceOrderedMap[K, V]) Find(key K) (V, bool)
Find 根据键获取值
func (*SliceOrderedMap[K, V]) Foreach ¶
func (p *SliceOrderedMap[K, V]) Foreach(f func(key K, value V) (isContinue bool))
Foreach 迭代,按插入顺序
[⚠️] Foreach 中调用增加或移除元素的方法,可能会影响遍历结果
func (*SliceOrderedMap[K, V]) ReverseForeach ¶
func (p *SliceOrderedMap[K, V]) ReverseForeach(f func(key K, value V) (isContinue bool))
ReverseForeach 反向迭代,按插入顺序
[⚠️] ReverseForeach 中调用增加或移除元素的方法,可能会影响遍历结果
Click to show internal directories.
Click to hide internal directories.