github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/pkg/graveler/ref/commit_generation_priority_queue.go (about) 1 package ref 2 3 import ( 4 "github.com/treeverse/lakefs/pkg/graveler" 5 ) 6 7 // CommitsGenerationPriorityQueue implements heap.Interface such that the commit with the greatest Generation value is 8 // at the root of the heap. 9 type CommitsGenerationPriorityQueue []*graveler.CommitRecord 10 11 func NewCommitsGenerationPriorityQueue() CommitsGenerationPriorityQueue { 12 return make(CommitsGenerationPriorityQueue, 0) 13 } 14 15 func (c CommitsGenerationPriorityQueue) Len() int { 16 return len(c) 17 } 18 19 func (c CommitsGenerationPriorityQueue) Swap(i, j int) { 20 c[i], c[j] = c[j], c[i] 21 } 22 23 func (c *CommitsGenerationPriorityQueue) Push(x interface{}) { 24 rec := x.(*graveler.CommitRecord) 25 *c = append(*c, rec) 26 } 27 28 func (c *CommitsGenerationPriorityQueue) Pop() interface{} { 29 cc := *c 30 n := len(cc) - 1 31 item := cc[n] 32 *c = cc[:n] 33 return item 34 } 35 36 func (c CommitsGenerationPriorityQueue) Less(i, j int) bool { 37 if c[i].Commit.Generation == c[j].Commit.Generation { 38 return c[i].Commit.CreationDate.After(c[j].Commit.CreationDate) 39 } 40 return c[i].Commit.Generation > c[j].Commit.Generation 41 }