Use ranges with fixed types

This commit is contained in:
Michael Krasnyk
2018-04-06 15:09:52 +02:00
committed by Patrick Niklaus
parent be123cd72f
commit 8d8042ebae
12 changed files with 190 additions and 152 deletions
+4 -4
View File
@@ -48,7 +48,7 @@ class NearestAPI final : public BaseAPI
std::uint64_t from_node = 0;
std::uint64_t to_node = 0;
datafacade::BaseDataFacade::NodesIDRangeT forward_geometry;
datafacade::BaseDataFacade::NodeForwardRange forward_geometry;
if (phantom_node.forward_segment_id.enabled)
{
auto segment_id = phantom_node.forward_segment_id.id;
@@ -56,7 +56,7 @@ class NearestAPI final : public BaseAPI
forward_geometry = facade.GetUncompressedForwardGeometry(geometry_id);
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);
}
@@ -66,7 +66,7 @@ class NearestAPI final : public BaseAPI
const auto geometry_id = facade.GetGeometryIndex(segment_id).id;
const auto geometry = facade.GetUncompressedForwardGeometry(geometry_id);
auto osm_node_id =
facade.GetOSMNodeIDOfNode(geometry[phantom_node.fwd_segment_position + 1]);
facade.GetOSMNodeIDOfNode(geometry(phantom_node.fwd_segment_position + 1));
from_node = static_cast<std::uint64_t>(osm_node_id);
}
else if (phantom_node.forward_segment_id.enabled &&
@@ -74,7 +74,7 @@ class NearestAPI final : public BaseAPI
{
// In the case of one way, rely on forward segment only
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);
}
nodes.values.push_back(from_node);
@@ -239,46 +239,46 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
return m_osmnodeid_list[id];
}
NodesIDRangeT GetUncompressedForwardGeometry(const EdgeID id) const override final
NodeForwardRange GetUncompressedForwardGeometry(const EdgeID id) const override final
{
return segment_data.GetForwardGeometry(id);
}
NodesIDRangeT GetUncompressedReverseGeometry(const EdgeID id) const override final
NodeReverseRange GetUncompressedReverseGeometry(const EdgeID id) const override final
{
return segment_data.GetReverseGeometry(id);
}
DurationsRangeT GetUncompressedForwardDurations(const EdgeID id) const override final
DurationForwardRange GetUncompressedForwardDurations(const EdgeID id) const override final
{
return segment_data.GetForwardDurations(id);
}
DurationsRangeT GetUncompressedReverseDurations(const EdgeID id) const override final
DurationReverseRange GetUncompressedReverseDurations(const EdgeID id) const override final
{
return segment_data.GetReverseDurations(id);
}
WeightsRangeT GetUncompressedForwardWeights(const EdgeID id) const override final
WeightForwardRange GetUncompressedForwardWeights(const EdgeID id) const override final
{
return segment_data.GetForwardWeights(id);
}
WeightsRangeT GetUncompressedReverseWeights(const EdgeID id) const override final
WeightReverseRange GetUncompressedReverseWeights(const EdgeID id) const override final
{
return segment_data.GetReverseWeights(id);
}
// Returns the data source ids that were used to supply the edge
// weights.
DatasourceIDRangeT GetUncompressedForwardDatasources(const EdgeID id) const override final
DatasourceForwardRange GetUncompressedForwardDatasources(const EdgeID id) const override final
{
return segment_data.GetForwardDatasources(id);
}
// Returns the data source ids that were used to supply the edge
// weights.
DatasourceIDRangeT GetUncompressedReverseDatasources(const EdgeID id) const override final
DatasourceReverseRange GetUncompressedReverseDatasources(const EdgeID id) const override final
{
return segment_data.GetReverseDatasources(id);
}
+26 -14
View File
@@ -12,6 +12,7 @@
#include "extractor/edge_based_node_segment.hpp"
#include "extractor/maneuver_override.hpp"
#include "extractor/query_node.hpp"
#include "extractor/segment_data_container.hpp"
#include "extractor/travel_mode.hpp"
#include "extractor/turn_lane_types.hpp"
@@ -23,12 +24,14 @@
#include "util/guidance/entry_class.hpp"
#include "util/guidance/turn_lanes.hpp"
#include "util/integer_range.hpp"
#include "util/packed_vector.hpp"
#include "util/string_util.hpp"
#include "util/string_view.hpp"
#include "util/typedefs.hpp"
#include "osrm/coordinate.hpp"
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/any_range.hpp>
#include <cstddef>
@@ -51,12 +54,21 @@ class BaseDataFacade
public:
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>;
using NodeForwardRange =
boost::iterator_range<extractor::SegmentDataView::SegmentNodeVector::const_iterator>;
using NodeReverseRange = boost::reversed_range<const NodeForwardRange>;
using WeightForwardRange =
boost::iterator_range<extractor::SegmentDataView::SegmentWeightVector::const_iterator>;
using WeightReverseRange = boost::reversed_range<const WeightForwardRange>;
using DurationForwardRange =
boost::iterator_range<extractor::SegmentDataView::SegmentDurationVector::const_iterator>;
using DurationReverseRange = boost::reversed_range<const DurationForwardRange>;
using DatasourceForwardRange =
boost::iterator_range<extractor::SegmentDataView::SegmentDatasourceVector::const_iterator>;
using DatasourceReverseRange = boost::reversed_range<const DatasourceForwardRange>;
BaseDataFacade() {}
virtual ~BaseDataFacade() {}
@@ -72,8 +84,8 @@ class BaseDataFacade
virtual ComponentID GetComponentID(const NodeID id) const = 0;
virtual NodesIDRangeT GetUncompressedForwardGeometry(const EdgeID id) const = 0;
virtual NodesIDRangeT GetUncompressedReverseGeometry(const EdgeID id) const = 0;
virtual NodeForwardRange GetUncompressedForwardGeometry(const EdgeID id) const = 0;
virtual NodeReverseRange GetUncompressedReverseGeometry(const EdgeID id) const = 0;
virtual TurnPenalty GetWeightPenaltyForEdgeID(const unsigned id) const = 0;
@@ -81,18 +93,18 @@ class BaseDataFacade
// Gets the weight values for each segment in an uncompressed geometry.
// Should always be 1 shorter than GetUncompressedGeometry
virtual WeightsRangeT GetUncompressedForwardWeights(const EdgeID id) const = 0;
virtual WeightsRangeT GetUncompressedReverseWeights(const EdgeID id) const = 0;
virtual WeightForwardRange GetUncompressedForwardWeights(const EdgeID id) const = 0;
virtual WeightReverseRange GetUncompressedReverseWeights(const EdgeID id) const = 0;
// Gets the duration values for each segment in an uncompressed geometry.
// Should always be 1 shorter than GetUncompressedGeometry
virtual DurationsRangeT GetUncompressedForwardDurations(const EdgeID id) const = 0;
virtual DurationsRangeT GetUncompressedReverseDurations(const EdgeID id) const = 0;
virtual DurationForwardRange GetUncompressedForwardDurations(const EdgeID id) const = 0;
virtual DurationReverseRange GetUncompressedReverseDurations(const EdgeID id) const = 0;
// 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.
virtual DatasourceIDRangeT GetUncompressedForwardDatasources(const EdgeID id) const = 0;
virtual DatasourceIDRangeT GetUncompressedReverseDatasources(const EdgeID id) const = 0;
virtual DatasourceForwardRange GetUncompressedForwardDatasources(const EdgeID id) const = 0;
virtual DatasourceReverseRange GetUncompressedReverseDatasources(const EdgeID id) const = 0;
// Gets the name of a datasource
virtual StringView GetDatasourceName(const DatasourceID id) const = 0;
@@ -58,7 +58,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
const auto source_geometry = facade.GetUncompressedForwardGeometry(source_geometry_id);
geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(source_geometry[source_segment_start_coordinate]));
facade.GetOSMNodeIDOfNode(source_geometry(source_segment_start_coordinate)));
auto cumulative_distance = 0.;
auto current_distance = 0.;
@@ -135,7 +135,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
LegGeometry::Annotation{current_distance,
duration,
weight,
forward_datasources[target_node.fwd_segment_position]});
forward_datasources(target_node.fwd_segment_position)});
}
else
{
@@ -144,7 +144,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
(reversed_target ? target_node.reverse_duration : target_node.forward_duration) / 10.,
(reversed_target ? target_node.reverse_weight : target_node.forward_weight) /
facade.GetWeightMultiplier(),
forward_datasources[target_node.fwd_segment_position]});
forward_datasources(target_node.fwd_segment_position)});
}
geometry.segment_offsets.push_back(geometry.locations.size());
@@ -159,7 +159,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
target_node.fwd_segment_position + (reversed_target ? 0 : 1);
const auto target_geometry = facade.GetUncompressedForwardGeometry(target_geometry_id);
geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(target_geometry[target_segment_end_coordinate]));
facade.GetOSMNodeIDOfNode(target_geometry(target_segment_end_coordinate)));
BOOST_ASSERT(geometry.segment_distances.size() == geometry.segment_offsets.size() - 1);
BOOST_ASSERT(geometry.locations.size() > geometry.segment_distances.size());
@@ -135,25 +135,30 @@ void annotatePath(const FacadeT &facade,
phantom_node_pair.target_phantom.reverse_segment_id.id == target_node_id);
// datastructures to hold extracted data from geometry
datafacade::ContiguousInternalMemoryDataFacadeBase::NodesIDRangeT id_range;
datafacade::ContiguousInternalMemoryDataFacadeBase::WeightsRangeT weight_range;
datafacade::ContiguousInternalMemoryDataFacadeBase::DurationsRangeT duration_range;
datafacade::ContiguousInternalMemoryDataFacadeBase::DatasourceIDRangeT datasource_range;
std::vector<NodeID> id_vector;
std::vector<SegmentWeight> weight_vector;
std::vector<SegmentDuration> duration_vector;
std::vector<DatasourceID> datasource_vector;
const auto get_segment_geometry = [&](const auto geometry_index) {
const auto copy = [](auto &vector, const auto range) {
vector.resize(range.size());
std::copy(range.begin(), range.end(), vector.begin());
};
if (geometry_index.forward)
{
id_range = facade.GetUncompressedForwardGeometry(geometry_index.id);
weight_range = facade.GetUncompressedForwardWeights(geometry_index.id);
duration_range = facade.GetUncompressedForwardDurations(geometry_index.id);
datasource_range = facade.GetUncompressedForwardDatasources(geometry_index.id);
copy(id_vector, facade.GetUncompressedForwardGeometry(geometry_index.id));
copy(weight_vector, facade.GetUncompressedForwardWeights(geometry_index.id));
copy(duration_vector, facade.GetUncompressedForwardDurations(geometry_index.id));
copy(datasource_vector, facade.GetUncompressedForwardDatasources(geometry_index.id));
}
else
{
id_range = facade.GetUncompressedReverseGeometry(geometry_index.id);
weight_range = facade.GetUncompressedReverseWeights(geometry_index.id);
duration_range = facade.GetUncompressedReverseDurations(geometry_index.id);
datasource_range = facade.GetUncompressedReverseDatasources(geometry_index.id);
copy(id_vector, facade.GetUncompressedReverseGeometry(geometry_index.id));
copy(weight_vector, facade.GetUncompressedReverseWeights(geometry_index.id));
copy(duration_vector, facade.GetUncompressedReverseDurations(geometry_index.id));
copy(datasource_vector, facade.GetUncompressedReverseDatasources(geometry_index.id));
}
};
@@ -172,19 +177,19 @@ void annotatePath(const FacadeT &facade,
const auto geometry_index = facade.GetGeometryIndex(node_id);
get_segment_geometry(geometry_index);
BOOST_ASSERT(id_range.size() > 0);
BOOST_ASSERT(datasource_range.size() > 0);
BOOST_ASSERT(weight_range.size() + 1 == id_range.size());
BOOST_ASSERT(duration_range.size() + 1 == id_range.size());
BOOST_ASSERT(id_vector.size() > 0);
BOOST_ASSERT(datasource_vector.size() > 0);
BOOST_ASSERT(weight_vector.size() + 1 == id_vector.size());
BOOST_ASSERT(duration_vector.size() + 1 == id_vector.size());
const bool is_first_segment = unpacked_path.empty();
const std::size_t start_index =
(is_first_segment ? ((start_traversed_in_reverse)
? weight_range.size() -
? weight_vector.size() -
phantom_node_pair.source_phantom.fwd_segment_position - 1
: phantom_node_pair.source_phantom.fwd_segment_position)
: 0);
const std::size_t end_index = weight_range.size();
const std::size_t end_index = weight_vector.size();
bool is_left_hand_driving = facade.IsLeftHandDriving(node_id);
@@ -192,23 +197,24 @@ void annotatePath(const FacadeT &facade,
BOOST_ASSERT(start_index < end_index);
for (std::size_t segment_idx = start_index; segment_idx < end_index; ++segment_idx)
{
unpacked_path.push_back(PathData{*node_from,
id_range[segment_idx + 1],
name_index,
is_segregated,
static_cast<EdgeWeight>(weight_range[segment_idx]),
0,
static_cast<EdgeDuration>(duration_range[segment_idx]),
0,
guidance::TurnInstruction::NO_TURN(),
{{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID},
travel_mode,
classes,
EMPTY_ENTRY_CLASS,
datasource_range[segment_idx],
osrm::guidance::TurnBearing(0),
osrm::guidance::TurnBearing(0),
is_left_hand_driving});
unpacked_path.push_back(
PathData{*node_from,
id_vector[segment_idx + 1],
name_index,
is_segregated,
static_cast<EdgeWeight>(weight_vector[segment_idx]),
0,
static_cast<EdgeDuration>(duration_vector[segment_idx]),
0,
guidance::TurnInstruction::NO_TURN(),
{{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID},
travel_mode,
classes,
EMPTY_ENTRY_CLASS,
datasource_vector[segment_idx],
osrm::guidance::TurnBearing(0),
osrm::guidance::TurnBearing(0),
is_left_hand_driving});
}
BOOST_ASSERT(unpacked_path.size() > 0);
if (facade.HasLaneData(turn_id))
@@ -239,9 +245,10 @@ void annotatePath(const FacadeT &facade,
if (is_local_path)
{
start_index =
weight_range.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1;
weight_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1;
}
end_index = weight_range.size() - phantom_node_pair.target_phantom.fwd_segment_position - 1;
end_index =
weight_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position - 1;
}
else
{
@@ -263,23 +270,23 @@ void annotatePath(const FacadeT &facade,
for (std::size_t segment_idx = start_index; segment_idx != end_index;
(start_index < end_index ? ++segment_idx : --segment_idx))
{
BOOST_ASSERT(segment_idx < static_cast<std::size_t>(id_range.size() - 1));
BOOST_ASSERT(segment_idx < static_cast<std::size_t>(id_vector.size() - 1));
BOOST_ASSERT(facade.GetTravelMode(target_node_id) > 0);
unpacked_path.push_back(
PathData{target_node_id,
id_range[start_index < end_index ? segment_idx + 1 : segment_idx - 1],
id_vector[start_index < end_index ? segment_idx + 1 : segment_idx - 1],
facade.GetNameIndex(target_node_id),
facade.IsSegregated(target_node_id),
static_cast<EdgeWeight>(weight_range[segment_idx]),
static_cast<EdgeWeight>(weight_vector[segment_idx]),
0,
static_cast<EdgeDuration>(duration_range[segment_idx]),
static_cast<EdgeDuration>(duration_vector[segment_idx]),
0,
guidance::TurnInstruction::NO_TURN(),
{{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID},
facade.GetTravelMode(target_node_id),
facade.GetClassData(target_node_id),
EMPTY_ENTRY_CLASS,
datasource_range[segment_idx],
datasource_vector[segment_idx],
guidance::TurnBearing(0),
guidance::TurnBearing(0),
is_target_left_hand_driving});
+3 -2
View File
@@ -55,6 +55,7 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl
// FIXME We should change the indexing to Edge-Based-Node id
using DirectionalGeometryID = std::uint32_t;
using SegmentOffset = std::uint32_t;
using SegmentNodeVector = Vector<NodeID>;
using SegmentWeightVector = PackedVector<SegmentWeight, SEGMENT_WEIGHT_BITS>;
using SegmentDurationVector = PackedVector<SegmentDuration, SEGMENT_DURATION_BITS>;
using SegmentDatasourceVector = Vector<DatasourceID>;
@@ -62,7 +63,7 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl
SegmentDataContainerImpl() = default;
SegmentDataContainerImpl(Vector<std::uint32_t> index_,
Vector<NodeID> nodes_,
SegmentNodeVector nodes_,
SegmentWeightVector fwd_weights_,
SegmentWeightVector rev_weights_,
SegmentDurationVector fwd_durations_,
@@ -212,7 +213,7 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl
private:
Vector<std::uint32_t> index;
Vector<NodeID> nodes;
SegmentNodeVector nodes;
SegmentWeightVector fwd_weights;
SegmentWeightVector rev_weights;
SegmentDurationVector fwd_durations;
+4 -2
View File
@@ -31,11 +31,13 @@ namespace util
template <typename DataT>
class VectorViewIterator : public boost::iterator_facade<VectorViewIterator<DataT>,
DataT,
boost::random_access_traversal_tag>
boost::random_access_traversal_tag,
DataT &>
{
typedef boost::iterator_facade<VectorViewIterator<DataT>,
DataT,
boost::random_access_traversal_tag>
boost::random_access_traversal_tag,
DataT &>
base_t;
public: