lib: use heap to manage timers
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/lib/pqueue.c b/lib/pqueue.c
index 12a779f..69ab8e6 100644
--- a/lib/pqueue.c
+++ b/lib/pqueue.c
@@ -168,3 +168,20 @@
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);
+ }
+}