mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +00:00
28 lines
392 B
Go
28 lines
392 B
Go
|
package two
|
||
|
|
||
|
type minHeap []*block
|
||
|
|
||
|
func (h minHeap) Len() int {
|
||
|
return len(h)
|
||
|
}
|
||
|
|
||
|
func (h minHeap) Less(i, j int) bool {
|
||
|
return h[i].id < h[j].id
|
||
|
}
|
||
|
|
||
|
func (h minHeap) Swap(i, j int) {
|
||
|
h[i], h[j] = h[j], h[i]
|
||
|
}
|
||
|
|
||
|
func (h *minHeap) Push(x interface{}) {
|
||
|
*h = append(*h, x.(*block))
|
||
|
}
|
||
|
|
||
|
func (h *minHeap) Pop() interface{} {
|
||
|
old := *h
|
||
|
n := len(old)
|
||
|
x := old[n-1]
|
||
|
*h = old[:n-1]
|
||
|
return x
|
||
|
}
|