forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_retrieval_heap.go
48 lines (39 loc) · 1.03 KB
/
block_retrieval_heap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package libkbfs
import "container/heap"
type blockRetrievalHeap []*blockRetrieval
var _ heap.Interface = (*blockRetrievalHeap)(nil)
// Heap methods: do not use directly
func (brh blockRetrievalHeap) Less(i, j int) bool {
reqI := brh[i]
reqJ := brh[j]
if reqI.priority > reqJ.priority {
return true
}
if reqI.priority < reqJ.priority {
return false
}
return reqI.insertionOrder < reqJ.insertionOrder
}
func (brh blockRetrievalHeap) Len() int { return len(brh) }
func (brh blockRetrievalHeap) Swap(i, j int) {
brh[i], brh[j] = brh[j], brh[i]
brh[i].index = i
brh[j].index = j
}
func (brh *blockRetrievalHeap) Push(item interface{}) {
n := len(*brh)
retrieval := item.(*blockRetrieval)
retrieval.index = n
*brh = append(*brh, retrieval)
}
func (brh *blockRetrievalHeap) Pop() interface{} {
old := *brh
n := len(old)
x := old[n-1]
x.index = -1
*brh = old[0 : n-1]
return x
}