Skip to content

Commit 938f8e3

Browse files
committed
pqueue: support not having a comparison function
In this case, we simply behave like a vector.
1 parent 0bd4337 commit 938f8e3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/pqueue.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,23 @@ int git_pqueue_insert(git_pqueue *pq, void *item)
9393
(void)git_pqueue_pop(pq);
9494
}
9595

96-
if (!(error = git_vector_insert(pq, item)))
96+
if (!(error = git_vector_insert(pq, item)) && pq->_cmp)
9797
pqueue_up(pq, pq->length - 1);
9898

9999
return error;
100100
}
101101

102102
void *git_pqueue_pop(git_pqueue *pq)
103103
{
104-
void *rval = git_pqueue_get(pq, 0);
104+
void *rval;
105105

106-
if (git_pqueue_size(pq) > 1) {
106+
if (!pq->_cmp) {
107+
rval = git_vector_last(pq);
108+
} else {
109+
rval = git_pqueue_get(pq, 0);
110+
}
111+
112+
if (git_pqueue_size(pq) > 1 && pq->_cmp) {
107113
/* move last item to top of heap, shrink, and push item down */
108114
pq->contents[0] = git_vector_last(pq);
109115
git_vector_pop(pq);

0 commit comments

Comments
 (0)