]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
in hindsight, count nodes, not elements
authorYuri Schaeffer <yuri@nlnetlabs.nl>
Mon, 14 Oct 2013 08:09:25 +0000 (08:09 +0000)
committerYuri Schaeffer <yuri@nlnetlabs.nl>
Mon, 14 Oct 2013 08:09:25 +0000 (08:09 +0000)
git-svn-id: file:///svn/unbound/branches/edns-subnet@2980 be551aaa-1e26-0410-a405-d3ace91eadb9

edns-subnet/addrtree.c
edns-subnet/addrtree.h
testcode/unitvandergaast.c

index e2ddb9e7cd0a4d24d78f93dc0acf4b30a525beb2..a13a88e395ab8d3775f6f9f39bab1c393b2742b1 100644 (file)
@@ -63,7 +63,7 @@ node_create(struct addrtree *tree, void* elem, addrlen_t scope,
        if (!node)
                return NULL;
        node->elem = elem;
-       if (elem) tree->elem_count++;
+       tree->node_count++;
        node->scope = scope;
        node->ttl = ttl;
        node->edge[0] = NULL;
@@ -94,7 +94,7 @@ struct addrtree* addrtree_create(addrlen_t max_depth,
        tree->delfunc = delfunc;
        tree->sizefunc = sizefunc;
        tree->env = env;
-       tree->elem_count = 0;
+       tree->node_count = 0;
        return tree;
 }
 
@@ -177,7 +177,6 @@ clean_node(struct addrtree* tree, struct addrnode* node)
        if (!node->elem) return;
        tree->delfunc(tree->env, node->elem);
        node->elem = NULL;
-       tree->elem_count--;
 }
 
 /** 
@@ -314,7 +313,6 @@ addrtree_insert(struct addrtree *tree, const addrkey_t *addr,
                if (depth == sourcemask) {
                        /* update this node's scope and data */
                        clean_node(tree, node);
-                       tree->elem_count++;
                        node->elem = elem;
                        node->scope = scope;
                        return;
index eeafaf42fdd6169b73d03f24c1ae2b9472a99b63..8a3969b0e2449855bef1d2070486811f488160f2 100644 (file)
@@ -40,7 +40,7 @@ struct addrtree {
        struct addrnode* root;
        /** Number of elements in the tree (not always equal to number of 
         * nodes) */
-       unsigned int elem_count;
+       unsigned int node_count;
        /** Maximum prefix length we are willing to cache. */
        addrlen_t max_depth;
        /** External function to delete elem. Called as 
@@ -102,7 +102,7 @@ size_t addrtree_size(const struct addrtree* tree);
  */
 struct addrtree* 
 addrtree_create(addrlen_t max_depth, void (*delfunc)(void *, void *), 
-       size_t (*sizefunc)(void *), void *env, int max_elem_count);
+       size_t (*sizefunc)(void *), void *env);
 
 /** 
  * Free tree and all nodes below
index 32df27c4e8a53ea648ea3b425f9f73b8f20067f0..875467eaeab2ff696d516f18e83e78ad13ef06a1 100644 (file)
@@ -166,7 +166,7 @@ static void consistency_test(void)
        srand(9195); /* just some value for reproducibility */
 
        t = addrtree_create(100, &elemfree, NULL, &env);
-       count = t->elem_count;
+       count = t->node_count;
        unit_assert(count == 0);
        for (i = 0; i < 1000; i++) {
                l = randomkey(&k, 128);
@@ -174,15 +174,15 @@ static void consistency_test(void)
                addrtree_insert(t, k, l, 64, elem, timenow + 10, timenow);
                /* This should always hold because no items ever expire. They
                 * could be overwritten, though. */
-               unit_assert( count <= t->elem_count );
-               count = t->elem_count;
+               unit_assert( count <= t->node_count );
+               count = t->node_count;
                free(k);
                unit_assert( !addrtree_inconsistent(t) );
        }
        addrtree_delete(t);
        unit_show_func("edns-subnet/addrtree.h", "Tree consistency with purge");
        t = addrtree_create(8, &elemfree, NULL, &env);
-       unit_assert(t->elem_count == 0);
+       unit_assert(t->node_count == 0);
        for (i = 0; i < 1000; i++) {
                l = randomkey(&k, 128);
                elem = (struct reply_info *) calloc(1, sizeof(struct reply_info));