Commit 8d2fbe22 authored by Xiao Shi's avatar Xiao Shi Committed by Facebook Github Bot

more reordering of methods in preparation for `commutative_hash_combine_*`

Summary: No semantic changes. Reordering, and removal of an unnecessary fwd decl

Reviewed By: nbronson

Differential Revision: D9851048

fbshipit-source-id: dd306435ad2f77e42f74dc29b19ec5d6fe09ae2a
parent 344f704b
......@@ -540,6 +540,21 @@ struct IsAvalanchingHasher<hasher<std::tuple<T1, T2, Ts...>>, K>
: std::true_type {};
namespace hash {
// Simply uses std::hash to hash. Note that std::hash is not guaranteed
// to be a very good hash function; provided std::hash doesn't collide on
// the individual inputs, you are fine, but that won't be true for, say,
// strings or pairs
class StdHasher {
public:
// The standard requires all explicit and partial specializations of std::hash
// supplied by either the standard library or by users to be default
// constructible.
template <typename T>
size_t operator()(const T& t) const noexcept(noexcept(std::hash<T>()(t))) {
return std::hash<T>()(t);
}
};
// This is a general-purpose way to create a single hash from multiple
// hashable objects. hash_combine_generic takes a class Hasher implementing
// hash<T>; hash_combine uses a default hasher StdHasher that uses std::hash.
......@@ -562,12 +577,6 @@ inline uint64_t hash_128_to_64(
return b;
}
// Never used, but gcc demands it.
template <class Hasher>
inline size_t hash_combine_generic(const Hasher&) noexcept {
return 0;
}
template <
class Iter,
class Hash = std::hash<typename std::iterator_traits<Iter>::value_type>>
......@@ -579,12 +588,16 @@ hash_range(Iter begin, Iter end, uint64_t hash = 0, Hash hasher = Hash()) {
return hash;
}
inline uint32_t twang_32from64(uint64_t key) noexcept;
namespace detail {
using c_array_size_t = size_t[];
} // namespace detail
// Never used, but gcc demands it.
template <class Hasher>
inline size_t hash_combine_generic(const Hasher&) noexcept {
return 0;
}
template <class Hasher, typename T, typename... Ts>
size_t hash_combine_generic(
const Hasher& h,
......@@ -603,20 +616,6 @@ size_t hash_combine_generic(
}
}
// Simply uses std::hash to hash. Note that std::hash is not guaranteed
// to be a very good hash function; provided std::hash doesn't collide on
// the individual inputs, you are fine, but that won't be true for, say,
// strings or pairs
class StdHasher {
public:
// The standard requires all explicit and partial specializations of std::hash
// supplied by either the standard library or by users to be default
// constructible.
template <typename T>
size_t operator()(const T& t) const noexcept(noexcept(std::hash<T>()(t))) {
return std::hash<T>()(t);
}
};
template <typename T, typename... Ts>
size_t hash_combine(const T& t, const Ts&... ts) noexcept(
......@@ -624,6 +623,7 @@ size_t hash_combine(const T& t, const Ts&... ts) noexcept(
return hash_combine_generic(StdHasher{}, t, ts...);
}
} // namespace hash
// recursion
template <size_t index, typename... Ts>
struct TupleHasher {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment