reserve when possible
This commit is contained in:
		
							parent
							
								
									12ded539aa
								
							
						
					
					
						commit
						f88ac989ea
					
				@ -42,7 +42,8 @@ std::string modeToString(const extractor::TravelMode mode);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
} // namespace detail
 | 
					} // namespace detail
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <unsigned POLYLINE_PRECISION, typename ForwardIter> util::json::String makePolyline(ForwardIter begin, ForwardIter end)
 | 
					template <unsigned POLYLINE_PRECISION, typename ForwardIter>
 | 
				
			||||||
 | 
					util::json::String makePolyline(ForwardIter begin, ForwardIter end)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return {encodePolyline<POLYLINE_PRECISION>(begin, end)};
 | 
					    return {encodePolyline<POLYLINE_PRECISION>(begin, end)};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -196,15 +196,15 @@ class RouteAPI : public BaseAPI
 | 
				
			|||||||
                [this, &leg_geometry](const guidance::RouteStep &step) {
 | 
					                [this, &leg_geometry](const guidance::RouteStep &step) {
 | 
				
			||||||
                    if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
 | 
					                    if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        return static_cast<util::json::Value>(
 | 
					                        return static_cast<util::json::Value>(json::makePolyline<100000>(
 | 
				
			||||||
                            json::makePolyline<100000>(leg_geometry.locations.begin() + step.geometry_begin,
 | 
					                            leg_geometry.locations.begin() + step.geometry_begin,
 | 
				
			||||||
                            leg_geometry.locations.begin() + step.geometry_end));
 | 
					                            leg_geometry.locations.begin() + step.geometry_end));
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (parameters.geometries == RouteParameters::GeometriesType::Polyline6)
 | 
					                    if (parameters.geometries == RouteParameters::GeometriesType::Polyline6)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        return static_cast<util::json::Value>(
 | 
					                        return static_cast<util::json::Value>(json::makePolyline<1000000>(
 | 
				
			||||||
                            json::makePolyline<1000000>(leg_geometry.locations.begin() + step.geometry_begin,
 | 
					                            leg_geometry.locations.begin() + step.geometry_begin,
 | 
				
			||||||
                            leg_geometry.locations.begin() + step.geometry_end));
 | 
					                            leg_geometry.locations.begin() + step.geometry_end));
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -233,7 +233,6 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
 | 
				
			|||||||
                WaypointType::Arrive,
 | 
					                WaypointType::Arrive,
 | 
				
			||||||
                0};
 | 
					                0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    BOOST_ASSERT(!leg_geometry.locations.empty());
 | 
					    BOOST_ASSERT(!leg_geometry.locations.empty());
 | 
				
			||||||
    steps.push_back(RouteStep{target_node.name_id,
 | 
					    steps.push_back(RouteStep{target_node.name_id,
 | 
				
			||||||
                              facade.GetNameForID(target_node.name_id),
 | 
					                              facade.GetNameForID(target_node.name_id),
 | 
				
			||||||
 | 
				
			|||||||
@ -3,8 +3,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "util/coordinate.hpp"
 | 
					#include "util/coordinate.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <boost/assert.hpp>
 | 
					 | 
				
			||||||
#include <algorithm>
 | 
					#include <algorithm>
 | 
				
			||||||
 | 
					#include <boost/assert.hpp>
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -39,7 +39,10 @@ std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter
 | 
				
			|||||||
    int current_lat = 0;
 | 
					    int current_lat = 0;
 | 
				
			||||||
    int current_lon = 0;
 | 
					    int current_lon = 0;
 | 
				
			||||||
    std::for_each(
 | 
					    std::for_each(
 | 
				
			||||||
        begin, end, [&delta_numbers, ¤t_lat, ¤t_lon, coordinate_to_polyline](const util::Coordinate loc) {
 | 
					        begin,
 | 
				
			||||||
 | 
					        end,
 | 
				
			||||||
 | 
					        [&delta_numbers, ¤t_lat, ¤t_lon, coordinate_to_polyline](
 | 
				
			||||||
 | 
					            const util::Coordinate loc) {
 | 
				
			||||||
            const int lat_diff =
 | 
					            const int lat_diff =
 | 
				
			||||||
                std::round(static_cast<int>(loc.lat) * coordinate_to_polyline) - current_lat;
 | 
					                std::round(static_cast<int>(loc.lat) * coordinate_to_polyline) - current_lat;
 | 
				
			||||||
            const int lon_diff =
 | 
					            const int lon_diff =
 | 
				
			||||||
 | 
				
			|||||||
@ -87,7 +87,8 @@ struct LengthLimitedCoordinateAccumulator
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * The SelectRoadByNameOnlyChoiceAndStraightness tries to follow a given name along a route. We offer methods to skip
 | 
					 * The SelectRoadByNameOnlyChoiceAndStraightness tries to follow a given name along a route. We
 | 
				
			||||||
 | 
					 * offer methods to skip
 | 
				
			||||||
 * over bridges/similar situations if desired, following narrow turns
 | 
					 * over bridges/similar situations if desired, following narrow turns
 | 
				
			||||||
 * This struct offers an example implementation of a possible road selector for traversing the
 | 
					 * This struct offers an example implementation of a possible road selector for traversing the
 | 
				
			||||||
 * node-based graph using the NodeBasedGraphWalker
 | 
					 * node-based graph using the NodeBasedGraphWalker
 | 
				
			||||||
@ -115,14 +116,13 @@ struct SelectRoadByNameOnlyChoiceAndStraightness
 | 
				
			|||||||
// find the next intersection given a hop limit
 | 
					// find the next intersection given a hop limit
 | 
				
			||||||
struct IntersectionFinderAccumulator
 | 
					struct IntersectionFinderAccumulator
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    IntersectionFinderAccumulator(const std::uint8_t hop_limit, const IntersectionGenerator &intersection_generator);
 | 
					    IntersectionFinderAccumulator(const std::uint8_t hop_limit,
 | 
				
			||||||
 | 
					                                  const IntersectionGenerator &intersection_generator);
 | 
				
			||||||
    // true if the path has traversed enough distance
 | 
					    // true if the path has traversed enough distance
 | 
				
			||||||
    bool terminate();
 | 
					    bool terminate();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // update the accumulator
 | 
					    // update the accumulator
 | 
				
			||||||
    void update(const NodeID from_node,
 | 
					    void update(const NodeID from_node, const EdgeID via_edge, const NodeID to_node);
 | 
				
			||||||
                const EdgeID via_edge,
 | 
					 | 
				
			||||||
                const NodeID to_node);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::uint8_t hops;
 | 
					    std::uint8_t hops;
 | 
				
			||||||
    const std::uint8_t hop_limit;
 | 
					    const std::uint8_t hop_limit;
 | 
				
			||||||
@ -136,8 +136,6 @@ struct IntersectionFinderAccumulator
 | 
				
			|||||||
    Intersection intersection;
 | 
					    Intersection intersection;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template <class accumulator_type, class selector_type>
 | 
					template <class accumulator_type, class selector_type>
 | 
				
			||||||
boost::optional<std::pair<NodeID, EdgeID>>
 | 
					boost::optional<std::pair<NodeID, EdgeID>>
 | 
				
			||||||
NodeBasedGraphWalker::TraverseRoad(NodeID current_node_id,
 | 
					NodeBasedGraphWalker::TraverseRoad(NodeID current_node_id,
 | 
				
			||||||
 | 
				
			|||||||
@ -25,8 +25,8 @@ inline void print(const engine::guidance::RouteStep &step)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    std::cout << static_cast<int>(step.maneuver.instruction.type) << " "
 | 
					    std::cout << static_cast<int>(step.maneuver.instruction.type) << " "
 | 
				
			||||||
              << static_cast<int>(step.maneuver.instruction.direction_modifier) << "  "
 | 
					              << static_cast<int>(step.maneuver.instruction.direction_modifier) << "  "
 | 
				
			||||||
              << static_cast<int>(step.maneuver.waypoint_type) << " "
 | 
					              << static_cast<int>(step.maneuver.waypoint_type) << " " << step.maneuver.location
 | 
				
			||||||
              << step.maneuver.location << " "
 | 
					              << " "
 | 
				
			||||||
              << " Duration: " << step.duration << " Distance: " << step.distance
 | 
					              << " Duration: " << step.duration << " Distance: " << step.distance
 | 
				
			||||||
              << " Geometry: " << step.geometry_begin << " " << step.geometry_end
 | 
					              << " Geometry: " << step.geometry_begin << " " << step.geometry_end
 | 
				
			||||||
              << "\n\tIntersections: " << step.intersections.size() << " [";
 | 
					              << "\n\tIntersections: " << step.intersections.size() << " [";
 | 
				
			||||||
@ -44,7 +44,8 @@ inline void print(const engine::guidance::RouteStep &step)
 | 
				
			|||||||
            std::cout << " " << (entry ? "true" : "false");
 | 
					            std::cout << " " << (entry ? "true" : "false");
 | 
				
			||||||
        std::cout << ")";
 | 
					        std::cout << ")";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    std::cout << "] name[" << step.name_id << "]: " << step.name << " Ref: " << step.ref << " Pronunciation: " << step.pronunciation;
 | 
					    std::cout << "] name[" << step.name_id << "]: " << step.name << " Ref: " << step.ref
 | 
				
			||||||
 | 
					              << " Pronunciation: " << step.pronunciation;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inline void print(const std::vector<engine::guidance::RouteStep> &steps)
 | 
					inline void print(const std::vector<engine::guidance::RouteStep> &steps)
 | 
				
			||||||
 | 
				
			|||||||
@ -39,6 +39,8 @@ namespace guidance
 | 
				
			|||||||
class BearingClass
 | 
					class BearingClass
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  public:
 | 
					  public:
 | 
				
			||||||
 | 
					    BearingClass();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Add a bearing to the set
 | 
					    // Add a bearing to the set
 | 
				
			||||||
    void add(const DiscreteBearing bearing);
 | 
					    void add(const DiscreteBearing bearing);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -56,6 +56,8 @@ Intersection IntersectionGenerator::GetConnectedRoads(const NodeID from_node,
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    Intersection intersection;
 | 
					    Intersection intersection;
 | 
				
			||||||
    const NodeID turn_node = node_based_graph.GetTarget(via_eid);
 | 
					    const NodeID turn_node = node_based_graph.GetTarget(via_eid);
 | 
				
			||||||
 | 
					    // reserve enough items (+ the possibly missing u-turn edge)
 | 
				
			||||||
 | 
					    intersection.reserve(node_based_graph.GetOutDegree(turn_node) + 1);
 | 
				
			||||||
    const NodeID only_restriction_to_node = [&]() {
 | 
					    const NodeID only_restriction_to_node = [&]() {
 | 
				
			||||||
        // If only restrictions refer to invalid ways somewhere far away, we rather ignore the
 | 
					        // If only restrictions refer to invalid ways somewhere far away, we rather ignore the
 | 
				
			||||||
        // restriction than to not route over the intersection at all.
 | 
					        // restriction than to not route over the intersection at all.
 | 
				
			||||||
 | 
				
			|||||||
@ -215,16 +215,15 @@ operator()(const NodeID, const EdgeID source_edge_id, Intersection intersection)
 | 
				
			|||||||
            const bool is_through_street =
 | 
					            const bool is_through_street =
 | 
				
			||||||
                !target_intersection.empty() && link_data.name_id != EMPTY_NAMEID &&
 | 
					                !target_intersection.empty() && link_data.name_id != EMPTY_NAMEID &&
 | 
				
			||||||
                target_intersection.end() !=
 | 
					                target_intersection.end() !=
 | 
				
			||||||
                    std::find_if(target_intersection.begin() + 1,
 | 
					                    std::find_if(
 | 
				
			||||||
 | 
					                        target_intersection.begin() + 1,
 | 
				
			||||||
                        target_intersection.end(),
 | 
					                        target_intersection.end(),
 | 
				
			||||||
                        [this, &link_data](const ConnectedRoad &road) {
 | 
					                        [this, &link_data](const ConnectedRoad &road) {
 | 
				
			||||||
                                     const auto &road_edge_data =
 | 
					                            const auto &road_edge_data = node_based_graph.GetEdgeData(road.eid);
 | 
				
			||||||
                                         node_based_graph.GetEdgeData(road.eid);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            const auto same_name =
 | 
					                            const auto same_name =
 | 
				
			||||||
                                road_edge_data.name_id != EMPTY_NAMEID &&
 | 
					                                road_edge_data.name_id != EMPTY_NAMEID &&
 | 
				
			||||||
                                         !util::guidance::requiresNameAnnounced(
 | 
					                                !util::guidance::requiresNameAnnounced(road_edge_data.name_id,
 | 
				
			||||||
                                             road_edge_data.name_id,
 | 
					 | 
				
			||||||
                                                                       link_data.name_id,
 | 
					                                                                       link_data.name_id,
 | 
				
			||||||
                                                                       name_table,
 | 
					                                                                       name_table,
 | 
				
			||||||
                                                                       street_name_suffix_table);
 | 
					                                                                       street_name_suffix_table);
 | 
				
			||||||
 | 
				
			|||||||
@ -106,6 +106,7 @@ LaneDataVector laneDataFromDescription(TurnLaneDescription turn_lane_description
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // transform the map into the lane data vector
 | 
					    // transform the map into the lane data vector
 | 
				
			||||||
    LaneDataVector lane_data;
 | 
					    LaneDataVector lane_data;
 | 
				
			||||||
 | 
					    lane_data.reserve(lane_map.size());
 | 
				
			||||||
    for (const auto tag : lane_map)
 | 
					    for (const auto tag : lane_map)
 | 
				
			||||||
        lane_data.push_back({tag.first, tag.second.first, tag.second.second, false});
 | 
					        lane_data.push_back({tag.first, tag.second.first, tag.second.second, false});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -619,6 +619,8 @@ std::pair<LaneDataVector, LaneDataVector> TurnLaneHandler::partitionLaneData(
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    LaneDataVector first, second;
 | 
					    LaneDataVector first, second;
 | 
				
			||||||
 | 
					    first.reserve(turn_lane_data.size());
 | 
				
			||||||
 | 
					    second.reserve(turn_lane_data.size());
 | 
				
			||||||
    for (std::size_t lane = 0; lane < turn_lane_data.size(); ++lane)
 | 
					    for (std::size_t lane = 0; lane < turn_lane_data.size(); ++lane)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (matched_at_second[lane])
 | 
					        if (matched_at_second[lane])
 | 
				
			||||||
 | 
				
			|||||||
@ -11,6 +11,8 @@ namespace util
 | 
				
			|||||||
namespace guidance
 | 
					namespace guidance
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					BearingClass::BearingClass() { available_bearings.reserve(10); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool BearingClass::operator==(const BearingClass &other) const
 | 
					bool BearingClass::operator==(const BearingClass &other) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    BOOST_ASSERT(std::is_sorted(available_bearings.begin(), available_bearings.end()));
 | 
					    BOOST_ASSERT(std::is_sorted(available_bearings.begin(), available_bearings.end()));
 | 
				
			||||||
 | 
				
			|||||||
@ -65,7 +65,6 @@ BOOST_AUTO_TEST_CASE(encode)
 | 
				
			|||||||
    BOOST_CHECK_EQUAL(encodedPolyline, polyline);
 | 
					    BOOST_CHECK_EQUAL(encodedPolyline, polyline);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
BOOST_AUTO_TEST_CASE(encode6)
 | 
					BOOST_AUTO_TEST_CASE(encode6)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // Coordinates; these would be the coordinates we give the loc parameter,
 | 
					    // Coordinates; these would be the coordinates we give the loc parameter,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user