Replace boost::hash by std::hash (#6892)

* Replace boost::hash by std::hash

* Fix formatting

* Update CHANGELOG.md
This commit is contained in:
Dennis Luxen
2024-05-23 14:35:56 +02:00
committed by GitHub
parent 73fb53cf36
commit 46dc660801
16 changed files with 93 additions and 126 deletions
+1 -22
View File
@@ -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 <boost/functional/hash.hpp>
#include <boost/optional/optional_fwd.hpp>
#include <string>
#include <unordered_map>
@@ -18,25 +16,6 @@ class Way;
class Relation;
} // namespace osmium
namespace std
{
template <> struct hash<std::tuple<std::string, std::string, std::string, std::string, std::string>>
{
std::size_t operator()(
const std::tuple<std::string, std::string, std::string, std::string, std::string> &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
{
+7 -6
View File
@@ -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 <algorithm>
#include <boost/functional/hash.hpp>
#include <mapbox/variant.hpp>
#include <algorithm>
namespace osrm::extractor
{
@@ -147,7 +149,6 @@ struct UnresolvedManeuverOverride
namespace std
{
template <> struct hash<osrm::extractor::NodeBasedTurn>
{
using argument_type = osrm::extractor::NodeBasedTurn;
using result_type = std::size_t;
@@ -155,9 +156,9 @@ template <> struct hash<osrm::extractor::NodeBasedTurn>
{
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;
}
+3 -3
View File
@@ -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 <boost/functional/hash.hpp>
#include <unordered_set>
#include <utility>
namespace osrm::extractor
{
@@ -12,8 +13,7 @@ namespace osrm::extractor
struct TrafficSignals
{
std::unordered_set<NodeID> bidirectional_nodes;
std::unordered_set<std::pair<NodeID, NodeID>, boost::hash<std::pair<NodeID, NodeID>>>
unidirectional_segments;
std::unordered_set<std::pair<NodeID, NodeID>> unidirectional_segments;
inline bool HasSignal(NodeID from, NodeID to) const
{
+2 -15
View File
@@ -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 <boost/functional/hash.hpp>
#include <bitset>
#include <cstddef>
#include <cstdint>
@@ -54,19 +53,7 @@ const constexpr Mask merge_to_right = 1u << 10u;
using TurnLaneDescription = std::vector<TurnLaneType::Mask>;
// 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<TurnLaneDescription, LaneDescriptionID, TurnLaneDescription_hash>;
using LaneDescriptionMap = util::ConcurrentIDMap<TurnLaneDescription, LaneDescriptionID>;
using TurnLanesIndexedArray =
std::tuple<std::vector<std::uint32_t>, std::vector<TurnLaneType::Mask>>;
+7 -5
View File
@@ -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 <cstddef>
#include <cstdint>
#include <functional>
#include <vector>
#include <boost/functional/hash.hpp>
#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
+28 -32
View File
@@ -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 <cstddef>
#include <cstdint>
#include <functional>
#include <unordered_map>
#include <vector>
#include "util/concurrent_id_map.hpp"
#include "util/typedefs.hpp"
#include <boost/functional/hash.hpp>
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<LaneTupleIdPair, LaneDataID>;
} // 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<LaneTupleIdPair, LaneDataID, boost::hash<LaneTupleIdPair>>;
} // 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 */
+39 -1
View File
@@ -1,7 +1,11 @@
#ifndef STD_HASH_HPP
#define STD_HASH_HPP
#include <cstddef>
#include <functional>
#include <tuple>
#include <utility>
#include <vector>
// 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 <typename T> void hash_combine(std::size_t &seed, const T &val)
seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template <typename It> void hash_range(std::size_t &seed, It first, const It last)
{
for (; first != last; ++first)
{
hash_combine(seed, *first);
}
}
template <typename T> void hash_val(std::size_t &seed, const T &val) { hash_combine(seed, val); }
template <typename T, typename... Types>
@@ -29,13 +41,39 @@ template <typename... Types> std::size_t hash_val(const Types &...args)
namespace std
{
template <typename... T> struct hash<std::tuple<T...>>
{
template <std::size_t... I>
static auto apply_tuple(const std::tuple<T...> &t, std::index_sequence<I...>)
{
std::size_t seed = 0;
return ((seed = hash_val(std::get<I>(t), seed)), ...);
}
auto operator()(const std::tuple<T...> &t) const
{
return apply_tuple(t, std::make_index_sequence<sizeof...(T)>());
}
};
template <typename T1, typename T2> struct hash<std::pair<T1, T2>>
{
size_t operator()(const std::pair<T1, T2> &pair) const
std::size_t operator()(const std::pair<T1, T2> &pair) const
{
return hash_val(pair.first, pair.second);
}
};
template <typename T> struct hash<std::vector<T>>
{
auto operator()(const std::vector<T> &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
-1
View File
@@ -364,7 +364,6 @@ const constexpr double SCALING_FACTOR = 4. / boost::math::constants::pi<double>(
inline double atan2_lookup(double y, double x)
{
using namespace boost::math::constants;
if (std::abs(x) < std::numeric_limits<double>::epsilon())