clusterlin: abstract out DepGraph::GetReduced{Parents,Children}

A fuzz test already relies on these operations, and a future commit will need
the same logic too. Therefore, abstract them out into proper member functions,
with proper testing.
This commit is contained in:
Pieter Wuille
2024-09-06 15:32:48 -04:00
parent 62e4516722
commit 5901cf7100
3 changed files with 90 additions and 15 deletions

View File

@@ -896,24 +896,12 @@ FUZZ_TARGET(clusterlin_postlinearize_tree)
}
if (direction & 1) {
for (ClusterIndex i = 0; i < depgraph_gen.TxCount(); ++i) {
auto children = depgraph_gen.Descendants(i) - TestBitSet::Singleton(i);
// Remove descendants that are children of other descendants.
for (auto j : children) {
if (!children[j]) continue;
children -= depgraph_gen.Descendants(j);
children.Set(j);
}
auto children = depgraph_gen.GetReducedChildren(i);
if (children.Any()) depgraph_tree.AddDependency(i, children.First());
}
} else {
for (ClusterIndex i = 0; i < depgraph_gen.TxCount(); ++i) {
auto parents = depgraph_gen.Ancestors(i) - TestBitSet::Singleton(i);
// Remove ancestors that are parents of other ancestors.
for (auto j : parents) {
if (!parents[j]) continue;
parents -= depgraph_gen.Ancestors(j);
parents.Set(j);
}
auto parents = depgraph_gen.GetReducedParents(i);
if (parents.Any()) depgraph_tree.AddDependency(parents.First(), i);
}
}