diff options
Diffstat (limited to 'internal/commitquery/priority_queue.go')
| -rw-r--r-- | internal/commitquery/priority_queue.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/internal/commitquery/priority_queue.go b/internal/commitquery/priority_queue.go index a7a4876e..d6dbf54f 100644 --- a/internal/commitquery/priority_queue.go +++ b/internal/commitquery/priority_queue.go @@ -2,37 +2,37 @@ package commitquery import "container/heap" -// PriorityQueue orders internal nodes using one query context's comparator. -type PriorityQueue struct { +// priorityQueue orders internal nodes using one query context's comparator. +type priorityQueue struct { ctx *Context items []NodeIndex } -// NewPriorityQueue builds one empty priority queue over one query context. -func NewPriorityQueue(ctx *Context) *PriorityQueue { - queue := &PriorityQueue{ctx: ctx} +// newPriorityQueue builds one empty priority queue over one query context. +func newPriorityQueue(ctx *Context) *priorityQueue { + queue := &priorityQueue{ctx: ctx} heap.Init(queue) return queue } // Len reports the number of queued items. -func (queue *PriorityQueue) Len() int { +func (queue *priorityQueue) Len() int { return len(queue.items) } // Less reports whether one heap slot sorts ahead of another. -func (queue *PriorityQueue) Less(left, right int) bool { +func (queue *priorityQueue) Less(left, right int) bool { return queue.ctx.Compare(queue.items[left], queue.items[right]) > 0 } // Swap exchanges two heap slots. -func (queue *PriorityQueue) Swap(left, right int) { +func (queue *priorityQueue) Swap(left, right int) { queue.items[left], queue.items[right] = queue.items[right], queue.items[left] } // Push appends one heap element. -func (queue *PriorityQueue) Push(item any) { +func (queue *priorityQueue) Push(item any) { idx, ok := item.(NodeIndex) if !ok { panic("commitquery: heap push item is not a NodeIndex") @@ -42,7 +42,7 @@ func (queue *PriorityQueue) Push(item any) { } // Pop removes one heap element. -func (queue *PriorityQueue) Pop() any { +func (queue *priorityQueue) Pop() any { last := len(queue.items) - 1 item := queue.items[last] queue.items = queue.items[:last] @@ -51,12 +51,12 @@ func (queue *PriorityQueue) Pop() any { } // PushNode inserts one internal node. -func (queue *PriorityQueue) PushNode(idx NodeIndex) { +func (queue *priorityQueue) PushNode(idx NodeIndex) { heap.Push(queue, idx) } // PopNode removes the highest-priority internal node. -func (queue *PriorityQueue) PopNode() NodeIndex { +func (queue *priorityQueue) PopNode() NodeIndex { item := heap.Pop(queue) idx, ok := item.(NodeIndex) |
