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

34 lines
512 B
Go

package two
import "sync"
type antiNodeCache struct {
mu sync.RWMutex
data map[coords]struct{}
}
func newAntiNodeCache() antiNodeCache {
return antiNodeCache{
data: make(map[coords]struct{}),
}
}
func (c *antiNodeCache) len() int {
return len(c.data)
}
func (c *antiNodeCache) contains(coords coords) bool {
c.mu.RLock()
defer c.mu.RUnlock()
_, ok := c.data[coords]
return ok
}
func (c *antiNodeCache) insert(coords coords) {
c.mu.Lock()
defer c.mu.Unlock()
c.data[coords] = struct{}{}
}