2022-06-28 14:18:57 +08:00
|
|
|
package policyreport
|
|
|
|
|
|
|
|
import cmap "github.com/orcaman/concurrent-map"
|
|
|
|
|
|
|
|
type concurrentMap struct{ cmap.ConcurrentMap }
|
|
|
|
|
|
|
|
func (m concurrentMap) increase(ns string) {
|
|
|
|
count, ok := m.Get(ns)
|
|
|
|
if ok && count != -1 {
|
|
|
|
m.Set(ns, count.(int)+1)
|
|
|
|
} else {
|
|
|
|
m.Set(ns, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m concurrentMap) decrease(keyHash string) {
|
|
|
|
_, ns := parseKeyHash(keyHash)
|
|
|
|
count, ok := m.Get(ns)
|
|
|
|
if ok && count.(int) > 0 {
|
|
|
|
m.Set(ns, count.(int)-1)
|
|
|
|
} else {
|
|
|
|
m.Set(ns, 0)
|
|
|
|
}
|
|
|
|
}
|
2022-09-13 10:30:14 +02:00
|
|
|
|
|
|
|
func newConcurrentMap() concurrentMap {
|
|
|
|
return concurrentMap{cmap.New()}
|
|
|
|
}
|