This commit is contained in:
matst80
2025-11-14 20:21:53 +01:00
commit 4dbbd30d4d
38 changed files with 10969837 additions and 0 deletions

36
cmd/planner/prio-queue.go Normal file
View File

@@ -0,0 +1,36 @@
package main
import "time"
type pqItem struct {
Stop string
Cost time.Time
index int
}
type priorityQueue []*pqItem
func (pq priorityQueue) Len() int { return len(pq) }
func (pq priorityQueue) Less(i, j int) bool { return pq[i].Cost.Before(pq[j].Cost) }
func (pq priorityQueue) Swap(i, j int) {
pq[i], pq[j] = pq[j], pq[i]
pq[i].index = i
pq[j].index = j
}
func (pq *priorityQueue) Push(x any) {
item := x.(*pqItem)
item.index = len(*pq)
*pq = append(*pq, item)
}
func (pq *priorityQueue) Pop() any {
old := *pq
n := len(old)
item := old[n-1]
item.index = -1
*pq = old[:n-1]
return item
}