Refactor: Replace std::map and std::set with unordered versions
This commit is contained in:
@@ -10,7 +10,7 @@ class BreadthFirstTree : public Digraph<T> {
|
||||
public:
|
||||
BreadthFirstTree() = default;
|
||||
|
||||
BreadthFirstTree(std::map<T, std::set<T>> G, T root)
|
||||
BreadthFirstTree(std::unordered_map<T, std::unordered_set<T>> G, T root)
|
||||
: BreadthFirstTree<T>(Digraph<T>(G), root) {}
|
||||
|
||||
BreadthFirstTree(Digraph<T> G, T root);
|
||||
|
||||
@@ -11,7 +11,7 @@ class Digraph : public Graph<T> {
|
||||
public:
|
||||
Digraph() = default;
|
||||
|
||||
Digraph(std::map<T, std::set<T>> G);
|
||||
Digraph(std::unordered_map<T, std::unordered_set<T>> G);
|
||||
|
||||
// Return true if there is a path from u to v
|
||||
bool contains(const T& u, const T& v);
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Digraph<T>::Digraph(std::map<T, std::set<T>> G) {
|
||||
Digraph<T>::Digraph(std::unordered_map<T, std::unordered_set<T>> G) {
|
||||
this->adjList = G;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void Digraph<T>::remove(const T& u, const T& v) {
|
||||
|
||||
template<typename T>
|
||||
auto Digraph<T>::reverse() {
|
||||
std::map<T, std::set<T>> revMatrix;
|
||||
std::unordered_map<T, std::unordered_set<T>> revMatrix;
|
||||
|
||||
for (const auto& u : this->vertices()) {
|
||||
for (const auto& v : this->adjList[u]) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef GRAPH_H_
|
||||
#define GRAPH_H_
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <ostream>
|
||||
#include <ranges>
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
std::uint16_t E();
|
||||
|
||||
// Adjacency matrix representation
|
||||
std::map<T, std::set<T>> adjList;
|
||||
std::unordered_map<T, std::unordered_set<T>> adjList;
|
||||
|
||||
friend std::ostream& operator<<<>(std::ostream& os, Graph<T>& G);
|
||||
};
|
||||
|
||||
@@ -13,7 +13,8 @@ class SCC : public Digraph<T> {
|
||||
public:
|
||||
SCC() = default;
|
||||
|
||||
SCC(std::map<T, std::set<T>> G, T id) : Digraph<T>(G), id(id) { normalize(); }
|
||||
SCC(std::unordered_map<T, std::unordered_set<T>> G, T id)
|
||||
: Digraph<T>(G), id(id) { normalize(); }
|
||||
|
||||
SCC(Digraph<T> G, T id) : id(id) { normalize(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user