Add contains method for single vertex and hash function for SCCs

This commit is contained in:
stefiosif
2023-02-10 18:20:00 +02:00
parent 54eee41f7d
commit 2175ac0ca9
3 changed files with 47 additions and 25 deletions

View File

@@ -24,6 +24,12 @@ public:
// Reverse graph directions
auto reverse();
//
auto contains(const T& u);
friend std::ostream& operator<<<>(std::ostream& os, Digraph<T>& G);
};
template<typename T>
@@ -60,6 +66,26 @@ auto Digraph<T>::reverse() {
return revMatrix;
}
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) {
os << "V: " << G.V() << " E: " << G.E() << '\n';
for (const auto& u : G.vertices()) {
if (!G.adjList[u].empty()) {
for (const auto& v : G.adjList[u]) {
os << u << "->" << v << ' ';
}
os << '\n';
}
}
os << '\n';
return os;
}
} // namespace graph
#endif