fixup! Implementation of Lengauer-Tarjan algorithm to find dominators

This commit is contained in:
Kamil Śliwak 2023-08-11 18:58:20 +02:00 committed by r0qs
parent 56cabdc69a
commit a9a09bea6d
No known key found for this signature in database
GPG Key ID: 61503DBA6667276C

View File

@ -40,10 +40,10 @@ class Dominator
{ {
public: public:
Dominator(Vertex _entry, size_t _numVertices) Dominator(Vertex _entry, size_t _numVertices):
m_vertex(_numVertices),
m_immediateDominator(lengauerTarjanDominator(_entry, _numVertices))
{ {
m_vertex = std::vector<Vertex>(_numVertices);
m_immediateDominator = lengauerTarjanDominator(_entry, _numVertices);
buildDominatorTree(); buildDominatorTree();
} }
@ -97,18 +97,18 @@ public:
{ {
solAssert(!m_vertex.empty()); solAssert(!m_vertex.empty());
// The entry node always dominates all other nodes // The entry node always dominates all other nodes
std::vector<Vertex> dominators = std::vector<Vertex>{m_vertex[0]}; std::vector<Vertex> dominators{m_vertex[0]};
size_t idomIdx = m_immediateDominator[m_vertexIndex[_v]]; size_t idomIdx = m_immediateDominator[m_vertexIndex[_v]];
if (idomIdx == 0) if (idomIdx == 0)
return std::move(dominators); return dominators;
while (idomIdx != 0) while (idomIdx != 0)
{ {
dominators.emplace_back(m_vertex[idomIdx]); dominators.emplace_back(m_vertex[idomIdx]);
idomIdx = m_immediateDominator[idomIdx]; idomIdx = m_immediateDominator[idomIdx];
} }
return std::move(dominators); return dominators;
} }
void buildDominatorTree() { void buildDominatorTree() {