Skip to content

Commit 46dc660

Browse files
authored
Replace boost::hash by std::hash (#6892)
* Replace boost::hash by std::hash * Fix formatting * Update CHANGELOG.md
1 parent 73fb53c commit 46dc660

16 files changed

+93
-126
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- NodeJS:
2020
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
2121
- Misc:
22+
- CHANGED: Replace boost::hash by std::hash [#6892](https://github.com/Project-OSRM/osrm-backend/pull/6892)
2223
- CHANGED: Partial fix migration from boost::optional to std::optional [#6551](https://github.com/Project-OSRM/osrm-backend/issues/6551)
2324
- CHANGED: Update Conan Boost version to 1.85.0. [#6868](https://github.com/Project-OSRM/osrm-backend/pull/6868)
2425
- FIXED: Fix an error in a RouteParameters AnnotationsType operator overload. [#6646](https://github.com/Project-OSRM/osrm-backend/pull/6646)

include/extractor/extractor_callbacks.hpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33

44
#include "extractor/class_data.hpp"
55
#include "extractor/turn_lane_types.hpp"
6+
#include "util/std_hash.hpp"
67
#include "util/typedefs.hpp"
78

8-
#include <boost/functional/hash.hpp>
9-
#include <boost/optional/optional_fwd.hpp>
10-
119
#include <string>
1210
#include <unordered_map>
1311

@@ -18,25 +16,6 @@ class Way;
1816
class Relation;
1917
} // namespace osmium
2018

21-
namespace std
22-
{
23-
template <> struct hash<std::tuple<std::string, std::string, std::string, std::string, std::string>>
24-
{
25-
std::size_t operator()(
26-
const std::tuple<std::string, std::string, std::string, std::string, std::string> &mk)
27-
const noexcept
28-
{
29-
std::size_t seed = 0;
30-
boost::hash_combine(seed, std::get<0>(mk));
31-
boost::hash_combine(seed, std::get<1>(mk));
32-
boost::hash_combine(seed, std::get<2>(mk));
33-
boost::hash_combine(seed, std::get<3>(mk));
34-
boost::hash_combine(seed, std::get<4>(mk));
35-
return seed;
36-
}
37-
};
38-
} // namespace std
39-
4019
namespace osrm::extractor
4120
{
4221

include/extractor/maneuver_override.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
#include "turn_path.hpp"
99
#include "util/integer_range.hpp"
1010
#include "util/log.hpp"
11+
#include "util/std_hash.hpp"
1112
#include "util/vector_view.hpp"
12-
#include <algorithm>
13-
#include <boost/functional/hash.hpp>
13+
1414
#include <mapbox/variant.hpp>
1515

16+
#include <algorithm>
17+
1618
namespace osrm::extractor
1719
{
1820

@@ -147,17 +149,16 @@ struct UnresolvedManeuverOverride
147149
namespace std
148150
{
149151
template <> struct hash<osrm::extractor::NodeBasedTurn>
150-
151152
{
152153
using argument_type = osrm::extractor::NodeBasedTurn;
153154
using result_type = std::size_t;
154155
result_type operator()(argument_type const &s) const noexcept
155156
{
156157

157158
std::size_t seed = 0;
158-
boost::hash_combine(seed, s.from);
159-
boost::hash_combine(seed, s.via);
160-
boost::hash_combine(seed, s.to);
159+
hash_combine(seed, s.from);
160+
hash_combine(seed, s.via);
161+
hash_combine(seed, s.to);
161162

162163
return seed;
163164
}

include/extractor/traffic_signals.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#ifndef OSRM_EXTRACTOR_TRAFFIC_SIGNALS_HPP
22
#define OSRM_EXTRACTOR_TRAFFIC_SIGNALS_HPP
33

4+
#include "util/std_hash.hpp"
45
#include "util/typedefs.hpp"
56

6-
#include <boost/functional/hash.hpp>
77
#include <unordered_set>
8+
#include <utility>
89

910
namespace osrm::extractor
1011
{
1112

1213
struct TrafficSignals
1314
{
1415
std::unordered_set<NodeID> bidirectional_nodes;
15-
std::unordered_set<std::pair<NodeID, NodeID>, boost::hash<std::pair<NodeID, NodeID>>>
16-
unidirectional_segments;
16+
std::unordered_set<std::pair<NodeID, NodeID>> unidirectional_segments;
1717

1818
inline bool HasSignal(NodeID from, NodeID to) const
1919
{

include/extractor/turn_lane_types.hpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
#include "util/concurrent_id_map.hpp"
55
#include "util/integer_range.hpp"
6+
#include "util/std_hash.hpp"
67
#include "util/typedefs.hpp"
78

8-
#include <boost/functional/hash.hpp>
9-
109
#include <bitset>
1110
#include <cstddef>
1211
#include <cstdint>
@@ -54,19 +53,7 @@ const constexpr Mask merge_to_right = 1u << 10u;
5453

5554
using TurnLaneDescription = std::vector<TurnLaneType::Mask>;
5655

57-
// hash function for TurnLaneDescription
58-
struct TurnLaneDescription_hash
59-
{
60-
std::size_t operator()(const TurnLaneDescription &lane_description) const
61-
{
62-
std::size_t seed = 0;
63-
boost::hash_range(seed, lane_description.begin(), lane_description.end());
64-
return seed;
65-
}
66-
};
67-
68-
using LaneDescriptionMap =
69-
util::ConcurrentIDMap<TurnLaneDescription, LaneDescriptionID, TurnLaneDescription_hash>;
56+
using LaneDescriptionMap = util::ConcurrentIDMap<TurnLaneDescription, LaneDescriptionID>;
7057

7158
using TurnLanesIndexedArray =
7259
std::tuple<std::vector<std::uint32_t>, std::vector<TurnLaneType::Mask>>;

include/util/guidance/bearing_class.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#ifndef OSRM_UTIL_GUIDANCE_BEARING_CLASS_HPP_
22
#define OSRM_UTIL_GUIDANCE_BEARING_CLASS_HPP_
33

4+
#include "util/std_hash.hpp"
5+
#include "util/typedefs.hpp"
6+
47
#include <cstddef>
58
#include <cstdint>
69
#include <functional>
710
#include <vector>
811

9-
#include <boost/functional/hash.hpp>
10-
11-
#include "util/typedefs.hpp"
12-
1312
namespace osrm::util::guidance
1413
{
1514
class BearingClass;
@@ -62,7 +61,10 @@ namespace std
6261
inline size_t hash<::osrm::util::guidance::BearingClass>::operator()(
6362
const ::osrm::util::guidance::BearingClass &bearing_class) const
6463
{
65-
return boost::hash_value(bearing_class.available_bearings);
64+
std::size_t value = 0;
65+
hash_range(
66+
value, bearing_class.available_bearings.cbegin(), bearing_class.available_bearings.cend());
67+
return value;
6668
}
6769
} // namespace std
6870

include/util/guidance/turn_lanes.hpp

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
11
#ifndef OSRM_UTIL_GUIDANCE_TURN_LANES_HPP
22
#define OSRM_UTIL_GUIDANCE_TURN_LANES_HPP
33

4+
#include "util/concurrent_id_map.hpp"
5+
#include "util/std_hash.hpp"
6+
#include "util/typedefs.hpp"
7+
48
#include <cstddef>
59
#include <cstdint>
610
#include <functional>
711
#include <unordered_map>
812
#include <vector>
913

10-
#include "util/concurrent_id_map.hpp"
11-
#include "util/typedefs.hpp"
12-
13-
#include <boost/functional/hash.hpp>
14-
1514
namespace osrm::util::guidance
1615
{
1716
class LaneTuple;
1817
class LaneTupleIdPair;
1918
} // namespace osrm::util::guidance
2019

21-
namespace std
22-
{
23-
template <> struct hash<::osrm::util::guidance::LaneTuple>
24-
{
25-
inline std::size_t operator()(const ::osrm::util::guidance::LaneTuple &bearing_class) const;
26-
};
27-
template <> struct hash<::osrm::util::guidance::LaneTupleIdPair>
28-
{
29-
inline std::size_t
30-
operator()(const ::osrm::util::guidance::LaneTupleIdPair &bearing_class) const;
31-
};
32-
} // namespace std
33-
3420
namespace osrm::util::guidance
3521
{
3622

@@ -61,14 +47,6 @@ class LaneTuple
6147

6248
LaneID lanes_in_turn;
6349
LaneID first_lane_from_the_right; // is INVALID_LANEID when no lanes present
64-
65-
friend std::size_t hash_value(const LaneTuple &tup)
66-
{
67-
std::size_t seed{0};
68-
boost::hash_combine(seed, tup.lanes_in_turn);
69-
boost::hash_combine(seed, tup.first_lane_from_the_right);
70-
return seed;
71-
}
7250
};
7351

7452
class LaneTupleIdPair
@@ -78,18 +56,36 @@ class LaneTupleIdPair
7856
LaneDescriptionID second;
7957

8058
bool operator==(const LaneTupleIdPair &other) const;
59+
};
60+
61+
using LaneDataIdMap = ConcurrentIDMap<LaneTupleIdPair, LaneDataID>;
62+
63+
} // namespace osrm::util::guidance
8164

82-
friend std::size_t hash_value(const LaneTupleIdPair &pair)
65+
namespace std
66+
{
67+
template <> struct hash<::osrm::util::guidance::LaneTuple>
68+
{
69+
inline std::size_t operator()(const ::osrm::util::guidance::LaneTuple &lane_tuple) const
8370
{
8471
std::size_t seed{0};
85-
boost::hash_combine(seed, pair.first);
86-
boost::hash_combine(seed, pair.second);
72+
hash_combine(seed, lane_tuple.lanes_in_turn);
73+
hash_combine(seed, lane_tuple.first_lane_from_the_right);
8774
return seed;
8875
}
8976
};
9077

91-
using LaneDataIdMap = ConcurrentIDMap<LaneTupleIdPair, LaneDataID, boost::hash<LaneTupleIdPair>>;
92-
93-
} // namespace osrm::util::guidance
78+
template <> struct hash<::osrm::util::guidance::LaneTupleIdPair>
79+
{
80+
inline std::size_t
81+
operator()(const ::osrm::util::guidance::LaneTupleIdPair &lane_tuple_id_pair) const
82+
{
83+
std::size_t seed{0};
84+
hash_combine(seed, lane_tuple_id_pair.first);
85+
hash_combine(seed, lane_tuple_id_pair.second);
86+
return seed;
87+
}
88+
};
89+
} // namespace std
9490

9591
#endif /* OSRM_UTIL_GUIDANCE_TURN_LANES_HPP */

include/util/std_hash.hpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#ifndef STD_HASH_HPP
22
#define STD_HASH_HPP
33

4+
#include <cstddef>
45
#include <functional>
6+
#include <tuple>
7+
#include <utility>
8+
#include <vector>
59

610
// this is largely inspired by boost's hash combine as can be found in
711
// "The C++ Standard Library" 2nd Edition. Nicolai M. Josuttis. 2012.
@@ -11,6 +15,14 @@ template <typename T> void hash_combine(std::size_t &seed, const T &val)
1115
seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1216
}
1317

18+
template <typename It> void hash_range(std::size_t &seed, It first, const It last)
19+
{
20+
for (; first != last; ++first)
21+
{
22+
hash_combine(seed, *first);
23+
}
24+
}
25+
1426
template <typename T> void hash_val(std::size_t &seed, const T &val) { hash_combine(seed, val); }
1527

1628
template <typename T, typename... Types>
@@ -29,13 +41,39 @@ template <typename... Types> std::size_t hash_val(const Types &...args)
2941

3042
namespace std
3143
{
44+
template <typename... T> struct hash<std::tuple<T...>>
45+
{
46+
template <std::size_t... I>
47+
static auto apply_tuple(const std::tuple<T...> &t, std::index_sequence<I...>)
48+
{
49+
std::size_t seed = 0;
50+
return ((seed = hash_val(std::get<I>(t), seed)), ...);
51+
}
52+
53+
auto operator()(const std::tuple<T...> &t) const
54+
{
55+
return apply_tuple(t, std::make_index_sequence<sizeof...(T)>());
56+
}
57+
};
58+
3259
template <typename T1, typename T2> struct hash<std::pair<T1, T2>>
3360
{
34-
size_t operator()(const std::pair<T1, T2> &pair) const
61+
std::size_t operator()(const std::pair<T1, T2> &pair) const
3562
{
3663
return hash_val(pair.first, pair.second);
3764
}
3865
};
66+
67+
template <typename T> struct hash<std::vector<T>>
68+
{
69+
auto operator()(const std::vector<T> &lane_description) const
70+
{
71+
std::size_t seed = 0;
72+
hash_range(seed, lane_description.begin(), lane_description.end());
73+
return seed;
74+
}
75+
};
76+
3977
} // namespace std
4078

4179
#endif // STD_HASH_HPP

include/util/trigonometry_table.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ const constexpr double SCALING_FACTOR = 4. / boost::math::constants::pi<double>(
364364

365365
inline double atan2_lookup(double y, double x)
366366
{
367-
368367
using namespace boost::math::constants;
369368

370369
if (std::abs(x) < std::numeric_limits<double>::epsilon())

src/extractor/edge_based_graph_factory.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "util/timing_util.hpp"
2020

2121
#include <boost/assert.hpp>
22-
#include <boost/functional/hash.hpp>
2322
#include <boost/numeric/conversion/cast.hpp>
2423

2524
#include <algorithm>

0 commit comments

Comments
 (0)