aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/fuzzer/queue/prio_queue.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-05-16 17:54:30 +0200
committerAleksandr Nogikh <nogikh@google.com>2024-05-16 16:34:04 +0000
commitc2e0726105cc811a456d900c62443159acc29c32 (patch)
treeba442735151dd21102a9395d55219c2ea876647d /pkg/fuzzer/queue/prio_queue.go
parentad5321c6e31dd6b723935e195830789efdda12c5 (diff)
pkg/fuzzer/queue: simplify the priority queue
We don't need the full priority queue functionality anymore. For our purposes it's enough to only enforce the order between the elements of different sub-queues.
Diffstat (limited to 'pkg/fuzzer/queue/prio_queue.go')
-rw-r--r--pkg/fuzzer/queue/prio_queue.go40
1 files changed, 4 insertions, 36 deletions
diff --git a/pkg/fuzzer/queue/prio_queue.go b/pkg/fuzzer/queue/prio_queue.go
index a71afe61d..5e7c65fba 100644
--- a/pkg/fuzzer/queue/prio_queue.go
+++ b/pkg/fuzzer/queue/prio_queue.go
@@ -7,37 +7,6 @@ import (
"container/heap"
)
-type priority []int64
-
-func (p priority) greaterThan(other priority) bool {
- for i := range p {
- if i >= len(other) || p[i] > other[i] {
- return true
- }
- if p[i] < other[i] {
- return false
- }
- }
- for i := len(p); i < len(other); i++ {
- if other[i] < 0 {
- return true
- }
- if other[i] > 0 {
- return false
- }
- }
- return false
-}
-
-func (p priority) next() priority {
- if len(p) == 0 {
- return p
- }
- newPrio := append([]int64{}, p...)
- newPrio[len(newPrio)-1]--
- return newPrio
-}
-
type priorityQueueOps[T any] struct {
impl priorityQueueImpl[T]
}
@@ -46,7 +15,7 @@ func (pq *priorityQueueOps[T]) Len() int {
return pq.impl.Len()
}
-func (pq *priorityQueueOps[T]) Push(item T, prio priority) {
+func (pq *priorityQueueOps[T]) Push(item T, prio int) {
heap.Push(&pq.impl, &priorityQueueItem[T]{item, prio})
}
@@ -63,7 +32,7 @@ func (pq *priorityQueueOps[T]) Pop() T {
type priorityQueueItem[T any] struct {
value T
- prio priority
+ prio int
}
type priorityQueueImpl[T any] []*priorityQueueItem[T]
@@ -71,9 +40,8 @@ type priorityQueueImpl[T any] []*priorityQueueItem[T]
func (pq priorityQueueImpl[T]) Len() int { return len(pq) }
func (pq priorityQueueImpl[T]) Less(i, j int) bool {
- // We want Pop to give us the highest, not lowest,
- // priority so we use greater than here.
- return pq[i].prio.greaterThan(pq[j].prio)
+ // We want Pop to give us the lowest priority.
+ return pq[i].prio < pq[j].prio
}
func (pq priorityQueueImpl[T]) Swap(i, j int) {