aoc2024/day-22/internal/two/cache.go

22 lines
323 B
Go
Raw Normal View History

2024-12-22 16:54:03 +00:00
package two
import "sync"
type sequenceCache struct {
mu sync.RWMutex
data map[sequence]int
}
func newSequenceCache() sequenceCache {
return sequenceCache{
data: make(map[sequence]int),
}
}
func (sc *sequenceCache) upsert(seq sequence, value int) {
sc.mu.Lock()
defer sc.mu.Unlock()
sc.data[seq] += value
}