Refactor: Rename adjMatrix to adjList

This commit is contained in:
stefiosif
2022-10-12 16:57:48 +03:00
parent 8b6d341d18
commit c525aeaa43
14 changed files with 56 additions and 56 deletions

View File

@@ -16,7 +16,7 @@ class Tarjan {
public:
Tarjan() = default;
Tarjan(std::map<T, std::set<T>> adjMatrix) : adjMatrix(adjMatrix) {}
Tarjan(std::map<T, std::set<T>> adjList) : adjList(adjList) {}
//
auto execute();
@@ -24,7 +24,7 @@ public:
//
void strongConnect(const T& u);
private:
std::map<T, std::set<T>> adjMatrix;
std::map<T, std::set<T>> adjList;
std::stack<T> S;
std::int16_t index = 0;
std::vector<SCC<T>> SCCs;
@@ -44,7 +44,7 @@ void Tarjan<T>::strongConnect(const T& u) {
S.push(u);
vmap[u].onStack = true;
for (const auto& w : adjMatrix[u]) {
for (const auto& w : adjList[u]) {
if (vmap[w].index == -1) {
strongConnect(w);
vmap[u].lowlink = std::min(vmap[u].lowlink, vmap[w].lowlink);
@@ -63,7 +63,7 @@ void Tarjan<T>::strongConnect(const T& u) {
const auto w = S.top();
S.pop();
vmap[w].onStack = false;
scc[w] = adjMatrix[w];
scc[w] = adjList[w];
finished = (w == u);
} while (!finished);
@@ -73,7 +73,7 @@ void Tarjan<T>::strongConnect(const T& u) {
template<typename T>
auto Tarjan<T>::execute() {
for (const auto& u : std::views::keys(adjMatrix)) {
for (const auto& u : std::views::keys(adjList)) {
if (vmap[u].index == -1)
strongConnect(u);
}