Add contains method for single vertex and hash function for SCCs
This commit is contained in:
@@ -27,7 +27,7 @@ public:
|
||||
virtual void remove(const T& u, const T& v) =0;
|
||||
|
||||
// Return graph vertices
|
||||
auto vertices();
|
||||
auto vertices() const;
|
||||
|
||||
// Return num. of vertices
|
||||
std::uint16_t V();
|
||||
@@ -38,11 +38,10 @@ public:
|
||||
// Adjacency matrix representation
|
||||
std::unordered_map<T, std::unordered_set<T>> adjList;
|
||||
|
||||
friend std::ostream& operator<<<>(std::ostream& os, Graph<T>& G);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
auto Graph<T>::vertices() {
|
||||
auto Graph<T>::vertices() const{
|
||||
return std::views::keys(adjList);
|
||||
}
|
||||
|
||||
@@ -60,20 +59,7 @@ std::uint16_t Graph<T>::E() {
|
||||
return edges;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& os, Graph<T>& G) {
|
||||
os << "V: " << G.V() << " E: " << G.E() << '\n';
|
||||
for (const auto& u : this->vertices()) {
|
||||
if (!this->adjList[u].empty()) {
|
||||
for (const auto& v : this->adjList[u]) {
|
||||
os << u << "->" << v << ' ';
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
} // namespace graph
|
||||
|
||||
|
||||
Reference in New Issue
Block a user