codex optz.
This commit is contained in:
56
cache/mapsync/map_int.go
vendored
56
cache/mapsync/map_int.go
vendored
@@ -1,64 +1,12 @@
|
||||
package mapsync
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
// sync map
|
||||
MapInt *mapInt
|
||||
)
|
||||
|
||||
// lock
|
||||
type mapInt struct {
|
||||
sync.RWMutex
|
||||
Data map[string]int
|
||||
}
|
||||
type mapInt = syncMap[int]
|
||||
|
||||
func NewMapInt() *mapInt {
|
||||
return &mapInt{
|
||||
Data: make(map[string]int),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *mapInt) Set(key string, val int) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.Data[key] = val
|
||||
}
|
||||
|
||||
func (c *mapInt) Get(key string) int {
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
|
||||
vals, ok := c.Data[key]
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
|
||||
return vals
|
||||
}
|
||||
|
||||
func (c *mapInt) Del(key string) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
delete(c.Data, key)
|
||||
}
|
||||
|
||||
func (c *mapInt) All() map[string]int {
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
|
||||
return c.Data
|
||||
}
|
||||
func (c *mapInt) Keys() (keys []string) {
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
|
||||
for k, _ := range c.Data {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
return
|
||||
return newSyncMap[int]()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user