From aca4240f6a32423df5f95de6a9354b524fe57ec5 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 1 Nov 2018 13:46:17 +0000 Subject: prio-queue: add 'peek' operation When consuming a priority queue, it can be convenient to inspect the next object that will be dequeued without actually dequeueing it. Our existing library did not have such a 'peek' operation, so add it as prio_queue_peek(). Add a reference-level comparison in t/helper/test-prio-queue.c so this method is exercised by t0009-prio-queue.sh. Further, add a test that checks the behavior when the compare function is NULL (i.e. the queue becomes a stack). Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- prio-queue.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'prio-queue.h') diff --git a/prio-queue.h b/prio-queue.h index d030ec9dd6..682e51867a 100644 --- a/prio-queue.h +++ b/prio-queue.h @@ -46,6 +46,12 @@ extern void prio_queue_put(struct prio_queue *, void *thing); */ extern void *prio_queue_get(struct prio_queue *); +/* + * Gain access to the "thing" that would be returned by + * prio_queue_get, but do not remove it from the queue. + */ +extern void *prio_queue_peek(struct prio_queue *); + extern void clear_prio_queue(struct prio_queue *); /* Reverse the LIFO elements */ -- cgit v1.2.3