Skip to content

Commit

Permalink
fixup! Add PriorityQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
tpantelis committed Jan 25, 2025
1 parent 8d9628f commit 1497d90
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/workqueue/priority_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ func (p *PriorityQueue) SetPriority(item any, priority int) {
var priorityItem priorityType
priorityItem.priority = priority

existing, found := p.priorities.Load(item)
v, found := p.priorities.Load(item)
if !found {
p.priorities.LoadOrStore(item, priorityItem)

return
}

if existing.(priorityType).priority != priority {
existing := v.(priorityType)
priorityItem.dirty = existing.dirty

if existing.priority != priority {
priorityItem.dirty = true
}

Expand Down
1 change: 1 addition & 0 deletions pkg/workqueue/priority_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var _ = Describe("PriorityQueue", func() {
push("third", 1)

pq.SetPriority("second", 20)
pq.SetPriority("second", 20) // should be a no-op
pq.Adjust("second")
pq.Adjust("second") // should be a no-op
Expect(heap.Pop(pq)).To(Equal("second"))
Expand Down

0 comments on commit 1497d90

Please sign in to comment.