mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +00:00
34 lines
512 B
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{}{}
|
||
|
}
|