并发安全map新增Iterator遍历方法

This commit is contained in:
John
2018-02-07 17:55:52 +08:00
parent 3418f3d547
commit 9333beaf26
10 changed files with 89 additions and 0 deletions

View File

@ -22,6 +22,15 @@ func NewStringBoolMap() *StringBoolMap {
}
}
// 给定回调函数对原始内容进行遍历
func (this *StringBoolMap) Iterator(f func (k string, v bool)) {
this.mu.RLock()
for k, v := range this.m {
f(k, v)
}
this.mu.RUnlock()
}
// 哈希表克隆
func (this *StringBoolMap) Clone() *map[string]bool {
m := make(map[string]bool)