From 2cc01b2acac847533e931a0c89cd7117756022fc Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 12 Apr 2017 18:56:41 -0700 Subject: Remove Graph class --- toolsrc/include/vcpkg_Graphs.h | 92 ------------------------------------------ 1 file changed, 92 deletions(-) (limited to 'toolsrc/include') 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 -#include namespace vcpkg::Graphs { @@ -67,95 +66,4 @@ namespace vcpkg::Graphs return sorted; } - - template - struct GraphAdjacencyProvider final : AdjacencyProvider - { - const std::unordered_map>& vertices; - - GraphAdjacencyProvider(const std::unordered_map>& vertices) : vertices(vertices) {} - - std::vector adjacency_list(const V& vertex) const override - { - const std::unordered_set& as_set = this->vertices.at(vertex); - return std::vector(as_set.cbegin(), as_set.cend()); // TODO: Avoid redundant copy - } - - V load_vertex_data(const V& vertex) const override - { - return vertex; - } - }; - - template - class Graph - { - public: - void add_vertex(V v) - { - this->vertices[v]; - } - - // TODO: Change with iterators - void add_vertices(const std::vector& 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 topological_sort() const - { - GraphAdjacencyProvider adjacency_provider{ this->vertices }; - std::unordered_map indegrees = count_indegrees(); - - std::vector sorted; - sorted.reserve(indegrees.size()); - - std::unordered_map 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 count_indegrees() const - { - std::unordered_map indegrees; - - for (auto& pair : this->vertices) - { - indegrees[pair.first]; - for (V neighbour : pair.second) - { - ++indegrees[neighbour]; - } - } - - return indegrees; - } - - const std::unordered_map>& adjacency_list() const - { - return this->vertices; - } - - private: - std::unordered_map> vertices; - }; } -- cgit v1.2.3