1 Star 1 Fork 0

Breeze/bzv2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pop.go 494 Bytes
一键复制 编辑 原始数据 按行查看 历史
Breeze 提交于 2023-08-13 23:16 +08:00 . first commit
package bzgncmap
import (
"sync/atomic"
)
// Pop 随机出栈
func (m *Map[K, V]) Pop(count int) map[K]V {
if count <= 0 {
return nil
}
if int(m.Len()) < count {
count = int(m.Len())
}
// 根据 key 匹配 value
newM := make(map[K]V, count)
var i int32
m.getFunc(func(ms map[K]V) {
for key, value := range ms {
it := atomic.LoadInt32(&i)
if it > int32(count-1) {
break
}
atomic.AddInt32(&i, 1)
newM[key] = value
delete(m.m, key)
}
})
return newM
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/breezeHub/bzv2.git
git@gitee.com:breezeHub/bzv2.git
breezeHub
bzv2
bzv2
v0.0.5

搜索帮助