1
1
#include "git-compat-util.h"
2
2
#include "prio-queue.h"
3
3
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 )
5
5
{
6
6
int cmp = queue -> compare (queue -> array [i ].data , queue -> array [j ].data ,
7
7
queue -> cb_data );
8
8
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 );
10
11
return cmp ;
11
12
}
12
13
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 )
14
15
{
15
16
SWAP (queue -> array [i ], queue -> array [j ]);
16
17
}
17
18
18
19
void prio_queue_reverse (struct prio_queue * queue )
19
20
{
20
- int i , j ;
21
+ size_t i , j ;
21
22
22
23
if (queue -> compare )
23
24
BUG ("prio_queue_reverse() on non-LIFO queue" );
25
+ if (!queue -> nr )
26
+ return ;
24
27
for (i = 0 ; i < (j = (queue -> nr - 1 ) - i ); i ++ )
25
28
swap (queue , i , j );
26
29
}
@@ -35,7 +38,7 @@ void clear_prio_queue(struct prio_queue *queue)
35
38
36
39
void prio_queue_put (struct prio_queue * queue , void * thing )
37
40
{
38
- int ix , parent ;
41
+ size_t ix , parent ;
39
42
40
43
/* Append at the end */
41
44
ALLOC_GROW (queue -> array , queue -> nr + 1 , queue -> alloc );
@@ -58,7 +61,7 @@ void prio_queue_put(struct prio_queue *queue, void *thing)
58
61
void * prio_queue_get (struct prio_queue * queue )
59
62
{
60
63
void * result ;
61
- int ix , child ;
64
+ size_t ix , child ;
62
65
63
66
if (!queue -> nr )
64
67
return NULL ;
0 commit comments