]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Add ancestor pointer to enable faster lookup of ancestor with non-null bucket
authorIgor Putovny <igor.putovny@nic.cz>
Wed, 17 Jul 2024 12:04:19 +0000 (14:04 +0200)
committerIgor Putovny <igor.putovny@nic.cz>
Wed, 31 Jul 2024 14:48:59 +0000 (16:48 +0200)
proto/aggregator/aggregator.c
proto/aggregator/aggregator.h

index 1644d8d16ea282254f729dfde1da0165f5eea5eb..441e63f4ec5504b0fd44d10051f1417fc6fa4222 100644 (file)
@@ -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 */
index abe6f7d8ff8649a4f6af6feaa4fb2e4bac61641c..f30d14d43a31c6c9cf756b2298ecbb5f60589624 100644 (file)
@@ -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;