From: Igor Putovny Date: Wed, 17 Jul 2024 12:04:19 +0000 (+0200) Subject: Add ancestor pointer to enable faster lookup of ancestor with non-null bucket X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a9f68131a81a66c6e19e386b14d0d03dcbfa181;p=thirdparty%2Fbird.git Add ancestor pointer to enable faster lookup of ancestor with non-null bucket --- diff --git a/proto/aggregator/aggregator.c b/proto/aggregator/aggregator.c index 1644d8d16..441e63f4e 100644 --- a/proto/aggregator/aggregator.c +++ b/proto/aggregator/aggregator.c @@ -565,6 +565,9 @@ third_pass(struct trie_node *node) assert(node->potential_buckets_count > 0); assert(node->potential_buckets[0] != NULL); node->bucket = node->potential_buckets[0]; + + /* Root is the first node with a bucket */ + node->ancestor = node; } else { @@ -572,7 +575,8 @@ third_pass(struct trie_node *node) if (!is_leaf(node)) assert(node->bucket == NULL); - const struct aggregator_bucket *inherited_bucket = get_ancestor_bucket(node); + /* Bucket inherited from the closest ancestor with a non-null bucket */ + const struct aggregator_bucket *inherited_bucket = node->parent->ancestor->bucket; /* * If bucket inherited from ancestor is one of potential buckets of this node, @@ -588,6 +592,12 @@ third_pass(struct trie_node *node) assert(node->potential_buckets_count > 0); node->bucket = node->potential_buckets[0]; } + + /* + * Node with a bucket is the closest ancestor for all his descendants. + * Otherwise, it must refer to the closest ancestor of its parent. + */ + node->ancestor = node->bucket ? node : node->parent->ancestor; } /* Preorder traversal */ diff --git a/proto/aggregator/aggregator.h b/proto/aggregator/aggregator.h index abe6f7d8f..f30d14d43 100644 --- a/proto/aggregator/aggregator.h +++ b/proto/aggregator/aggregator.h @@ -111,6 +111,7 @@ struct aggr_item_node { struct trie_node { struct trie_node *parent; struct trie_node *child[2]; + struct trie_node *ancestor; struct aggregator_bucket *bucket; struct aggregator_bucket *potential_buckets[MAX_POTENTIAL_BUCKETS_COUNT]; int potential_buckets_count;