summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2016-09-23 13:25:35 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2016-10-06 11:04:55 +0200
commit938f8e32ec3fa467454ac44c01b916d17e5731af (patch)
tree3924badb754c14904ff70b785bdbf491b103faba
parent0bd43371c27b5fee23768c1b369bf2c62601578f (diff)
downloadlibgit2-938f8e32ec3fa467454ac44c01b916d17e5731af.tar.gz
pqueue: support not having a comparison function
In this case, we simply behave like a vector.
-rw-r--r--src/pqueue.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/pqueue.c b/src/pqueue.c
index 54a60ca04..8cfc4390f 100644
--- a/src/pqueue.c
+++ b/src/pqueue.c
@@ -93,7 +93,7 @@ int git_pqueue_insert(git_pqueue *pq, void *item)
(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);
return error;
@@ -101,9 +101,15 @@ int git_pqueue_insert(git_pqueue *pq, void *item)
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 */
pq->contents[0] = git_vector_last(pq);
git_vector_pop(pq);