aboutsummaryrefslogtreecommitdiff
path: root/internal/priorityqueue/pop.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-29 14:14:21 +0000
committerGravatar Runxi Yu2026-03-29 14:14:21 +0000
commit69452f58fb0d6c1ed561df1e25efe51e5b3089fd (patch)
tree3e9cf39ffc197acca3da05bc4162581767ac2b64 /internal/priorityqueue/pop.go
parentcommitquery: Use internal/heap for the priority queue (diff)
signatureNo signature
internal/priorityqueue: Actually just make our own priority queue
Diffstat (limited to 'internal/priorityqueue/pop.go')
-rw-r--r--internal/priorityqueue/pop.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/priorityqueue/pop.go b/internal/priorityqueue/pop.go
new file mode 100644
index 00000000..2190b065
--- /dev/null
+++ b/internal/priorityqueue/pop.go
@@ -0,0 +1,21 @@
+package priorityqueue
+
+// Pop removes one highest-priority item.
+func (queue *Queue[T]) Pop() (T, bool) {
+ if len(queue.items) == 0 {
+ var zero T
+
+ return zero, false
+ }
+
+ last := len(queue.items) - 1
+ top := queue.items[0]
+ queue.items[0] = queue.items[last]
+ queue.items = queue.items[:last]
+
+ if len(queue.items) > 0 {
+ queue.siftDown(0)
+ }
+
+ return top, true
+}