adjust for comments by daniel-j-h

This commit is contained in:
Moritz Kobitzsch
2016-09-30 14:33:43 +02:00
parent 805d93912d
commit d1f1358e48
8 changed files with 180 additions and 162 deletions
+14 -11
View File
@@ -8,8 +8,8 @@
#include "util/guidance/turn_lanes.hpp"
#include "util/typedefs.hpp"
#include <vector>
#include <stack>
#include <vector>
namespace osrm
{
@@ -37,16 +37,19 @@ namespace engine
* original edge found.
*/
template <typename DataFacadeT, typename RandomIter, typename Callback>
inline void UnpackCHEdge(DataFacadeT *facade,
RandomIter packed_path_begin,
RandomIter packed_path_end,
const Callback &callback)
template <typename DataFacadeT, typename BidirectionalIterator, typename Callback>
inline void UnpackCHPath(const DataFacadeT &facade,
BidirectionalIterator packed_path_begin,
BidirectionalIterator packed_path_end,
Callback &&callback)
{
// make sure we have at least something to unpack
if( packed_path_begin == packed_path_end )
return;
using EdgeData = typename DataFacadeT::EdgeData;
std::stack<std::pair<NodeID, NodeID>> recursion_stack;
std::stack<std::pair<NodeID,NodeID>> recursion_stack;
// We have to push the path in reverse order onto the stack because it's LIFO.
for (auto current = std::prev(packed_path_end); current != packed_path_begin;
@@ -62,7 +65,7 @@ inline void UnpackCHEdge(DataFacadeT *facade,
recursion_stack.pop();
// Look for an edge on the forward CH graph (.forward)
EdgeID smaller_edge_id = facade->FindSmallestEdge(
EdgeID smaller_edge_id = facade.FindSmallestEdge(
edge.first, edge.second, [](const EdgeData &data) { return data.forward; });
// If we didn't find one there, the we might be looking at a part of the path that
@@ -70,7 +73,7 @@ inline void UnpackCHEdge(DataFacadeT *facade,
// and only consider edges with the `.backward` flag.
if (SPECIAL_EDGEID == smaller_edge_id)
{
smaller_edge_id = facade->FindSmallestEdge(
smaller_edge_id = facade.FindSmallestEdge(
edge.second, edge.first, [](const EdgeData &data) { return data.backward; });
}
@@ -78,7 +81,7 @@ inline void UnpackCHEdge(DataFacadeT *facade,
// called this function with bad values.
BOOST_ASSERT_MSG(smaller_edge_id != SPECIAL_EDGEID, "Invalid smaller edge ID");
const auto &data = facade->GetEdgeData(smaller_edge_id);
const auto &data = facade.GetEdgeData(smaller_edge_id);
BOOST_ASSERT_MSG(data.distance != std::numeric_limits<EdgeWeight>::max(),
"edge weight invalid");
@@ -94,7 +97,7 @@ inline void UnpackCHEdge(DataFacadeT *facade,
else
{
// We found an original edge, call our callback.
callback(edge, data);
std::forward<Callback>(callback)(edge, data);
}
}
}
@@ -229,8 +229,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
*std::prev(packed_path_end) == phantom_node_pair.target_phantom.forward_segment_id.id ||
*std::prev(packed_path_end) == phantom_node_pair.target_phantom.reverse_segment_id.id);
UnpackCHEdge(
facade,
UnpackCHPath(
*facade,
packed_path_begin,
packed_path_end,
[this,
@@ -238,17 +238,17 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
&phantom_node_pair,
&start_traversed_in_reverse,
&target_traversed_in_reverse](std::pair<NodeID, NodeID> & /* edge */,
const EdgeData &data) {
const EdgeData &edge_data) {
BOOST_ASSERT_MSG(!data.shortcut, "original edge flagged as shortcut");
unsigned name_index = facade->GetNameIndexFromEdgeID(data.id);
const auto turn_instruction = facade->GetTurnInstructionForEdgeID(data.id);
BOOST_ASSERT_MSG(!edge_data.shortcut, "original edge flagged as shortcut");
const auto name_index = facade->GetNameIndexFromEdgeID(edge_data.id);
const auto turn_instruction = facade->GetTurnInstructionForEdgeID(edge_data.id);
const extractor::TravelMode travel_mode =
(unpacked_path.empty() && start_traversed_in_reverse)
? phantom_node_pair.source_phantom.backward_travel_mode
: facade->GetTravelModeForEdgeID(data.id);
: facade->GetTravelModeForEdgeID(edge_data.id);
const auto geometry_index = facade->GetGeometryIndexForEdgeID(data.id);
const auto geometry_index = facade->GetGeometryIndexForEdgeID(edge_data.id);
std::vector<NodeID> id_vector;
facade->GetUncompressedGeometry(geometry_index, id_vector);
BOOST_ASSERT(id_vector.size() > 0);
@@ -260,7 +260,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
std::vector<DatasourceID> datasource_vector;
facade->GetUncompressedDatasources(geometry_index, datasource_vector);
auto total_weight = std::accumulate(weight_vector.begin(), weight_vector.end(), 0);
const auto total_weight = std::accumulate(weight_vector.begin(), weight_vector.end(), 0);
BOOST_ASSERT(weight_vector.size() == id_vector.size());
const bool is_first_segment = unpacked_path.empty();
@@ -289,12 +289,12 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
datasource_vector[i]});
}
BOOST_ASSERT(unpacked_path.size() > 0);
if (facade->hasLaneData(data.id))
unpacked_path.back().lane_data = facade->GetLaneData(data.id);
if (facade->hasLaneData(edge_data.id))
unpacked_path.back().lane_data = facade->GetLaneData(edge_data.id);
unpacked_path.back().entry_classid = facade->GetEntryClassID(data.id);
unpacked_path.back().entry_classid = facade->GetEntryClassID(edge_data.id);
unpacked_path.back().turn_instruction = turn_instruction;
unpacked_path.back().duration_until_turn += (data.distance - total_weight);
unpacked_path.back().duration_until_turn += (edge_data.distance - total_weight);
});
std::size_t start_index = 0, end_index = 0;
@@ -415,8 +415,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
void UnpackEdge(const NodeID from, const NodeID to, std::vector<NodeID> &unpacked_path) const
{
std::array<NodeID, 2> path{{from, to}};
UnpackCHEdge(
facade,
UnpackCHPath(
*facade,
path.begin(),
path.end(),
[&unpacked_path](const std::pair<NodeID, NodeID> &edge, const EdgeData & /* data */) {