From 1eae1a29340986fa5b8fca99bd797806891a511f Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Thu, 5 Jan 2017 12:31:48 -0500 Subject: Return vertices in a vector --- src/graph.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/graph.h') diff --git a/src/graph.h b/src/graph.h index f687ff3..47dce16 100644 --- a/src/graph.h +++ b/src/graph.h @@ -13,6 +13,7 @@ public: void add_vertex(int vertex) { if (vertices_.find(vertex) == vertices_.end()) { vertices_.insert(vertex); + orderable_vertices_.push_back(vertex); graph_[vertex] = std::vector(); } } @@ -24,8 +25,12 @@ public: has_out_edges_.insert(from); } - const std::set & get_vertices() const { - return vertices_; + void sort_vertices() { + std::sort(orderable_vertices_.begin(), orderable_vertices_.end()); + } + + const std::vector & get_vertices() const { + return orderable_vertices_; } const std::vector & get_neighbors(int vertex) const { @@ -37,7 +42,8 @@ public: } private: - std::set vertices_; + std::unordered_set vertices_; + std::vector orderable_vertices_; std::unordered_map> graph_; std::unordered_set has_out_edges_; }; -- cgit v1.2.3