From b8b58f6c434633637f92232c0e83f138dbf51b29 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Thu, 16 Mar 2017 07:52:17 +0100 Subject: [PATCH] Avoid dynamic binding in getNodeQureyLevel --- .../routing_algorithms/routing_base_mld.hpp | 46 ++++++++++++++----- .../direct_shortest_path.cpp | 25 +--------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index dd90617d664..807d2a9c351 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -21,17 +21,38 @@ namespace mld namespace { -// Unrestricted search (Args is std::function): -// * use `query_level` closure of partition.GetQueryLevel to find the query level +// Unrestricted search (Args is const PhantomNodes &): +// * use partition.GetQueryLevel to find the node query level based on source and target phantoms // * allow to traverse all cells -using QueryLevelFunction = std::function; -LevelID getNodeQureyLevel(NodeID node, const QueryLevelFunction &functor) { return functor(node); } -bool checkParentCellRestriction(CellID, const QueryLevelFunction &) { return true; } +LevelID getNodeQureyLevel(const partition::MultiLevelPartitionView &partition, + NodeID node, + const PhantomNodes &phantom_nodes) +{ + auto level = [&partition, node](const SegmentID &source, const SegmentID &target) { + if (source.enabled && target.enabled) + return partition.GetQueryLevel(source.id, target.id, node); + return INVALID_LEVEL_ID; + }; + return std::min(std::min(level(phantom_nodes.source_phantom.forward_segment_id, + phantom_nodes.target_phantom.forward_segment_id), + level(phantom_nodes.source_phantom.forward_segment_id, + phantom_nodes.target_phantom.reverse_segment_id)), + std::min(level(phantom_nodes.source_phantom.reverse_segment_id, + phantom_nodes.target_phantom.forward_segment_id), + level(phantom_nodes.source_phantom.reverse_segment_id, + phantom_nodes.target_phantom.reverse_segment_id))); +} + +bool checkParentCellRestriction(CellID, const PhantomNodes &) { return true; } // Restricted search (Args is LevelID, CellID): // * use the fixed level for queries // * check if the node cell is the same as the specified parent onr -LevelID getNodeQureyLevel(NodeID, LevelID level, CellID) { return level; } +LevelID getNodeQureyLevel(const partition::MultiLevelPartitionView &, NodeID, LevelID level, CellID) +{ + return level; +} + bool checkParentCellRestriction(CellID cell, LevelID, CellID parent) { return cell == parent; } } @@ -65,7 +86,7 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade= 1) && // only if at least the first level and @@ -155,10 +176,11 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade -auto search(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::MultiLayerDijkstraHeap &forward_heap, - SearchEngineData::MultiLayerDijkstraHeap &reverse_heap, - Args... args) +std::tuple> +search(const datafacade::ContiguousInternalMemoryDataFacade &facade, + SearchEngineData::MultiLayerDijkstraHeap &forward_heap, + SearchEngineData::MultiLayerDijkstraHeap &reverse_heap, + Args... args) { const auto &partition = facade.GetMultiLevelPartition(); @@ -234,7 +256,7 @@ auto search(const datafacade::ContiguousInternalMemoryDataFacade } else { // an overlay graph edge - LevelID level = getNodeQureyLevel(source, args...); + LevelID level = getNodeQureyLevel(partition, source, args...); CellID parent_cell_id = partition.GetCell(level, source); BOOST_ASSERT(parent_cell_id == partition.GetCell(level, target)); diff --git a/src/engine/routing_algorithms/direct_shortest_path.cpp b/src/engine/routing_algorithms/direct_shortest_path.cpp index 284d9277852..a7af4a16c80 100644 --- a/src/engine/routing_algorithms/direct_shortest_path.cpp +++ b/src/engine/routing_algorithms/direct_shortest_path.cpp @@ -138,36 +138,13 @@ InternalRouteResult directShortestPathSearch( reverse_heap.Clear(); insertNodesInHeaps(forward_heap, reverse_heap, phantom_nodes); - const auto &partition = facade.GetMultiLevelPartition(); - - auto get_query_level = [&partition, &phantom_nodes](const NodeID node) -> LevelID { - auto level = - [&partition](const SegmentID &source, const SegmentID &target, const NodeID node) { - if (source.enabled && target.enabled) - return partition.GetQueryLevel(source.id, target.id, node); - return INVALID_LEVEL_ID; - }; - return std::min(std::min(level(phantom_nodes.source_phantom.forward_segment_id, - phantom_nodes.target_phantom.forward_segment_id, - node), - level(phantom_nodes.source_phantom.forward_segment_id, - phantom_nodes.target_phantom.reverse_segment_id, - node)), - std::min(level(phantom_nodes.source_phantom.reverse_segment_id, - phantom_nodes.target_phantom.forward_segment_id, - node), - level(phantom_nodes.source_phantom.reverse_segment_id, - phantom_nodes.target_phantom.reverse_segment_id, - node))); - }; - // TODO: when structured bindings will be allowed change to // auto [weight, source_node, target_node, unpacked_edges] = ... EdgeWeight weight; NodeID source_node, target_node; std::vector unpacked_edges; std::tie(weight, source_node, target_node, unpacked_edges) = - mld::search(facade, forward_heap, reverse_heap, get_query_level); + mld::search(facade, forward_heap, reverse_heap, phantom_nodes); return extractRoute(facade, weight, source_node, target_node, unpacked_edges, phantom_nodes); }