44 lines
799 B
C++
44 lines
799 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;
|
|
auto kv = std::views::keys(Graph<T>::adjMatrix);
|
|
Graph<T>::vertices = std::set<T>{ kv.begin(), kv.end() };
|
|
}
|
|
|
|
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 |