fixup! Implementation of Lengauer-Tarjan algorithm to find dominators

This commit is contained in:
Kamil Śliwak 2023-08-11 18:28:31 +02:00 committed by r0qs
parent d33f8f951d
commit 83abb3b8ab
No known key found for this signature in database
GPG Key ID: 61503DBA6667276C

View File

@ -62,7 +62,7 @@ class DominatorFixture
{ {
typedef ImmediateDominatorTest::Vertex Vertex; typedef ImmediateDominatorTest::Vertex Vertex;
protected: protected:
static ImmediateDominatorTest const* generateGraph( static ImmediateDominatorTest const* prepareTestDefinition(
std::vector<std::string> _vertices, std::vector<std::string> _vertices,
std::vector<ImmediateDominatorTest::Edge> _edges, std::vector<ImmediateDominatorTest::Edge> _edges,
std::vector<size_t> _expectedIdom, std::vector<size_t> _expectedIdom,
@ -102,7 +102,7 @@ BOOST_AUTO_TEST_SUITE(Dominators)
BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture) BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
{ {
typedef ImmediateDominatorTest::Edge Edge; typedef ImmediateDominatorTest::Edge Edge;
std::vector<ImmediateDominatorTest const*> inputGraph(9); std::vector<ImmediateDominatorTest const*> testDefinitions(9);
// A // A
// │ // │
@ -119,7 +119,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
// E H // E H
// │ │ // │ │
// └──►F◄──┘ // └──►F◄──┘
inputGraph[0] = generateGraph( testDefinitions[0] = prepareTestDefinition(
{"A", "B", "C", "D", "E", "F", "G", "H"}, {"A", "B", "C", "D", "E", "F", "G", "H"},
{ {
Edge("A", "B"), Edge("A", "B"),
@ -153,7 +153,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
// └─C◄───┐ E F // └─C◄───┐ E F
// │ │ │ │ // │ │ │ │
// └───►G◄─┴─────┘ // └───►G◄─┴─────┘
inputGraph[1] = generateGraph( testDefinitions[1] = prepareTestDefinition(
{"A", "B", "C", "D", "E", "F", "G"}, {"A", "B", "C", "D", "E", "F", "G"},
{ {
Edge("A", "B"), Edge("A", "B"),
@ -200,7 +200,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
// │ └─────┴─G◄─┴──────┘ // │ └─────┴─G◄─┴──────┘
// │ │ // │ │
// └─────────────┘ // └─────────────┘
inputGraph[2] = generateGraph( testDefinitions[2] = prepareTestDefinition(
{"A", "B", "C", "D", "E", "F", "G", "H", "I"}, {"A", "B", "C", "D", "E", "F", "G", "H", "I"},
{ {
Edge("A", "B"), Edge("A", "B"),
@ -237,7 +237,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
// T. Lengauer and R. E. Tarjan pg. 122 fig. 1 // T. Lengauer and R. E. Tarjan pg. 122 fig. 1
// ref: https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf // ref: https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf
inputGraph[3] = generateGraph( testDefinitions[3] = prepareTestDefinition(
{"R", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "K"}, {"R", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "K"},
{ {
Edge("R", "B"), Edge("R", "B"),
@ -283,7 +283,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
// Extracted from Loukas Georgiadis Dissertation - Linear-Time Algorithms for Dominators and Related Problems // Extracted from Loukas Georgiadis Dissertation - Linear-Time Algorithms for Dominators and Related Problems
// pg. 12 Fig. 2.2 // pg. 12 Fig. 2.2
// ref: https://www.cs.princeton.edu/techreports/2005/737.pdf // ref: https://www.cs.princeton.edu/techreports/2005/737.pdf
inputGraph[4] = generateGraph( testDefinitions[4] = prepareTestDefinition(
{"R", "W", "X1", "X2", "X3", "X4", "X5", "X6", "X7", "Y"}, {"R", "W", "X1", "X2", "X3", "X4", "X5", "X6", "X7", "Y"},
{ {
Edge("R", "W"), Edge("R", "W"),
@ -321,7 +321,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
// Worst-case families for k = 3 // Worst-case families for k = 3
// Example itworst(3) pg. 26 fig. 2.9 // Example itworst(3) pg. 26 fig. 2.9
// ref: https://www.cs.princeton.edu/techreports/2005/737.pdf // ref: https://www.cs.princeton.edu/techreports/2005/737.pdf
inputGraph[5] = generateGraph( testDefinitions[5] = prepareTestDefinition(
{"R", "W1", "W2", "W3", "X1", "X2", "X3", "Y1", "Y2", "Y3", "Z1", "Z2", "Z3"}, {"R", "W1", "W2", "W3", "X1", "X2", "X3", "Y1", "Y2", "Y3", "Z1", "Z2", "Z3"},
{ {
Edge("R", "W1"), Edge("R", "W1"),
@ -371,7 +371,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
// Worst-case families for k = 3 // Worst-case families for k = 3
// Example idfsquad(3) pg. 26 fig. 2.9 // Example idfsquad(3) pg. 26 fig. 2.9
// ref: https://www.cs.princeton.edu/techreports/2005/737.pdf // ref: https://www.cs.princeton.edu/techreports/2005/737.pdf
inputGraph[6] = generateGraph( testDefinitions[6] = prepareTestDefinition(
{"R", "X1", "X2", "X3", "Y1", "Y2", "Y3", "Z1", "Z2", "Z3"}, {"R", "X1", "X2", "X3", "Y1", "Y2", "Y3", "Z1", "Z2", "Z3"},
{ {
Edge("R", "X1"), Edge("R", "X1"),
@ -408,7 +408,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
// Worst-case families for k = 3 // Worst-case families for k = 3
// Example ibfsquad(3) pg. 26 fig. 2.9 // Example ibfsquad(3) pg. 26 fig. 2.9
// ref: https://www.cs.princeton.edu/techreports/2005/737.pdf // ref: https://www.cs.princeton.edu/techreports/2005/737.pdf
inputGraph[7] = generateGraph( testDefinitions[7] = prepareTestDefinition(
{"R", "W", "X1", "X2", "X3", "Y", "Z"}, {"R", "W", "X1", "X2", "X3", "Y", "Z"},
{ {
Edge("R", "W"), Edge("R", "W"),
@ -436,7 +436,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
// Worst-case families for k = 3 // Worst-case families for k = 3
// Example sncaworst(3) pg. 26 fig. 2.9 // Example sncaworst(3) pg. 26 fig. 2.9
// ref: https://www.cs.princeton.edu/techreports/2005/737.pdf // ref: https://www.cs.princeton.edu/techreports/2005/737.pdf
inputGraph[8] = generateGraph( testDefinitions[8] = prepareTestDefinition(
{"R", "X1", "X2", "X3", "Y1", "Y2", "Y3"}, {"R", "X1", "X2", "X3", "Y1", "Y2", "Y3"},
{ {
Edge("R", "X1"), Edge("R", "X1"),
@ -461,7 +461,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
} }
); );
for (ImmediateDominatorTest const* test: inputGraph) for (ImmediateDominatorTest const* test: testDefinitions)
{ {
Dominator< Dominator<
ImmediateDominatorTest::Vertex, ImmediateDominatorTest::Vertex,