]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Add modified implementation of the first pass
authorIgor Putovny <igor.putovny@nic.cz>
Tue, 9 Apr 2024 08:55:36 +0000 (10:55 +0200)
committerIgor Putovny <igor.putovny@nic.cz>
Thu, 30 May 2024 10:30:00 +0000 (12:30 +0200)
proto/aggregator/aggregator.c

index d09bf4d149f3bb9966bd97fa03f81ae7678de8ca..47e05f026ca709463a9f1f02993c276371200c31 100644 (file)
@@ -209,6 +209,80 @@ get_ancestor_bucket(const struct trie_node *node)
   }
 }
 
+static void
+first_pass_new(struct trie_node *node, slab *trie_slab)
+{
+  assert(node != NULL);
+  assert(trie_slab != NULL);
+
+  if (is_leaf(node))
+  {
+    assert(node->bucket != NULL);
+    assert(node->potential_buckets_count == 0);
+    node->potential_buckets[node->potential_buckets_count++] = node->bucket;
+    return;
+  }
+
+  if (node->bucket == NULL)
+  {
+    node->bucket = node->parent->bucket;
+  }
+
+  for (int i = 0; i < 2; i++)
+  {
+    if (!node->child[i])
+    {
+      struct trie_node *new = new_node(trie_slab);
+      new->parent = node;
+      new->bucket = node->bucket;
+      new->depth = node->depth + 1;
+      node->child[i] = new;
+    }
+  }
+
+  if (node->child[0])
+  {
+    first_pass_new(node->child[0], trie_slab);
+    log("Entering first pass with node %p", node->child[0]);
+  }
+
+  if (node->child[1])
+  {
+    first_pass_new(node->child[1], trie_slab);
+    log("Entering first pass with node %p", node->child[1]);
+  }
+
+  node->bucket = NULL;
+}
+
+static void
+first_pass_after_check_helper(const struct trie_node *node)
+{
+  for (int i = 0; i < node->potential_buckets_count; i++)
+  {
+    for (int j = i + 1; j < node->potential_buckets_count; j++)
+    {
+      assert(node->potential_buckets[i] != node->potential_buckets[j]);
+    }
+  }
+}
+
+static void
+first_pass_after_check(const struct trie_node *node)
+{
+  first_pass_after_check_helper(node);
+
+  if (node->child[0])
+  {
+    first_pass_after_check_helper(node->child[0]);
+  }
+
+  if (node->child[1])
+  {
+    first_pass_after_check_helper(node->child[1]);
+  }
+}
+
 /*
  * First pass of Optimal Route Table Construction (ORTC) algorithm
  */