1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
concurrent_set.go 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-09-02 00:40 . refactor
package list
import "gitee.com/kristas/booting-go/framework/common/util/ccmap"
type ConcurrentSets struct {
cm *ccmap.ConcurrentMap
}
func NewConcurrentSets(arr ...string) (s *ConcurrentSets) {
s = &ConcurrentSets{
cm: ccmap.NewConcurrentMap(),
}
s.PutAll(arr...)
return
}
func (r *ConcurrentSets) Put(s string) {
r.cm.Set(s, struct{}{})
}
func (r *ConcurrentSets) PutAll(arr ...string) {
for _, s := range arr {
r.Put(s)
}
}
func (r *ConcurrentSets) ToArray() (arr []string) {
r.cm.ForEach(func(k string, v interface{}) {
arr = append(arr, k)
})
return
}
func (r *ConcurrentSets) Exists(t string) (ok bool) {
return r.cm.Exists(t)
}
func (r *ConcurrentSets) ExistsAny(t ...string) (ok bool) {
for _, s := range t {
if r.Exists(s) {
return true
}
}
return false
}
func (r *ConcurrentSets) ExistsAll(t ...string) (ok bool) {
for _, s := range t {
if !r.Exists(s) {
return false
}
}
return true
}
func (r *ConcurrentSets) Remove(s string) {
r.cm.Delete(s)
}
func (r *ConcurrentSets) RemoveAll(arr ...string) {
for _, s := range arr {
r.Remove(s)
}
}
func (r *ConcurrentSets) Length() int {
return r.cm.Size()
}
func (r *ConcurrentSets) ForEach(accept func(key string)) {
r.cm.ForEach(func(k string, v interface{}) {
accept(k)
})
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.3.8

搜索帮助