#ifndef DIGRAPH_H_ #define DIGRAPH_H_ #include "graph.h" #include "algorithm/breadth_first_search.h" namespace graph { template class Digraph : public Graph { public: Digraph() = default; Digraph(std::map> G); // Return true if there is a path from u to v bool contains(const T& u, const T& v); // Add edge e(u,v) void insert(const T& u, const T& v); // Remove edge e(u,v) void remove(const T& u, const T& v); // Reverse graph directions auto reverse(); }; template Digraph::Digraph(std::map> G) { this->adjMatrix = G; } template bool Digraph::contains(const T& u, const T& v) { return algo::BreadthFirstSearch().query(u, v); } template void Digraph::insert(const T& u, const T& v) { this->adjMatrix[u].insert(v); this->adjMatrix[v]; } template void Digraph::remove(const T& u, const T& v) { this->adjMatrix[u].erase(v); //if (this->adjMatrix[u].size() == 0) // this->adjMatrix.erase(u); } template auto Digraph::reverse() { std::map> revMatrix; for (const auto& u : this->adjMatrix) { for (const auto& v : u.second) { revMatrix[v].insert(u.first); } } return revMatrix; } } // namespace graph #endif