diff options
| author | Junio C Hamano <gitster@pobox.com> | 2024-12-23 09:32:20 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-12-23 09:32:21 -0800 |
| commit | 8650022fab49afa46cd63cdee7aa7625240abdb4 (patch) | |
| tree | 4f1b4f19ae86b0ad708f85b977ecf07f4947d02b /prio-queue.c | |
| parent | 77825f755300f5ef84729b55e6e1e33e1dc60039 (diff) | |
| parent | 62e745ced221263717d86d1d50ffcaa029d63c4c (diff) | |
| download | git-8650022fab49afa46cd63cdee7aa7625240abdb4.tar.xz | |
Merge branch 'jk/prio-queue-sign-compare-fix'
Type clean-up.
* jk/prio-queue-sign-compare-fix:
prio-queue: use size_t rather than int for size
Diffstat (limited to 'prio-queue.c')
| -rw-r--r-- | prio-queue.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/prio-queue.c b/prio-queue.c index 450775a374..ec33ac27db 100644 --- a/prio-queue.c +++ b/prio-queue.c @@ -1,26 +1,29 @@ #include "git-compat-util.h" #include "prio-queue.h" -static inline int compare(struct prio_queue *queue, int i, int j) +static inline int compare(struct prio_queue *queue, size_t i, size_t j) { int cmp = queue->compare(queue->array[i].data, queue->array[j].data, queue->cb_data); if (!cmp) - cmp = queue->array[i].ctr - queue->array[j].ctr; + cmp = (queue->array[i].ctr > queue->array[j].ctr) - + (queue->array[i].ctr < queue->array[j].ctr); return cmp; } -static inline void swap(struct prio_queue *queue, int i, int j) +static inline void swap(struct prio_queue *queue, size_t i, size_t j) { SWAP(queue->array[i], queue->array[j]); } void prio_queue_reverse(struct prio_queue *queue) { - int i, j; + size_t i, j; if (queue->compare) BUG("prio_queue_reverse() on non-LIFO queue"); + if (!queue->nr) + return; for (i = 0; i < (j = (queue->nr - 1) - i); i++) swap(queue, i, j); } @@ -35,7 +38,7 @@ void clear_prio_queue(struct prio_queue *queue) void prio_queue_put(struct prio_queue *queue, void *thing) { - int ix, parent; + size_t ix, parent; /* Append at the end */ ALLOC_GROW(queue->array, queue->nr + 1, queue->alloc); @@ -58,7 +61,7 @@ void prio_queue_put(struct prio_queue *queue, void *thing) void *prio_queue_get(struct prio_queue *queue) { void *result; - int ix, child; + size_t ix, child; if (!queue->nr) return NULL; |
