tangled
alpha
login
or
join now
runxiyu.tngl.sh
/
furgit
6
fork
atom
Fast implementation of Git in pure Go
6
fork
atom
overview
issues
pulls
pipelines
internal/commitquery: Unexport priority queue
runxiyu.tngl.sh
1 day ago
cea24e9d
17342072
verified
This commit was signed with the committer's
known signature
.
runxiyu.tngl.sh
SSH Key Fingerprint:
SHA256:jdcgZM4f40eqgoEW57poBu5vM9WoGE02ZzhWbfbNzc0=
+14
-14
2 changed files
expand all
collapse all
unified
split
internal
commitquery
merge_bases.go
priority_queue.go
+2
-2
internal/commitquery/merge_bases.go
···
44
44
return nil
45
45
}
46
46
47
47
-
queue := NewPriorityQueue(ctx)
47
47
+
queue := newPriorityQueue(ctx)
48
48
queue.PushNode(left)
49
49
50
50
for _, right := range rights {
···
87
87
return nil
88
88
}
89
89
90
90
-
func queueHasNonStale(ctx *Context, queue *PriorityQueue) bool {
90
90
+
func queueHasNonStale(ctx *Context, queue *priorityQueue) bool {
91
91
for _, idx := range queue.items {
92
92
if !ctx.HasAnyMarks(idx, markStale) {
93
93
return true
+12
-12
internal/commitquery/priority_queue.go
···
2
2
3
3
import "container/heap"
4
4
5
5
-
// PriorityQueue orders internal nodes using one query context's comparator.
6
6
-
type PriorityQueue struct {
5
5
+
// priorityQueue orders internal nodes using one query context's comparator.
6
6
+
type priorityQueue struct {
7
7
ctx *Context
8
8
items []NodeIndex
9
9
}
10
10
11
11
-
// NewPriorityQueue builds one empty priority queue over one query context.
12
12
-
func NewPriorityQueue(ctx *Context) *PriorityQueue {
13
13
-
queue := &PriorityQueue{ctx: ctx}
11
11
+
// newPriorityQueue builds one empty priority queue over one query context.
12
12
+
func newPriorityQueue(ctx *Context) *priorityQueue {
13
13
+
queue := &priorityQueue{ctx: ctx}
14
14
heap.Init(queue)
15
15
16
16
return queue
17
17
}
18
18
19
19
// Len reports the number of queued items.
20
20
-
func (queue *PriorityQueue) Len() int {
20
20
+
func (queue *priorityQueue) Len() int {
21
21
return len(queue.items)
22
22
}
23
23
24
24
// Less reports whether one heap slot sorts ahead of another.
25
25
-
func (queue *PriorityQueue) Less(left, right int) bool {
25
25
+
func (queue *priorityQueue) Less(left, right int) bool {
26
26
return queue.ctx.Compare(queue.items[left], queue.items[right]) > 0
27
27
}
28
28
29
29
// Swap exchanges two heap slots.
30
30
-
func (queue *PriorityQueue) Swap(left, right int) {
30
30
+
func (queue *priorityQueue) Swap(left, right int) {
31
31
queue.items[left], queue.items[right] = queue.items[right], queue.items[left]
32
32
}
33
33
34
34
// Push appends one heap element.
35
35
-
func (queue *PriorityQueue) Push(item any) {
35
35
+
func (queue *priorityQueue) Push(item any) {
36
36
idx, ok := item.(NodeIndex)
37
37
if !ok {
38
38
panic("commitquery: heap push item is not a NodeIndex")
···
42
42
}
43
43
44
44
// Pop removes one heap element.
45
45
-
func (queue *PriorityQueue) Pop() any {
45
45
+
func (queue *priorityQueue) Pop() any {
46
46
last := len(queue.items) - 1
47
47
item := queue.items[last]
48
48
queue.items = queue.items[:last]
···
51
51
}
52
52
53
53
// PushNode inserts one internal node.
54
54
-
func (queue *PriorityQueue) PushNode(idx NodeIndex) {
54
54
+
func (queue *priorityQueue) PushNode(idx NodeIndex) {
55
55
heap.Push(queue, idx)
56
56
}
57
57
58
58
// PopNode removes the highest-priority internal node.
59
59
-
func (queue *PriorityQueue) PopNode() NodeIndex {
59
59
+
func (queue *priorityQueue) PopNode() NodeIndex {
60
60
item := heap.Pop(queue)
61
61
62
62
idx, ok := item.(NodeIndex)