From 404c27510174ae7ff988f4cdfa6a7572fb51c50e Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Thu, 12 Oct 2017 00:15:27 +0000 Subject: [PATCH] Add a specilization for contraction without exclude flags This saves about 10% overhead and avoids contraction changes to previous releases. --- .../contractor/contract_excludable_graph.hpp | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/include/contractor/contract_excludable_graph.hpp b/include/contractor/contract_excludable_graph.hpp index a4a49285b..775b65faa 100644 --- a/include/contractor/contract_excludable_graph.hpp +++ b/include/contractor/contract_excludable_graph.hpp @@ -12,12 +12,32 @@ namespace osrm namespace contractor { -using GraphFilterAndCore = std::tuple>>; +using GraphAndFilter = std::tuple>>; + +inline auto contractFullGraph(ContractorGraph contractor_graph, + std::vector node_weights) +{ + auto num_nodes = contractor_graph.GetNumberOfNodes(); + contractGraph(contractor_graph, node_weights); + + auto edges = toEdges(std::move(contractor_graph)); + std::vector edge_filter(edges.size(), true); + + return GraphAndFilter{QueryGraph{num_nodes, std::move(edges)}, {std::move(edge_filter)}}; +} inline auto contractExcludableGraph(ContractorGraph contractor_graph_, std::vector node_weights, const std::vector> &filters) { + if (filters.size() == 1) + { + if (std::all_of(filters.front().begin(), filters.front().end(), [](auto v) { return v; })) + { + return contractFullGraph(std::move(contractor_graph_), std::move(node_weights)); + } + } + auto num_nodes = contractor_graph_.GetNumberOfNodes(); ContractedEdgeContainer edge_container; ContractorGraph shared_core_graph; @@ -64,8 +84,8 @@ inline auto contractExcludableGraph(ContractorGraph contractor_graph_, edge_container.Merge(toEdges(std::move(filtered_core_graph))); } - return GraphFilterAndCore{QueryGraph{num_nodes, std::move(edge_container.edges)}, - edge_container.MakeEdgeFilters()}; + return GraphAndFilter{QueryGraph{num_nodes, std::move(edge_container.edges)}, + edge_container.MakeEdgeFilters()}; } } }