Use clang-format

This commit is contained in:
stefiosif
2024-08-03 13:14:42 +03:00
parent d216a9611f
commit 3951db7ff9
17 changed files with 262 additions and 287 deletions

View File

@@ -1,64 +1,59 @@
#ifndef DIGRAPH_H_
#define DIGRAPH_H_
#include "graph.h"
#include "algorithm/breadth_first_search.h"
#include "graph.h"
namespace graph {
template<typename T>
class Digraph : public Graph<T> {
template <typename T> class Digraph : public Graph<T> {
public:
Digraph() = default;
explicit 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);
bool contains(const T &u, const T &v);
// Add edge e(u,v)
void insert(const T& u, const T& v);
void insert(const T &u, const T &v);
// Remove edge e(u,v)
void remove(const T& u, const T& v);
void remove(const T &u, const T &v);
// Reverse graph directions
auto reverse();
//
auto contains(const T& u);
friend std::ostream& operator<<<>(std::ostream& os, Digraph<T>& G);
auto contains(const T &u);
template <typename U>
friend std::ostream &operator<<(std::ostream &os, const Digraph<U> &G);
};
template<typename T>
template <typename T>
Digraph<T>::Digraph(std::unordered_map<T, std::unordered_set<T>> G) {
this->adjList = G;
}
template<typename T>
bool Digraph<T>::contains(const T& u, const T& v) {
template <typename T> bool Digraph<T>::contains(const T &u, const T &v) {
return algo::BreadthFirstSearch<T>(this->adjList).query(u, v);
}
template<typename T>
void Digraph<T>::insert(const T& u, const T& v) {
template <typename T> void Digraph<T>::insert(const T &u, const T &v) {
this->adjList[u].insert(v);
this->adjList[v];
}
template<typename T>
void Digraph<T>::remove(const T& u, const T& v) {
template <typename T> void Digraph<T>::remove(const T &u, const T &v) {
this->adjList[u].erase(v);
}
template<typename T>
auto Digraph<T>::reverse() {
template <typename T> auto Digraph<T>::reverse() {
std::unordered_map<T, std::unordered_set<T>> revMatrix;
for (const auto& u : this->vertices()) {
for (const auto& v : this->adjList[u]) {
for (const auto &u : this->vertices()) {
for (const auto &v : this->adjList[u]) {
revMatrix[v].insert(u);
}
}
@@ -66,17 +61,16 @@ auto Digraph<T>::reverse() {
return revMatrix;
}
template<typename T>
auto Digraph<T>::contains(const T& u) {
template <typename T> auto Digraph<T>::contains(const T &u) {
return this->adjList.count(u);
}
template<typename T>
std::ostream& operator<<(std::ostream& os, Digraph<T>& G) {
template <typename T>
std::ostream &operator<<(std::ostream &os, Digraph<T> &G) {
os << "V: " << G.V() << " E: " << G.E() << '\n';
for (const auto& u : G.vertices()) {
for (const auto &u : G.vertices()) {
if (!G.adjList[u].empty()) {
for (const auto& v : G.adjList[u]) {
for (const auto &v : G.adjList[u]) {
os << u << "->" << v << ' ';
}
os << '\n';