-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
52 lines (43 loc) · 899 Bytes
/
registry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package aoc
type (
Registry struct {
days map[uint]DaySolution
}
DaySolution struct {
Part1 Solver
Part2 Solver
}
Solver func(lines []string) (result interface{})
)
func (r *Registry) GetSolver(day uint, part uint) (solver Solver, ok bool) {
s, ok := r.days[day]
if !ok {
return nil, false
}
switch part {
case 1:
return s.Part1, true
case 2:
return s.Part2, true
default:
return nil, false
}
}
var defaultRegistry *Registry
func init() {
defaultRegistry = NewRegistry()
}
func DefaultRegistry() *Registry {
return defaultRegistry
}
func NewRegistry() *Registry {
return &Registry{
days: map[uint]DaySolution{},
}
}
func RegisterSolutionWithRegistry(day uint, solution DaySolution, registry *Registry) {
registry.days[day] = solution
}
func RegisterSolution(day uint, solution DaySolution) {
RegisterSolutionWithRegistry(day, solution, defaultRegistry)
}