]> granicus.if.org Git - apache/commitdiff
add some debugging code -- verifies that the heap property is satisfied
authorCliff Woolley <jwoolley@apache.org>
Tue, 13 Aug 2002 23:47:50 +0000 (23:47 +0000)
committerCliff Woolley <jwoolley@apache.org>
Tue, 13 Aug 2002 23:47:50 +0000 (23:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96367 13f79535-47bb-0310-9956-ffa450edef68

modules/experimental/cache_pqueue.c
modules/experimental/cache_pqueue.h

index 0b458b79c65b6855e86228b1a574f6c01ebf8b82..610f426c8669fc59eb238f9cdf0f8f5a5284dfa7 100644 (file)
@@ -336,3 +336,19 @@ void cache_pq_print(cache_pqueue_t *q,
     }
     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);
+}
index a650f44dac2c3454e6c7b6607b6eb8af4a7610a5..f3efea48788d4be1ef591ff10ee20bd10f809e78 100644 (file)
@@ -187,6 +187,14 @@ void cache_pq_dump(cache_pqueue_t *q,
                    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