From efe6840d0874f1b53271162177cdca19d6079e9c Mon Sep 17 00:00:00 2001 From: Mugr Rex <105881973+mugr1x@users.noreply.github.com> Date: Wed, 22 May 2024 14:58:07 +0200 Subject: [PATCH 1/5] Replace boost::optional with std::optional (#6611) --- CHANGELOG.md | 1 + include/engine/geospatial_query.hpp | 2 + .../routing_algorithms/routing_base_ch.hpp | 2 +- .../routing_algorithms/routing_base_mld.hpp | 2 +- .../intersection/node_based_graph_walker.hpp | 46 +++++++++---------- .../maneuver_override_relation_parser.hpp | 4 +- include/extractor/profile_properties.hpp | 4 +- include/guidance/intersection_handler.hpp | 5 +- include/guidance/sliproad_handler.hpp | 9 ++-- include/guidance/turn_handler.hpp | 7 ++- include/updater/csv_file_parser.hpp | 2 +- include/updater/source.hpp | 9 ++-- include/util/coordinate_calculation.hpp | 8 ++-- include/util/geojson_debug_policies.hpp | 11 ++--- include/util/geojson_debug_policy_toolkit.hpp | 5 +- include/util/query_heap.hpp | 14 +++--- include/util/timezones.hpp | 4 +- .../intersection/node_based_graph_walker.cpp | 6 +-- .../maneuver_override_relation_parser.cpp | 8 ++-- src/guidance/intersection_handler.cpp | 9 ++-- src/guidance/sliproad_handler.cpp | 18 ++++---- src/guidance/turn_handler.cpp | 12 ++--- src/util/coordinate_calculation.cpp | 11 +++-- src/util/geojson_debug_policies.cpp | 8 ++-- src/util/timezones.cpp | 6 +-- 25 files changed, 105 insertions(+), 108 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72cea29b9..8976db51b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - NodeJS: - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - Misc: + - CHANGED: Partial fix migration from boost::optional to std::optional [#6551](https://github.com/Project-OSRM/osrm-backend/issues/6551) - CHANGED: Update Conan Boost version to 1.85.0. [#6868](https://github.com/Project-OSRM/osrm-backend/pull/6868) - FIXED: Fix an error in a RouteParameters AnnotationsType operator overload. [#6646](https://github.com/Project-OSRM/osrm-backend/pull/6646) - ADDED: Add support for "unlimited" to be passed as a value for the default-radius and max-matching-radius flags. [#6599](https://github.com/Project-OSRM/osrm-backend/pull/6599) diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 2fce9c0c9..c4efbcbbb 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -12,6 +12,8 @@ #include "osrm/coordinate.hpp" +#include + #include #include #include diff --git a/include/engine/routing_algorithms/routing_base_ch.hpp b/include/engine/routing_algorithms/routing_base_ch.hpp index b3da739de..e2e3b5400 100644 --- a/include/engine/routing_algorithms/routing_base_ch.hpp +++ b/include/engine/routing_algorithms/routing_base_ch.hpp @@ -122,7 +122,7 @@ void routingStep(const DataFacade &facade, const EdgeWeight new_weight = reverseHeapNode->weight + heapNode.weight; if (new_weight < upper_bound) { - if (shouldForceStep(force_step_nodes, heapNode, reverseHeapNode.get()) || + if (shouldForceStep(force_step_nodes, heapNode, *reverseHeapNode) || // in this case we are looking at a bi-directional way where the source // and target phantom are on the same edge based node new_weight < EdgeWeight{0}) diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index b85ce5496..ca1d1e407 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -408,7 +408,7 @@ void routingStep(const DataFacade &facade, auto reverse_weight = reverseHeapNode->weight; auto path_weight = weight + reverse_weight; - if (!shouldForceStep(force_step_nodes, heapNode, reverseHeapNode.get()) && + if (!shouldForceStep(force_step_nodes, heapNode, *reverseHeapNode) && (path_weight >= EdgeWeight{0}) && (path_weight < path_upper_bound)) { middle_node = heapNode.node; diff --git a/include/extractor/intersection/node_based_graph_walker.hpp b/include/extractor/intersection/node_based_graph_walker.hpp index 869e934bc..f3915ee9f 100644 --- a/include/extractor/intersection/node_based_graph_walker.hpp +++ b/include/extractor/intersection/node_based_graph_walker.hpp @@ -11,8 +11,8 @@ #include "util/typedefs.hpp" #include -#include #include +#include #include namespace osrm::extractor::intersection @@ -42,10 +42,10 @@ class NodeBasedGraphWalker * selector not provinding any further edge to traverse) */ template - boost::optional> TraverseRoad(NodeID starting_at_node_id, - EdgeID following_edge_id, - accumulator_type &accumulator, - const selector_type &selector) const; + std::optional> TraverseRoad(NodeID starting_at_node_id, + EdgeID following_edge_id, + accumulator_type &accumulator, + const selector_type &selector) const; private: const util::NodeBasedDynamicGraph &node_based_graph; @@ -111,11 +111,11 @@ struct SelectRoadByNameOnlyChoiceAndStraightness * traversal. If no such edge is found, return {} is allowed. Usually you want to choose some * form of obious turn to follow. */ - boost::optional operator()(const NodeID nid, - const EdgeID via_edge_id, - const IntersectionView &intersection, - const util::NodeBasedDynamicGraph &node_based_graph, - const EdgeBasedNodeDataContainer &node_data_container) const; + std::optional operator()(const NodeID nid, + const EdgeID via_edge_id, + const IntersectionView &intersection, + const util::NodeBasedDynamicGraph &node_based_graph, + const EdgeBasedNodeDataContainer &node_data_container) const; private: const NameID desired_name_id; @@ -138,11 +138,11 @@ struct SelectStraightmostRoadByNameAndOnlyChoice * traversal. If no such edge is found, return {} is allowed. Usually you want to choose some * form of obious turn to follow. */ - boost::optional operator()(const NodeID nid, - const EdgeID via_edge_id, - const IntersectionView &intersection, - const util::NodeBasedDynamicGraph &node_based_graph, - const EdgeBasedNodeDataContainer &node_data_container) const; + std::optional operator()(const NodeID nid, + const EdgeID via_edge_id, + const IntersectionView &intersection, + const util::NodeBasedDynamicGraph &node_based_graph, + const EdgeBasedNodeDataContainer &node_data_container) const; private: const NameID desired_name_id; @@ -187,7 +187,7 @@ struct IntersectionFinderAccumulator }; template -boost::optional> +std::optional> NodeBasedGraphWalker::TraverseRoad(NodeID current_node_id, EdgeID current_edge_id, accumulator_type &accumulator, @@ -254,19 +254,19 @@ NodeBasedGraphWalker::TraverseRoad(NodeID current_node_id, struct SkipTrafficSignalBarrierRoadSelector { - boost::optional operator()(const NodeID, - const EdgeID, - const IntersectionView &intersection, - const util::NodeBasedDynamicGraph &, - const EdgeBasedNodeDataContainer &) const + std::optional operator()(const NodeID, + const EdgeID, + const IntersectionView &intersection, + const util::NodeBasedDynamicGraph &, + const EdgeBasedNodeDataContainer &) const { if (intersection.isTrafficSignalOrBarrier()) { - return boost::make_optional(intersection[1].eid); + return std::make_optional(intersection[1].eid); } else { - return boost::none; + return std::nullopt; } } }; diff --git a/include/extractor/maneuver_override_relation_parser.hpp b/include/extractor/maneuver_override_relation_parser.hpp index df4b93a3d..c6084ad70 100644 --- a/include/extractor/maneuver_override_relation_parser.hpp +++ b/include/extractor/maneuver_override_relation_parser.hpp @@ -3,7 +3,7 @@ #include "maneuver_override.hpp" -#include +#include #include #include @@ -55,7 +55,7 @@ class ManeuverOverrideRelationParser { public: ManeuverOverrideRelationParser(); - boost::optional TryParse(const osmium::Relation &relation) const; + std::optional TryParse(const osmium::Relation &relation) const; }; } // namespace osrm::extractor diff --git a/include/extractor/profile_properties.hpp b/include/extractor/profile_properties.hpp index 817e7b763..371155b17 100644 --- a/include/extractor/profile_properties.hpp +++ b/include/extractor/profile_properties.hpp @@ -7,11 +7,11 @@ #include #include -#include #include #include #include +#include namespace osrm::extractor { @@ -80,7 +80,7 @@ struct ProfileProperties } // Check if this classes are excludable - boost::optional ClassesAreExcludable(ClassData classes) const + std::optional ClassesAreExcludable(ClassData classes) const { auto iter = std::find(excludable_classes.begin(), excludable_classes.end(), classes); if (iter != excludable_classes.end()) diff --git a/include/guidance/intersection_handler.hpp b/include/guidance/intersection_handler.hpp index b54d82230..5a7068e40 100644 --- a/include/guidance/intersection_handler.hpp +++ b/include/guidance/intersection_handler.hpp @@ -15,11 +15,10 @@ #include #include +#include #include #include -#include - namespace osrm::guidance { @@ -129,7 +128,7 @@ class IntersectionHandler // ^ via // // For this scenario returns intersection at `b` and `b`. - boost::optional + std::optional getNextIntersection(const NodeID at, const EdgeID via) const; bool isSameName(const EdgeID source_edge_id, const EdgeID target_edge_id) const; diff --git a/include/guidance/sliproad_handler.hpp b/include/guidance/sliproad_handler.hpp index a75f70a52..533ac4dcf 100644 --- a/include/guidance/sliproad_handler.hpp +++ b/include/guidance/sliproad_handler.hpp @@ -9,10 +9,9 @@ #include "util/node_based_graph.hpp" +#include #include -#include - namespace osrm::guidance { @@ -43,9 +42,9 @@ class SliproadHandler final : public IntersectionHandler Intersection intersection) const override final; private: - boost::optional getObviousIndexWithSliproads(const EdgeID from, - const Intersection &intersection, - const NodeID at) const; + std::optional getObviousIndexWithSliproads(const EdgeID from, + const Intersection &intersection, + const NodeID at) const; // Next intersection from `start` onto `onto` is too far away for a Siproad scenario bool nextIntersectionIsTooFarAway(const NodeID start, const EdgeID onto) const; diff --git a/include/guidance/turn_handler.hpp b/include/guidance/turn_handler.hpp index d3e25c79a..6a5210992 100644 --- a/include/guidance/turn_handler.hpp +++ b/include/guidance/turn_handler.hpp @@ -11,9 +11,8 @@ #include "util/attributes.hpp" #include "util/node_based_graph.hpp" -#include - #include +#include #include #include @@ -72,7 +71,7 @@ class TurnHandler final : public IntersectionHandler bool hasObvious(const EdgeID &via_edge, const Fork &fork) const; - boost::optional findForkCandidatesByGeometry(Intersection &intersection) const; + std::optional findForkCandidatesByGeometry(Intersection &intersection) const; bool isCompatibleByRoadClass(const Intersection &intersection, const Fork fork) const; @@ -96,7 +95,7 @@ class TurnHandler final : public IntersectionHandler handleDistinctConflict(const EdgeID via_edge, ConnectedRoad &left, ConnectedRoad &right) const; // Classification - boost::optional findFork(const EdgeID via_edge, Intersection &intersection) const; + std::optional findFork(const EdgeID via_edge, Intersection &intersection) const; OSRM_ATTR_WARN_UNUSED Intersection assignLeftTurns(const EdgeID via_edge, diff --git a/include/updater/csv_file_parser.hpp b/include/updater/csv_file_parser.hpp index 1b1bffb92..c8d5d4cde 100644 --- a/include/updater/csv_file_parser.hpp +++ b/include/updater/csv_file_parser.hpp @@ -39,7 +39,7 @@ template struct CSVFilesParser { } - // Operator returns a lambda function that maps input Key to boost::optional. + // Operator returns a lambda function that maps input Key to std::optional. auto operator()(const std::vector &csv_filenames) const { try diff --git a/include/updater/source.hpp b/include/updater/source.hpp index 72bea7f54..852b21216 100644 --- a/include/updater/source.hpp +++ b/include/updater/source.hpp @@ -3,8 +3,7 @@ #include "util/typedefs.hpp" -#include - +#include #include namespace osrm::updater @@ -12,9 +11,9 @@ namespace osrm::updater template struct LookupTable { - boost::optional operator()(const Key &key) const + std::optional operator()(const Key &key) const { - using Result = boost::optional; + using Result = std::optional; const auto it = std::lower_bound(lookup.begin(), lookup.end(), @@ -50,7 +49,7 @@ struct SpeedSource final { SpeedSource() : speed(0.), rate() {} double speed; - boost::optional rate; + std::optional rate; std::uint8_t source; }; diff --git a/include/util/coordinate_calculation.hpp b/include/util/coordinate_calculation.hpp index 6a716ffaf..1013555ed 100644 --- a/include/util/coordinate_calculation.hpp +++ b/include/util/coordinate_calculation.hpp @@ -4,11 +4,11 @@ #include "util/coordinate.hpp" #include -#include #include #include #include +#include #include #include @@ -109,9 +109,9 @@ double bearing(const Coordinate first_coordinate, const Coordinate second_coordi double computeAngle(const Coordinate first, const Coordinate second, const Coordinate third); // find the center of a circle through three coordinates -boost::optional circleCenter(const Coordinate first_coordinate, - const Coordinate second_coordinate, - const Coordinate third_coordinate); +std::optional circleCenter(const Coordinate first_coordinate, + const Coordinate second_coordinate, + const Coordinate third_coordinate); // find the radius of a circle through three coordinates double circleRadius(const Coordinate first_coordinate, diff --git a/include/util/geojson_debug_policies.hpp b/include/util/geojson_debug_policies.hpp index 3a209db0a..0f25badd0 100644 --- a/include/util/geojson_debug_policies.hpp +++ b/include/util/geojson_debug_policies.hpp @@ -1,6 +1,7 @@ #ifndef OSRM_GEOJSON_DEBUG_POLICIES #define OSRM_GEOJSON_DEBUG_POLICIES +#include #include #include "extractor/query_node.hpp" @@ -9,8 +10,6 @@ #include "util/node_based_graph.hpp" #include "util/typedefs.hpp" -#include - namespace osrm::util { @@ -20,7 +19,7 @@ struct NodeIdVectorToLineString // converts a vector of node ids into a linestring geojson feature util::json::Object operator()(const std::vector &node_ids, - const boost::optional &properties = {}) const; + const std::optional &properties = {}) const; const std::vector &node_coordinates; }; @@ -29,7 +28,7 @@ struct CoordinateVectorToLineString { // converts a vector of node ids into a linestring geojson feature util::json::Object operator()(const std::vector &coordinates, - const boost::optional &properties = {}) const; + const std::optional &properties = {}) const; }; struct NodeIdVectorToMultiPoint @@ -38,7 +37,7 @@ struct NodeIdVectorToMultiPoint // converts a vector of node ids into a linestring geojson feature util::json::Object operator()(const std::vector &node_ids, - const boost::optional &properties = {}) const; + const std::optional &properties = {}) const; const std::vector &node_coordinates; }; @@ -47,7 +46,7 @@ struct CoordinateVectorToMultiPoint { // converts a vector of node ids into a linestring geojson feature util::json::Object operator()(const std::vector &coordinates, - const boost::optional &properties = {}) const; + const std::optional &properties = {}) const; }; } // namespace osrm::util diff --git a/include/util/geojson_debug_policy_toolkit.hpp b/include/util/geojson_debug_policy_toolkit.hpp index 62c1019ef..fcddc21a1 100644 --- a/include/util/geojson_debug_policy_toolkit.hpp +++ b/include/util/geojson_debug_policy_toolkit.hpp @@ -7,8 +7,7 @@ #include #include - -#include +#include namespace osrm::util { @@ -84,7 +83,7 @@ struct NodeIdToCoordinate inline util::json::Object makeFeature(std::string type, util::json::Array coordinates, - const boost::optional &properties = {}) + const std::optional &properties = {}) { util::json::Object result; result.values["type"] = "Feature"; diff --git a/include/util/query_heap.hpp b/include/util/query_heap.hpp index 2c27ad745..c9f1fc6c5 100644 --- a/include/util/query_heap.hpp +++ b/include/util/query_heap.hpp @@ -3,12 +3,12 @@ #include #include -#include #include #include #include #include +#include #include #include @@ -290,26 +290,26 @@ class QueryHeap return inserted_nodes[index].node == node; } - boost::optional GetHeapNodeIfWasInserted(const NodeID node) + HeapNode *GetHeapNodeIfWasInserted(const NodeID node) { const auto index = node_index.peek_index(node); if (index >= static_cast(inserted_nodes.size()) || inserted_nodes[index].node != node) { - return {}; + return nullptr; } - return inserted_nodes[index]; + return &inserted_nodes[index]; } - boost::optional GetHeapNodeIfWasInserted(const NodeID node) const + const HeapNode *GetHeapNodeIfWasInserted(const NodeID node) const { const auto index = node_index.peek_index(node); if (index >= static_cast(inserted_nodes.size()) || inserted_nodes[index].node != node) { - return {}; + return nullptr; } - return inserted_nodes[index]; + return &inserted_nodes[index]; } NodeID Min() const diff --git a/include/util/timezones.hpp b/include/util/timezones.hpp index ff6b0bc98..8105aaae4 100644 --- a/include/util/timezones.hpp +++ b/include/util/timezones.hpp @@ -6,11 +6,11 @@ #include #include #include -#include #include #include +#include namespace osrm::updater { @@ -34,7 +34,7 @@ class Timezoner Timezoner(const char geojson[], std::time_t utc_time_now); Timezoner(const boost::filesystem::path &tz_shapes_filename, std::time_t utc_time_now); - boost::optional operator()(const point_t &point) const; + std::optional operator()(const point_t &point) const; private: void LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t utc_time); diff --git a/src/extractor/intersection/node_based_graph_walker.cpp b/src/extractor/intersection/node_based_graph_walker.cpp index 3f3b67fb9..c1ee0fc64 100644 --- a/src/extractor/intersection/node_based_graph_walker.cpp +++ b/src/extractor/intersection/node_based_graph_walker.cpp @@ -66,7 +66,7 @@ SelectRoadByNameOnlyChoiceAndStraightness::SelectRoadByNameOnlyChoiceAndStraight { } -boost::optional SelectRoadByNameOnlyChoiceAndStraightness::operator()( +std::optional SelectRoadByNameOnlyChoiceAndStraightness::operator()( const NodeID /*nid*/, const EdgeID /*via_edge_id*/, const IntersectionView &intersection, @@ -118,7 +118,7 @@ SelectStraightmostRoadByNameAndOnlyChoice::SelectStraightmostRoadByNameAndOnlyCh { } -boost::optional SelectStraightmostRoadByNameAndOnlyChoice::operator()( +std::optional SelectStraightmostRoadByNameAndOnlyChoice::operator()( const NodeID /*nid*/, const EdgeID /*via_edge_id*/, const IntersectionView &intersection, @@ -241,7 +241,7 @@ boost::optional SelectStraightmostRoadByNameAndOnlyChoice::operator()( return {}; } - return is_only_choice_with_same_name ? boost::optional(min_element->eid) : boost::none; + return is_only_choice_with_same_name ? std::optional(min_element->eid) : std::nullopt; } // --------------------------------------------------------------------------------- diff --git a/src/extractor/maneuver_override_relation_parser.cpp b/src/extractor/maneuver_override_relation_parser.cpp index 737edf670..a0fcb2d1a 100644 --- a/src/extractor/maneuver_override_relation_parser.cpp +++ b/src/extractor/maneuver_override_relation_parser.cpp @@ -1,9 +1,9 @@ #include "extractor/maneuver_override_relation_parser.hpp" #include "extractor/maneuver_override.hpp" -#include #include +#include #include #include #include @@ -21,7 +21,7 @@ ManeuverOverrideRelationParser::ManeuverOverrideRelationParser() {} * into an InputManeuverOverride object, if the relation is considered * valid (i.e. has the minimum tags we expect). */ -boost::optional +std::optional ManeuverOverrideRelationParser::TryParse(const osmium::Relation &relation) const { @@ -35,7 +35,7 @@ ManeuverOverrideRelationParser::TryParse(const osmium::Relation &relation) const if (osmium::tags::match_none_of(tag_list, filter)) // if it's not a maneuver, continue; { - return boost::none; + return std::nullopt; } // we pretend every restriction is a conditional restriction. If we do not find any restriction, @@ -130,7 +130,7 @@ ManeuverOverrideRelationParser::TryParse(const osmium::Relation &relation) const } else { - return boost::none; + return std::nullopt; } return maneuver_override; } diff --git a/src/guidance/intersection_handler.cpp b/src/guidance/intersection_handler.cpp index 5fe6bc21a..b11597d5f 100644 --- a/src/guidance/intersection_handler.cpp +++ b/src/guidance/intersection_handler.cpp @@ -427,7 +427,7 @@ void IntersectionHandler::assignTrivialTurns(const EdgeID via_eid, } } -boost::optional +std::optional IntersectionHandler::getNextIntersection(const NodeID at, const EdgeID via) const { // We use the intersection generator to jump over traffic signals, barriers. The intersection @@ -450,7 +450,7 @@ IntersectionHandler::getNextIntersection(const NodeID at, const EdgeID via) cons if (intersection_parameters.node == SPECIAL_NODEID || intersection_parameters.edge == SPECIAL_EDGEID) { - return boost::none; + return std::nullopt; } auto intersection = extractor::intersection::getConnectedRoads(node_based_graph, @@ -465,11 +465,10 @@ IntersectionHandler::getNextIntersection(const NodeID at, const EdgeID via) cons if (intersection.size() <= 2 || intersection.isTrafficSignalOrBarrier()) { - return boost::none; + return std::nullopt; } - return boost::make_optional( - IntersectionViewAndNode{std::move(intersection), intersection_node}); + return std::make_optional(IntersectionViewAndNode{std::move(intersection), intersection_node}); } bool IntersectionHandler::isSameName(const EdgeID source_edge_id, const EdgeID target_edge_id) const diff --git a/src/guidance/sliproad_handler.cpp b/src/guidance/sliproad_handler.cpp index 5339ed6c6..90a92801f 100644 --- a/src/guidance/sliproad_handler.cpp +++ b/src/guidance/sliproad_handler.cpp @@ -634,7 +634,7 @@ Intersection SliproadHandler::operator()(const NodeID /*nid*/, // Implementation details -boost::optional SliproadHandler::getObviousIndexWithSliproads( +std::optional SliproadHandler::getObviousIndexWithSliproads( const EdgeID from, const Intersection &intersection, const NodeID at) const { BOOST_ASSERT(from != SPECIAL_EDGEID); @@ -645,14 +645,14 @@ boost::optional SliproadHandler::getObviousIndexWithSliproads( if (index != 0) { - return boost::make_optional(index); + return std::make_optional(index); } // Otherwise check if the road is forking into two and one of them is a Sliproad; // then the non-Sliproad is the obvious one. if (intersection.size() != 3) { - return boost::none; + return std::nullopt; } const auto forking = intersection[1].instruction.type == TurnType::Fork && @@ -660,7 +660,7 @@ boost::optional SliproadHandler::getObviousIndexWithSliproads( if (!forking) { - return boost::none; + return std::nullopt; } const auto first = getNextIntersection(at, intersection.getRightmostRoad().eid); @@ -668,27 +668,27 @@ boost::optional SliproadHandler::getObviousIndexWithSliproads( if (!first || !second) { - return boost::none; + return std::nullopt; } if (first->intersection.isDeadEnd() || second->intersection.isDeadEnd()) { - return boost::none; + return std::nullopt; } // In case of loops at the end of the road, we will arrive back at the intersection // itself. If that is the case, the road is obviously not a sliproad. if (canBeTargetOfSliproad(first->intersection) && at != second->node) { - return boost::make_optional(std::size_t{2}); + return std::make_optional(std::size_t{2}); } if (canBeTargetOfSliproad(second->intersection) && at != first->node) { - return boost::make_optional(std::size_t{1}); + return std::make_optional(std::size_t{1}); } - return boost::none; + return std::nullopt; } bool SliproadHandler::nextIntersectionIsTooFarAway(const NodeID start, const EdgeID onto) const diff --git a/src/guidance/turn_handler.cpp b/src/guidance/turn_handler.cpp index ec77b6356..0a7724360 100644 --- a/src/guidance/turn_handler.cpp +++ b/src/guidance/turn_handler.cpp @@ -6,10 +6,10 @@ #include #include +#include #include #include -#include using osrm::util::angularDeviation; @@ -590,7 +590,7 @@ Intersection TurnHandler::assignRightTurns(const EdgeID via_edge, } // finds a fork candidate by just looking at the geometry and angle of an intersection -boost::optional +std::optional TurnHandler::findForkCandidatesByGeometry(Intersection &intersection) const { if (intersection.size() >= 3) @@ -647,7 +647,7 @@ TurnHandler::findForkCandidatesByGeometry(Intersection &intersection) const } } } - return boost::none; + return std::nullopt; } // check if the fork candidates (all roads between left and right) and the @@ -695,8 +695,8 @@ bool TurnHandler::isCompatibleByRoadClass(const Intersection &intersection, cons // Checks whether a three-way-intersection coming from `via_edge` is a fork // with `intersection` as described as in #IntersectionExplanation@intersection_handler.hpp -boost::optional TurnHandler::findFork(const EdgeID via_edge, - Intersection &intersection) const +std::optional TurnHandler::findFork(const EdgeID via_edge, + Intersection &intersection) const { auto fork = findForkCandidatesByGeometry(intersection); if (fork) @@ -740,7 +740,7 @@ boost::optional TurnHandler::findFork(const EdgeID via_edge, } } - return boost::none; + return std::nullopt; } void TurnHandler::handleDistinctConflict(const EdgeID via_edge, diff --git a/src/util/coordinate_calculation.cpp b/src/util/coordinate_calculation.cpp index 70a0d2cb4..00c5efbf5 100644 --- a/src/util/coordinate_calculation.cpp +++ b/src/util/coordinate_calculation.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace osrm::util::coordinate_calculation @@ -173,14 +174,14 @@ double computeAngle(const Coordinate first, const Coordinate second, const Coord return angle; } -boost::optional +std::optional circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3) { // free after http://paulbourke.net/geometry/circlesphere/ // require three distinct points if (C1 == C2 || C2 == C3 || C1 == C3) { - return boost::none; + return std::nullopt; } // define line through c1, c2 and c2,c3 @@ -195,7 +196,7 @@ circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3) (std::abs(C2C1_lat) < std::numeric_limits::epsilon() && std::abs(C3C2_lat) < std::numeric_limits::epsilon())) { - return boost::none; + return std::nullopt; } else if (std::abs(C2C1_lon) < std::numeric_limits::epsilon()) { @@ -233,7 +234,7 @@ circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3) // can this ever happen? if (std::abs(C2C1_slope - C3C2_slope) < std::numeric_limits::epsilon()) - return boost::none; + return std::nullopt; const double C1_y = static_cast(toFloating(C1.lat)); const double C1_x = static_cast(toFloating(C1.lon)); @@ -247,7 +248,7 @@ circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3) (2 * (C3C2_slope - C2C1_slope)); const double lat = (0.5 * (C1_x + C2_x) - lon) / C2C1_slope + 0.5 * (C1_y + C2_y); if (lon < -180.0 || lon > 180.0 || lat < -90.0 || lat > 90.0) - return boost::none; + return std::nullopt; else return Coordinate(FloatLongitude{lon}, FloatLatitude{lat}); } diff --git a/src/util/geojson_debug_policies.cpp b/src/util/geojson_debug_policies.cpp index afdba87ab..9fd2ad60d 100644 --- a/src/util/geojson_debug_policies.cpp +++ b/src/util/geojson_debug_policies.cpp @@ -17,7 +17,7 @@ NodeIdVectorToLineString::NodeIdVectorToLineString( // converts a vector of node ids into a linestring geojson feature util::json::Object NodeIdVectorToLineString::operator()(const std::vector &node_ids, - const boost::optional &properties) const + const std::optional &properties) const { util::json::Array coordinates; std::transform(node_ids.begin(), @@ -37,7 +37,7 @@ NodeIdVectorToMultiPoint::NodeIdVectorToMultiPoint( util::json::Object NodeIdVectorToMultiPoint::operator()(const std::vector &node_ids, - const boost::optional &properties) const + const std::optional &properties) const { util::json::Array coordinates; std::transform(node_ids.begin(), @@ -51,7 +51,7 @@ NodeIdVectorToMultiPoint::operator()(const std::vector &node_ids, //---------------------------------------------------------------- util::json::Object CoordinateVectorToMultiPoint::operator()(const std::vector &input_coordinates, - const boost::optional &properties) const + const std::optional &properties) const { auto coordinates = makeJsonArray(input_coordinates); return makeFeature("MultiPoint", std::move(coordinates), properties); @@ -60,7 +60,7 @@ CoordinateVectorToMultiPoint::operator()(const std::vector &in //---------------------------------------------------------------- util::json::Object CoordinateVectorToLineString::operator()(const std::vector &input_coordinates, - const boost::optional &properties) const + const std::optional &properties) const { auto coordinates = makeJsonArray(input_coordinates); return makeFeature("LineString", std::move(coordinates), properties); diff --git a/src/util/timezones.cpp b/src/util/timezones.cpp index 3f478eff3..3fd527d69 100644 --- a/src/util/timezones.cpp +++ b/src/util/timezones.cpp @@ -5,13 +5,13 @@ #include #include -#include #include #include #include #include +#include #include #include #include @@ -158,7 +158,7 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut rtree = rtree_t(polygons); } -boost::optional Timezoner::operator()(const point_t &point) const +std::optional Timezoner::operator()(const point_t &point) const { std::vector result; rtree.query(boost::geometry::index::intersects(point), std::back_inserter(result)); @@ -168,6 +168,6 @@ boost::optional Timezoner::operator()(const point_t &point) const if (boost::geometry::within(point, local_times[index].first)) return local_times[index].second; } - return boost::none; + return std::nullopt; } } // namespace osrm::updater From 73fb53cf3678ad9d801624a5b94bf45baf3fd30a Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Thu, 23 May 2024 14:27:43 +0200 Subject: [PATCH 2/5] Add benchmark for route (#6890) --- scripts/ci/run_benchmarks.sh | 2 + src/benchmarks/CMakeLists.txt | 15 ++- src/benchmarks/route.cpp | 166 ++++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 src/benchmarks/route.cpp diff --git a/scripts/ci/run_benchmarks.sh b/scripts/ci/run_benchmarks.sh index 94cf57a57..6aea4e089 100755 --- a/scripts/ci/run_benchmarks.sh +++ b/scripts/ci/run_benchmarks.sh @@ -13,6 +13,8 @@ function run_benchmarks_for_folder { ./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench" ./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench" + ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/route_mld.bench" || true # TODO: remove `true` when this benchmark will be merged to master + ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/route_ch.bench" || true # TODO: remove `true` when this benchmark will be merged to master ./$BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench" ./$BENCHMARKS_FOLDER/json-render-bench "./$FOLDER/src/benchmarks/portugal_to_korea.json" > "$RESULTS_FOLDER/json-render.bench" ./$BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench" diff --git a/src/benchmarks/CMakeLists.txt b/src/benchmarks/CMakeLists.txt index 233445c4b..86353dbbf 100644 --- a/src/benchmarks/CMakeLists.txt +++ b/src/benchmarks/CMakeLists.txt @@ -30,6 +30,18 @@ target_link_libraries(match-bench ${TBB_LIBRARIES} ${MAYBE_SHAPEFILE}) +add_executable(route-bench + EXCLUDE_FROM_ALL + route.cpp + $) + +target_link_libraries(route-bench + osrm + ${BOOST_BASE_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${TBB_LIBRARIES} + ${MAYBE_SHAPEFILE}) + add_executable(json-render-bench EXCLUDE_FROM_ALL json_render.cpp @@ -72,5 +84,6 @@ add_custom_target(benchmarks rtree-bench packedvector-bench match-bench + route-bench json-render-bench - alias-bench) + alias-bench) diff --git a/src/benchmarks/route.cpp b/src/benchmarks/route.cpp new file mode 100644 index 000000000..ea95d06fb --- /dev/null +++ b/src/benchmarks/route.cpp @@ -0,0 +1,166 @@ +#include "engine/engine_config.hpp" +#include "util/coordinate.hpp" +#include "util/timing_util.hpp" + +#include "osrm/route_parameters.hpp" + +#include "osrm/coordinate.hpp" +#include "osrm/engine_config.hpp" +#include "osrm/json_container.hpp" + +#include "osrm/osrm.hpp" +#include "osrm/status.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, const char *argv[]) +try +{ + if (argc < 2) + { + std::cerr << "Usage: " << argv[0] << " data.osrm\n"; + return EXIT_FAILURE; + } + + using namespace osrm; + + // Configure based on a .osrm base path, and no datasets in shared mem from osrm-datastore + EngineConfig config; + config.storage_config = {argv[1]}; + config.algorithm = (argc > 2 && std::string{argv[2]} == "mld") ? EngineConfig::Algorithm::MLD + : EngineConfig::Algorithm::CH; + config.use_shared_memory = false; + + // Routing machine with several services (such as Route, Table, Nearest, Trip, Match) + OSRM osrm{config}; + + struct Benchmark + { + std::string name; + std::vector coordinates; + RouteParameters::OverviewType overview; + bool steps = false; + std::optional alternatives = std::nullopt; + std::optional radius = std::nullopt; + }; + + auto run_benchmark = [&](const Benchmark &benchmark) + { + RouteParameters params; + params.overview = benchmark.overview; + params.steps = benchmark.steps; + params.coordinates = benchmark.coordinates; + if (benchmark.alternatives) + { + params.alternatives = *benchmark.alternatives; + } + + if (benchmark.radius) + { + params.radiuses = std::vector>( + params.coordinates.size(), boost::make_optional(*benchmark.radius)); + } + + TIMER_START(routes); + auto NUM = 1000; + for (int i = 0; i < NUM; ++i) + { + engine::api::ResultT result = json::Object(); + const auto rc = osrm.Route(params, result); + auto &json_result = result.get(); + if (rc != Status::Ok || json_result.values.find("routes") == json_result.values.end()) + { + throw std::runtime_error{"Couldn't route"}; + } + } + TIMER_STOP(routes); + std::cout << benchmark.name << std::endl; + std::cout << TIMER_MSEC(routes) << "ms" << std::endl; + std::cout << TIMER_MSEC(routes) / NUM << "ms/req" << std::endl; + }; + + std::vector benchmarks = { + {"1000 routes, 3 coordinates, no alternatives, overview=full, steps=true", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::Full, + true, + std::nullopt}, + {"1000 routes, 2 coordinates, no alternatives, overview=full, steps=true", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::Full, + true, + std::nullopt}, + {"1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::Full, + true, + 3}, + {"1000 routes, 3 coordinates, no alternatives, overview=false, steps=false", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + std::nullopt}, + {"1000 routes, 2 coordinates, no alternatives, overview=false, steps=false", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + std::nullopt}, + {"1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + 3}, + {"1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + std::nullopt, + 750}, + {"1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + std::nullopt, + 750}, + {"1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + 3, + 750} + + }; + + for (const auto &benchmark : benchmarks) + { + run_benchmark(benchmark); + } + + return EXIT_SUCCESS; +} +catch (const std::exception &e) +{ + std::cerr << "Error: " << e.what() << std::endl; + return EXIT_FAILURE; +} From 46dc660801d5974c03f8f9422e339ee0b1a24804 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 23 May 2024 14:35:56 +0200 Subject: [PATCH 3/5] Replace boost::hash by std::hash (#6892) * Replace boost::hash by std::hash * Fix formatting * Update CHANGELOG.md --- CHANGELOG.md | 1 + include/extractor/extractor_callbacks.hpp | 23 +-------- include/extractor/maneuver_override.hpp | 13 ++--- include/extractor/traffic_signals.hpp | 6 +-- include/extractor/turn_lane_types.hpp | 17 +----- include/util/guidance/bearing_class.hpp | 12 +++-- include/util/guidance/turn_lanes.hpp | 60 ++++++++++------------ include/util/std_hash.hpp | 40 ++++++++++++++- include/util/trigonometry_table.hpp | 1 - src/extractor/edge_based_graph_factory.cpp | 1 - src/extractor/extraction_containers.cpp | 4 +- src/updater/updater.cpp | 20 +------- third_party/vtzero/test/mvt-fixtures | 1 - unit_tests/util/bearing.cpp | 1 - unit_tests/util/static_rtree.cpp | 18 +------ unit_tests/util/viewport.cpp | 1 - 16 files changed, 93 insertions(+), 126 deletions(-) delete mode 160000 third_party/vtzero/test/mvt-fixtures diff --git a/CHANGELOG.md b/CHANGELOG.md index 8976db51b..1db4de437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - NodeJS: - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - Misc: + - CHANGED: Replace boost::hash by std::hash [#6892](https://github.com/Project-OSRM/osrm-backend/pull/6892) - CHANGED: Partial fix migration from boost::optional to std::optional [#6551](https://github.com/Project-OSRM/osrm-backend/issues/6551) - CHANGED: Update Conan Boost version to 1.85.0. [#6868](https://github.com/Project-OSRM/osrm-backend/pull/6868) - FIXED: Fix an error in a RouteParameters AnnotationsType operator overload. [#6646](https://github.com/Project-OSRM/osrm-backend/pull/6646) diff --git a/include/extractor/extractor_callbacks.hpp b/include/extractor/extractor_callbacks.hpp index 69f53ab2b..83672f549 100644 --- a/include/extractor/extractor_callbacks.hpp +++ b/include/extractor/extractor_callbacks.hpp @@ -3,11 +3,9 @@ #include "extractor/class_data.hpp" #include "extractor/turn_lane_types.hpp" +#include "util/std_hash.hpp" #include "util/typedefs.hpp" -#include -#include - #include #include @@ -18,25 +16,6 @@ class Way; class Relation; } // namespace osmium -namespace std -{ -template <> struct hash> -{ - std::size_t operator()( - const std::tuple &mk) - const noexcept - { - std::size_t seed = 0; - boost::hash_combine(seed, std::get<0>(mk)); - boost::hash_combine(seed, std::get<1>(mk)); - boost::hash_combine(seed, std::get<2>(mk)); - boost::hash_combine(seed, std::get<3>(mk)); - boost::hash_combine(seed, std::get<4>(mk)); - return seed; - } -}; -} // namespace std - namespace osrm::extractor { diff --git a/include/extractor/maneuver_override.hpp b/include/extractor/maneuver_override.hpp index db647359b..49668f2c1 100644 --- a/include/extractor/maneuver_override.hpp +++ b/include/extractor/maneuver_override.hpp @@ -8,11 +8,13 @@ #include "turn_path.hpp" #include "util/integer_range.hpp" #include "util/log.hpp" +#include "util/std_hash.hpp" #include "util/vector_view.hpp" -#include -#include + #include +#include + namespace osrm::extractor { @@ -147,7 +149,6 @@ struct UnresolvedManeuverOverride namespace std { template <> struct hash - { using argument_type = osrm::extractor::NodeBasedTurn; using result_type = std::size_t; @@ -155,9 +156,9 @@ template <> struct hash { std::size_t seed = 0; - boost::hash_combine(seed, s.from); - boost::hash_combine(seed, s.via); - boost::hash_combine(seed, s.to); + hash_combine(seed, s.from); + hash_combine(seed, s.via); + hash_combine(seed, s.to); return seed; } diff --git a/include/extractor/traffic_signals.hpp b/include/extractor/traffic_signals.hpp index 739b57bcb..febb5d25d 100644 --- a/include/extractor/traffic_signals.hpp +++ b/include/extractor/traffic_signals.hpp @@ -1,10 +1,11 @@ #ifndef OSRM_EXTRACTOR_TRAFFIC_SIGNALS_HPP #define OSRM_EXTRACTOR_TRAFFIC_SIGNALS_HPP +#include "util/std_hash.hpp" #include "util/typedefs.hpp" -#include #include +#include namespace osrm::extractor { @@ -12,8 +13,7 @@ namespace osrm::extractor struct TrafficSignals { std::unordered_set bidirectional_nodes; - std::unordered_set, boost::hash>> - unidirectional_segments; + std::unordered_set> unidirectional_segments; inline bool HasSignal(NodeID from, NodeID to) const { diff --git a/include/extractor/turn_lane_types.hpp b/include/extractor/turn_lane_types.hpp index 275b6365c..88a124f54 100644 --- a/include/extractor/turn_lane_types.hpp +++ b/include/extractor/turn_lane_types.hpp @@ -3,10 +3,9 @@ #include "util/concurrent_id_map.hpp" #include "util/integer_range.hpp" +#include "util/std_hash.hpp" #include "util/typedefs.hpp" -#include - #include #include #include @@ -54,19 +53,7 @@ const constexpr Mask merge_to_right = 1u << 10u; using TurnLaneDescription = std::vector; -// hash function for TurnLaneDescription -struct TurnLaneDescription_hash -{ - std::size_t operator()(const TurnLaneDescription &lane_description) const - { - std::size_t seed = 0; - boost::hash_range(seed, lane_description.begin(), lane_description.end()); - return seed; - } -}; - -using LaneDescriptionMap = - util::ConcurrentIDMap; +using LaneDescriptionMap = util::ConcurrentIDMap; using TurnLanesIndexedArray = std::tuple, std::vector>; diff --git a/include/util/guidance/bearing_class.hpp b/include/util/guidance/bearing_class.hpp index 9274a305c..1e5fce1eb 100644 --- a/include/util/guidance/bearing_class.hpp +++ b/include/util/guidance/bearing_class.hpp @@ -1,15 +1,14 @@ #ifndef OSRM_UTIL_GUIDANCE_BEARING_CLASS_HPP_ #define OSRM_UTIL_GUIDANCE_BEARING_CLASS_HPP_ +#include "util/std_hash.hpp" +#include "util/typedefs.hpp" + #include #include #include #include -#include - -#include "util/typedefs.hpp" - namespace osrm::util::guidance { class BearingClass; @@ -62,7 +61,10 @@ namespace std inline size_t hash<::osrm::util::guidance::BearingClass>::operator()( const ::osrm::util::guidance::BearingClass &bearing_class) const { - return boost::hash_value(bearing_class.available_bearings); + std::size_t value = 0; + hash_range( + value, bearing_class.available_bearings.cbegin(), bearing_class.available_bearings.cend()); + return value; } } // namespace std diff --git a/include/util/guidance/turn_lanes.hpp b/include/util/guidance/turn_lanes.hpp index c19a5086c..21126ee16 100644 --- a/include/util/guidance/turn_lanes.hpp +++ b/include/util/guidance/turn_lanes.hpp @@ -1,36 +1,22 @@ #ifndef OSRM_UTIL_GUIDANCE_TURN_LANES_HPP #define OSRM_UTIL_GUIDANCE_TURN_LANES_HPP +#include "util/concurrent_id_map.hpp" +#include "util/std_hash.hpp" +#include "util/typedefs.hpp" + #include #include #include #include #include -#include "util/concurrent_id_map.hpp" -#include "util/typedefs.hpp" - -#include - namespace osrm::util::guidance { class LaneTuple; class LaneTupleIdPair; } // namespace osrm::util::guidance -namespace std -{ -template <> struct hash<::osrm::util::guidance::LaneTuple> -{ - inline std::size_t operator()(const ::osrm::util::guidance::LaneTuple &bearing_class) const; -}; -template <> struct hash<::osrm::util::guidance::LaneTupleIdPair> -{ - inline std::size_t - operator()(const ::osrm::util::guidance::LaneTupleIdPair &bearing_class) const; -}; -} // namespace std - namespace osrm::util::guidance { @@ -61,14 +47,6 @@ class LaneTuple LaneID lanes_in_turn; LaneID first_lane_from_the_right; // is INVALID_LANEID when no lanes present - - friend std::size_t hash_value(const LaneTuple &tup) - { - std::size_t seed{0}; - boost::hash_combine(seed, tup.lanes_in_turn); - boost::hash_combine(seed, tup.first_lane_from_the_right); - return seed; - } }; class LaneTupleIdPair @@ -78,18 +56,36 @@ class LaneTupleIdPair LaneDescriptionID second; bool operator==(const LaneTupleIdPair &other) const; +}; - friend std::size_t hash_value(const LaneTupleIdPair &pair) +using LaneDataIdMap = ConcurrentIDMap; + +} // namespace osrm::util::guidance + +namespace std +{ +template <> struct hash<::osrm::util::guidance::LaneTuple> +{ + inline std::size_t operator()(const ::osrm::util::guidance::LaneTuple &lane_tuple) const { std::size_t seed{0}; - boost::hash_combine(seed, pair.first); - boost::hash_combine(seed, pair.second); + hash_combine(seed, lane_tuple.lanes_in_turn); + hash_combine(seed, lane_tuple.first_lane_from_the_right); return seed; } }; -using LaneDataIdMap = ConcurrentIDMap>; - -} // namespace osrm::util::guidance +template <> struct hash<::osrm::util::guidance::LaneTupleIdPair> +{ + inline std::size_t + operator()(const ::osrm::util::guidance::LaneTupleIdPair &lane_tuple_id_pair) const + { + std::size_t seed{0}; + hash_combine(seed, lane_tuple_id_pair.first); + hash_combine(seed, lane_tuple_id_pair.second); + return seed; + } +}; +} // namespace std #endif /* OSRM_UTIL_GUIDANCE_TURN_LANES_HPP */ diff --git a/include/util/std_hash.hpp b/include/util/std_hash.hpp index 16bf278dc..4f64f940d 100644 --- a/include/util/std_hash.hpp +++ b/include/util/std_hash.hpp @@ -1,7 +1,11 @@ #ifndef STD_HASH_HPP #define STD_HASH_HPP +#include #include +#include +#include +#include // this is largely inspired by boost's hash combine as can be found in // "The C++ Standard Library" 2nd Edition. Nicolai M. Josuttis. 2012. @@ -11,6 +15,14 @@ template void hash_combine(std::size_t &seed, const T &val) seed ^= std::hash()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } +template void hash_range(std::size_t &seed, It first, const It last) +{ + for (; first != last; ++first) + { + hash_combine(seed, *first); + } +} + template void hash_val(std::size_t &seed, const T &val) { hash_combine(seed, val); } template @@ -29,13 +41,39 @@ template std::size_t hash_val(const Types &...args) namespace std { +template struct hash> +{ + template + static auto apply_tuple(const std::tuple &t, std::index_sequence) + { + std::size_t seed = 0; + return ((seed = hash_val(std::get(t), seed)), ...); + } + + auto operator()(const std::tuple &t) const + { + return apply_tuple(t, std::make_index_sequence()); + } +}; + template struct hash> { - size_t operator()(const std::pair &pair) const + std::size_t operator()(const std::pair &pair) const { return hash_val(pair.first, pair.second); } }; + +template struct hash> +{ + auto operator()(const std::vector &lane_description) const + { + std::size_t seed = 0; + hash_range(seed, lane_description.begin(), lane_description.end()); + return seed; + } +}; + } // namespace std #endif // STD_HASH_HPP diff --git a/include/util/trigonometry_table.hpp b/include/util/trigonometry_table.hpp index eedfe59a5..412674960 100644 --- a/include/util/trigonometry_table.hpp +++ b/include/util/trigonometry_table.hpp @@ -364,7 +364,6 @@ const constexpr double SCALING_FACTOR = 4. / boost::math::constants::pi( inline double atan2_lookup(double y, double x) { - using namespace boost::math::constants; if (std::abs(x) < std::numeric_limits::epsilon()) diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index a84fdbebe..bc50a031e 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -19,7 +19,6 @@ #include "util/timing_util.hpp" #include -#include #include #include diff --git a/src/extractor/extraction_containers.cpp b/src/extractor/extraction_containers.cpp index bea449390..eed6a3c43 100644 --- a/src/extractor/extraction_containers.cpp +++ b/src/extractor/extraction_containers.cpp @@ -13,6 +13,7 @@ #include "util/for_each_indexed.hpp" #include "util/for_each_pair.hpp" #include "util/log.hpp" +#include "util/std_hash.hpp" #include "util/timing_util.hpp" #include @@ -955,8 +956,7 @@ void ExtractionContainers::PrepareTrafficSignals( TIMER_START(prepare_traffic_signals); std::unordered_set bidirectional; - std::unordered_set, boost::hash>> - unidirectional; + std::unordered_set> unidirectional; for (const auto &osm_node : bidirectional_signal_nodes) { diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index d467675df..e82f854f8 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -18,6 +18,7 @@ #include "util/mmap_tar.hpp" #include "util/opening_hours.hpp" #include "util/static_rtree.hpp" +#include "util/std_hash.hpp" #include "util/string_util.hpp" #include "util/timezones.hpp" #include "util/timing_util.hpp" @@ -42,25 +43,6 @@ #include #include -namespace std -{ -template struct hash> -{ - size_t operator()(const std::tuple &t) const - { - return hash_val(std::get<0>(t), std::get<1>(t), std::get<2>(t)); - } -}; - -template struct hash> -{ - size_t operator()(const std::tuple &t) const - { - return hash_val(std::get<0>(t), std::get<1>(t)); - } -}; -} // namespace std - namespace osrm::updater { namespace diff --git a/third_party/vtzero/test/mvt-fixtures b/third_party/vtzero/test/mvt-fixtures deleted file mode 160000 index a351144a7..000000000 --- a/third_party/vtzero/test/mvt-fixtures +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a351144a7aa6ca4b826295cd4454cd4ce3a6f71f diff --git a/unit_tests/util/bearing.cpp b/unit_tests/util/bearing.cpp index 797b36c34..9643f46c8 100644 --- a/unit_tests/util/bearing.cpp +++ b/unit_tests/util/bearing.cpp @@ -1,7 +1,6 @@ #include "util/bearing.hpp" #include "util/typedefs.hpp" -#include #include BOOST_AUTO_TEST_SUITE(bearing_test) diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index 812202d38..2557a2df9 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -5,12 +5,12 @@ #include "util/coordinate_calculation.hpp" #include "util/exception.hpp" #include "util/rectangle.hpp" +#include "util/std_hash.hpp" #include "util/typedefs.hpp" #include "../common/temporary_file.hpp" #include "mocks/mock_datafacade.hpp" -#include #include #include @@ -91,20 +91,6 @@ template class LinearSearchNN template struct RandomGraphFixture { - struct TupleHash - { - using argument_type = std::pair; - using result_type = std::size_t; - - result_type operator()(const argument_type &t) const - { - std::size_t val{0}; - boost::hash_combine(val, t.first); - boost::hash_combine(val, t.second); - return val; - } - }; - RandomGraphFixture() { std::mt19937 g(RANDOM_SEED); @@ -121,7 +107,7 @@ template struct RandomGraphFixture std::uniform_int_distribution<> edge_udist(0, coords.size() - 1); - std::unordered_set, TupleHash> used_edges; + std::unordered_set> used_edges; while (edges.size() < NUM_EDGES) { diff --git a/unit_tests/util/viewport.cpp b/unit_tests/util/viewport.cpp index 3ec1dff39..70a2003af 100644 --- a/unit_tests/util/viewport.cpp +++ b/unit_tests/util/viewport.cpp @@ -2,7 +2,6 @@ using namespace osrm::util; -#include #include #include From ed5003b502ea9ef9f6cdf7abdbfdd946897ff422 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 23 May 2024 14:40:47 +0200 Subject: [PATCH 4/5] Upgrade CI actions to latest versions (#6893) * Upgrade actions * Update remaining actions * Update CHANGELOG.md * Update CHANGELOG.md --- .github/workflows/osrm-backend.yml | 46 +++++++++++++++--------------- CHANGELOG.md | 1 + 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index 3b8242153..ed0407f68 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -31,11 +31,11 @@ jobs: env: BUILD_TYPE: Release steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: pip install "conan<2.0.0" - run: conan --version - run: cmake --version - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: 18 - run: node --version @@ -47,7 +47,7 @@ jobs: echo PUBLISH=$([[ "${GITHUB_REF:-}" == "refs/tags/v${PACKAGE_JSON_VERSION}" ]] && echo "On" || echo "Off") >> $GITHUB_ENV - run: npm install --ignore-scripts - run: npm link --ignore-scripts - - uses: microsoft/setup-msbuild@v1.1 + - uses: microsoft/setup-msbuild@v2 - name: Build run: | .\scripts\ci\windows-build.bat @@ -76,13 +76,13 @@ jobs: format-taginfo-docs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18 - name: Enable Node.js cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} @@ -106,9 +106,9 @@ jobs: continue-on-error: false steps: - name: Check out the repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Enable osm.pbf cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: berlin-latest.osm.pbf key: v1-berlin-osm-pbf @@ -342,36 +342,36 @@ jobs: OSRM_CONNECTION_RETRIES: ${{ matrix.OSRM_CONNECTION_RETRIES }} OSRM_CONNECTION_EXP_BACKOFF_COEF: ${{ matrix.OSRM_CONNECTION_EXP_BACKOFF_COEF }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build machine architecture run: uname -m - name: Use Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - name: Enable Node.js cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - name: Enable compiler cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.ccache key: ccache-${{ matrix.name }}-${{ github.sha }} restore-keys: | ccache-${{ matrix.name }}- - name: Enable Conan cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.conan key: v9-conan-${{ matrix.name }}-${{ github.sha }} restore-keys: | v9-conan-${{ matrix.name }}- - name: Enable test cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{github.workspace}}/test/cache key: v4-test-${{ matrix.name }}-${{ github.sha }} @@ -511,7 +511,7 @@ jobs: - name: Use Node 18 if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18 - name: Run Node package tests on Node 18 @@ -521,7 +521,7 @@ jobs: npm run nodejs-tests - name: Use Node 20 if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 20 - name: Run Node package tests on Node 20 @@ -531,7 +531,7 @@ jobs: npm run nodejs-tests - name: Use Node latest if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: latest - name: Run Node package tests on Node-latest @@ -541,7 +541,7 @@ jobs: npm run nodejs-tests - name: Upload test logs - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() with: name: logs @@ -557,7 +557,7 @@ jobs: # # Uploading report to CodeCov # - name: Upload code coverage # if: ${{ matrix.ENABLE_COVERAGE == 'ON' }} - # uses: codecov/codecov-action@v1 + # uses: codecov/codecov-action@v4 # with: # files: coverage.info # name: codecov-osrm-backend @@ -595,21 +595,21 @@ jobs: GITHUB_REPOSITORY: ${{ github.repository }} steps: - name: Enable compiler cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.ccache key: v1-ccache-benchmarks-${{ github.sha }} restore-keys: | v1-ccache-benchmarks- - name: Enable Conan cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.conan key: v1-conan-benchmarks-${{ github.sha }} restore-keys: | v1-conan-benchmarks- - name: Checkout PR Branch - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} path: pr @@ -624,7 +624,7 @@ jobs: cd .. make -C test/data - name: Checkout Base Branch - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.base.ref }} path: base diff --git a/CHANGELOG.md b/CHANGELOG.md index 1db4de437..302b7cc9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - ADDED: Add support for opposite approach request parameter. [#6842](https://github.com/Project-OSRM/osrm-backend/pull/6842) - ADDED: Add support for accessing edge flags in `process_segment` [#6658](https://github.com/Project-OSRM/osrm-backend/pull/6658) - Build: + - CHANGED: Upgrade CI actions to latest versions [#6893](https://github.com/Project-OSRM/osrm-backend/pull/6893) - ADDED: Add CI job which builds OSRM with gcc 12. [#6455](https://github.com/Project-OSRM/osrm-backend/pull/6455) - CHANGED: Upgrade to clang-tidy 15. [#6439](https://github.com/Project-OSRM/osrm-backend/pull/6439) - CHANGED: Update actions/cache to v3. [#6420](https://github.com/Project-OSRM/osrm-backend/pull/6420) From 51b74a99aa5a7f04693455e4fb758feb4f939b73 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 23 May 2024 18:51:51 +0200 Subject: [PATCH 5/5] Avoid copy of std::function-based callback in path unpacking (#6895) * Avoid copy of std::function-based callback in path unpacking * Fix formatting * Update CHANGELOG.md --- CHANGELOG.md | 1 + include/engine/datafacade/algorithm_datafacade.hpp | 2 +- .../datafacade/contiguous_internalmem_datafacade.hpp | 7 ++++--- unit_tests/mocks/mock_datafacade.hpp | 7 ++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 302b7cc9a..daa7c1d5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - NodeJS: - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - Misc: + - CHANGED: Avoid copy of std::function-based callback in path unpacking [#6895](https://github.com/Project-OSRM/osrm-backend/pull/6895) - CHANGED: Replace boost::hash by std::hash [#6892](https://github.com/Project-OSRM/osrm-backend/pull/6892) - CHANGED: Partial fix migration from boost::optional to std::optional [#6551](https://github.com/Project-OSRM/osrm-backend/issues/6551) - CHANGED: Update Conan Boost version to 1.85.0. [#6868](https://github.com/Project-OSRM/osrm-backend/pull/6868) diff --git a/include/engine/datafacade/algorithm_datafacade.hpp b/include/engine/datafacade/algorithm_datafacade.hpp index 7965784bc..192d024fc 100644 --- a/include/engine/datafacade/algorithm_datafacade.hpp +++ b/include/engine/datafacade/algorithm_datafacade.hpp @@ -55,7 +55,7 @@ template <> class AlgorithmDataFacade virtual EdgeID FindSmallestEdge(const NodeID edge_based_node_from, const NodeID edge_based_node_to, - const std::function filter) const = 0; + const std::function &filter) const = 0; }; template <> class AlgorithmDataFacade diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index ac9497eb0..b6e1532d3 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -130,9 +130,10 @@ class ContiguousInternalMemoryAlgorithmDataFacade : public datafacade::Algor edge_based_node_from, edge_based_node_to, result); } - EdgeID FindSmallestEdge(const NodeID edge_based_node_from, - const NodeID edge_based_node_to, - std::function filter) const override final + EdgeID + FindSmallestEdge(const NodeID edge_based_node_from, + const NodeID edge_based_node_to, + const std::function &filter) const override final { return m_query_graph.FindSmallestEdge(edge_based_node_from, edge_based_node_to, filter); } diff --git a/unit_tests/mocks/mock_datafacade.hpp b/unit_tests/mocks/mock_datafacade.hpp index a0de5a245..dc2541713 100644 --- a/unit_tests/mocks/mock_datafacade.hpp +++ b/unit_tests/mocks/mock_datafacade.hpp @@ -238,9 +238,10 @@ class MockAlgorithmDataFacade return SPECIAL_EDGEID; } - EdgeID FindSmallestEdge(const NodeID /* from */, - const NodeID /* to */, - std::function /* filter */) const override + EdgeID + FindSmallestEdge(const NodeID /* from */, + const NodeID /* to */, + const std::function & /* filter */) const override { return SPECIAL_EDGEID; }