From: Igor Putovny Date: Wed, 27 Mar 2024 11:03:47 +0000 (+0100) Subject: Add variable to track node depth in the trie X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7dd30de09d1905890c0b0a9e4c06298e34e695d3;p=thirdparty%2Fbird.git Add variable to track node depth in the trie --- diff --git a/proto/aggregator/aggregator.c b/proto/aggregator/aggregator.c index a1889588c..a1834ccc7 100644 --- a/proto/aggregator/aggregator.c +++ b/proto/aggregator/aggregator.c @@ -169,6 +169,7 @@ trie_insert_prefix_ip4(const struct net_addr_ip4 *addr, struct trie_node *const struct trie_node *new = new_node(trie_slab); new->parent = node; node->child[bit] = new; + new->depth = new->parent->depth + 1; } node = node->child[bit]; @@ -197,10 +198,14 @@ trie_insert_prefix_ip6(const struct net_addr_ip6 *addr, struct trie_node * const struct trie_node *new = new_node(trie_slab); new->parent = node; node->child[bit] = new; + new->depth = new->parent->depth + 1; } node = node->child[bit]; } + + /* Assign bucket to the last node */ + node->bucket = bucket; } /* @@ -255,6 +260,7 @@ first_pass(struct trie_node *node, slab *trie_slab) new->parent = node; new->bucket = get_ancestor_bucket(new); node->child[i] = new; + new->depth = new->parent->depth + 1; } } @@ -1537,6 +1543,7 @@ aggregator_start(struct proto *P) p->trie_slab = sl_new(p->p.pool, sizeof(struct trie_node)); p->root = new_node(p->trie_slab); + p->root->depth = 1; p->reload_trie = (event) { .hook = calculate_trie, diff --git a/proto/aggregator/aggregator.h b/proto/aggregator/aggregator.h index a40fb8120..c92c46462 100644 --- a/proto/aggregator/aggregator.h +++ b/proto/aggregator/aggregator.h @@ -100,6 +100,7 @@ struct trie_node { struct aggregator_bucket *bucket; struct aggregator_bucket *potential_buckets[MAX_POTENTIAL_BUCKETS_COUNT]; int potential_buckets_count; + int depth; }; struct prefix_bucket {