Refactor: Replace std::map and std::set with unordered versions

This commit is contained in:
stefiosif
2022-10-12 17:26:11 +03:00
parent c525aeaa43
commit dc7fa93a6a
13 changed files with 44 additions and 41 deletions

View File

@@ -28,20 +28,20 @@ public:
void remove(const T& u, const T& v) override;
private:
// Transitive closure matrix
std::map<T, std::map<T, bool>> TC;
std::unordered_map<T, std::unordered_map<T, bool>> TC;
// For each vertex, store a reachability tree created as a BFS tree
std::map<T, BreadthFirstTree<T>> RT;
std::unordered_map<T, BreadthFirstTree<T>> RT;
// For each vertex, store collections of its incoming and outgoing edges
struct Edges {
std::set<T> inc;
std::set<T> out;
};
std::map<T, Edges> E;
std::unordered_map<T, Edges> E;
// Repair reachability trees after edge deletions
void repairTrees(std::map<T, std::stack<T>>& H);
void repairTrees(std::unordered_map<T, std::stack<T>>& H);
};
template<typename T>
@@ -68,7 +68,7 @@ template<typename T>
void Italiano<T>::remove(const T& u, const T& v) {
if (!this->G.adjList[u].contains(v)) return;
std::map<T, std::stack<T>> H;
std::unordered_map<T, std::stack<T>> H;
for (const auto& w : this->G.vertices()) {
if (RT[w].contains(u, v)) {
if (E[v].inc.size() > 1)
@@ -89,7 +89,7 @@ void Italiano<T>::remove(const T& u, const T& v) {
}
template<typename T>
void Italiano<T>::repairTrees(std::map<T, std::stack<T>>& H) {
void Italiano<T>::repairTrees(std::unordered_map<T, std::stack<T>>& H) {
for (const auto& z : this->G.vertices()) {
while (H[z].size() > 0) {
const auto& h = H[z].top();