Improve readability

This commit is contained in:
stefiosif
2023-02-10 18:26:48 +02:00
parent 2175ac0ca9
commit 3591c58f6d
6 changed files with 217 additions and 158 deletions

View File

@@ -29,7 +29,7 @@ public:
// Remove edge (u,v) and update A accordingly for fast checking query
void remove(const T& u, const T& v);
std::unordered_map<T, SCC<T>> getSCCs() { return C; }
std::unordered_map<T, SCC<T>> getComponentMap() { return C; }
private:
// Array used to answer strong connectivity queries in O(1) time
std::unordered_map<T, T> A;
@@ -51,16 +51,16 @@ template<typename T>
void RodittyZwick<T>::findSCC(graph::Digraph<T> G) {
auto SCCs = Tarjan<T>(G.adjList).execute();
for (auto& SCC : SCCs) {
const auto& w = SCC.id;
for (auto& c : SCCs) {
const auto& w = c.id;
for (const auto& v : SCC.vertices())
for (const auto& v : c.vertices())
A[v] = w;
Out[w] = BreadthFirstTree<T>(SCC, w);
In[w] = BreadthFirstTree<T>(SCC.reverse(), w);
Out[w] = BreadthFirstTree<T>(c, w);
In[w] = BreadthFirstTree<T>(c.reverse(), w);
C[w] = SCC;
C[w] = c;
}
}
@@ -82,19 +82,20 @@ void RodittyZwick<T>::remove(const T& u, const T& v) {
this->G.remove(u, v);
// If u and v are not in the same SCC, do nothing
if (A[u] != A[v]) return;
if (A[u] != A[v])
return;
// If edge (u,v) is not contained in both inTree and outTree do nothing
if (!In[w].adjList[u].contains(v) &&
!Out[w].adjList[u].contains(v))
// If edge (u,v) is not contained in both inTree and outTree do nothing TODO:remove useless comments
// is this not better if i utilize A matrix, since we are going traversing between components.. ? TODO
if (!In[w].adjList[u].contains(v) && !Out[w].adjList[u].contains(v))
return;
// Update In(w) and Out(w)
Out[w] = BreadthFirstTree<T>(C[w], w);
In[w] = BreadthFirstTree<T>(C[w].reverse(), w);
// If a SCC is broken, compute all SCCs again
if (!In[w].adjList.count(u) || !Out[w].adjList.count(v))
// If a SCC is broken, compute the new SCCs
if (!In[w].contains(u) || !Out[w].contains(v))
findSCC(C[w]);
}