11#include "git-compat-util.h"
22#include "prio-queue.h"
33
4- static inline int compare (struct prio_queue * queue , int i , int j )
4+ static inline int compare (struct prio_queue * queue , size_t i , size_t j )
55{
66 int cmp = queue -> compare (queue -> array [i ].data , queue -> array [j ].data ,
77 queue -> cb_data );
88 if (!cmp )
9- cmp = queue -> array [i ].ctr - queue -> array [j ].ctr ;
9+ cmp = (queue -> array [i ].ctr > queue -> array [j ].ctr ) -
10+ (queue -> array [i ].ctr < queue -> array [j ].ctr );
1011 return cmp ;
1112}
1213
13- static inline void swap (struct prio_queue * queue , int i , int j )
14+ static inline void swap (struct prio_queue * queue , size_t i , size_t j )
1415{
1516 SWAP (queue -> array [i ], queue -> array [j ]);
1617}
1718
1819void prio_queue_reverse (struct prio_queue * queue )
1920{
20- int i , j ;
21+ size_t i , j ;
2122
2223 if (queue -> compare )
2324 BUG ("prio_queue_reverse() on non-LIFO queue" );
25+ if (!queue -> nr )
26+ return ;
2427 for (i = 0 ; i < (j = (queue -> nr - 1 ) - i ); i ++ )
2528 swap (queue , i , j );
2629}
@@ -35,7 +38,7 @@ void clear_prio_queue(struct prio_queue *queue)
3538
3639void prio_queue_put (struct prio_queue * queue , void * thing )
3740{
38- int ix , parent ;
41+ size_t ix , parent ;
3942
4043 /* Append at the end */
4144 ALLOC_GROW (queue -> array , queue -> nr + 1 , queue -> alloc );
@@ -58,7 +61,7 @@ void prio_queue_put(struct prio_queue *queue, void *thing)
5861void * prio_queue_get (struct prio_queue * queue )
5962{
6063 void * result ;
61- int ix , child ;
64+ size_t ix , child ;
6265
6366 if (!queue -> nr )
6467 return NULL ;
0 commit comments