mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2026-04-08 18:13:36 +00:00
implement using custom sort function on an update struct
rerun benchmarks
This commit is contained in:
20
day-05/internal/update/update.go
Normal file
20
day-05/internal/update/update.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package update
|
||||
|
||||
import "slices"
|
||||
|
||||
type Update struct {
|
||||
Pages []int
|
||||
}
|
||||
|
||||
func (u Update) Sort(orderings map[int][]int) {
|
||||
slices.SortFunc(u.Pages, func(p, q int) int {
|
||||
v, ok := orderings[p]
|
||||
if ok {
|
||||
if slices.Contains(v, q) {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
return 1
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user