并发安全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

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