codex optz.

This commit is contained in:
2026-06-20 23:29:58 +08:00
parent 40afc6c0d5
commit ebed85772f
11 changed files with 282 additions and 422 deletions

View File

@@ -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]()
}