diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-12 18:56:41 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-12 22:05:03 -0700 |
| commit | 2cc01b2acac847533e931a0c89cd7117756022fc (patch) | |
| tree | 2b5386bda6df7bbac24fe1701499639599e3cd0e /toolsrc/include | |
| parent | 7f79f44b0c7084a80af541db04c54f3d1e95316c (diff) | |
| download | vcpkg-2cc01b2acac847533e931a0c89cd7117756022fc.tar.gz vcpkg-2cc01b2acac847533e931a0c89cd7117756022fc.zip | |
Remove Graph class
Diffstat (limited to 'toolsrc/include')
| -rw-r--r-- | toolsrc/include/vcpkg_Graphs.h | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/toolsrc/include/vcpkg_Graphs.h b/toolsrc/include/vcpkg_Graphs.h index 8af2ad053..1b9cbcb5a 100644 --- a/toolsrc/include/vcpkg_Graphs.h +++ b/toolsrc/include/vcpkg_Graphs.h @@ -1,7 +1,6 @@ #pragma once #include <unordered_map> -#include <unordered_set> namespace vcpkg::Graphs { @@ -67,95 +66,4 @@ namespace vcpkg::Graphs return sorted; } - - template <class V> - struct GraphAdjacencyProvider final : AdjacencyProvider<V, V> - { - const std::unordered_map<V, std::unordered_set<V>>& vertices; - - GraphAdjacencyProvider(const std::unordered_map<V, std::unordered_set<V>>& vertices) : vertices(vertices) {} - - std::vector<V> adjacency_list(const V& vertex) const override - { - const std::unordered_set<V>& as_set = this->vertices.at(vertex); - return std::vector<V>(as_set.cbegin(), as_set.cend()); // TODO: Avoid redundant copy - } - - V load_vertex_data(const V& vertex) const override - { - return vertex; - } - }; - - template <class V> - class Graph - { - public: - void add_vertex(V v) - { - this->vertices[v]; - } - - // TODO: Change with iterators - void add_vertices(const std::vector<V>& vs) - { - for (const V& v : vs) - { - this->vertices[v]; - } - } - - void add_edge(V u, V v) - { - this->vertices[v]; - this->vertices[u].insert(v); - } - - std::vector<V> topological_sort() const - { - GraphAdjacencyProvider<V> adjacency_provider{ this->vertices }; - std::unordered_map<V, int> indegrees = count_indegrees(); - - std::vector<V> sorted; - sorted.reserve(indegrees.size()); - - std::unordered_map<V, ExplorationStatus> exploration_status; - exploration_status.reserve(indegrees.size()); - - for (auto& pair : indegrees) - { - if (pair.second == 0) // Starting from vertices with indegree == 0. Not required. - { - V vertex = pair.first; - topological_sort_internal(vertex, adjacency_provider, exploration_status, sorted); - } - } - - return sorted; - } - - std::unordered_map<V, int> count_indegrees() const - { - std::unordered_map<V, int> indegrees; - - for (auto& pair : this->vertices) - { - indegrees[pair.first]; - for (V neighbour : pair.second) - { - ++indegrees[neighbour]; - } - } - - return indegrees; - } - - const std::unordered_map<V, std::unordered_set<V>>& adjacency_list() const - { - return this->vertices; - } - - private: - std::unordered_map<V, std::unordered_set<V>> vertices; - }; } |
