1#if !defined(phmap_utils_h_guard_)
2#define phmap_utils_h_guard_
26 #pragma warning(disable : 4514)
27 #pragma warning(disable : 4710)
28 #pragma warning(disable : 4711)
34#include "phmap_bits.h"
39#if defined(PHMAP_USE_ABSL_HASH) && !defined(phmap_fwd_decl_h_guard_) && !defined(ABSL_HASH_HASH_H_)
40 namespace absl {
template <
class T>
struct Hash; };
51 inline size_t operator()(
size_t)
const;
57 inline size_t operator()(
size_t a)
const
59 static constexpr uint64_t kmul = 0xcc9e2d51UL;
61 uint64_t l = a * kmul;
62 return static_cast<size_t>(l ^ (l >> 32));
66#if defined(PHMAP_HAS_UMUL128)
71 inline size_t operator()(
size_t a)
const
73 static constexpr uint64_t k = 0xde5fb9d2630458e9ULL;
76 uint64_t l = umul128(a, k, &h);
77 return static_cast<size_t>(h + l);
84 inline size_t operator()(
size_t a)
const
88 a = (a + (a << 3)) + (a << 8);
90 a = (a + (a << 2)) + (a << 4);
93 return static_cast<size_t>(a);
102 inline size_t operator()(uint64_t)
const;
108 inline size_t operator()(uint64_t a)
const
110 return static_cast<size_t>(a ^ (a >> 32));
117 inline size_t operator()(uint64_t a)
const
119 return static_cast<size_t>(a);
130 typedef std::true_type yes;
131 typedef std::false_type no;
133 template<
typename U>
static auto test(
int) ->
decltype(hash_value(std::declval<const U&>()) == 1, yes());
135 template<
typename>
static no test(...);
138 static constexpr bool value = std::is_same<decltype(test<T>(0)), yes>::value;
141#if defined(PHMAP_USE_ABSL_HASH) && !defined(phmap_fwd_decl_h_guard_)
142 template <
class T>
using Hash = ::absl::Hash<T>;
143#elif !defined(PHMAP_USE_ABSL_HASH)
150 template <class U, typename std::enable_if<has_hash_value<U>::value,
int>::type = 0>
151 size_t _hash(
const T& val)
const
153 return hash_value(val);
156 template <class U, typename std::enable_if<!has_hash_value<U>::value,
int>::type = 0>
157 size_t _hash(
const T& val)
const
159 return std::hash<T>()(val);
162 inline size_t operator()(
const T& val)
const
164 return _hash<T>(val);
171 inline size_t operator()(
const T *val)
const noexcept
173 return static_cast<size_t>(
reinterpret_cast<const uintptr_t
>(val));
177template<
class ArgumentType,
class ResultType>
180 typedef ArgumentType argument_type;
181 typedef ResultType result_type;
187 inline size_t operator()(
bool val)
const noexcept
188 {
return static_cast<size_t>(val); }
194 inline size_t operator()(
char val)
const noexcept
195 {
return static_cast<size_t>(val); }
201 inline size_t operator()(
signed char val)
const noexcept
202 {
return static_cast<size_t>(val); }
208 inline size_t operator()(
unsigned char val)
const noexcept
209 {
return static_cast<size_t>(val); }
215 inline size_t operator()(
wchar_t val)
const noexcept
216 {
return static_cast<size_t>(val); }
222 inline size_t operator()(int16_t val)
const noexcept
223 {
return static_cast<size_t>(val); }
229 inline size_t operator()(uint16_t val)
const noexcept
230 {
return static_cast<size_t>(val); }
236 inline size_t operator()(int32_t val)
const noexcept
237 {
return static_cast<size_t>(val); }
243 inline size_t operator()(uint32_t val)
const noexcept
244 {
return static_cast<size_t>(val); }
250 inline size_t operator()(int64_t val)
const noexcept
257 inline size_t operator()(uint64_t val)
const noexcept
264 inline size_t operator()(
float val)
const noexcept
267 uint32_t *as_int =
reinterpret_cast<uint32_t *
>(&val);
268 return (val == 0) ?
static_cast<size_t>(0) :
269 static_cast<size_t>(*as_int);
276 inline size_t operator()(
double val)
const noexcept
279 uint64_t *as_int =
reinterpret_cast<uint64_t *
>(&val);
280 return (val == 0) ?
static_cast<size_t>(0) :
289 H operator()(H seed,
size_t value);
294 H operator()(H seed,
size_t value)
296 return seed ^ (value + 0x9e3779b9 + (seed << 6) + (seed >> 2));
302 H operator()(H seed,
size_t value)
304 return seed ^ (value + size_t(0xc6a4a7935bd1e995) + (seed << 6) + (seed >> 2));
313 template <
typename T,
typename... Ts>
314 static H combine(H state,
const T& value,
const Ts&... values);
316 static H combine(H state) {
return state; }
320template <
typename T,
typename... Ts>
328using HashState = HashStateBase<size_t>;
332#if !defined(PHMAP_USE_ABSL_HASH)
336template<
class T1,
class T2>
337struct Hash<std::pair<T1, T2>> {
338 size_t operator()(std::pair<T1, T2>
const& p)
const noexcept {
347 size_t operator()(std::tuple<T...>
const& t)
const noexcept {
348 return _hash_helper(t);
352 template<
size_t I = 0,
class ...P>
353 typename std::enable_if<I ==
sizeof...(P),
size_t>::type
354 _hash_helper(
const std::tuple<P...> &)
const noexcept {
return 0; }
356 template<
size_t I = 0,
class ...P>
357 typename std::enable_if<I <
sizeof...(P),
size_t>::type
358 _hash_helper(
const std::tuple<P...> &t)
const noexcept {
359 const auto &el = std::get<I>(t);
360 using el_type =
typename std::remove_cv<
typename std::remove_reference<
decltype(el)>::type>::type;
Definition phmap_utils.h:311
Definition phmap_utils.h:288
Definition phmap_utils.h:149
Definition phmap_utils.h:101
Definition phmap_utils.h:128
Definition phmap_utils.h:50
Definition phmap_utils.h:179