diff --git a/include/engine/api/nearest_api.hpp b/include/engine/api/nearest_api.hpp index 4aca90d7c..8793af6ca 100644 --- a/include/engine/api/nearest_api.hpp +++ b/include/engine/api/nearest_api.hpp @@ -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(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(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(osm_node_id); } nodes.values.push_back(from_node); diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index b84df9d24..4ec640324 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -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); } diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index dea7abd9d..beb71674e 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -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 #include #include @@ -51,12 +54,21 @@ class BaseDataFacade public: using RTreeLeaf = extractor::EdgeBasedNodeSegment; - template - using RangeT = boost::any_range; - using NodesIDRangeT = RangeT; - using WeightsRangeT = RangeT; - using DurationsRangeT = RangeT; - using DatasourceIDRangeT = RangeT; + using NodeForwardRange = + boost::iterator_range; + using NodeReverseRange = boost::reversed_range; + + using WeightForwardRange = + boost::iterator_range; + using WeightReverseRange = boost::reversed_range; + + using DurationForwardRange = + boost::iterator_range; + using DurationReverseRange = boost::reversed_range; + + using DatasourceForwardRange = + boost::iterator_range; + using DatasourceReverseRange = boost::reversed_range; 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; diff --git a/include/engine/guidance/assemble_geometry.hpp b/include/engine/guidance/assemble_geometry.hpp index c076e349f..eb4f9cf95 100644 --- a/include/engine/guidance/assemble_geometry.hpp +++ b/include/engine/guidance/assemble_geometry.hpp @@ -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()); diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index 139afd117..90e5e73e2 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -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 id_vector; + std::vector weight_vector; + std::vector duration_vector; + std::vector 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(weight_range[segment_idx]), - 0, - static_cast(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(weight_vector[segment_idx]), + 0, + static_cast(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(id_range.size() - 1)); + BOOST_ASSERT(segment_idx < static_cast(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(weight_range[segment_idx]), + static_cast(weight_vector[segment_idx]), 0, - static_cast(duration_range[segment_idx]), + static_cast(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}); diff --git a/include/extractor/segment_data_container.hpp b/include/extractor/segment_data_container.hpp index 7f4f06c51..bb7825000 100644 --- a/include/extractor/segment_data_container.hpp +++ b/include/extractor/segment_data_container.hpp @@ -55,6 +55,7 @@ template 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; using SegmentWeightVector = PackedVector; using SegmentDurationVector = PackedVector; using SegmentDatasourceVector = Vector; @@ -62,7 +63,7 @@ template class SegmentDataContainerImpl SegmentDataContainerImpl() = default; SegmentDataContainerImpl(Vector index_, - Vector nodes_, + SegmentNodeVector nodes_, SegmentWeightVector fwd_weights_, SegmentWeightVector rev_weights_, SegmentDurationVector fwd_durations_, @@ -212,7 +213,7 @@ template class SegmentDataContainerImpl private: Vector index; - Vector nodes; + SegmentNodeVector nodes; SegmentWeightVector fwd_weights; SegmentWeightVector rev_weights; SegmentDurationVector fwd_durations; diff --git a/include/util/vector_view.hpp b/include/util/vector_view.hpp index ae77e19b3..ab6e91fd6 100644 --- a/include/util/vector_view.hpp +++ b/include/util/vector_view.hpp @@ -31,11 +31,13 @@ namespace util template class VectorViewIterator : public boost::iterator_facade, DataT, - boost::random_access_traversal_tag> + boost::random_access_traversal_tag, + DataT &> { typedef boost::iterator_facade, DataT, - boost::random_access_traversal_tag> + boost::random_access_traversal_tag, + DataT &> base_t; public: diff --git a/src/engine/plugins/tile.cpp b/src/engine/plugins/tile.cpp index 8418d62be..46a1493dd 100644 --- a/src/engine/plugins/tile.cpp +++ b/src/engine/plugins/tile.cpp @@ -401,10 +401,10 @@ void encodeVectorTile(const DataFacadeBase &facade, const auto reverse_datasource_range = facade.GetUncompressedReverseDatasources(geometry_id); BOOST_ASSERT(edge.fwd_segment_position < forward_datasource_range.size()); - const auto forward_datasource = forward_datasource_range[edge.fwd_segment_position]; + const auto forward_datasource = forward_datasource_range(edge.fwd_segment_position); BOOST_ASSERT(edge.fwd_segment_position < reverse_datasource_range.size()); - const auto reverse_datasource = reverse_datasource_range[reverse_datasource_range.size() - - edge.fwd_segment_position - 1]; + const auto reverse_datasource = reverse_datasource_range(reverse_datasource_range.size() - + edge.fwd_segment_position - 1); // Keep track of the highest datasource seen so that we don't write unnecessary // data to the layer attribute values @@ -518,10 +518,9 @@ void encodeVectorTile(const DataFacadeBase &facade, edge.fwd_segment_position - 1]; const auto forward_datasource_idx = - forward_datasource_range[edge.fwd_segment_position]; - const auto reverse_datasource_idx = - reverse_datasource_range[reverse_datasource_range.size() - - edge.fwd_segment_position - 1]; + forward_datasource_range(edge.fwd_segment_position); + const auto reverse_datasource_idx = reverse_datasource_range( + reverse_datasource_range.size() - edge.fwd_segment_position - 1); const auto component_id = facade.GetComponentID(edge.forward_segment_id.id); const auto name_id = facade.GetNameIndex(edge.forward_segment_id.id); @@ -925,16 +924,18 @@ void encodeVectorTile(const DataFacadeBase &facade, for (auto edgeNodeID : segregated_nodes) { auto const geomIndex = facade.GetGeometryIndex(edgeNodeID); - DataFacadeBase::NodesIDRangeT geometry; - - if (geomIndex.forward) - geometry = facade.GetUncompressedForwardGeometry(geomIndex.id); - else - geometry = facade.GetUncompressedReverseGeometry(geomIndex.id); std::vector points; - for (auto const nodeID : geometry) - points.push_back(facade.GetCoordinateOfNode(nodeID)); + if (geomIndex.forward) + { + for (auto const nodeID : facade.GetUncompressedForwardGeometry(geomIndex.id)) + points.push_back(facade.GetCoordinateOfNode(nodeID)); + } + else + { + for (auto const nodeID : facade.GetUncompressedReverseGeometry(geomIndex.id)) + points.push_back(facade.GetCoordinateOfNode(nodeID)); + } const auto encode_tile_line = [&line_layer_writer, &id]( const FixedLine &tile_line, std::int32_t &start_x, std::int32_t &start_y) { diff --git a/src/engine/routing_algorithms/tile_turns.cpp b/src/engine/routing_algorithms/tile_turns.cpp index dd204f85f..17ea540e3 100644 --- a/src/engine/routing_algorithms/tile_turns.cpp +++ b/src/engine/routing_algorithms/tile_turns.cpp @@ -101,8 +101,6 @@ std::vector generateTurns(const datafacade &facade, // w // uv is the "approach" // vw is the "exit" - typename datafacade::BaseDataFacade::WeightsRangeT approach_weight_range; - typename datafacade::BaseDataFacade::DurationsRangeT approach_duration_range; // Look at every node in the directed graph we created for (const auto &startnode : sorted_startnodes) @@ -148,30 +146,32 @@ std::vector generateTurns(const datafacade &facade, const auto &data = facade.GetEdgeData(edge_based_edge_id); // Now, calculate the sum of the weight of all the segments. - if (edge_based_node_info.find(approachedge.edge_based_node_id) - ->second.is_geometry_forward) + const auto &geometry = + edge_based_node_info.find(approachedge.edge_based_node_id)->second; + EdgeWeight sum_node_weight = 0; + EdgeDuration sum_node_duration = 0; + if (geometry.is_geometry_forward) { - approach_weight_range = facade.GetUncompressedForwardWeights( - edge_based_node_info.find(approachedge.edge_based_node_id) - ->second.packed_geometry_id); - approach_duration_range = facade.GetUncompressedForwardDurations( - edge_based_node_info.find(approachedge.edge_based_node_id) - ->second.packed_geometry_id); + const auto approach_weight = + facade.GetUncompressedForwardWeights(geometry.packed_geometry_id); + const auto approach_duration = + facade.GetUncompressedForwardDurations(geometry.packed_geometry_id); + sum_node_weight = std::accumulate( + approach_weight.begin(), approach_weight.end(), EdgeWeight{0}); + sum_node_duration = std::accumulate( + approach_duration.begin(), approach_duration.end(), EdgeDuration{0}); } else { - approach_weight_range = facade.GetUncompressedReverseWeights( - edge_based_node_info.find(approachedge.edge_based_node_id) - ->second.packed_geometry_id); - approach_duration_range = facade.GetUncompressedReverseDurations( - edge_based_node_info.find(approachedge.edge_based_node_id) - ->second.packed_geometry_id); + const auto approach_weight = + facade.GetUncompressedReverseWeights(geometry.packed_geometry_id); + const auto approach_duration = + facade.GetUncompressedReverseDurations(geometry.packed_geometry_id); + sum_node_weight = std::accumulate( + approach_weight.begin(), approach_weight.end(), EdgeWeight{0}); + sum_node_duration = std::accumulate( + approach_duration.begin(), approach_duration.end(), EdgeDuration{0}); } - const auto sum_node_weight = std::accumulate( - approach_weight_range.begin(), approach_weight_range.end(), EdgeWeight{0}); - const auto sum_node_duration = std::accumulate(approach_duration_range.begin(), - approach_duration_range.end(), - EdgeWeight{0}); // The edge.weight is the whole edge weight, which includes the turn // cost. diff --git a/unit_tests/engine/offline_facade.cpp b/unit_tests/engine/offline_facade.cpp index ea404de14..d11997a29 100644 --- a/unit_tests/engine/offline_facade.cpp +++ b/unit_tests/engine/offline_facade.cpp @@ -156,9 +156,15 @@ class ContiguousInternalMemoryDataFacade GeometryID GetGeometryIndex(const NodeID /*id*/) const override { return GeometryID{0, false}; } - NodesIDRangeT GetUncompressedForwardGeometry(const EdgeID /*id*/) const override { return {}; } + NodeForwardRange GetUncompressedForwardGeometry(const EdgeID /*id*/) const override + { + return {}; + } - NodesIDRangeT GetUncompressedReverseGeometry(const EdgeID /*id*/) const override { return {}; } + NodeReverseRange GetUncompressedReverseGeometry(const EdgeID /*id*/) const override + { + return NodeReverseRange(NodeForwardRange()); + } TurnPenalty GetWeightPenaltyForEdgeID(const unsigned /*id*/) const override { @@ -170,28 +176,34 @@ class ContiguousInternalMemoryDataFacade return INVALID_TURN_PENALTY; } - WeightsRangeT GetUncompressedForwardWeights(const EdgeID /*id*/) const override { return {}; } - - WeightsRangeT GetUncompressedReverseWeights(const EdgeID /*id*/) const override { return {}; } - - DurationsRangeT GetUncompressedForwardDurations(const EdgeID /*geomID*/) const override + WeightForwardRange GetUncompressedForwardWeights(const EdgeID /*id*/) const override { return {}; } - DurationsRangeT GetUncompressedReverseDurations(const EdgeID /*geomID*/) const override + WeightReverseRange GetUncompressedReverseWeights(const EdgeID /*id*/) const override + { + return WeightReverseRange(WeightForwardRange()); + } + + DurationForwardRange GetUncompressedForwardDurations(const EdgeID /*geomID*/) const override { return {}; } - DatasourceIDRangeT GetUncompressedForwardDatasources(const EdgeID /*id*/) const override + DurationReverseRange GetUncompressedReverseDurations(const EdgeID /*geomID*/) const override + { + return DurationReverseRange(DurationForwardRange()); + } + + DatasourceForwardRange GetUncompressedForwardDatasources(const EdgeID /*id*/) const override { return {}; } - DatasourceIDRangeT GetUncompressedReverseDatasources(const EdgeID /*id*/) const override + DatasourceReverseRange GetUncompressedReverseDatasources(const EdgeID /*id*/) const override { - return {}; + return DatasourceReverseRange(DatasourceForwardRange()); } StringView GetDatasourceName(const DatasourceID /*id*/) const override { return StringView{}; } diff --git a/unit_tests/mocks/mock_datafacade.hpp b/unit_tests/mocks/mock_datafacade.hpp index 23b9393ed..75a864fd8 100644 --- a/unit_tests/mocks/mock_datafacade.hpp +++ b/unit_tests/mocks/mock_datafacade.hpp @@ -54,41 +54,44 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade { return 0; } - NodesIDRangeT GetUncompressedForwardGeometry(const EdgeID /* id */) const override + NodeForwardRange GetUncompressedForwardGeometry(const EdgeID /* id */) const override { return {}; } - NodesIDRangeT GetUncompressedReverseGeometry(const EdgeID /* id */) const override + NodeReverseRange GetUncompressedReverseGeometry(const EdgeID id) const override { - return {}; + return NodeReverseRange(GetUncompressedForwardGeometry(id)); } - WeightsRangeT GetUncompressedForwardWeights(const EdgeID /* id */) const override + WeightForwardRange GetUncompressedForwardWeights(const EdgeID /* id */) const override { - static const std::vector result_weights{1, 2, 3}; - return result_weights; + static std::uint64_t data[] = {1, 2, 3}; + static const extractor::SegmentDataView::SegmentWeightVector weights( + util::vector_view(data, 3), 3); + return WeightForwardRange(weights.begin(), weights.end()); } - WeightsRangeT GetUncompressedReverseWeights(const EdgeID id) const override + WeightReverseRange GetUncompressedReverseWeights(const EdgeID id) const override { - return GetUncompressedForwardWeights(id); + return WeightReverseRange(GetUncompressedForwardWeights(id)); } - DurationsRangeT GetUncompressedForwardDurations(const EdgeID /*id*/) const override + DurationForwardRange GetUncompressedForwardDurations(const EdgeID /*id*/) const override { - static const std::vector data{1, 2, 3}; - return data; + static std::uint64_t data[] = {1, 2, 3}; + static const extractor::SegmentDataView::SegmentDurationVector durations( + util::vector_view(data, 3), 3); + return DurationForwardRange(durations.begin(), durations.end()); } - DurationsRangeT GetUncompressedReverseDurations(const EdgeID /*id*/) const override + DurationReverseRange GetUncompressedReverseDurations(const EdgeID id) const override { - static const std::vector data{1, 2, 3}; - return data; + return DurationReverseRange(GetUncompressedForwardDurations(id)); } - DatasourceIDRangeT GetUncompressedForwardDatasources(const EdgeID /*id*/) const override + DatasourceForwardRange GetUncompressedForwardDatasources(const EdgeID /*id*/) const override { return {}; } - DatasourceIDRangeT GetUncompressedReverseDatasources(const EdgeID /*id*/) const override + DatasourceReverseRange GetUncompressedReverseDatasources(const EdgeID /*id*/) const override { - return {}; + return DatasourceReverseRange(DatasourceForwardRange()); } StringView GetDatasourceName(const DatasourceID) const override final { return {}; } diff --git a/unit_tests/util/packed_vector.cpp b/unit_tests/util/packed_vector.cpp index f75c4a616..56a66f1b2 100644 --- a/unit_tests/util/packed_vector.cpp +++ b/unit_tests/util/packed_vector.cpp @@ -209,22 +209,22 @@ BOOST_AUTO_TEST_CASE(packed_vector_33bit_continious) BOOST_AUTO_TEST_CASE(packed_weights_container_with_type_erasure) { using Vector = PackedVector; - using WeightsRangeT = boost::any_range; + using WeightsAnyRange = boost::any_range; PackedVector 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()); + auto forward_any = WeightsAnyRange(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); + auto reverse_any = WeightsAnyRange(reverse); CHECK_EQUAL_RANGE(reverse, 5, 4, 3, 2, 1); CHECK_EQUAL_RANGE(reverse_any, 5, 4, 3, 2, 1); } @@ -233,21 +233,21 @@ BOOST_AUTO_TEST_CASE(packed_weights_view_with_type_erasure) { using View = PackedVectorView; using PackedDataWord = std::uint64_t; // PackedVectorView<>::WordT - using WeightsRangeT = boost::any_range; + using WeightsAnyRange = boost::any_range; PackedDataWord data[] = {0x200000400000, 0xc, 0}; View view(vector_view(data, 3), 7); auto forward = boost::make_iterator_range(view.begin() + 1, view.begin() + 4); - auto forward_any = WeightsRangeT(forward.begin(), forward.end()); + auto forward_any = WeightsAnyRange(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); + auto reverse_any = WeightsAnyRange(reverse); CHECK_EQUAL_RANGE(reverse, 3, 2, 1); CHECK_EQUAL_RANGE(reverse_any, 3, 2, 1); }