wip: grib

This commit is contained in:
Anatoly Antonov 2025-06-22 22:36:10 +03:00
parent 5240968c33
commit b9c1a98895
12 changed files with 414 additions and 5 deletions

View file

@ -0,0 +1,40 @@
package grib
import (
"encoding/binary"
"math"
"sync"
"time"
)
type vec [2]float64
type item struct {
v vec
exp time.Time
}
type memCache struct {
ttl time.Duration
m sync.Map
}
func (c *memCache) get(k uint64) (vec, bool) {
if v, ok := c.m.Load(k); ok {
it := v.(item)
if time.Now().Before(it.exp) {
return it.v, true
}
c.m.Delete(k)
}
return vec{}, false
}
func (c *memCache) set(k uint64, v vec) { c.m.Store(k, item{v, time.Now().Add(c.ttl)}) }
func encodeVec(v vec) []byte {
var b [16]byte
binary.LittleEndian.PutUint64(b[:8], math.Float64bits(v[0]))
binary.LittleEndian.PutUint64(b[8:], math.Float64bits(v[1]))
return b[:]
}