wrong arg order for qcompare, peek doesn't return boolean
@@ -14,7 +14,6 @@ static inline void swap(pqueue q, index x, index y)
vector_set(q->body, y-1, temp);
}
-
#define qcompare(__q, __x, __y)\
(q->sort(vector_get((__q)->body, (__x-1)), \
vector_get((__q)->body, (__y-1))))
@@ -42,13 +41,12 @@ static void add_pqueue(pqueue q, index i)
{
index parent = i >> 1;
- if ((parent > 0) && qcompare(q, i, parent)) {
+ if ((parent > 0) && qcompare(q, parent, i)) {
swap(q, i, parent);
add_pqueue(q, parent);
}
}
-
void pqueue_insert(pqueue q, void *v)
{
vector_push(q->body, v);
@@ -73,7 +71,7 @@ void *pqueue_pop(pqueue q)
void *pqueue_peek(pqueue q)
{
if (vector_length(q->body)) return(vector_get(q->body, 0));
- return(false);
+ return 0; // XXX INVALID_ADDRESS?
}
pqueue allocate_pqueue(heap h, boolean(*sort)(void *, void *))
