0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-09 20:58:44 +00:00

Refactor and fix aggregator_bucket_unionize()

This commit is contained in:
Igor Putovny 2023-09-19 17:00:16 +02:00
parent 45c7a5463e
commit 6d5e75e46d

View File

@ -275,16 +275,32 @@ aggregator_bucket_unionize(struct trie_node *node, const struct trie_node *left,
int res = aggregator_bucket_compare(left->potential_buckets[i], right->potential_buckets[j]);
if (res == 0)
switch (res)
{
case 0:
if (node->potential_buckets_count == 0 || node->potential_buckets[node->potential_buckets_count - 1] != left->potential_buckets[i])
node->potential_buckets[node->potential_buckets_count++] = left->potential_buckets[i];
i++;
j++;
}
else if (res == -1)
node->potential_buckets[node->potential_buckets_count++] = left->potential_buckets[i++];
else if (res == 1)
node->potential_buckets[node->potential_buckets_count++] = right->potential_buckets[j++];
break;
case -1:
if (node->potential_buckets_count == 0 || node->potential_buckets[node->potential_buckets_count - 1] != left->potential_buckets[i])
node->potential_buckets[node->potential_buckets_count++] = left->potential_buckets[i];
i++;
break;
case 1:
if (node->potential_buckets_count == 0 || node->potential_buckets[node->potential_buckets_count - 1] != right->potential_buckets[j])
node->potential_buckets[node->potential_buckets_count++] = right->potential_buckets[j];
j++;
break;
default:
bug("Impossible");
}
while (i < left->potential_buckets_count)
@ -292,7 +308,10 @@ aggregator_bucket_unionize(struct trie_node *node, const struct trie_node *left,
if (node->potential_buckets_count >= MAX_POTENTIAL_NEXTHOP_COUNT)
return;
node->potential_buckets[node->potential_buckets_count++] = left->potential_buckets[i++];
if (node->potential_buckets_count == 0 || node->potential_buckets[node->potential_buckets_count - 1] != left->potential_buckets[i])
node->potential_buckets[node->potential_buckets_count++] = left->potential_buckets[i];
i++;
}
while (j < right->potential_buckets_count)
@ -300,7 +319,11 @@ aggregator_bucket_unionize(struct trie_node *node, const struct trie_node *left,
if (node->potential_buckets_count >= MAX_POTENTIAL_NEXTHOP_COUNT)
return;
node->potential_buckets[node->potential_buckets_count++] = right->potential_buckets[j++];
if (node->potential_buckets_count == 0 || node->potential_buckets[node->potential_buckets_count - 1] != right->potential_buckets[j])
node->potential_buckets[node->potential_buckets_count++] = right->potential_buckets[j];
j++;
}
}
}