Files
reachability-algorithms/graph/digraph.h

42 lines
688 B
C++

#ifndef DIGRAPH_H_
#define DIGRAPH_H_
#include "graph.h"
#include <algorithm>
#include <ranges>
namespace graph {
template<typename T>
class Digraph : public Graph<T> {
public:
Digraph() = default;
Digraph(std::map<T, std::set<T>> digraph);
// Reverse graph directions
auto reverse();
};
template<typename T>
Digraph<T>::Digraph(std::map<T, std::set<T>> digraph) {
Graph<T>::adjMatrix = digraph;
}
template<typename T>
auto Digraph<T>::reverse() {
std::map<T, std::set<T>> revMatrix;
for (const auto& v : Graph<T>::adjMatrix) {
for (const auto& u : v.second) {
revMatrix[u].insert(v.first);
}
}
return revMatrix;
}
} // namespace graph
#endif