Skip to content

Commit 6e37824

Browse files
committed
clusterlin tests: optimize clusterlin_simple_linearize
Whenever a non-topological permutation is encountered, fast forward to the last permutation with the same non-topological prefix, skipping over potentially many permutations that are non-topological for the same reason. With that, increase the checking of all permutations to clusters of size 8 instead of 7.
1 parent 98c1c88 commit 6e37824

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/test/fuzz/cluster_linearize.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -972,27 +972,33 @@ FUZZ_TARGET(clusterlin_simple_linearize)
972972

973973
// If SimpleLinearize claims optimal result, and the cluster is sufficiently small (there are
974974
// n! linearizations), test that the result is as good as every valid linearization.
975-
if (optimal && depgraph.TxCount() <= 7) {
975+
if (optimal && depgraph.TxCount() <= 8) {
976976
std::vector<DepGraphIndex> perm_linearization;
977977
// Initialize with the lexicographically-first linearization.
978978
for (DepGraphIndex i : depgraph.Positions()) perm_linearization.push_back(i);
979979
// Iterate over all valid permutations.
980980
do {
981-
// Determine whether perm_linearization is topological.
981+
/** What prefix of perm_linearization is topological. */
982+
DepGraphIndex topo_length{0};
982983
TestBitSet perm_done;
983-
bool perm_is_topo{true};
984-
for (auto i : perm_linearization) {
984+
while (topo_length < perm_linearization.size()) {
985+
auto i = perm_linearization[topo_length];
985986
perm_done.Set(i);
986-
if (!depgraph.Ancestors(i).IsSubsetOf(perm_done)) {
987-
perm_is_topo = false;
988-
break;
989-
}
987+
if (!depgraph.Ancestors(i).IsSubsetOf(perm_done)) break;
988+
++topo_length;
990989
}
991-
// If so, verify that the obtained linearization is as good as the permutation.
992-
if (perm_is_topo) {
990+
if (topo_length == perm_linearization.size()) {
991+
// If all of perm_linearization is topological, verify that the obtained
992+
// linearization is no worse than it.
993993
auto perm_chunking = ChunkLinearization(depgraph, perm_linearization);
994994
auto cmp = CompareChunks(simple_chunking, perm_chunking);
995995
assert(cmp >= 0);
996+
} else {
997+
// Otherwise, fast forward to the last permutation with the same non-topological
998+
// prefix.
999+
auto first_non_topo = perm_linearization.begin() + topo_length;
1000+
assert(std::is_sorted(first_non_topo + 1, perm_linearization.end()));
1001+
std::reverse(first_non_topo + 1, perm_linearization.end());
9961002
}
9971003
} while(std::next_permutation(perm_linearization.begin(), perm_linearization.end()));
9981004
}

0 commit comments

Comments
 (0)