aboutsummaryrefslogtreecommitdiff
path: root/prio-queue.h
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2025-07-18 11:39:14 +0200
committerJunio C Hamano <gitster@pobox.com>2025-07-22 07:28:35 -0700
commit3d5091d232ea991a6a991c86e9fb000f5a9009a0 (patch)
treecbc48f1816bea87ac7f374d11029cfa1a725a0ff /prio-queue.h
parentd6ec08788e667d4f556e9c2d97bbd7adb7e582be (diff)
downloadgit-3d5091d232ea991a6a991c86e9fb000f5a9009a0.tar.xz
prio-queue: add prio_queue_replace()
Add a function to replace the top element of the queue that basically does the same as prio_queue_get() followed by prio_queue_put(), but without the work by prio_queue_get() to rebalance the heap. It can be used to optimize loops that get one element and then immediately add another one. That's common e.g., with commit history traversal, where we get out a commit and then put in its parents. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'prio-queue.h')
-rw-r--r--prio-queue.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/prio-queue.h b/prio-queue.h
index 38d032636d..da7fad2f1f 100644
--- a/prio-queue.h
+++ b/prio-queue.h
@@ -52,6 +52,14 @@ void *prio_queue_get(struct prio_queue *);
*/
void *prio_queue_peek(struct prio_queue *);
+/*
+ * Replace the "thing" that compares the smallest with a new "thing",
+ * like prio_queue_get()+prio_queue_put() would do, but in a more
+ * efficient way. Does the same as prio_queue_put() if the queue is
+ * empty.
+ */
+void prio_queue_replace(struct prio_queue *queue, void *thing);
+
void clear_prio_queue(struct prio_queue *);
/* Reverse the LIFO elements */