From 612d941afc1339154354145f6fa5264d3c573cc0 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 10 Apr 2017 18:45:44 -0700 Subject: toposort: use lambda to obtain the neighbours of a vertex --- toolsrc/include/vcpkg_Graphs.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Graphs.h b/toolsrc/include/vcpkg_Graphs.h index 933d9ac67..fb57a38db 100644 --- a/toolsrc/include/vcpkg_Graphs.h +++ b/toolsrc/include/vcpkg_Graphs.h @@ -20,20 +20,23 @@ namespace vcpkg::Graphs template class Graph { + template static void find_topological_sort_internal(V vertex, ExplorationStatus& status, - const std::unordered_map>& adjacency_list, + const Func adjacency_list_provider, std::unordered_map& exploration_status, std::vector& sorted) { status = ExplorationStatus::PARTIALLY_EXPLORED; - for (V neighbour : adjacency_list.at(vertex)) + auto neighbours = adjacency_list_provider(vertex); + + for (V neighbour : neighbours) { ExplorationStatus& neighbour_status = exploration_status[neighbour]; if (neighbour_status == ExplorationStatus::NOT_EXPLORED) { - find_topological_sort_internal(neighbour, neighbour_status, adjacency_list, exploration_status, sorted); + find_topological_sort_internal(neighbour, neighbour_status, adjacency_list_provider, exploration_status, sorted); } else if (neighbour_status == ExplorationStatus::PARTIALLY_EXPLORED) { @@ -85,7 +88,11 @@ namespace vcpkg::Graphs ExplorationStatus& status = exploration_status[vertex]; if (status == ExplorationStatus::NOT_EXPLORED) { - find_topological_sort_internal(vertex, status, this->vertices, exploration_status, sorted); + find_topological_sort_internal(vertex, + status, + [this](const V& v) { return this->vertices.at(v); }, + exploration_status, + sorted); } } } -- cgit v1.2.3 From cfbfa0d81327b32478e57cda85059c6063cd4bfd Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 11 Apr 2017 14:30:49 -0700 Subject: Rename --- toolsrc/include/vcpkg_Graphs.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Graphs.h b/toolsrc/include/vcpkg_Graphs.h index fb57a38db..b97f7ac50 100644 --- a/toolsrc/include/vcpkg_Graphs.h +++ b/toolsrc/include/vcpkg_Graphs.h @@ -21,7 +21,7 @@ namespace vcpkg::Graphs class Graph { template - static void find_topological_sort_internal(V vertex, + static void topological_sort_internal(V vertex, ExplorationStatus& status, const Func adjacency_list_provider, std::unordered_map& exploration_status, @@ -36,7 +36,7 @@ namespace vcpkg::Graphs ExplorationStatus& neighbour_status = exploration_status[neighbour]; if (neighbour_status == ExplorationStatus::NOT_EXPLORED) { - find_topological_sort_internal(neighbour, neighbour_status, adjacency_list_provider, exploration_status, sorted); + topological_sort_internal(neighbour, neighbour_status, adjacency_list_provider, exploration_status, sorted); } else if (neighbour_status == ExplorationStatus::PARTIALLY_EXPLORED) { @@ -70,7 +70,7 @@ namespace vcpkg::Graphs this->vertices[u].insert(v); } - std::vector find_topological_sort() const + std::vector topological_sort() const { std::unordered_map indegrees = count_indegrees(); @@ -88,7 +88,7 @@ namespace vcpkg::Graphs ExplorationStatus& status = exploration_status[vertex]; if (status == ExplorationStatus::NOT_EXPLORED) { - find_topological_sort_internal(vertex, + topological_sort_internal(vertex, status, [this](const V& v) { return this->vertices.at(v); }, exploration_status, -- cgit v1.2.3 From d7466d98bb192952a31255bee53c9d74192dedd6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 11 Apr 2017 14:44:14 -0700 Subject: Extract toposort into a free function --- toolsrc/include/vcpkg_Graphs.h | 72 +++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 29 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Graphs.h b/toolsrc/include/vcpkg_Graphs.h index b97f7ac50..1f90710fd 100644 --- a/toolsrc/include/vcpkg_Graphs.h +++ b/toolsrc/include/vcpkg_Graphs.h @@ -17,39 +17,55 @@ namespace vcpkg::Graphs FULLY_EXPLORED }; - template - class Graph + template + static void topological_sort_internal(V vertex, + ExplorationStatus& status, + const Func adjacency_list_provider, + std::unordered_map& exploration_status, + std::vector& sorted) { - template - static void topological_sort_internal(V vertex, - ExplorationStatus& status, - const Func adjacency_list_provider, - std::unordered_map& exploration_status, - std::vector& sorted) - { - status = ExplorationStatus::PARTIALLY_EXPLORED; + status = ExplorationStatus::PARTIALLY_EXPLORED; - auto neighbours = adjacency_list_provider(vertex); + auto neighbours = adjacency_list_provider(vertex); - for (V neighbour : neighbours) + for (V neighbour : neighbours) + { + ExplorationStatus& neighbour_status = exploration_status[neighbour]; + if (neighbour_status == ExplorationStatus::NOT_EXPLORED) { - ExplorationStatus& neighbour_status = exploration_status[neighbour]; - if (neighbour_status == ExplorationStatus::NOT_EXPLORED) - { - topological_sort_internal(neighbour, neighbour_status, adjacency_list_provider, exploration_status, sorted); - } - else if (neighbour_status == ExplorationStatus::PARTIALLY_EXPLORED) - { - throw std::runtime_error("cycle in graph"); - } + topological_sort_internal(neighbour, neighbour_status, adjacency_list_provider, exploration_status, sorted); } + else if (neighbour_status == ExplorationStatus::PARTIALLY_EXPLORED) + { + throw std::runtime_error("cycle in graph"); + } + } + status = ExplorationStatus::FULLY_EXPLORED; + sorted.push_back(vertex); + } - status = ExplorationStatus::FULLY_EXPLORED; - sorted.push_back(vertex); + template + std::vector topological_sort(const std::vector& starting_vertices, const Func adjacency_list_provider) + { + std::vector sorted; + std::unordered_map exploration_status; + + for (auto& vertex : starting_vertices) + { + ExplorationStatus& status = exploration_status[vertex]; + if (status == ExplorationStatus::NOT_EXPLORED) + { + topological_sort_internal(vertex, status, adjacency_list_provider, exploration_status, sorted); + } } - public: + return sorted; + } + template + class Graph + { + public: void add_vertex(V v) { this->vertices[v]; @@ -88,11 +104,9 @@ namespace vcpkg::Graphs ExplorationStatus& status = exploration_status[vertex]; if (status == ExplorationStatus::NOT_EXPLORED) { - topological_sort_internal(vertex, - status, - [this](const V& v) { return this->vertices.at(v); }, - exploration_status, - sorted); + topological_sort_internal(vertex, status, + [this](const V& v) { return this->vertices.at(v); }, + exploration_status, sorted); } } } -- cgit v1.2.3 From 24ba9f94ea346e3ce79441a4752a4f635d410088 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 11 Apr 2017 17:44:35 -0700 Subject: Parameter by const& --- toolsrc/include/vcpkg_Graphs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Graphs.h b/toolsrc/include/vcpkg_Graphs.h index 1f90710fd..3ba26c017 100644 --- a/toolsrc/include/vcpkg_Graphs.h +++ b/toolsrc/include/vcpkg_Graphs.h @@ -18,7 +18,7 @@ namespace vcpkg::Graphs }; template - static void topological_sort_internal(V vertex, + static void topological_sort_internal(const V& vertex, ExplorationStatus& status, const Func adjacency_list_provider, std::unordered_map& exploration_status, -- cgit v1.2.3 From 58f46ab6527b79fcef59cf828133aa9092cba3eb Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 11 Apr 2017 19:37:38 -0700 Subject: Rework toposort and create_install_plan --- toolsrc/include/vcpkg_Dependencies.h | 12 +++++ toolsrc/include/vcpkg_Graphs.h | 90 ++++++++++++++++++++++-------------- 2 files changed, 67 insertions(+), 35 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Dependencies.h b/toolsrc/include/vcpkg_Dependencies.h index 0e629ffef..36dd3cb2d 100644 --- a/toolsrc/include/vcpkg_Dependencies.h +++ b/toolsrc/include/vcpkg_Dependencies.h @@ -4,9 +4,20 @@ #include "StatusParagraphs.h" #include "VcpkgPaths.h" #include "vcpkg_optional.h" +#include "Paragraphs.h" namespace vcpkg::Dependencies { + struct AnyParagraph + { + std::vector edges() const; + + PackageSpec spec; + Optional status_paragraph; + Optional binary_paragraph; + Optional source_paragraph; + }; + enum class RequestType { UNKNOWN, @@ -27,6 +38,7 @@ namespace vcpkg::Dependencies struct InstallPlanAction { InstallPlanAction(); + explicit InstallPlanAction(const AnyParagraph& any_paragraph, const RequestType& request_type); InstallPlanAction(const InstallPlanType& plan_type, const RequestType& request_type, Optional binary_pgh, Optional source_pgh); InstallPlanAction(const InstallPlanAction&) = delete; InstallPlanAction(InstallPlanAction&&) = default; diff --git a/toolsrc/include/vcpkg_Graphs.h b/toolsrc/include/vcpkg_Graphs.h index 3ba26c017..8af2ad053 100644 --- a/toolsrc/include/vcpkg_Graphs.h +++ b/toolsrc/include/vcpkg_Graphs.h @@ -17,51 +17,76 @@ namespace vcpkg::Graphs FULLY_EXPLORED }; - template - static void topological_sort_internal(const V& vertex, - ExplorationStatus& status, - const Func adjacency_list_provider, - std::unordered_map& exploration_status, - std::vector& sorted) + template + __interface AdjacencyProvider { - status = ExplorationStatus::PARTIALLY_EXPLORED; + std::vector adjacency_list(const U& vertex) const; - auto neighbours = adjacency_list_provider(vertex); + U load_vertex_data(const V& vertex) const; + }; - for (V neighbour : neighbours) + template + static void topological_sort_internal(const V& vertex, + const AdjacencyProvider& f, + std::unordered_map& exploration_status, + std::vector& sorted) + { + ExplorationStatus& status = exploration_status[vertex]; + switch (status) { - ExplorationStatus& neighbour_status = exploration_status[neighbour]; - if (neighbour_status == ExplorationStatus::NOT_EXPLORED) - { - topological_sort_internal(neighbour, neighbour_status, adjacency_list_provider, exploration_status, sorted); - } - else if (neighbour_status == ExplorationStatus::PARTIALLY_EXPLORED) - { - throw std::runtime_error("cycle in graph"); - } + case ExplorationStatus::FULLY_EXPLORED: + return; + case ExplorationStatus::PARTIALLY_EXPLORED: + Checks::exit_with_message(VCPKG_LINE_INFO, "cycle in graph"); + case ExplorationStatus::NOT_EXPLORED: + { + status = ExplorationStatus::PARTIALLY_EXPLORED; + const U& vertex_data = f.load_vertex_data(vertex); + for (const V& neighbour : f.adjacency_list(vertex_data)) + topological_sort_internal(neighbour, f, exploration_status, sorted); + + sorted.push_back(std::move(vertex_data)); + status = ExplorationStatus::FULLY_EXPLORED; + return; + } + default: + Checks::unreachable(VCPKG_LINE_INFO); } - status = ExplorationStatus::FULLY_EXPLORED; - sorted.push_back(vertex); } - template - std::vector topological_sort(const std::vector& starting_vertices, const Func adjacency_list_provider) + template + std::vector topological_sort(const std::vector& starting_vertices, const AdjacencyProvider& f) { - std::vector sorted; + std::vector sorted; std::unordered_map exploration_status; for (auto& vertex : starting_vertices) { - ExplorationStatus& status = exploration_status[vertex]; - if (status == ExplorationStatus::NOT_EXPLORED) - { - topological_sort_internal(vertex, status, adjacency_list_provider, exploration_status, sorted); - } + topological_sort_internal(vertex, f, exploration_status, sorted); } 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 { @@ -88,6 +113,7 @@ namespace vcpkg::Graphs std::vector topological_sort() const { + GraphAdjacencyProvider adjacency_provider{ this->vertices }; std::unordered_map indegrees = count_indegrees(); std::vector sorted; @@ -101,13 +127,7 @@ namespace vcpkg::Graphs if (pair.second == 0) // Starting from vertices with indegree == 0. Not required. { V vertex = pair.first; - ExplorationStatus& status = exploration_status[vertex]; - if (status == ExplorationStatus::NOT_EXPLORED) - { - topological_sort_internal(vertex, status, - [this](const V& v) { return this->vertices.at(v); }, - exploration_status, sorted); - } + topological_sort_internal(vertex, adjacency_provider, exploration_status, sorted); } } -- cgit v1.2.3 From 6ef84f8a629d3a1578bedb7c02596e81a5e8714b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 12 Apr 2017 16:11:31 -0700 Subject: Add default constructor to Optional --- toolsrc/include/vcpkg_optional.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_optional.h b/toolsrc/include/vcpkg_optional.h index 4a2ceec30..28bdc81fa 100644 --- a/toolsrc/include/vcpkg_optional.h +++ b/toolsrc/include/vcpkg_optional.h @@ -15,6 +15,8 @@ namespace vcpkg class Optional { public: + constexpr Optional() : m_is_present(false), m_t() { } + // Constructors are intentionally implicit constexpr Optional(NullOpt) : m_is_present(false), m_t() { } -- cgit v1.2.3 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 From 5cd921c2b55340d2d300250537de5600b48a2b12 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 12 Apr 2017 18:57:45 -0700 Subject: edges() -> dependencies() --- toolsrc/include/vcpkg_Dependencies.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Dependencies.h b/toolsrc/include/vcpkg_Dependencies.h index 36dd3cb2d..47cbb6da3 100644 --- a/toolsrc/include/vcpkg_Dependencies.h +++ b/toolsrc/include/vcpkg_Dependencies.h @@ -4,13 +4,12 @@ #include "StatusParagraphs.h" #include "VcpkgPaths.h" #include "vcpkg_optional.h" -#include "Paragraphs.h" namespace vcpkg::Dependencies { struct AnyParagraph { - std::vector edges() const; + std::vector dependencies() const; PackageSpec spec; Optional status_paragraph; -- cgit v1.2.3 From 76f2c557ef915a13b37bc9a3ff0f9299373fe923 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 12 Apr 2017 19:29:43 -0700 Subject: Fix issue in the toposort algorithm and move-only types --- toolsrc/include/vcpkg_Graphs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Graphs.h b/toolsrc/include/vcpkg_Graphs.h index 1b9cbcb5a..97cd29236 100644 --- a/toolsrc/include/vcpkg_Graphs.h +++ b/toolsrc/include/vcpkg_Graphs.h @@ -40,7 +40,7 @@ namespace vcpkg::Graphs case ExplorationStatus::NOT_EXPLORED: { status = ExplorationStatus::PARTIALLY_EXPLORED; - const U& vertex_data = f.load_vertex_data(vertex); + U vertex_data = f.load_vertex_data(vertex); for (const V& neighbour : f.adjacency_list(vertex_data)) topological_sort_internal(neighbour, f, exploration_status, sorted); -- cgit v1.2.3 From 5131e955a809b421345506cd614c8578ab86fa71 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 12 Apr 2017 21:28:49 -0700 Subject: Simplify Install plan generation --- toolsrc/include/vcpkg_Dependencies.h | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Dependencies.h b/toolsrc/include/vcpkg_Dependencies.h index 47cbb6da3..155fb12e6 100644 --- a/toolsrc/include/vcpkg_Dependencies.h +++ b/toolsrc/include/vcpkg_Dependencies.h @@ -9,9 +9,8 @@ namespace vcpkg::Dependencies { struct AnyParagraph { - std::vector dependencies() const; + std::vector dependencies(const Triplet& triplet) const; - PackageSpec spec; Optional status_paragraph; Optional binary_paragraph; Optional source_paragraph; @@ -36,28 +35,19 @@ namespace vcpkg::Dependencies struct InstallPlanAction { + static bool compare_by_name(const InstallPlanAction* left, const InstallPlanAction* right); + InstallPlanAction(); - explicit InstallPlanAction(const AnyParagraph& any_paragraph, const RequestType& request_type); - InstallPlanAction(const InstallPlanType& plan_type, const RequestType& request_type, Optional binary_pgh, Optional source_pgh); + explicit InstallPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type); InstallPlanAction(const InstallPlanAction&) = delete; InstallPlanAction(InstallPlanAction&&) = default; InstallPlanAction& operator=(const InstallPlanAction&) = delete; InstallPlanAction& operator=(InstallPlanAction&&) = default; + PackageSpec spec; + AnyParagraph any_paragraph; InstallPlanType plan_type; RequestType request_type; - Optional binary_pgh; - Optional source_pgh; - }; - - struct PackageSpecWithInstallPlan - { - static bool compare_by_name(const PackageSpecWithInstallPlan* left, const PackageSpecWithInstallPlan* right); - - PackageSpecWithInstallPlan(const PackageSpec& spec, InstallPlanAction&& plan); - - PackageSpec spec; - InstallPlanAction plan; }; enum class RemovePlanType @@ -67,6 +57,12 @@ namespace vcpkg::Dependencies REMOVE }; + struct SpecAndRemovePlanType + { + PackageSpec spec; + RemovePlanType plan_type; + }; + struct RemovePlanAction { RemovePlanAction(); @@ -90,7 +86,7 @@ namespace vcpkg::Dependencies RemovePlanAction plan; }; - std::vector create_install_plan(const VcpkgPaths& paths, const std::vector& specs, const StatusParagraphs& status_db); + std::vector create_install_plan(const VcpkgPaths& paths, const std::vector& specs, const StatusParagraphs& status_db); std::vector create_remove_plan(const std::vector& specs, const StatusParagraphs& status_db); } -- cgit v1.2.3 From 2fa87fbb0aba1eba96994beb0c7b32d52f7f7161 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 12 Apr 2017 21:37:55 -0700 Subject: Simplify Remove plan generation --- toolsrc/include/vcpkg_Dependencies.h | 41 ++++++++++++------------------------ 1 file changed, 14 insertions(+), 27 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Dependencies.h b/toolsrc/include/vcpkg_Dependencies.h index 155fb12e6..f35250447 100644 --- a/toolsrc/include/vcpkg_Dependencies.h +++ b/toolsrc/include/vcpkg_Dependencies.h @@ -7,15 +7,6 @@ namespace vcpkg::Dependencies { - struct AnyParagraph - { - std::vector dependencies(const Triplet& triplet) const; - - Optional status_paragraph; - Optional binary_paragraph; - Optional source_paragraph; - }; - enum class RequestType { UNKNOWN, @@ -25,6 +16,15 @@ namespace vcpkg::Dependencies std::string to_output_string(RequestType request_type, const CStringView s); + struct AnyParagraph + { + std::vector dependencies(const Triplet& triplet) const; + + Optional status_paragraph; + Optional binary_paragraph; + Optional source_paragraph; + }; + enum class InstallPlanType { UNKNOWN, @@ -57,36 +57,23 @@ namespace vcpkg::Dependencies REMOVE }; - struct SpecAndRemovePlanType - { - PackageSpec spec; - RemovePlanType plan_type; - }; - struct RemovePlanAction { + static bool compare_by_name(const RemovePlanAction* left, const RemovePlanAction* right); + RemovePlanAction(); - RemovePlanAction(const RemovePlanType& plan_type, const RequestType& request_type); + RemovePlanAction(const PackageSpec& spec, const RemovePlanType& plan_type, const RequestType& request_type); RemovePlanAction(const RemovePlanAction&) = delete; RemovePlanAction(RemovePlanAction&&) = default; RemovePlanAction& operator=(const RemovePlanAction&) = delete; RemovePlanAction& operator=(RemovePlanAction&&) = default; + PackageSpec spec; RemovePlanType plan_type; RequestType request_type; }; - struct PackageSpecWithRemovePlan - { - static bool compare_by_name(const PackageSpecWithRemovePlan* left, const PackageSpecWithRemovePlan* right); - - PackageSpecWithRemovePlan(const PackageSpec& spec, RemovePlanAction&& plan); - - PackageSpec spec; - RemovePlanAction plan; - }; - std::vector create_install_plan(const VcpkgPaths& paths, const std::vector& specs, const StatusParagraphs& status_db); - std::vector create_remove_plan(const std::vector& specs, const StatusParagraphs& status_db); + std::vector create_remove_plan(const std::vector& specs, const StatusParagraphs& status_db); } -- cgit v1.2.3 From 8972bd3067f363c055e29ad66254b04513d1df65 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 12 Apr 2017 22:12:37 -0700 Subject: Introduce keep_if function --- toolsrc/include/vcpkg_Util.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Util.h b/toolsrc/include/vcpkg_Util.h index 4ebb2a802..fedf93c7a 100644 --- a/toolsrc/include/vcpkg_Util.h +++ b/toolsrc/include/vcpkg_Util.h @@ -21,4 +21,10 @@ namespace vcpkg::Util return ret; } + + template + void keep_if(Container& cont, Pred pred) + { + cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end()); + } } \ No newline at end of file -- cgit v1.2.3 From b578320d9c3f282ecc8d0ee0d8564a321a31796d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 12 Apr 2017 22:36:44 -0700 Subject: Add PackageSpec != operator --- toolsrc/include/PackageSpec.h | 1 + 1 file changed, 1 insertion(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/PackageSpec.h b/toolsrc/include/PackageSpec.h index 4c3b47365..0d69ac89c 100644 --- a/toolsrc/include/PackageSpec.h +++ b/toolsrc/include/PackageSpec.h @@ -25,6 +25,7 @@ namespace vcpkg }; bool operator==(const PackageSpec& left, const PackageSpec& right); + bool operator!=(const PackageSpec& left, const PackageSpec& right); } //namespace vcpkg namespace std -- cgit v1.2.3