}
cache_pq_free(dup);
}
+
+static int cache_pq_subtree_is_valid(cache_pqueue_t *q, int pos)
+{
+ if ((left(pos) <q->size &&(q->pri(q->d[pos]) < q->pri(q->d[left(pos)]))) ||
+ (right(pos)<q->size &&(q->pri(q->d[pos]) < q->pri(q->d[right(pos)]))))
+ {
+ return 0;
+ }
+ return ((left(pos)>=q->size ||(cache_pq_subtree_is_valid(q, left(pos)))) &&
+ (right(pos)>=q->size||(cache_pq_subtree_is_valid(q, right(pos)))));
+}
+
+int cache_pq_is_valid(cache_pqueue_t *q)
+{
+ return cache_pq_subtree_is_valid(q, 1);
+}
FILE *out,
cache_pqueue_print_entry print);
+/**
+ * checks that the pq is in the right order, etc
+ * @internal
+ * debug function only
+ * @param q the queue
+ */
+int cache_pq_is_valid(cache_pqueue_t *q);
+
#ifdef __cplusplus
}
#endif