Add contains method for single vertex and hash function for SCCs
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user