package main import ( "time" ) // From https://golang.org/pkg/container/heap/ type Song struct { time time.Time song string week int sync bool index int } type SongPriorityQueue []*Song func (pq SongPriorityQueue) Len() int { return len(pq) } func (pq SongPriorityQueue) Less(i, j int) bool { return pq[i].time.Before(pq[j].time) } func (pq SongPriorityQueue) Swap(i, j int) { pq[i], pq[j] = pq[j], pq[i] pq[i].index = i pq[j].index = j } func (pq *SongPriorityQueue) Push(x interface{}) { n := len(*pq) item := x.(*Song) item.index = n *pq = append(*pq, item) } func (pq *SongPriorityQueue) Pop() interface{} { old := *pq n := len(old) item := old[n-1] item.index = -1 // for safety *pq = old[0 : n-1] return item }