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