From: "Kristofer Karlsson via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "René Scharfe" <l.s.r@web.de>,
"Kristofer Karlsson" <krka@spotify.com>,
"Kristofer Karlsson" <krka@spotify.com>,
"Kristofer Karlsson" <krka@spotify.com>
Subject: [PATCH v3 1/2] prio-queue: extract sift_up() from prio_queue_put()
Date: Wed, 08 Jul 2026 17:49:47 +0000 [thread overview]
Message-ID: <ec6a448563ad57a40dd7d964ea4b2f9bb3dafb7c.1783532989.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2132.v3.git.1783532989.gitgitgadget@gmail.com>
From: Kristofer Karlsson <krka@spotify.com>
Factor out the bubble-up loop from prio_queue_put() into a
standalone sift_up() function. This is a pure refactor with
no behavior change, preparing for reuse in a subsequent commit.
Suggested-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Kristofer Karlsson <krka@spotify.com>
---
prio-queue.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/prio-queue.c b/prio-queue.c
index 199775d5af..926fc04e85 100644
--- a/prio-queue.c
+++ b/prio-queue.c
@@ -37,6 +37,17 @@ void clear_prio_queue(struct prio_queue *queue)
queue->get_pending = 0;
}
+static void sift_up(struct prio_queue *queue, size_t ix)
+{
+ while (ix) {
+ size_t parent = (ix - 1) / 2;
+ if (compare(queue, parent, ix) <= 0)
+ break;
+ swap(queue, parent, ix);
+ ix = parent;
+ }
+}
+
static void sift_down_root(struct prio_queue *queue)
{
size_t ix, child;
@@ -66,8 +77,6 @@ static inline void flush_get(struct prio_queue *queue)
void prio_queue_put(struct prio_queue *queue, void *thing)
{
- size_t ix, parent;
-
if (queue->get_pending) {
queue->get_pending = 0;
queue->array[0].ctr = queue->insertion_ctr++;
@@ -85,13 +94,7 @@ void prio_queue_put(struct prio_queue *queue, void *thing)
return; /* LIFO */
/* Bubble up the new one */
- for (ix = queue->nr_ - 1; ix; ix = parent) {
- parent = (ix - 1) / 2;
- if (compare(queue, parent, ix) <= 0)
- break;
-
- swap(queue, parent, ix);
- }
+ sift_up(queue, queue->nr_ - 1);
}
void *prio_queue_get(struct prio_queue *queue)
--
gitgitgadget
next prev parent reply other threads:[~2026-07-08 17:49 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-31 17:57 [PATCH] prio-queue: use cascade-down sift for faster extract-min Kristofer Karlsson via GitGitGadget
2026-06-01 0:09 ` Junio C Hamano
2026-06-01 6:16 ` Junio C Hamano
2026-06-01 6:21 ` Kristofer Karlsson
2026-06-01 8:17 ` [PATCH v2] prio-queue: use cascade-down " Kristofer Karlsson via GitGitGadget
2026-06-02 16:36 ` René Scharfe
2026-06-02 22:40 ` Kristofer Karlsson
2026-06-05 20:39 ` Kristofer Karlsson
2026-06-07 7:30 ` René Scharfe
2026-06-07 12:07 ` Kristofer Karlsson
2026-06-29 21:16 ` Junio C Hamano
2026-06-08 11:56 ` Junio C Hamano
2026-07-06 21:52 ` Kristofer Karlsson
2026-07-08 10:43 ` René Scharfe
2026-07-08 10:59 ` Kristofer Karlsson
2026-07-08 11:55 ` René Scharfe
2026-07-08 12:44 ` Kristofer Karlsson
2026-07-08 17:49 ` [PATCH v3 0/2] prio-queue: use bottom-up sift for extract-min Kristofer Karlsson via GitGitGadget
2026-07-08 17:49 ` Kristofer Karlsson via GitGitGadget [this message]
2026-07-08 17:49 ` [PATCH v3 2/2] prio-queue: use cascade for unfused gets Kristofer Karlsson via GitGitGadget
2026-07-10 16:37 ` René Scharfe
2026-07-10 17:28 ` Kristofer Karlsson
2026-07-10 16:37 ` [PATCH v3 0/2] prio-queue: use bottom-up sift for extract-min René Scharfe
2026-07-10 17:40 ` Kristofer Karlsson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ec6a448563ad57a40dd7d964ea4b2f9bb3dafb7c.1783532989.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=krka@spotify.com \
--cc=l.s.r@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.