代码拉取完成,页面将自动刷新
package eventbus
import (
"sync"
"sync/atomic"
)
// CowMap is a wrapper of Copy-On-Write map
//
// If a fully meaningful CowMap is implemented, both sync.Map and
// CowMap utilize atomic.Value atomic operations to access the map
// during data reading, resulting in similar read performance.
// In reality, sync.Map is already a read-write separated structure,
// yet it has better write performance. Therefore, CowMap directly
// utilizes sync.Map as its internal structure.
type CowMap struct {
sync.Map
}
// CowMap creates a new CowMap instance
func NewCowMap() *CowMap {
return &CowMap{}
}
// Len returns the number of key-value pairs stored in the map
func (c *CowMap) Len() uint32 {
var size uint32
c.Range(func(k, v any) bool {
atomic.AddUint32(&size, 1)
return true
})
return size
}
// Clear Removes all key-value pairs from the map
func (c *CowMap) Clear() {
c.Range(func(k, v any) bool {
c.Delete(k)
return true
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。