r491 - trunk/varnish-cache/lib/libvarnish
phk at projects.linpro.no
phk at projects.linpro.no
Tue Jul 18 14:40:17 CEST 2006
Author: phk
Date: 2006-07-18 14:40:17 +0200 (Tue, 18 Jul 2006)
New Revision: 491
Modified:
trunk/varnish-cache/lib/libvarnish/binary_heap.c
Log:
Move the root index from zero to one
Modified: trunk/varnish-cache/lib/libvarnish/binary_heap.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/binary_heap.c 2006-07-18 12:29:11 UTC (rev 490)
+++ trunk/varnish-cache/lib/libvarnish/binary_heap.c 2006-07-18 12:40:17 UTC (rev 491)
@@ -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 @@
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 @@
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 @@
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 @@
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;
More information about the varnish-commit
mailing list