This commit is contained in:
Shawn Smith
2017-08-12 17:01:47 +09:00
parent 12924ef077
commit 03597df76d

View File

@@ -13,12 +13,14 @@ func (h ScoreHeap) Len() int { return len(h) }
func (h ScoreHeap) Less(i, j int) bool { return h[i].Score < h[j].Score }
func (h ScoreHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
// Push onto the heap
func (h *ScoreHeap) Push(x interface{}) {
// Push and Pop use pointer receivers because they modify the slice's length,
// not just its contents.
*h = append(*h, x.(scoreItem))
}
// Pop item off of the heap
func (h *ScoreHeap) Pop() interface{} {
old := *h
n := len(old)