Fast implementation of Git in pure Go codeberg.org/lindenii/furgit
git go
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

commitquery: Use our proper priority queue thingy

Runxi Yu e0e493fb 69452f58

+9 -37
+9 -5
commitquery/node_paint_down_to_common.go
··· 1 1 package commitquery 2 2 3 + import "codeberg.org/lindenii/furgit/internal/priorityqueue" 4 + 3 5 func (query *query) paintDownToCommon(left nodeIndex, rights []nodeIndex, minGeneration uint64) error { 4 6 query.beginMarkPhase() 5 7 ··· 11 13 return nil 12 14 } 13 15 14 - queue := newPriorityQueue(query) 15 - queue.PushNode(left) 16 + queue := priorityqueue.New(func(left, right nodeIndex) bool { 17 + return query.compare(left, right) > 0 18 + }) 19 + queue.Push(left) 16 20 17 21 for _, right := range rights { 18 22 query.setMarks(right, markRight) 19 - queue.PushNode(right) 23 + queue.Push(right) 20 24 } 21 25 22 26 lastGeneration := generationInfinity 23 27 24 28 for queue.Len() > 0 { 25 - idx, ok := queue.PopNode() 29 + idx, ok := queue.Pop() 26 30 if !ok { 27 31 break 28 32 } ··· 54 58 } 55 59 56 60 query.setMarks(parent, flags) 57 - queue.PushNode(parent) 61 + queue.Push(parent) 58 62 } 59 63 } 60 64
-32
commitquery/priority_queue.go
··· 1 - package commitquery 2 - 3 - import internalheap "codeberg.org/lindenii/furgit/internal/heap" 4 - 5 - // priorityQueue orders internal nodes using one query context's comparator. 6 - type priorityQueue struct { 7 - items *internalheap.Heap[nodeIndex] 8 - } 9 - 10 - // newPriorityQueue builds one empty priority queue over one query context. 11 - func newPriorityQueue(query *query) *priorityQueue { 12 - return &priorityQueue{ 13 - items: internalheap.New(func(left, right nodeIndex) bool { 14 - return query.compare(left, right) > 0 15 - }), 16 - } 17 - } 18 - 19 - // Len reports the number of queued items. 20 - func (queue *priorityQueue) Len() int { 21 - return queue.items.Len() 22 - } 23 - 24 - // PushNode inserts one internal node. 25 - func (queue *priorityQueue) PushNode(idx nodeIndex) { 26 - queue.items.Push(idx) 27 - } 28 - 29 - // PopNode removes the highest-priority internal node. 30 - func (queue *priorityQueue) PopNode() (nodeIndex, bool) { 31 - return queue.items.Pop() 32 - }