From 5ed54e672b5fdb59586d1d211035d8c7d462c18d Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 8 Dec 2024 20:11:03 +0000 Subject: [PATCH] add factory method newAntiNodeCache() --- day-08/internal/one/graph.go | 4 ++++ day-08/internal/one/solve.go | 2 -- day-08/internal/one/util.go | 4 ++-- day-08/internal/two/graph.go | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/day-08/internal/one/graph.go b/day-08/internal/one/graph.go index 0b3bcf8..d85a752 100644 --- a/day-08/internal/one/graph.go +++ b/day-08/internal/one/graph.go @@ -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") } diff --git a/day-08/internal/one/solve.go b/day-08/internal/one/solve.go index 2005c7f..5d7aa0a 100644 --- a/day-08/internal/one/solve.go +++ b/day-08/internal/one/solve.go @@ -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 { diff --git a/day-08/internal/one/util.go b/day-08/internal/one/util.go index 9c9b493..76fff67 100644 --- a/day-08/internal/one/util.go +++ b/day-08/internal/one/util.go @@ -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 } diff --git a/day-08/internal/two/graph.go b/day-08/internal/two/graph.go index 98efec5..9d06da5 100644 --- a/day-08/internal/two/graph.go +++ b/day-08/internal/two/graph.go @@ -13,7 +13,7 @@ type graph struct { } func newGraph() *graph { - return &graph{[]string{}, []antenna{}, newAntiNodeCache()} + return &graph{antinodes: newAntiNodeCache()} } func (g *graph) String() string {