aboutsummaryrefslogtreecommitdiffstats
path: root/prio-queue.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-07-22 07:27:39 -0700
committerJunio C Hamano <gitster@pobox.com>2025-07-22 07:27:39 -0700
commitc7a5d9a13c53c91fd012aea7fbfdf05286cbf3d9 (patch)
tree70326abe19a3c7df4b81049f9b8910f05030fb9f /prio-queue.c
parentSync with 'master' (diff)
downloadgit-c7a5d9a13c53c91fd012aea7fbfdf05286cbf3d9.tar.gz
git-c7a5d9a13c53c91fd012aea7fbfdf05286cbf3d9.zip
Revert "Merge branch 'rs/pop-recent-commit-with-prio-queue' into next"
This reverts commit 03dce625bff6598e7f77d9f4a4a25d0288e5e5a8, reversing changes made to 6ba607880dc2bbf7e13e5734880ce0f9b87d2670.
Diffstat (limited to 'prio-queue.c')
-rw-r--r--prio-queue.c45
1 files changed, 13 insertions, 32 deletions
diff --git a/prio-queue.c b/prio-queue.c
index 9748528ce6..ec33ac27db 100644
--- a/prio-queue.c
+++ b/prio-queue.c
@@ -58,10 +58,22 @@ void prio_queue_put(struct prio_queue *queue, void *thing)
}
}
-static void sift_down_root(struct prio_queue *queue)
+void *prio_queue_get(struct prio_queue *queue)
{
+ void *result;
size_t ix, child;
+ if (!queue->nr)
+ return NULL;
+ if (!queue->compare)
+ return queue->array[--queue->nr].data; /* LIFO */
+
+ result = queue->array[0].data;
+ if (!--queue->nr)
+ return result;
+
+ queue->array[0] = queue->array[queue->nr];
+
/* Push down the one at the root */
for (ix = 0; ix * 2 + 1 < queue->nr; ix = child) {
child = ix * 2 + 1; /* left */
@@ -74,23 +86,6 @@ static void sift_down_root(struct prio_queue *queue)
swap(queue, child, ix);
}
-}
-
-void *prio_queue_get(struct prio_queue *queue)
-{
- void *result;
-
- if (!queue->nr)
- return NULL;
- if (!queue->compare)
- return queue->array[--queue->nr].data; /* LIFO */
-
- result = queue->array[0].data;
- if (!--queue->nr)
- return result;
-
- queue->array[0] = queue->array[queue->nr];
- sift_down_root(queue);
return result;
}
@@ -102,17 +97,3 @@ void *prio_queue_peek(struct prio_queue *queue)
return queue->array[queue->nr - 1].data;
return queue->array[0].data;
}
-
-void prio_queue_replace(struct prio_queue *queue, void *thing)
-{
- if (!queue->nr) {
- prio_queue_put(queue, thing);
- } else if (!queue->compare) {
- queue->array[queue->nr - 1].ctr = queue->insertion_ctr++;
- queue->array[queue->nr - 1].data = thing;
- } else {
- queue->array[0].ctr = queue->insertion_ctr++;
- queue->array[0].data = thing;
- sift_down_root(queue);
- }
-}