From 337ec809393b709b36ca7b64d77489ae4bc1af1c Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 27 May 2023 09:44:14 +0200 Subject: More scheduling and probabilisticity --- src/lib/pqueue.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/lib/pqueue.c') diff --git a/src/lib/pqueue.c b/src/lib/pqueue.c index 6f21e5f..c080bb2 100644 --- a/src/lib/pqueue.c +++ b/src/lib/pqueue.c @@ -157,3 +157,19 @@ void *pqueue_pop(struct pqueue *q) return head; } + +void *pqueue_pop_at(struct pqueue *q, size_t p) +{ + void *head; + if (!q || q->size == 1 || p >= q->size) + return NULL; + + head = q->d[p]; + q->d[p] = q->d[--q->size]; + if (q->cmppri(q->getpri(head), q->getpri(q->d[p]))) + bubble_up(q, p); + else + percolate_down(q, p); + + return head; +} -- cgit v1.2.3