ConcurrentDict Remove add decreaseCount

This commit is contained in:
liyuxing
2021-07-01 10:46:42 +08:00
committed by finley
parent af0ffe6e83
commit 453fef5de1
2 changed files with 17 additions and 3 deletions

View File

@@ -168,6 +168,7 @@ func (dict *ConcurrentDict) Remove(key string) (result int) {
if _, ok := shard.m[key]; ok {
delete(shard.m, key)
dict.decreaseCount()
return 1
}
return 0
@@ -177,6 +178,10 @@ func (dict *ConcurrentDict) addCount() int32 {
return atomic.AddInt32(&dict.count, 1)
}
func (dict *ConcurrentDict) decreaseCount() int32 {
return atomic.AddInt32(&dict.count, -1)
}
// ForEach traversal the dict
// it may not visits new entry inserted during traversal
func (dict *ConcurrentDict) ForEach(consumer Consumer) {