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 --- t/t0009-prio-queue.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 't/t0009-prio-queue.sh') diff --git a/t/t0009-prio-queue.sh b/t/t0009-prio-queue.sh index e56dfce668..3941ad2528 100755 --- a/t/t0009-prio-queue.sh +++ b/t/t0009-prio-queue.sh @@ -47,4 +47,18 @@ test_expect_success 'notice empty queue' ' test_cmp expect actual ' +cat >expect <<'EOF' +3 +2 +6 +4 +5 +1 +8 +EOF +test_expect_success 'stack order' ' + test-tool prio-queue stack 8 1 5 4 6 2 3 dump >actual && + test_cmp expect actual +' + test_done -- cgit v1.2.3