mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-05 14:37:37 +00:00
pqueue: support not having a comparison function
In this case, we simply behave like a vector.
This commit is contained in:
parent
0bd43371c2
commit
938f8e32ec
12
src/pqueue.c
12
src/pqueue.c
@ -93,7 +93,7 @@ int git_pqueue_insert(git_pqueue *pq, void *item)
|
|||||||
(void)git_pqueue_pop(pq);
|
(void)git_pqueue_pop(pq);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(error = git_vector_insert(pq, item)))
|
if (!(error = git_vector_insert(pq, item)) && pq->_cmp)
|
||||||
pqueue_up(pq, pq->length - 1);
|
pqueue_up(pq, pq->length - 1);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
@ -101,9 +101,15 @@ int git_pqueue_insert(git_pqueue *pq, void *item)
|
|||||||
|
|
||||||
void *git_pqueue_pop(git_pqueue *pq)
|
void *git_pqueue_pop(git_pqueue *pq)
|
||||||
{
|
{
|
||||||
void *rval = git_pqueue_get(pq, 0);
|
void *rval;
|
||||||
|
|
||||||
if (git_pqueue_size(pq) > 1) {
|
if (!pq->_cmp) {
|
||||||
|
rval = git_vector_last(pq);
|
||||||
|
} else {
|
||||||
|
rval = git_pqueue_get(pq, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (git_pqueue_size(pq) > 1 && pq->_cmp) {
|
||||||
/* move last item to top of heap, shrink, and push item down */
|
/* move last item to top of heap, shrink, and push item down */
|
||||||
pq->contents[0] = git_vector_last(pq);
|
pq->contents[0] = git_vector_last(pq);
|
||||||
git_vector_pop(pq);
|
git_vector_pop(pq);
|
||||||
|
Loading…
Reference in New Issue
Block a user