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

@@ -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