Use ranges in datafacade instead of vectors

Range type must use immutable references due to a
regression in `boost::any_range`.
References:
https://svn.boost.org/trac10/ticket/10493
https://stackoverflow.com/questions/42427395/boostany-range-with-optimization-level-o2-causes-crash/42427662
This commit is contained in:
Kajari Ghosh 2018-03-19 19:41:02 +01:00 committed by Patrick Niklaus
parent 282415bbc1
commit be123cd72f
14 changed files with 293 additions and 256 deletions

View File

@ -31,6 +31,7 @@
- ADDED: Add documentation about OSM node ids in nearest service response [#4436](https://github.com/Project-OSRM/osrm-backend/pull/4436) - ADDED: Add documentation about OSM node ids in nearest service response [#4436](https://github.com/Project-OSRM/osrm-backend/pull/4436)
- Performance - Performance
- FIXED: Speed up response time when lots of legs exist and geojson is used with `steps=true` [#4936](https://github.com/Project-OSRM/osrm-backend/pull/4936) - FIXED: Speed up response time when lots of legs exist and geojson is used with `steps=true` [#4936](https://github.com/Project-OSRM/osrm-backend/pull/4936)
- FIXED: Return iterators instead of vectors in datafacade_base functions [#4969](https://github.com/Project-OSRM/osrm-backend/issues/4969)
- Misc: - Misc:
- ADDED: expose name for datasource annotations as metadata [#4973](https://github.com/Project-OSRM/osrm-backend/pull/4973) - ADDED: expose name for datasource annotations as metadata [#4973](https://github.com/Project-OSRM/osrm-backend/pull/4973)

View File

@ -34,56 +34,55 @@ class NearestAPI final : public BaseAPI
util::json::Array waypoints; util::json::Array waypoints;
waypoints.values.resize(phantom_nodes.front().size()); waypoints.values.resize(phantom_nodes.front().size());
std::transform(phantom_nodes.front().begin(), std::transform(
phantom_nodes.front().end(), phantom_nodes.front().begin(),
waypoints.values.begin(), phantom_nodes.front().end(),
[this](const PhantomNodeWithDistance &phantom_with_distance) { waypoints.values.begin(),
auto &phantom_node = phantom_with_distance.phantom_node; [this](const PhantomNodeWithDistance &phantom_with_distance) {
auto waypoint = MakeWaypoint(phantom_node); auto &phantom_node = phantom_with_distance.phantom_node;
waypoint.values["distance"] = phantom_with_distance.distance; auto waypoint = MakeWaypoint(phantom_node);
waypoint.values["distance"] = phantom_with_distance.distance;
util::json::Array nodes; util::json::Array nodes;
std::uint64_t from_node = 0; std::uint64_t from_node = 0;
std::uint64_t to_node = 0; std::uint64_t to_node = 0;
std::vector<NodeID> forward_geometry; datafacade::BaseDataFacade::NodesIDRangeT forward_geometry;
if (phantom_node.forward_segment_id.enabled) if (phantom_node.forward_segment_id.enabled)
{ {
auto segment_id = phantom_node.forward_segment_id.id; auto segment_id = phantom_node.forward_segment_id.id;
const auto geometry_id = facade.GetGeometryIndex(segment_id).id; const auto geometry_id = facade.GetGeometryIndex(segment_id).id;
forward_geometry = forward_geometry = facade.GetUncompressedForwardGeometry(geometry_id);
facade.GetUncompressedForwardGeometry(geometry_id);
auto osm_node_id = facade.GetOSMNodeIDOfNode( auto osm_node_id = facade.GetOSMNodeIDOfNode(
forward_geometry[phantom_node.fwd_segment_position]); forward_geometry[phantom_node.fwd_segment_position]);
to_node = static_cast<std::uint64_t>(osm_node_id); to_node = static_cast<std::uint64_t>(osm_node_id);
} }
if (phantom_node.reverse_segment_id.enabled) if (phantom_node.reverse_segment_id.enabled)
{ {
auto segment_id = phantom_node.reverse_segment_id.id; auto segment_id = phantom_node.reverse_segment_id.id;
const auto geometry_id = facade.GetGeometryIndex(segment_id).id; const auto geometry_id = facade.GetGeometryIndex(segment_id).id;
std::vector<NodeID> geometry = const auto geometry = facade.GetUncompressedForwardGeometry(geometry_id);
facade.GetUncompressedForwardGeometry(geometry_id); auto osm_node_id =
auto osm_node_id = facade.GetOSMNodeIDOfNode( facade.GetOSMNodeIDOfNode(geometry[phantom_node.fwd_segment_position + 1]);
geometry[phantom_node.fwd_segment_position + 1]); from_node = static_cast<std::uint64_t>(osm_node_id);
from_node = static_cast<std::uint64_t>(osm_node_id); }
} else if (phantom_node.forward_segment_id.enabled &&
else if (phantom_node.forward_segment_id.enabled && phantom_node.fwd_segment_position > 0)
phantom_node.fwd_segment_position > 0) {
{ // In the case of one way, rely on forward segment only
// In the case of one way, rely on forward segment only auto osm_node_id = facade.GetOSMNodeIDOfNode(
auto osm_node_id = facade.GetOSMNodeIDOfNode( forward_geometry[phantom_node.fwd_segment_position - 1]);
forward_geometry[phantom_node.fwd_segment_position - 1]); from_node = static_cast<std::uint64_t>(osm_node_id);
from_node = static_cast<std::uint64_t>(osm_node_id); }
} nodes.values.push_back(from_node);
nodes.values.push_back(from_node); nodes.values.push_back(to_node);
nodes.values.push_back(to_node); waypoint.values["nodes"] = std::move(nodes);
waypoint.values["nodes"] = std::move(nodes);
return waypoint; return waypoint;
}); });
response.values["code"] = "Ok"; response.values["code"] = "Ok";
response.values["waypoints"] = std::move(waypoints); response.values["waypoints"] = std::move(waypoints);

View File

@ -239,72 +239,57 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
return m_osmnodeid_list[id]; return m_osmnodeid_list[id];
} }
std::vector<NodeID> GetUncompressedForwardGeometry(const EdgeID id) const override final NodesIDRangeT GetUncompressedForwardGeometry(const EdgeID id) const override final
{ {
return segment_data.GetForwardGeometry(id);
auto range = segment_data.GetForwardGeometry(id);
return std::vector<NodeID>{range.begin(), range.end()};
} }
virtual std::vector<NodeID> GetUncompressedReverseGeometry(const EdgeID id) const override final NodesIDRangeT GetUncompressedReverseGeometry(const EdgeID id) const override final
{ {
auto range = segment_data.GetReverseGeometry(id); return segment_data.GetReverseGeometry(id);
return std::vector<NodeID>{range.begin(), range.end()};
} }
virtual std::vector<EdgeWeight> DurationsRangeT GetUncompressedForwardDurations(const EdgeID id) const override final
GetUncompressedForwardDurations(const EdgeID id) const override final
{ {
auto range = segment_data.GetForwardDurations(id); return segment_data.GetForwardDurations(id);
return std::vector<EdgeWeight>{range.begin(), range.end()};
} }
virtual std::vector<EdgeWeight> DurationsRangeT GetUncompressedReverseDurations(const EdgeID id) const override final
GetUncompressedReverseDurations(const EdgeID id) const override final
{ {
auto range = segment_data.GetReverseDurations(id); return segment_data.GetReverseDurations(id);
return std::vector<EdgeWeight>{range.begin(), range.end()};
} }
virtual std::vector<EdgeWeight> WeightsRangeT GetUncompressedForwardWeights(const EdgeID id) const override final
GetUncompressedForwardWeights(const EdgeID id) const override final
{ {
auto range = segment_data.GetForwardWeights(id); return segment_data.GetForwardWeights(id);
return std::vector<EdgeWeight>{range.begin(), range.end()};
} }
virtual std::vector<EdgeWeight> WeightsRangeT GetUncompressedReverseWeights(const EdgeID id) const override final
GetUncompressedReverseWeights(const EdgeID id) const override final
{ {
auto range = segment_data.GetReverseWeights(id); return segment_data.GetReverseWeights(id);
return std::vector<EdgeWeight>{range.begin(), range.end()};
} }
// Returns the data source ids that were used to supply the edge // Returns the data source ids that were used to supply the edge
// weights. // weights.
virtual std::vector<DatasourceID> DatasourceIDRangeT GetUncompressedForwardDatasources(const EdgeID id) const override final
GetUncompressedForwardDatasources(const EdgeID id) const override final
{ {
auto range = segment_data.GetForwardDatasources(id); return segment_data.GetForwardDatasources(id);
return std::vector<DatasourceID>{range.begin(), range.end()};
} }
// Returns the data source ids that were used to supply the edge // Returns the data source ids that were used to supply the edge
// weights. // weights.
virtual std::vector<DatasourceID> DatasourceIDRangeT GetUncompressedReverseDatasources(const EdgeID id) const override final
GetUncompressedReverseDatasources(const EdgeID id) const override final
{ {
auto range = segment_data.GetReverseDatasources(id); return segment_data.GetReverseDatasources(id);
return std::vector<DatasourceID>{range.begin(), range.end()};
} }
virtual TurnPenalty GetWeightPenaltyForEdgeID(const unsigned id) const override final TurnPenalty GetWeightPenaltyForEdgeID(const unsigned id) const override final
{ {
BOOST_ASSERT(m_turn_weight_penalties.size() > id); BOOST_ASSERT(m_turn_weight_penalties.size() > id);
return m_turn_weight_penalties[id]; return m_turn_weight_penalties[id];
} }
virtual TurnPenalty GetDurationPenaltyForEdgeID(const unsigned id) const override final TurnPenalty GetDurationPenaltyForEdgeID(const unsigned id) const override final
{ {
BOOST_ASSERT(m_turn_duration_penalties.size() > id); BOOST_ASSERT(m_turn_duration_penalties.size() > id);
return m_turn_duration_penalties[id]; return m_turn_duration_penalties[id];

View File

@ -10,9 +10,7 @@
#include "extractor/class_data.hpp" #include "extractor/class_data.hpp"
#include "extractor/edge_based_node_segment.hpp" #include "extractor/edge_based_node_segment.hpp"
//#include "extractor/guidance/turn_lane_types.hpp"
#include "extractor/maneuver_override.hpp" #include "extractor/maneuver_override.hpp"
//#include "extractor/original_edge_data.hpp"
#include "extractor/query_node.hpp" #include "extractor/query_node.hpp"
#include "extractor/travel_mode.hpp" #include "extractor/travel_mode.hpp"
#include "extractor/turn_lane_types.hpp" #include "extractor/turn_lane_types.hpp"
@ -31,6 +29,8 @@
#include "osrm/coordinate.hpp" #include "osrm/coordinate.hpp"
#include <boost/range/any_range.hpp>
#include <cstddef> #include <cstddef>
#include <string> #include <string>
@ -50,6 +50,14 @@ class BaseDataFacade
{ {
public: public:
using RTreeLeaf = extractor::EdgeBasedNodeSegment; using RTreeLeaf = extractor::EdgeBasedNodeSegment;
template <typename T>
using RangeT = boost::any_range<T, boost::random_access_traversal_tag, const T, std::ptrdiff_t>;
using NodesIDRangeT = RangeT<NodeID>;
using WeightsRangeT = RangeT<SegmentWeight>;
using DurationsRangeT = RangeT<SegmentDuration>;
using DatasourceIDRangeT = RangeT<DatasourceID>;
BaseDataFacade() {} BaseDataFacade() {}
virtual ~BaseDataFacade() {} virtual ~BaseDataFacade() {}
@ -64,9 +72,8 @@ class BaseDataFacade
virtual ComponentID GetComponentID(const NodeID id) const = 0; virtual ComponentID GetComponentID(const NodeID id) const = 0;
virtual std::vector<NodeID> GetUncompressedForwardGeometry(const EdgeID id) const = 0; virtual NodesIDRangeT GetUncompressedForwardGeometry(const EdgeID id) const = 0;
virtual NodesIDRangeT GetUncompressedReverseGeometry(const EdgeID id) const = 0;
virtual std::vector<NodeID> GetUncompressedReverseGeometry(const EdgeID id) const = 0;
virtual TurnPenalty GetWeightPenaltyForEdgeID(const unsigned id) const = 0; virtual TurnPenalty GetWeightPenaltyForEdgeID(const unsigned id) const = 0;
@ -74,18 +81,18 @@ class BaseDataFacade
// Gets the weight values for each segment in an uncompressed geometry. // Gets the weight values for each segment in an uncompressed geometry.
// Should always be 1 shorter than GetUncompressedGeometry // Should always be 1 shorter than GetUncompressedGeometry
virtual std::vector<EdgeWeight> GetUncompressedForwardWeights(const EdgeID id) const = 0; virtual WeightsRangeT GetUncompressedForwardWeights(const EdgeID id) const = 0;
virtual std::vector<EdgeWeight> GetUncompressedReverseWeights(const EdgeID id) const = 0; virtual WeightsRangeT GetUncompressedReverseWeights(const EdgeID id) const = 0;
// Gets the duration values for each segment in an uncompressed geometry. // Gets the duration values for each segment in an uncompressed geometry.
// Should always be 1 shorter than GetUncompressedGeometry // Should always be 1 shorter than GetUncompressedGeometry
virtual std::vector<EdgeWeight> GetUncompressedForwardDurations(const EdgeID id) const = 0; virtual DurationsRangeT GetUncompressedForwardDurations(const EdgeID id) const = 0;
virtual std::vector<EdgeWeight> GetUncompressedReverseDurations(const EdgeID id) const = 0; virtual DurationsRangeT GetUncompressedReverseDurations(const EdgeID id) const = 0;
// Returns the data source ids that were used to supply the edge // Returns the data source ids that were used to supply the edge
// weights. Will return an empty array when only the base profile is used. // weights. Will return an empty array when only the base profile is used.
virtual std::vector<DatasourceID> GetUncompressedForwardDatasources(const EdgeID id) const = 0; virtual DatasourceIDRangeT GetUncompressedForwardDatasources(const EdgeID id) const = 0;
virtual std::vector<DatasourceID> GetUncompressedReverseDatasources(const EdgeID id) const = 0; virtual DatasourceIDRangeT GetUncompressedReverseDatasources(const EdgeID id) const = 0;
// Gets the name of a datasource // Gets the name of a datasource
virtual StringView GetDatasourceName(const DatasourceID id) const = 0; virtual StringView GetDatasourceName(const DatasourceID id) const = 0;

View File

@ -434,11 +434,6 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Find the node-based-edge that this belongs to, and directly // Find the node-based-edge that this belongs to, and directly
// calculate the forward_weight, forward_offset, reverse_weight, reverse_offset // calculate the forward_weight, forward_offset, reverse_weight, reverse_offset
EdgeWeight forward_weight_offset = 0, forward_weight = 0;
EdgeWeight reverse_weight_offset = 0, reverse_weight = 0;
EdgeDuration forward_duration_offset = 0, forward_duration = 0;
EdgeDuration reverse_duration_offset = 0, reverse_duration = 0;
BOOST_ASSERT(data.forward_segment_id.enabled || data.reverse_segment_id.enabled); BOOST_ASSERT(data.forward_segment_id.enabled || data.reverse_segment_id.enabled);
BOOST_ASSERT(!data.reverse_segment_id.enabled || BOOST_ASSERT(!data.reverse_segment_id.enabled ||
datafacade.GetGeometryIndex(data.forward_segment_id.id).id == datafacade.GetGeometryIndex(data.forward_segment_id.id).id ==
@ -446,35 +441,42 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
const auto geometry_id = datafacade.GetGeometryIndex(data.forward_segment_id.id).id; const auto geometry_id = datafacade.GetGeometryIndex(data.forward_segment_id.id).id;
const auto component_id = datafacade.GetComponentID(data.forward_segment_id.id); const auto component_id = datafacade.GetComponentID(data.forward_segment_id.id);
const std::vector<EdgeWeight> forward_weight_vector = const auto forward_weights = datafacade.GetUncompressedForwardWeights(geometry_id);
datafacade.GetUncompressedForwardWeights(geometry_id); const auto reverse_weights = datafacade.GetUncompressedReverseWeights(geometry_id);
const std::vector<EdgeWeight> reverse_weight_vector =
datafacade.GetUncompressedReverseWeights(geometry_id);
const std::vector<EdgeWeight> forward_duration_vector =
datafacade.GetUncompressedForwardDurations(geometry_id);
const std::vector<EdgeWeight> reverse_duration_vector =
datafacade.GetUncompressedReverseDurations(geometry_id);
for (std::size_t i = 0; i < data.fwd_segment_position; i++) const auto forward_durations = datafacade.GetUncompressedForwardDurations(geometry_id);
{ const auto reverse_durations = datafacade.GetUncompressedReverseDurations(geometry_id);
forward_weight_offset += forward_weight_vector[i];
forward_duration_offset += forward_duration_vector[i];
}
forward_weight = forward_weight_vector[data.fwd_segment_position];
forward_duration = forward_duration_vector[data.fwd_segment_position];
BOOST_ASSERT(data.fwd_segment_position < reverse_weight_vector.size()); const auto forward_weight_offset =
std::accumulate(forward_weights.begin(),
forward_weights.begin() + data.fwd_segment_position,
EdgeWeight{0});
for (std::size_t i = 0; i < reverse_weight_vector.size() - data.fwd_segment_position - 1; const auto forward_duration_offset =
i++) std::accumulate(forward_durations.begin(),
{ forward_durations.begin() + data.fwd_segment_position,
reverse_weight_offset += reverse_weight_vector[i]; EdgeDuration{0});
reverse_duration_offset += reverse_duration_vector[i];
} EdgeWeight forward_weight = forward_weights[data.fwd_segment_position];
reverse_weight = EdgeDuration forward_duration = forward_durations[data.fwd_segment_position];
reverse_weight_vector[reverse_weight_vector.size() - data.fwd_segment_position - 1];
reverse_duration = BOOST_ASSERT(data.fwd_segment_position <
reverse_duration_vector[reverse_duration_vector.size() - data.fwd_segment_position - 1]; std::distance(forward_durations.begin(), forward_durations.end()));
const auto reverse_weight_offset =
std::accumulate(reverse_weights.begin(),
reverse_weights.end() - data.fwd_segment_position - 1,
EdgeWeight{0});
const auto reverse_duration_offset =
std::accumulate(reverse_durations.begin(),
reverse_durations.end() - data.fwd_segment_position - 1,
EdgeDuration{0});
EdgeWeight reverse_weight =
reverse_weights[reverse_weights.size() - data.fwd_segment_position - 1];
EdgeDuration reverse_duration =
reverse_durations[reverse_durations.size() - data.fwd_segment_position - 1];
ratio = std::min(1.0, std::max(0.0, ratio)); ratio = std::min(1.0, std::max(0.0, ratio));
if (data.forward_segment_id.id != SPECIAL_SEGMENTID) if (data.forward_segment_id.id != SPECIAL_SEGMENTID)
@ -493,14 +495,13 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
return std::find(first, last, INVALID_SEGMENT_WEIGHT) == last; return std::find(first, last, INVALID_SEGMENT_WEIGHT) == last;
}; };
bool is_forward_valid_source = bool is_forward_valid_source =
areSegmentsValid(forward_weight_vector.begin(), forward_weight_vector.end()); areSegmentsValid(forward_weights.begin(), forward_weights.end());
bool is_forward_valid_target = bool is_forward_valid_target = areSegmentsValid(
areSegmentsValid(forward_weight_vector.begin(), forward_weights.begin(), forward_weights.begin() + data.fwd_segment_position + 1);
forward_weight_vector.begin() + data.fwd_segment_position + 1);
bool is_reverse_valid_source = bool is_reverse_valid_source =
areSegmentsValid(reverse_weight_vector.begin(), reverse_weight_vector.end()); areSegmentsValid(reverse_weights.begin(), reverse_weights.end());
bool is_reverse_valid_target = areSegmentsValid( bool is_reverse_valid_target = areSegmentsValid(
reverse_weight_vector.begin(), reverse_weight_vector.end() - data.fwd_segment_position); reverse_weights.begin(), reverse_weights.end() - data.fwd_segment_position);
auto transformed = PhantomNodeWithDistance{ auto transformed = PhantomNodeWithDistance{
PhantomNode{data, PhantomNode{data,
@ -605,17 +606,14 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
BOOST_ASSERT(data.forward_segment_id.id != SPECIAL_NODEID); BOOST_ASSERT(data.forward_segment_id.id != SPECIAL_NODEID);
const auto geometry_id = datafacade.GetGeometryIndex(data.forward_segment_id.id).id; const auto geometry_id = datafacade.GetGeometryIndex(data.forward_segment_id.id).id;
const std::vector<EdgeWeight> forward_weight_vector = const auto forward_weights = datafacade.GetUncompressedForwardWeights(geometry_id);
datafacade.GetUncompressedForwardWeights(geometry_id); if (forward_weights[data.fwd_segment_position] != INVALID_SEGMENT_WEIGHT)
if (forward_weight_vector[data.fwd_segment_position] != INVALID_SEGMENT_WEIGHT)
{ {
forward_edge_valid = data.forward_segment_id.enabled; forward_edge_valid = data.forward_segment_id.enabled;
} }
const std::vector<EdgeWeight> reverse_weight_vector = const auto reverse_weights = datafacade.GetUncompressedReverseWeights(geometry_id);
datafacade.GetUncompressedReverseWeights(geometry_id); if (reverse_weights[reverse_weights.size() - data.fwd_segment_position - 1] !=
if (reverse_weight_vector[reverse_weight_vector.size() - data.fwd_segment_position - 1] !=
INVALID_SEGMENT_WEIGHT) INVALID_SEGMENT_WEIGHT)
{ {
reverse_edge_valid = data.reverse_segment_id.enabled; reverse_edge_valid = data.reverse_segment_id.enabled;

View File

@ -55,7 +55,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
const auto source_node_id = const auto source_node_id =
reversed_source ? source_node.reverse_segment_id.id : source_node.forward_segment_id.id; reversed_source ? source_node.reverse_segment_id.id : source_node.forward_segment_id.id;
const auto source_geometry_id = facade.GetGeometryIndex(source_node_id).id; const auto source_geometry_id = facade.GetGeometryIndex(source_node_id).id;
std::vector<NodeID> source_geometry = facade.GetUncompressedForwardGeometry(source_geometry_id); const auto source_geometry = facade.GetUncompressedForwardGeometry(source_geometry_id);
geometry.osm_node_ids.push_back( geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(source_geometry[source_segment_start_coordinate])); facade.GetOSMNodeIDOfNode(source_geometry[source_segment_start_coordinate]));
@ -111,8 +111,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
const auto target_node_id = const auto target_node_id =
reversed_target ? target_node.reverse_segment_id.id : target_node.forward_segment_id.id; reversed_target ? target_node.reverse_segment_id.id : target_node.forward_segment_id.id;
const auto target_geometry_id = facade.GetGeometryIndex(target_node_id).id; const auto target_geometry_id = facade.GetGeometryIndex(target_node_id).id;
const std::vector<DatasourceID> forward_datasources = const auto forward_datasources = facade.GetUncompressedForwardDatasources(target_geometry_id);
facade.GetUncompressedForwardDatasources(target_geometry_id);
// This happens when the source/target are on the same edge-based-node // This happens when the source/target are on the same edge-based-node
// There will be no entries in the unpacked path, thus no annotations. // There will be no entries in the unpacked path, thus no annotations.
@ -158,8 +157,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
// target node rev: 1 1 <- 2 <- 3 // target node rev: 1 1 <- 2 <- 3
const auto target_segment_end_coordinate = const auto target_segment_end_coordinate =
target_node.fwd_segment_position + (reversed_target ? 0 : 1); target_node.fwd_segment_position + (reversed_target ? 0 : 1);
const std::vector<NodeID> target_geometry = const auto target_geometry = facade.GetUncompressedForwardGeometry(target_geometry_id);
facade.GetUncompressedForwardGeometry(target_geometry_id);
geometry.osm_node_ids.push_back( geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(target_geometry[target_segment_end_coordinate])); facade.GetOSMNodeIDOfNode(target_geometry[target_segment_end_coordinate]));

View File

@ -135,25 +135,25 @@ void annotatePath(const FacadeT &facade,
phantom_node_pair.target_phantom.reverse_segment_id.id == target_node_id); phantom_node_pair.target_phantom.reverse_segment_id.id == target_node_id);
// datastructures to hold extracted data from geometry // datastructures to hold extracted data from geometry
std::vector<NodeID> id_vector; datafacade::ContiguousInternalMemoryDataFacadeBase::NodesIDRangeT id_range;
std::vector<EdgeWeight> weight_vector; datafacade::ContiguousInternalMemoryDataFacadeBase::WeightsRangeT weight_range;
std::vector<EdgeWeight> duration_vector; datafacade::ContiguousInternalMemoryDataFacadeBase::DurationsRangeT duration_range;
std::vector<DatasourceID> datasource_vector; datafacade::ContiguousInternalMemoryDataFacadeBase::DatasourceIDRangeT datasource_range;
const auto get_segment_geometry = [&](const auto geometry_index) { const auto get_segment_geometry = [&](const auto geometry_index) {
if (geometry_index.forward) if (geometry_index.forward)
{ {
id_vector = facade.GetUncompressedForwardGeometry(geometry_index.id); id_range = facade.GetUncompressedForwardGeometry(geometry_index.id);
weight_vector = facade.GetUncompressedForwardWeights(geometry_index.id); weight_range = facade.GetUncompressedForwardWeights(geometry_index.id);
duration_vector = facade.GetUncompressedForwardDurations(geometry_index.id); duration_range = facade.GetUncompressedForwardDurations(geometry_index.id);
datasource_vector = facade.GetUncompressedForwardDatasources(geometry_index.id); datasource_range = facade.GetUncompressedForwardDatasources(geometry_index.id);
} }
else else
{ {
id_vector = facade.GetUncompressedReverseGeometry(geometry_index.id); id_range = facade.GetUncompressedReverseGeometry(geometry_index.id);
weight_vector = facade.GetUncompressedReverseWeights(geometry_index.id); weight_range = facade.GetUncompressedReverseWeights(geometry_index.id);
duration_vector = facade.GetUncompressedReverseDurations(geometry_index.id); duration_range = facade.GetUncompressedReverseDurations(geometry_index.id);
datasource_vector = facade.GetUncompressedReverseDatasources(geometry_index.id); datasource_range = facade.GetUncompressedReverseDatasources(geometry_index.id);
} }
}; };
@ -172,19 +172,19 @@ void annotatePath(const FacadeT &facade,
const auto geometry_index = facade.GetGeometryIndex(node_id); const auto geometry_index = facade.GetGeometryIndex(node_id);
get_segment_geometry(geometry_index); get_segment_geometry(geometry_index);
BOOST_ASSERT(id_vector.size() > 0); BOOST_ASSERT(id_range.size() > 0);
BOOST_ASSERT(datasource_vector.size() > 0); BOOST_ASSERT(datasource_range.size() > 0);
BOOST_ASSERT(weight_vector.size() == id_vector.size() - 1); BOOST_ASSERT(weight_range.size() + 1 == id_range.size());
BOOST_ASSERT(duration_vector.size() == id_vector.size() - 1); BOOST_ASSERT(duration_range.size() + 1 == id_range.size());
const bool is_first_segment = unpacked_path.empty(); const bool is_first_segment = unpacked_path.empty();
const std::size_t start_index = const std::size_t start_index =
(is_first_segment ? ((start_traversed_in_reverse) (is_first_segment ? ((start_traversed_in_reverse)
? weight_vector.size() - ? weight_range.size() -
phantom_node_pair.source_phantom.fwd_segment_position - 1 phantom_node_pair.source_phantom.fwd_segment_position - 1
: phantom_node_pair.source_phantom.fwd_segment_position) : phantom_node_pair.source_phantom.fwd_segment_position)
: 0); : 0);
const std::size_t end_index = weight_vector.size(); const std::size_t end_index = weight_range.size();
bool is_left_hand_driving = facade.IsLeftHandDriving(node_id); bool is_left_hand_driving = facade.IsLeftHandDriving(node_id);
@ -193,19 +193,19 @@ void annotatePath(const FacadeT &facade,
for (std::size_t segment_idx = start_index; segment_idx < end_index; ++segment_idx) for (std::size_t segment_idx = start_index; segment_idx < end_index; ++segment_idx)
{ {
unpacked_path.push_back(PathData{*node_from, unpacked_path.push_back(PathData{*node_from,
id_vector[segment_idx + 1], id_range[segment_idx + 1],
name_index, name_index,
is_segregated, is_segregated,
weight_vector[segment_idx], static_cast<EdgeWeight>(weight_range[segment_idx]),
0, 0,
duration_vector[segment_idx], static_cast<EdgeDuration>(duration_range[segment_idx]),
0, 0,
guidance::TurnInstruction::NO_TURN(), guidance::TurnInstruction::NO_TURN(),
{{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID}, {{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID},
travel_mode, travel_mode,
classes, classes,
EMPTY_ENTRY_CLASS, EMPTY_ENTRY_CLASS,
datasource_vector[segment_idx], datasource_range[segment_idx],
osrm::guidance::TurnBearing(0), osrm::guidance::TurnBearing(0),
osrm::guidance::TurnBearing(0), osrm::guidance::TurnBearing(0),
is_left_hand_driving}); is_left_hand_driving});
@ -239,10 +239,9 @@ void annotatePath(const FacadeT &facade,
if (is_local_path) if (is_local_path)
{ {
start_index = start_index =
weight_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1; weight_range.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1;
} }
end_index = end_index = weight_range.size() - phantom_node_pair.target_phantom.fwd_segment_position - 1;
weight_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position - 1;
} }
else else
{ {
@ -264,23 +263,23 @@ void annotatePath(const FacadeT &facade,
for (std::size_t segment_idx = start_index; segment_idx != end_index; for (std::size_t segment_idx = start_index; segment_idx != end_index;
(start_index < end_index ? ++segment_idx : --segment_idx)) (start_index < end_index ? ++segment_idx : --segment_idx))
{ {
BOOST_ASSERT(segment_idx < id_vector.size() - 1); BOOST_ASSERT(segment_idx < static_cast<std::size_t>(id_range.size() - 1));
BOOST_ASSERT(facade.GetTravelMode(target_node_id) > 0); BOOST_ASSERT(facade.GetTravelMode(target_node_id) > 0);
unpacked_path.push_back( unpacked_path.push_back(
PathData{target_node_id, PathData{target_node_id,
id_vector[start_index < end_index ? segment_idx + 1 : segment_idx - 1], id_range[start_index < end_index ? segment_idx + 1 : segment_idx - 1],
facade.GetNameIndex(target_node_id), facade.GetNameIndex(target_node_id),
facade.IsSegregated(target_node_id), facade.IsSegregated(target_node_id),
weight_vector[segment_idx], static_cast<EdgeWeight>(weight_range[segment_idx]),
0, 0,
duration_vector[segment_idx], static_cast<EdgeDuration>(duration_range[segment_idx]),
0, 0,
guidance::TurnInstruction::NO_TURN(), guidance::TurnInstruction::NO_TURN(),
{{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID}, {{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID},
facade.GetTravelMode(target_node_id), facade.GetTravelMode(target_node_id),
facade.GetClassData(target_node_id), facade.GetClassData(target_node_id),
EMPTY_ENTRY_CLASS, EMPTY_ENTRY_CLASS,
datasource_vector[segment_idx], datasource_range[segment_idx],
guidance::TurnBearing(0), guidance::TurnBearing(0),
guidance::TurnBearing(0), guidance::TurnBearing(0),
is_target_left_hand_driving}); is_target_left_hand_driving});

View File

@ -56,7 +56,7 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl
using DirectionalGeometryID = std::uint32_t; using DirectionalGeometryID = std::uint32_t;
using SegmentOffset = std::uint32_t; using SegmentOffset = std::uint32_t;
using SegmentWeightVector = PackedVector<SegmentWeight, SEGMENT_WEIGHT_BITS>; using SegmentWeightVector = PackedVector<SegmentWeight, SEGMENT_WEIGHT_BITS>;
using SegmentDurationVector = PackedVector<SegmentDuration, SEGMENT_DURAITON_BITS>; using SegmentDurationVector = PackedVector<SegmentDuration, SEGMENT_DURATION_BITS>;
using SegmentDatasourceVector = Vector<DatasourceID>; using SegmentDatasourceVector = Vector<DatasourceID>;
SegmentDataContainerImpl() = default; SegmentDataContainerImpl() = default;

View File

@ -105,9 +105,9 @@ static const NameID INVALID_NAMEID = std::numeric_limits<NameID>::max();
static const NameID EMPTY_NAMEID = 0; static const NameID EMPTY_NAMEID = 0;
static const unsigned INVALID_COMPONENTID = 0; static const unsigned INVALID_COMPONENTID = 0;
static const std::size_t SEGMENT_WEIGHT_BITS = 22; static const std::size_t SEGMENT_WEIGHT_BITS = 22;
static const std::size_t SEGMENT_DURAITON_BITS = 22; static const std::size_t SEGMENT_DURATION_BITS = 22;
static const SegmentWeight INVALID_SEGMENT_WEIGHT = (1u << SEGMENT_WEIGHT_BITS) - 1; static const SegmentWeight INVALID_SEGMENT_WEIGHT = (1u << SEGMENT_WEIGHT_BITS) - 1;
static const SegmentDuration INVALID_SEGMENT_DURATION = (1u << SEGMENT_DURAITON_BITS) - 1; static const SegmentDuration INVALID_SEGMENT_DURATION = (1u << SEGMENT_DURATION_BITS) - 1;
static const SegmentWeight MAX_SEGMENT_WEIGHT = INVALID_SEGMENT_WEIGHT - 1; static const SegmentWeight MAX_SEGMENT_WEIGHT = INVALID_SEGMENT_WEIGHT - 1;
static const SegmentDuration MAX_SEGMENT_DURATION = INVALID_SEGMENT_DURATION - 1; static const SegmentDuration MAX_SEGMENT_DURATION = INVALID_SEGMENT_DURATION - 1;
static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits<EdgeWeight>::max(); static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits<EdgeWeight>::max();

View File

@ -397,16 +397,14 @@ void encodeVectorTile(const DataFacadeBase &facade,
const auto &edge = edges[edge_index]; const auto &edge = edges[edge_index];
const auto geometry_id = get_geometry_id(edge); const auto geometry_id = get_geometry_id(edge);
const auto forward_datasource_vector = const auto forward_datasource_range = facade.GetUncompressedForwardDatasources(geometry_id);
facade.GetUncompressedForwardDatasources(geometry_id); const auto reverse_datasource_range = facade.GetUncompressedReverseDatasources(geometry_id);
const auto reverse_datasource_vector =
facade.GetUncompressedReverseDatasources(geometry_id);
BOOST_ASSERT(edge.fwd_segment_position < forward_datasource_vector.size()); BOOST_ASSERT(edge.fwd_segment_position < forward_datasource_range.size());
const auto forward_datasource = forward_datasource_vector[edge.fwd_segment_position]; const auto forward_datasource = forward_datasource_range[edge.fwd_segment_position];
BOOST_ASSERT(edge.fwd_segment_position < reverse_datasource_vector.size()); BOOST_ASSERT(edge.fwd_segment_position < reverse_datasource_range.size());
const auto reverse_datasource = reverse_datasource_vector[reverse_datasource_vector.size() - const auto reverse_datasource = reverse_datasource_range[reverse_datasource_range.size() -
edge.fwd_segment_position - 1]; edge.fwd_segment_position - 1];
// Keep track of the highest datasource seen so that we don't write unnecessary // Keep track of the highest datasource seen so that we don't write unnecessary
// data to the layer attribute values // data to the layer attribute values
@ -453,13 +451,11 @@ void encodeVectorTile(const DataFacadeBase &facade,
const double length = osrm::util::coordinate_calculation::haversineDistance(a, b); const double length = osrm::util::coordinate_calculation::haversineDistance(a, b);
// Weight values // Weight values
const auto forward_weight_vector = const auto forward_weight_range = facade.GetUncompressedForwardWeights(geometry_id);
facade.GetUncompressedForwardWeights(geometry_id); const auto reverse_weight_range = facade.GetUncompressedReverseWeights(geometry_id);
const auto reverse_weight_vector = const auto forward_weight = forward_weight_range[edge.fwd_segment_position];
facade.GetUncompressedReverseWeights(geometry_id); const auto reverse_weight = reverse_weight_range[reverse_weight_range.size() -
const auto forward_weight = forward_weight_vector[edge.fwd_segment_position]; edge.fwd_segment_position - 1];
const auto reverse_weight = reverse_weight_vector[reverse_weight_vector.size() -
edge.fwd_segment_position - 1];
line_int_index.add(forward_weight); line_int_index.add(forward_weight);
line_int_index.add(reverse_weight); line_int_index.add(reverse_weight);
@ -472,14 +468,14 @@ void encodeVectorTile(const DataFacadeBase &facade,
line_int_index.add(reverse_rate); line_int_index.add(reverse_rate);
// Duration values // Duration values
const auto forward_duration_vector = const auto forward_duration_range =
facade.GetUncompressedForwardDurations(geometry_id); facade.GetUncompressedForwardDurations(geometry_id);
const auto reverse_duration_vector = const auto reverse_duration_range =
facade.GetUncompressedReverseDurations(geometry_id); facade.GetUncompressedReverseDurations(geometry_id);
const auto forward_duration = forward_duration_vector[edge.fwd_segment_position]; const auto forward_duration = forward_duration_range[edge.fwd_segment_position];
const auto reverse_duration = const auto reverse_duration = reverse_duration_range[reverse_duration_range.size() -
reverse_duration_vector[reverse_duration_vector.size() - edge.fwd_segment_position - 1];
edge.fwd_segment_position - 1];
line_int_index.add(forward_duration); line_int_index.add(forward_duration);
line_int_index.add(reverse_duration); line_int_index.add(reverse_duration);
} }
@ -500,32 +496,32 @@ void encodeVectorTile(const DataFacadeBase &facade,
const double length = const double length =
osrm::util::coordinate_calculation::haversineDistance(a, b); osrm::util::coordinate_calculation::haversineDistance(a, b);
const auto forward_weight_vector = const auto forward_weight_range =
facade.GetUncompressedForwardWeights(geometry_id); facade.GetUncompressedForwardWeights(geometry_id);
const auto reverse_weight_vector = const auto reverse_weight_range =
facade.GetUncompressedReverseWeights(geometry_id); facade.GetUncompressedReverseWeights(geometry_id);
const auto forward_duration_vector = const auto forward_duration_range =
facade.GetUncompressedForwardDurations(geometry_id); facade.GetUncompressedForwardDurations(geometry_id);
const auto reverse_duration_vector = const auto reverse_duration_range =
facade.GetUncompressedReverseDurations(geometry_id); facade.GetUncompressedReverseDurations(geometry_id);
const auto forward_datasource_vector = const auto forward_datasource_range =
facade.GetUncompressedForwardDatasources(geometry_id); facade.GetUncompressedForwardDatasources(geometry_id);
const auto reverse_datasource_vector = const auto reverse_datasource_range =
facade.GetUncompressedReverseDatasources(geometry_id); facade.GetUncompressedReverseDatasources(geometry_id);
const auto forward_weight = forward_weight_vector[edge.fwd_segment_position]; const auto forward_weight = forward_weight_range[edge.fwd_segment_position];
const auto reverse_weight = const auto reverse_weight = reverse_weight_range[reverse_weight_range.size() -
reverse_weight_vector[reverse_weight_vector.size() - edge.fwd_segment_position - 1];
edge.fwd_segment_position - 1];
const auto forward_duration = const auto forward_duration = forward_duration_range[edge.fwd_segment_position];
forward_duration_vector[edge.fwd_segment_position];
const auto reverse_duration = const auto reverse_duration =
reverse_duration_vector[reverse_duration_vector.size() - reverse_duration_range[reverse_duration_range.size() -
edge.fwd_segment_position - 1]; edge.fwd_segment_position - 1];
const auto forward_datasource_idx = const auto forward_datasource_idx =
forward_datasource_vector[edge.fwd_segment_position]; forward_datasource_range[edge.fwd_segment_position];
const auto reverse_datasource_idx = const auto reverse_datasource_idx =
reverse_datasource_vector[reverse_datasource_vector.size() - reverse_datasource_range[reverse_datasource_range.size() -
edge.fwd_segment_position - 1]; edge.fwd_segment_position - 1];
const auto component_id = facade.GetComponentID(edge.forward_segment_id.id); const auto component_id = facade.GetComponentID(edge.forward_segment_id.id);
const auto name_id = facade.GetNameIndex(edge.forward_segment_id.id); const auto name_id = facade.GetNameIndex(edge.forward_segment_id.id);
@ -929,7 +925,7 @@ void encodeVectorTile(const DataFacadeBase &facade,
for (auto edgeNodeID : segregated_nodes) for (auto edgeNodeID : segregated_nodes)
{ {
auto const geomIndex = facade.GetGeometryIndex(edgeNodeID); auto const geomIndex = facade.GetGeometryIndex(edgeNodeID);
std::vector<NodeID> geometry; DataFacadeBase::NodesIDRangeT geometry;
if (geomIndex.forward) if (geomIndex.forward)
geometry = facade.GetUncompressedForwardGeometry(geomIndex.id); geometry = facade.GetUncompressedForwardGeometry(geomIndex.id);

View File

@ -101,8 +101,8 @@ std::vector<TurnData> generateTurns(const datafacade &facade,
// w // w
// uv is the "approach" // uv is the "approach"
// vw is the "exit" // vw is the "exit"
std::vector<EdgeWeight> approach_weight_vector; typename datafacade::BaseDataFacade::WeightsRangeT approach_weight_range;
std::vector<EdgeWeight> approach_duration_vector; typename datafacade::BaseDataFacade::DurationsRangeT approach_duration_range;
// Look at every node in the directed graph we created // Look at every node in the directed graph we created
for (const auto &startnode : sorted_startnodes) for (const auto &startnode : sorted_startnodes)
@ -151,27 +151,26 @@ std::vector<TurnData> generateTurns(const datafacade &facade,
if (edge_based_node_info.find(approachedge.edge_based_node_id) if (edge_based_node_info.find(approachedge.edge_based_node_id)
->second.is_geometry_forward) ->second.is_geometry_forward)
{ {
approach_weight_vector = facade.GetUncompressedForwardWeights( approach_weight_range = facade.GetUncompressedForwardWeights(
edge_based_node_info.find(approachedge.edge_based_node_id) edge_based_node_info.find(approachedge.edge_based_node_id)
->second.packed_geometry_id); ->second.packed_geometry_id);
approach_duration_vector = facade.GetUncompressedForwardDurations( approach_duration_range = facade.GetUncompressedForwardDurations(
edge_based_node_info.find(approachedge.edge_based_node_id) edge_based_node_info.find(approachedge.edge_based_node_id)
->second.packed_geometry_id); ->second.packed_geometry_id);
} }
else else
{ {
approach_weight_vector = facade.GetUncompressedReverseWeights( approach_weight_range = facade.GetUncompressedReverseWeights(
edge_based_node_info.find(approachedge.edge_based_node_id) edge_based_node_info.find(approachedge.edge_based_node_id)
->second.packed_geometry_id); ->second.packed_geometry_id);
approach_duration_vector = facade.GetUncompressedReverseDurations( approach_duration_range = facade.GetUncompressedReverseDurations(
edge_based_node_info.find(approachedge.edge_based_node_id) edge_based_node_info.find(approachedge.edge_based_node_id)
->second.packed_geometry_id); ->second.packed_geometry_id);
} }
const auto sum_node_weight = std::accumulate(approach_weight_vector.begin(), const auto sum_node_weight = std::accumulate(
approach_weight_vector.end(), approach_weight_range.begin(), approach_weight_range.end(), EdgeWeight{0});
EdgeWeight{0}); const auto sum_node_duration = std::accumulate(approach_duration_range.begin(),
const auto sum_node_duration = std::accumulate(approach_duration_vector.begin(), approach_duration_range.end(),
approach_duration_vector.end(),
EdgeWeight{0}); EdgeWeight{0});
// The edge.weight is the whole edge weight, which includes the turn // The edge.weight is the whole edge weight, which includes the turn

View File

@ -156,15 +156,9 @@ class ContiguousInternalMemoryDataFacade<routing_algorithms::offline::Algorithm>
GeometryID GetGeometryIndex(const NodeID /*id*/) const override { return GeometryID{0, false}; } GeometryID GetGeometryIndex(const NodeID /*id*/) const override { return GeometryID{0, false}; }
std::vector<NodeID> GetUncompressedForwardGeometry(const EdgeID /*id*/) const override NodesIDRangeT GetUncompressedForwardGeometry(const EdgeID /*id*/) const override { return {}; }
{
return {};
}
std::vector<NodeID> GetUncompressedReverseGeometry(const EdgeID /*id*/) const override NodesIDRangeT GetUncompressedReverseGeometry(const EdgeID /*id*/) const override { return {}; }
{
return {};
}
TurnPenalty GetWeightPenaltyForEdgeID(const unsigned /*id*/) const override TurnPenalty GetWeightPenaltyForEdgeID(const unsigned /*id*/) const override
{ {
@ -176,32 +170,26 @@ class ContiguousInternalMemoryDataFacade<routing_algorithms::offline::Algorithm>
return INVALID_TURN_PENALTY; return INVALID_TURN_PENALTY;
} }
std::vector<EdgeWeight> GetUncompressedForwardWeights(const EdgeID /*id*/) const override WeightsRangeT GetUncompressedForwardWeights(const EdgeID /*id*/) const override { return {}; }
WeightsRangeT GetUncompressedReverseWeights(const EdgeID /*id*/) const override { return {}; }
DurationsRangeT GetUncompressedForwardDurations(const EdgeID /*geomID*/) const override
{ {
return {}; return {};
} }
std::vector<EdgeWeight> GetUncompressedReverseWeights(const EdgeID /*id*/) const override DurationsRangeT GetUncompressedReverseDurations(const EdgeID /*geomID*/) const override
{ {
return {}; return {};
} }
std::vector<EdgeWeight> GetUncompressedForwardDurations(const EdgeID /*geomID*/) const override DatasourceIDRangeT GetUncompressedForwardDatasources(const EdgeID /*id*/) const override
{ {
return {}; return {};
} }
std::vector<EdgeWeight> GetUncompressedReverseDurations(const EdgeID /*geomID*/) const override DatasourceIDRangeT GetUncompressedReverseDatasources(const EdgeID /*id*/) const override
{
return {};
}
std::vector<DatasourceID> GetUncompressedForwardDatasources(const EdgeID /*id*/) const override
{
return {};
}
std::vector<DatasourceID> GetUncompressedReverseDatasources(const EdgeID /*id*/) const override
{ {
return {}; return {};
} }
@ -438,4 +426,21 @@ BOOST_AUTO_TEST_CASE(shortest_path)
BOOST_CHECK_EQUAL(route.shortest_path_weight, INVALID_EDGE_WEIGHT); BOOST_CHECK_EQUAL(route.shortest_path_weight, INVALID_EDGE_WEIGHT);
} }
BOOST_AUTO_TEST_CASE(facade_uncompressed_methods)
{
using Algorithm = osrm::engine::routing_algorithms::offline::Algorithm;
osrm::engine::SearchEngineData<Algorithm> heaps;
osrm::engine::datafacade::ContiguousInternalMemoryDataFacade<Algorithm> facade;
BOOST_CHECK_EQUAL(facade.GetUncompressedForwardGeometry(0).size(), 0);
BOOST_CHECK_EQUAL(facade.GetUncompressedReverseGeometry(0).size(), 0);
BOOST_CHECK_EQUAL(facade.GetUncompressedForwardWeights(0).size(), 0);
BOOST_CHECK_EQUAL(facade.GetUncompressedReverseWeights(0).size(), 0);
BOOST_CHECK_EQUAL(facade.GetUncompressedForwardDurations(0).size(), 0);
BOOST_CHECK_EQUAL(facade.GetUncompressedReverseDurations(0).size(), 0);
BOOST_CHECK_EQUAL(facade.GetUncompressedForwardDatasources(0).size(), 0);
BOOST_CHECK_EQUAL(facade.GetUncompressedReverseDatasources(0).size(), 0);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -54,38 +54,39 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
{ {
return 0; return 0;
} }
std::vector<NodeID> GetUncompressedForwardGeometry(const EdgeID /* id */) const override NodesIDRangeT GetUncompressedForwardGeometry(const EdgeID /* id */) const override
{ {
return {}; return {};
} }
std::vector<NodeID> GetUncompressedReverseGeometry(const EdgeID /* id */) const override NodesIDRangeT GetUncompressedReverseGeometry(const EdgeID /* id */) const override
{ {
return {}; return {};
} }
std::vector<EdgeWeight> GetUncompressedForwardWeights(const EdgeID /* id */) const override WeightsRangeT GetUncompressedForwardWeights(const EdgeID /* id */) const override
{ {
std::vector<EdgeWeight> result_weights; static const std::vector<SegmentWeight> result_weights{1, 2, 3};
result_weights.resize(1);
result_weights[0] = 1;
return result_weights; return result_weights;
} }
std::vector<EdgeWeight> GetUncompressedReverseWeights(const EdgeID id) const override WeightsRangeT GetUncompressedReverseWeights(const EdgeID id) const override
{ {
return GetUncompressedForwardWeights(id); return GetUncompressedForwardWeights(id);
} }
std::vector<EdgeWeight> GetUncompressedForwardDurations(const EdgeID id) const override
DurationsRangeT GetUncompressedForwardDurations(const EdgeID /*id*/) const override
{ {
return GetUncompressedForwardWeights(id); static const std::vector<SegmentDuration> data{1, 2, 3};
return data;
} }
std::vector<EdgeWeight> GetUncompressedReverseDurations(const EdgeID id) const override DurationsRangeT GetUncompressedReverseDurations(const EdgeID /*id*/) const override
{ {
return GetUncompressedForwardWeights(id); static const std::vector<SegmentDuration> data{1, 2, 3};
return data;
} }
std::vector<DatasourceID> GetUncompressedForwardDatasources(const EdgeID /*id*/) const override DatasourceIDRangeT GetUncompressedForwardDatasources(const EdgeID /*id*/) const override
{ {
return {}; return {};
} }
std::vector<DatasourceID> GetUncompressedReverseDatasources(const EdgeID /*id*/) const override DatasourceIDRangeT GetUncompressedReverseDatasources(const EdgeID /*id*/) const override
{ {
return {}; return {};
} }

View File

@ -1,7 +1,10 @@
#include "util/packed_vector.hpp" #include "util/packed_vector.hpp"
#include "util/typedefs.hpp" #include "util/typedefs.hpp"
#include "common/range_tools.hpp"
#include <boost/range/adaptor/reversed.hpp> #include <boost/range/adaptor/reversed.hpp>
#include <boost/range/any_range.hpp>
#include <boost/range/iterator_range.hpp> #include <boost/range/iterator_range.hpp>
#include <boost/test/test_case_template.hpp> #include <boost/test/test_case_template.hpp>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
@ -203,4 +206,50 @@ BOOST_AUTO_TEST_CASE(packed_vector_33bit_continious)
} }
} }
BOOST_AUTO_TEST_CASE(packed_weights_container_with_type_erasure)
{
using Vector = PackedVector<SegmentWeight, SEGMENT_WEIGHT_BITS>;
using WeightsRangeT = boost::any_range<SegmentWeight,
boost::random_access_traversal_tag,
const typename Vector::internal_reference,
std::ptrdiff_t>;
PackedVector<SegmentWeight, SEGMENT_WEIGHT_BITS> vector(7);
std::iota(vector.begin(), vector.end(), 0);
auto forward = boost::make_iterator_range(vector.begin() + 1, vector.begin() + 6);
auto forward_any = WeightsRangeT(forward.begin(), forward.end());
CHECK_EQUAL_RANGE(forward, 1, 2, 3, 4, 5);
CHECK_EQUAL_RANGE(forward_any, 1, 2, 3, 4, 5);
auto reverse = boost::adaptors::reverse(forward);
auto reverse_any = WeightsRangeT(reverse);
CHECK_EQUAL_RANGE(reverse, 5, 4, 3, 2, 1);
CHECK_EQUAL_RANGE(reverse_any, 5, 4, 3, 2, 1);
}
BOOST_AUTO_TEST_CASE(packed_weights_view_with_type_erasure)
{
using View = PackedVectorView<SegmentWeight, SEGMENT_WEIGHT_BITS>;
using PackedDataWord = std::uint64_t; // PackedVectorView<>::WordT
using WeightsRangeT = boost::any_range<SegmentWeight,
boost::random_access_traversal_tag,
const typename View::internal_reference,
std::ptrdiff_t>;
PackedDataWord data[] = {0x200000400000, 0xc, 0};
View view(vector_view<PackedDataWord>(data, 3), 7);
auto forward = boost::make_iterator_range(view.begin() + 1, view.begin() + 4);
auto forward_any = WeightsRangeT(forward.begin(), forward.end());
CHECK_EQUAL_RANGE(forward, 1, 2, 3);
CHECK_EQUAL_RANGE(forward_any, 1, 2, 3);
auto reverse = boost::adaptors::reverse(forward);
auto reverse_any = WeightsRangeT(reverse);
CHECK_EQUAL_RANGE(reverse, 3, 2, 1);
CHECK_EQUAL_RANGE(reverse_any, 3, 2, 1);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()