From fc6167b611c25538ce97cb82fcd9c19f9a1f9b66 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 18 Jul 2006 12:40:17 +0000 Subject: [PATCH] Move the root index from zero to one git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@491 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/lib/libvarnish/binary_heap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/varnish-cache/lib/libvarnish/binary_heap.c b/varnish-cache/lib/libvarnish/binary_heap.c index 274d337b..b0bfed8a 100644 --- a/varnish-cache/lib/libvarnish/binary_heap.c +++ b/varnish-cache/lib/libvarnish/binary_heap.c @@ -19,6 +19,8 @@ #define MIN_LENGTH 16 +#define ROOT_IDX 1 + struct binheap { unsigned magic; #define BINHEAP_MAGIC 0xf581581aU /* from /dev/random */ @@ -57,7 +59,7 @@ binheap_new(void *priv, binheap_cmp_t *cmp_f, binheap_update_t *update_f) bh->priv = priv; bh->cmp = cmp_f; bh->update = update_f; - bh->next = 0; + bh->next = ROOT_IDX; bh->length = MIN_LENGTH; bh->array = calloc(sizeof *bh->array, bh->length); assert(bh->array != NULL); @@ -87,7 +89,7 @@ binheap_trickleup(struct binheap *bh, unsigned u) unsigned v; assert(bh->magic == BINHEAP_MAGIC); - while (u > 0) { + while (u > ROOT_IDX) { v = PARENT(u); if (bh->cmp(bh->priv, bh->array[u], bh->array[v])) { binhead_swap(bh, u, v); @@ -161,9 +163,9 @@ binheap_root(struct binheap *bh) assert(bh != NULL); assert(bh->magic == BINHEAP_MAGIC); - if(bh->next == 0) + if(bh->next == ROOT_IDX) return (NULL); - return (bh->array[0]); + return (bh->array[ROOT_IDX]); } void @@ -172,7 +174,7 @@ binheap_delete(struct binheap *bh, unsigned idx) assert(bh != NULL); assert(bh->magic == BINHEAP_MAGIC); - assert(bh->next > 0); + assert(bh->next > ROOT_IDX); assert(idx < bh->next); if (idx == --bh->next) return; -- 2.39.5