aboutsummaryrefslogtreecommitdiff
path: root/internal/calendar/precedence.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/calendar/precedence.go')
-rw-r--r--internal/calendar/precedence.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/internal/calendar/precedence.go b/internal/calendar/precedence.go
index b013b77..7919879 100644
--- a/internal/calendar/precedence.go
+++ b/internal/calendar/precedence.go
@@ -62,10 +62,18 @@ func precedence(c candidate) int {
}
// pick returns the highest-precedence candidate as observed and the rest as
-// others (commemorations / optional memorials), stably ordered by precedence.
+// others (commemorations / optional memorials). Ordering is deterministic:
+// by precedence band, then by slug, so equal-band collisions resolve the same
+// way on every run.
func pick(cands []candidate) (candidate, []candidate) {
sorted := make([]candidate, len(cands))
copy(sorted, cands)
- sort.SliceStable(sorted, func(i, j int) bool { return precedence(sorted[i]) < precedence(sorted[j]) })
+ sort.SliceStable(sorted, func(i, j int) bool {
+ pi, pj := precedence(sorted[i]), precedence(sorted[j])
+ if pi != pj {
+ return pi < pj
+ }
+ return sorted[i].Cel.Slug < sorted[j].Cel.Slug
+ })
return sorted[0], sorted[1:]
}