diff --git a/CHANGELOG.md b/CHANGELOG.md index 22bebae0d..4b0eb65a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - NodeJS: - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - Misc: + - CHANGED: Use struct instead of tuple to define UnpackedPath. [#6974](https://github.com/Project-OSRM/osrm-backend/pull/6974) - CHANGED: Micro performance optimisation in map matching. [#6976](https://github.com/Project-OSRM/osrm-backend/pull/6976) - CHANGED: Re-use priority queue in StaticRTree. [#6952](https://github.com/Project-OSRM/osrm-backend/pull/6952) - CHANGED: Optimise encodePolyline function. [#6940](https://github.com/Project-OSRM/osrm-backend/pull/6940) diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index a02d4a095..aedbcf75a 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -487,7 +487,13 @@ void routingStep(const DataFacade &facade, using UnpackedNodes = std::vector; using UnpackedEdges = std::vector; -using UnpackedPath = std::tuple; + +struct UnpackedPath +{ + EdgeWeight weight; + UnpackedNodes nodes; + UnpackedEdges edges; +}; template std::optional> runSearch(const DataFacade &facade, @@ -551,7 +557,7 @@ UnpackedPath search(SearchEngineData &engine_working_data, facade, forward_heap, reverse_heap, force_step_nodes, weight_upper_bound, args...); if (!searchResult) { - return std::make_tuple(INVALID_EDGE_WEIGHT, std::vector(), std::vector()); + return {INVALID_EDGE_WEIGHT, std::vector(), std::vector()}; } auto [middle, weight] = *searchResult; @@ -595,25 +601,27 @@ UnpackedPath search(SearchEngineData &engine_working_data, forward_heap.Insert(source, {0}, {source}); reverse_heap.Insert(target, {0}, {target}); - auto [subpath_weight, subpath_nodes, subpath_edges] = search(engine_working_data, - facade, - forward_heap, - reverse_heap, - force_step_nodes, - INVALID_EDGE_WEIGHT, - sublevel, - parent_cell_id); - BOOST_ASSERT(!subpath_edges.empty()); - BOOST_ASSERT(subpath_nodes.size() > 1); - BOOST_ASSERT(subpath_nodes.front() == source); - BOOST_ASSERT(subpath_nodes.back() == target); - unpacked_nodes.insert( - unpacked_nodes.end(), std::next(subpath_nodes.begin()), subpath_nodes.end()); - unpacked_edges.insert(unpacked_edges.end(), subpath_edges.begin(), subpath_edges.end()); + auto unpacked_subpath = search(engine_working_data, + facade, + forward_heap, + reverse_heap, + force_step_nodes, + INVALID_EDGE_WEIGHT, + sublevel, + parent_cell_id); + BOOST_ASSERT(!unpacked_subpath.edges.empty()); + BOOST_ASSERT(unpacked_subpath.nodes.size() > 1); + BOOST_ASSERT(unpacked_subpath.nodes.front() == source); + BOOST_ASSERT(unpacked_subpath.nodes.back() == target); + unpacked_nodes.insert(unpacked_nodes.end(), + std::next(unpacked_subpath.nodes.begin()), + unpacked_subpath.nodes.end()); + unpacked_edges.insert( + unpacked_edges.end(), unpacked_subpath.edges.begin(), unpacked_subpath.edges.end()); } } - return std::make_tuple(weight, std::move(unpacked_nodes), std::move(unpacked_edges)); + return {weight, std::move(unpacked_nodes), std::move(unpacked_edges)}; } template @@ -654,13 +662,15 @@ inline void search(SearchEngineData &engine_working_data, const EdgeWeight weight_upper_bound = INVALID_EDGE_WEIGHT) { // TODO: change search calling interface to use unpacked_edges result - std::tie(weight, unpacked_nodes, std::ignore) = search(engine_working_data, - facade, - forward_heap, - reverse_heap, - force_step_nodes, - weight_upper_bound, - endpoints); + auto unpacked_path = search(engine_working_data, + facade, + forward_heap, + reverse_heap, + force_step_nodes, + weight_upper_bound, + endpoints); + weight = unpacked_path.weight; + unpacked_nodes = std::move(unpacked_path.nodes); } // TODO: refactor CH-related stub to use unpacked_edges diff --git a/src/engine/routing_algorithms/alternative_path_mld.cpp b/src/engine/routing_algorithms/alternative_path_mld.cpp index 27bd0a4d5..9c0a579f5 100644 --- a/src/engine/routing_algorithms/alternative_path_mld.cpp +++ b/src/engine/routing_algorithms/alternative_path_mld.cpp @@ -621,27 +621,24 @@ void unpackPackedPaths(InputIt first, BOOST_ASSERT(!facade.ExcludeNode(source)); BOOST_ASSERT(!facade.ExcludeNode(target)); - // TODO: when structured bindings will be allowed change to - // auto [subpath_weight, subpath_source, subpath_target, subpath] = ... - EdgeWeight subpath_weight; - std::vector subpath_nodes; - std::vector subpath_edges; - std::tie(subpath_weight, subpath_nodes, subpath_edges) = search(search_engine_data, - facade, - forward_heap, - reverse_heap, - {}, - INVALID_EDGE_WEIGHT, - sublevel, - parent_cell_id); - BOOST_ASSERT(!subpath_edges.empty()); - BOOST_ASSERT(subpath_nodes.size() > 1); - BOOST_ASSERT(subpath_nodes.front() == source); - BOOST_ASSERT(subpath_nodes.back() == target); - unpacked_nodes.insert( - unpacked_nodes.end(), std::next(subpath_nodes.begin()), subpath_nodes.end()); - unpacked_edges.insert( - unpacked_edges.end(), subpath_edges.begin(), subpath_edges.end()); + auto unpacked_subpath = search(search_engine_data, + facade, + forward_heap, + reverse_heap, + {}, + INVALID_EDGE_WEIGHT, + sublevel, + parent_cell_id); + BOOST_ASSERT(!unpacked_subpath.edges.empty()); + BOOST_ASSERT(unpacked_subpath.nodes.size() > 1); + BOOST_ASSERT(unpacked_subpath.nodes.front() == source); + BOOST_ASSERT(unpacked_subpath.nodes.back() == target); + unpacked_nodes.insert(unpacked_nodes.end(), + std::next(unpacked_subpath.nodes.begin()), + unpacked_subpath.nodes.end()); + unpacked_edges.insert(unpacked_edges.end(), + unpacked_subpath.edges.begin(), + unpacked_subpath.edges.end()); } } diff --git a/src/engine/routing_algorithms/direct_shortest_path.cpp b/src/engine/routing_algorithms/direct_shortest_path.cpp index 65e924cf5..397bdf6e6 100644 --- a/src/engine/routing_algorithms/direct_shortest_path.cpp +++ b/src/engine/routing_algorithms/direct_shortest_path.cpp @@ -70,20 +70,19 @@ InternalRouteResult directShortestPathSearch(SearchEngineData &e auto &reverse_heap = *engine_working_data.reverse_heap_1; insertNodesInHeaps(forward_heap, reverse_heap, endpoint_candidates); - // TODO: when structured bindings will be allowed change to - // auto [weight, source_node, target_node, unpacked_edges] = ... - EdgeWeight weight = INVALID_EDGE_WEIGHT; - std::vector unpacked_nodes; - std::vector unpacked_edges; - std::tie(weight, unpacked_nodes, unpacked_edges) = mld::search(engine_working_data, - facade, - forward_heap, - reverse_heap, - {}, - INVALID_EDGE_WEIGHT, - endpoint_candidates); + auto unpacked_path = mld::search(engine_working_data, + facade, + forward_heap, + reverse_heap, + {}, + INVALID_EDGE_WEIGHT, + endpoint_candidates); - return extractRoute(facade, weight, endpoint_candidates, unpacked_nodes, unpacked_edges); + return extractRoute(facade, + unpacked_path.weight, + endpoint_candidates, + unpacked_path.nodes, + unpacked_path.edges); } } // namespace osrm::engine::routing_algorithms