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
MapFloat *mapFloat
)
// lock
type mapFloat struct {
sync.RWMutex
Data map[string]float64
}
type mapFloat = syncMap[float64]
func NewMapFloat() *mapFloat {
return &mapFloat{
Data: make(map[string]float64),
}
}
func (c *mapFloat) Set(key string, val float64) {
c.Lock()
defer c.Unlock()
c.Data[key] = val
}
func (c *mapFloat) Get(key string) float64 {
c.RLock()
defer c.RUnlock()
vals, ok := c.Data[key]
if !ok {
return 0
}
return vals
}
func (c *mapFloat) Del(key string) {
c.Lock()
defer c.Unlock()
delete(c.Data, key)
}
func (c *mapFloat) Keys() (keys []string) {
c.RLock()
defer c.RUnlock()
for k, _ := range c.Data {
keys = append(keys, k)
}
return
}
func (c *mapFloat) All() map[string]float64 {
c.RLock()
defer c.RUnlock()
return c.Data
return newSyncMap[float64]()
}