From: Cliff Woolley Date: Tue, 13 Aug 2002 23:47:50 +0000 (+0000) Subject: add some debugging code -- verifies that the heap property is satisfied X-Git-Tag: AGB_BEFORE_AAA_CHANGES~271 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f17febee2f36303d866754139520bb5e4e933ff;p=apache add some debugging code -- verifies that the heap property is satisfied git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96367 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/experimental/cache_pqueue.c b/modules/experimental/cache_pqueue.c index 0b458b79c6..610f426c86 100644 --- a/modules/experimental/cache_pqueue.c +++ b/modules/experimental/cache_pqueue.c @@ -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) size &&(q->pri(q->d[pos]) < q->pri(q->d[left(pos)]))) || + (right(pos)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); +} diff --git a/modules/experimental/cache_pqueue.h b/modules/experimental/cache_pqueue.h index a650f44dac..f3efea4878 100644 --- a/modules/experimental/cache_pqueue.h +++ b/modules/experimental/cache_pqueue.h @@ -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