summaryrefslogtreecommitdiffstats
path: root/lib/pqueue.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pqueue.c')
-rw-r--r--lib/pqueue.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/pqueue.c b/lib/pqueue.c
index 12a779f2..69ab8e65 100644
--- a/lib/pqueue.c
+++ b/lib/pqueue.c
@@ -168,3 +168,20 @@ pqueue_dequeue (struct pqueue *queue)
trickle_down (0, queue);
return data;
}
+
+void
+pqueue_remove_at (int index, struct pqueue *queue)
+{
+ queue->array[index] = queue->array[--queue->size];
+
+ if (index > 0
+ && (*queue->cmp) (queue->array[index],
+ queue->array[PARENT_OF(index)]) < 0)
+ {
+ trickle_up (index, queue);
+ }
+ else
+ {
+ trickle_down (index, queue);
+ }
+}