Skip to content

Commit bdc6ed8

Browse files
Use struct instead of tuple to define UnpackedPath (#6974)
1 parent 93c0e1d commit bdc6ed8

File tree

4 files changed

+66
-59
lines changed

4 files changed

+66
-59
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- NodeJS:
2525
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
2626
- Misc:
27+
- CHANGED: Use struct instead of tuple to define UnpackedPath. [#6974](https://github.com/Project-OSRM/osrm-backend/pull/6974)
2728
- CHANGED: Micro performance optimisation in map matching. [#6976](https://github.com/Project-OSRM/osrm-backend/pull/6976)
2829
- CHANGED: Re-use priority queue in StaticRTree. [#6952](https://github.com/Project-OSRM/osrm-backend/pull/6952)
2930
- CHANGED: Optimise encodePolyline function. [#6940](https://github.com/Project-OSRM/osrm-backend/pull/6940)

include/engine/routing_algorithms/routing_base_mld.hpp

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,13 @@ void routingStep(const DataFacade<Algorithm> &facade,
487487

488488
using UnpackedNodes = std::vector<NodeID>;
489489
using UnpackedEdges = std::vector<EdgeID>;
490-
using UnpackedPath = std::tuple<EdgeWeight, UnpackedNodes, UnpackedEdges>;
490+
491+
struct UnpackedPath
492+
{
493+
EdgeWeight weight;
494+
UnpackedNodes nodes;
495+
UnpackedEdges edges;
496+
};
491497

492498
template <typename Algorithm, typename Heap, typename... Args>
493499
std::optional<std::pair<NodeID, EdgeWeight>> runSearch(const DataFacade<Algorithm> &facade,
@@ -551,7 +557,7 @@ UnpackedPath search(SearchEngineData<Algorithm> &engine_working_data,
551557
facade, forward_heap, reverse_heap, force_step_nodes, weight_upper_bound, args...);
552558
if (!searchResult)
553559
{
554-
return std::make_tuple(INVALID_EDGE_WEIGHT, std::vector<NodeID>(), std::vector<EdgeID>());
560+
return {INVALID_EDGE_WEIGHT, std::vector<NodeID>(), std::vector<EdgeID>()};
555561
}
556562

557563
auto [middle, weight] = *searchResult;
@@ -595,25 +601,27 @@ UnpackedPath search(SearchEngineData<Algorithm> &engine_working_data,
595601
forward_heap.Insert(source, {0}, {source});
596602
reverse_heap.Insert(target, {0}, {target});
597603

598-
auto [subpath_weight, subpath_nodes, subpath_edges] = search(engine_working_data,
599-
facade,
600-
forward_heap,
601-
reverse_heap,
602-
force_step_nodes,
603-
INVALID_EDGE_WEIGHT,
604-
sublevel,
605-
parent_cell_id);
606-
BOOST_ASSERT(!subpath_edges.empty());
607-
BOOST_ASSERT(subpath_nodes.size() > 1);
608-
BOOST_ASSERT(subpath_nodes.front() == source);
609-
BOOST_ASSERT(subpath_nodes.back() == target);
610-
unpacked_nodes.insert(
611-
unpacked_nodes.end(), std::next(subpath_nodes.begin()), subpath_nodes.end());
612-
unpacked_edges.insert(unpacked_edges.end(), subpath_edges.begin(), subpath_edges.end());
604+
auto unpacked_subpath = search(engine_working_data,
605+
facade,
606+
forward_heap,
607+
reverse_heap,
608+
force_step_nodes,
609+
INVALID_EDGE_WEIGHT,
610+
sublevel,
611+
parent_cell_id);
612+
BOOST_ASSERT(!unpacked_subpath.edges.empty());
613+
BOOST_ASSERT(unpacked_subpath.nodes.size() > 1);
614+
BOOST_ASSERT(unpacked_subpath.nodes.front() == source);
615+
BOOST_ASSERT(unpacked_subpath.nodes.back() == target);
616+
unpacked_nodes.insert(unpacked_nodes.end(),
617+
std::next(unpacked_subpath.nodes.begin()),
618+
unpacked_subpath.nodes.end());
619+
unpacked_edges.insert(
620+
unpacked_edges.end(), unpacked_subpath.edges.begin(), unpacked_subpath.edges.end());
613621
}
614622
}
615623

616-
return std::make_tuple(weight, std::move(unpacked_nodes), std::move(unpacked_edges));
624+
return {weight, std::move(unpacked_nodes), std::move(unpacked_edges)};
617625
}
618626

619627
template <typename Algorithm, typename... Args>
@@ -654,13 +662,15 @@ inline void search(SearchEngineData<Algorithm> &engine_working_data,
654662
const EdgeWeight weight_upper_bound = INVALID_EDGE_WEIGHT)
655663
{
656664
// TODO: change search calling interface to use unpacked_edges result
657-
std::tie(weight, unpacked_nodes, std::ignore) = search(engine_working_data,
658-
facade,
659-
forward_heap,
660-
reverse_heap,
661-
force_step_nodes,
662-
weight_upper_bound,
663-
endpoints);
665+
auto unpacked_path = search(engine_working_data,
666+
facade,
667+
forward_heap,
668+
reverse_heap,
669+
force_step_nodes,
670+
weight_upper_bound,
671+
endpoints);
672+
weight = unpacked_path.weight;
673+
unpacked_nodes = std::move(unpacked_path.nodes);
664674
}
665675

666676
// TODO: refactor CH-related stub to use unpacked_edges

src/engine/routing_algorithms/alternative_path_mld.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -621,27 +621,24 @@ void unpackPackedPaths(InputIt first,
621621
BOOST_ASSERT(!facade.ExcludeNode(source));
622622
BOOST_ASSERT(!facade.ExcludeNode(target));
623623

624-
// TODO: when structured bindings will be allowed change to
625-
// auto [subpath_weight, subpath_source, subpath_target, subpath] = ...
626-
EdgeWeight subpath_weight;
627-
std::vector<NodeID> subpath_nodes;
628-
std::vector<EdgeID> subpath_edges;
629-
std::tie(subpath_weight, subpath_nodes, subpath_edges) = search(search_engine_data,
630-
facade,
631-
forward_heap,
632-
reverse_heap,
633-
{},
634-
INVALID_EDGE_WEIGHT,
635-
sublevel,
636-
parent_cell_id);
637-
BOOST_ASSERT(!subpath_edges.empty());
638-
BOOST_ASSERT(subpath_nodes.size() > 1);
639-
BOOST_ASSERT(subpath_nodes.front() == source);
640-
BOOST_ASSERT(subpath_nodes.back() == target);
641-
unpacked_nodes.insert(
642-
unpacked_nodes.end(), std::next(subpath_nodes.begin()), subpath_nodes.end());
643-
unpacked_edges.insert(
644-
unpacked_edges.end(), subpath_edges.begin(), subpath_edges.end());
624+
auto unpacked_subpath = search(search_engine_data,
625+
facade,
626+
forward_heap,
627+
reverse_heap,
628+
{},
629+
INVALID_EDGE_WEIGHT,
630+
sublevel,
631+
parent_cell_id);
632+
BOOST_ASSERT(!unpacked_subpath.edges.empty());
633+
BOOST_ASSERT(unpacked_subpath.nodes.size() > 1);
634+
BOOST_ASSERT(unpacked_subpath.nodes.front() == source);
635+
BOOST_ASSERT(unpacked_subpath.nodes.back() == target);
636+
unpacked_nodes.insert(unpacked_nodes.end(),
637+
std::next(unpacked_subpath.nodes.begin()),
638+
unpacked_subpath.nodes.end());
639+
unpacked_edges.insert(unpacked_edges.end(),
640+
unpacked_subpath.edges.begin(),
641+
unpacked_subpath.edges.end());
645642
}
646643
}
647644

src/engine/routing_algorithms/direct_shortest_path.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,19 @@ InternalRouteResult directShortestPathSearch(SearchEngineData<mld::Algorithm> &e
7070
auto &reverse_heap = *engine_working_data.reverse_heap_1;
7171
insertNodesInHeaps(forward_heap, reverse_heap, endpoint_candidates);
7272

73-
// TODO: when structured bindings will be allowed change to
74-
// auto [weight, source_node, target_node, unpacked_edges] = ...
75-
EdgeWeight weight = INVALID_EDGE_WEIGHT;
76-
std::vector<NodeID> unpacked_nodes;
77-
std::vector<EdgeID> unpacked_edges;
78-
std::tie(weight, unpacked_nodes, unpacked_edges) = mld::search(engine_working_data,
79-
facade,
80-
forward_heap,
81-
reverse_heap,
82-
{},
83-
INVALID_EDGE_WEIGHT,
84-
endpoint_candidates);
73+
auto unpacked_path = mld::search(engine_working_data,
74+
facade,
75+
forward_heap,
76+
reverse_heap,
77+
{},
78+
INVALID_EDGE_WEIGHT,
79+
endpoint_candidates);
8580

86-
return extractRoute(facade, weight, endpoint_candidates, unpacked_nodes, unpacked_edges);
81+
return extractRoute(facade,
82+
unpacked_path.weight,
83+
endpoint_candidates,
84+
unpacked_path.nodes,
85+
unpacked_path.edges);
8786
}
8887

8988
} // namespace osrm::engine::routing_algorithms

0 commit comments

Comments
 (0)