diff --git a/include/algorithm/tarjan.h b/include/algorithm/tarjan.h index ff047c9..d86fe35 100644 --- a/include/algorithm/tarjan.h +++ b/include/algorithm/tarjan.h @@ -70,9 +70,9 @@ template void Tarjan::strongConnect(const T &u) { } template auto Tarjan::execute() { - for (const auto &u : std::views::keys(adjList)) { - if (V[u].index == -1) - strongConnect(u); + for (const auto &u : adjList) { + if (V[u.first].index == -1) + strongConnect(u.first); } return SCCs; } diff --git a/include/graph/graph.h b/include/graph/graph.h index fca956a..a29594e 100644 --- a/include/graph/graph.h +++ b/include/graph/graph.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -38,8 +39,14 @@ public: std::unordered_map> adjList; }; -template auto Graph::vertices() const { - return std::views::keys(adjList); +template +auto Graph::vertices() const { + std::vector keys; + keys.reserve(adjList.size()); + for (const auto& pair : adjList) { + keys.push_back(pair.first); + } + return keys; } template std::uint16_t Graph::V() { diff --git a/test/algorithm_test.cc b/test/algorithm_test.cc index 8f68d4b..8c30528 100644 --- a/test/algorithm_test.cc +++ b/test/algorithm_test.cc @@ -3,6 +3,7 @@ #include "algorithm/tarjan.h" #include "algorithm/breadth_first_search.h" +#include #include #include #include @@ -51,7 +52,7 @@ TEST_SUITE("Algorithm") { }; for (auto i = 0; i < SCCs.size(); i++) { - auto kv = std::views::keys(SCCs[i].adjList); + auto kv = SCCs[i].vertices(); CHECK_EQ(std::is_permutation(kv.begin(), kv.end(), expected[i].begin()), true); }