add factory method newAntiNodeCache()

This commit is contained in:
onyx-and-iris 2024-12-08 20:11:03 +00:00
parent c1b8cb3f18
commit 5ed54e672b
4 changed files with 7 additions and 5 deletions

View File

@ -12,6 +12,10 @@ type graph struct {
antinodes map[coords]struct{}
}
func newGraph() *graph {
return &graph{antinodes: make(map[coords]struct{})}
}
func (g *graph) String() string {
return strings.Join(g.data, "\n")
}

View File

@ -14,8 +14,6 @@ func Solve(buf []byte) (int, error) {
return 0, err
}
graph.antinodes = make(map[coords]struct{})
for i, a := range graph.antennae {
for j, b := range graph.antennae {
if i == j || a.identifier != b.identifier {

View File

@ -9,7 +9,7 @@ import (
var reMatchAntennae = regexp.MustCompile(`[a-zA-Z0-9]`)
func parseLines(r io.Reader) (*graph, error) {
var graph graph
graph := newGraph()
var linecount int
scanner := bufio.NewScanner(r)
@ -30,5 +30,5 @@ func parseLines(r io.Reader) (*graph, error) {
return nil, err
}
return &graph, nil
return graph, nil
}

View File

@ -13,7 +13,7 @@ type graph struct {
}
func newGraph() *graph {
return &graph{[]string{}, []antenna{}, newAntiNodeCache()}
return &graph{antinodes: newAntiNodeCache()}
}
func (g *graph) String() string {