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)
42#if defined(PHMAP_USE_ABSL_HASH) && !defined(phmap_fwd_decl_h_guard_) && !defined(ABSL_HASH_HASH_H_)
61 static constexpr uint64_t kmul = 0xcc9e2d51UL;
63 uint64_t l = a * kmul;
64 return static_cast<size_t>(l ^ (l >> 32));
68#if defined(PHMAP_HAS_UMUL128)
73 static constexpr uint64_t k = 0xde5fb9d2630458e9ULL;
76 uint64_t l = umul128(a, k, &h);
77 return static_cast<size_t>(h + l);
86 a = (a + (a << 3)) + (a << 8);
88 a = (a + (a << 2)) + (a << 4);
91 return static_cast<size_t>(a);
104 inline size_t operator()(uint64_t a)
const {
return static_cast<size_t>(a ^ (a >> 32)); }
109 inline size_t operator()(uint64_t a)
const {
return static_cast<size_t>(a); }
118 typedef std::true_type
yes;
119 typedef std::false_type
no;
121 template <
typename U>
122 static auto test(
int) ->
decltype(hash_value(std::declval<const U&>()) == 1,
yes());
131#if defined(PHMAP_USE_ABSL_HASH) && !defined(phmap_fwd_decl_h_guard_)
133using Hash = ::absl::Hash<T>;
134#elif !defined(PHMAP_USE_ABSL_HASH)
140 template <class U, typename std::enable_if<has_hash_value<U>::value,
int>::type = 0>
142 return hash_value(val);
145 template <class U, typename std::enable_if<!has_hash_value<U>::value,
int>::type = 0>
147 return std::hash<T>()(val);
150 inline size_t operator()(
const T& val)
const {
return _hash<T>(val); }
155 inline size_t operator()(
const T* val)
const noexcept {
return static_cast<size_t>(
reinterpret_cast<const uintptr_t
>(val)); }
158template <
class ArgumentType,
class ResultType>
166 inline size_t operator()(
bool val)
const noexcept {
return static_cast<size_t>(val); }
171 inline size_t operator()(
char val)
const noexcept {
return static_cast<size_t>(val); }
176 inline size_t operator()(
signed char val)
const noexcept {
return static_cast<size_t>(val); }
181 inline size_t operator()(
unsigned char val)
const noexcept {
return static_cast<size_t>(val); }
184#ifdef PHMAP_HAS_NATIVE_WCHAR_T
187 inline size_t operator()(
wchar_t val)
const noexcept {
return static_cast<size_t>(val); }
193 inline size_t operator()(int16_t val)
const noexcept {
return static_cast<size_t>(val); }
198 inline size_t operator()(uint16_t val)
const noexcept {
return static_cast<size_t>(val); }
203 inline size_t operator()(int32_t val)
const noexcept {
return static_cast<size_t>(val); }
208 inline size_t operator()(uint32_t val)
const noexcept {
return static_cast<size_t>(val); }
225 uint32_t* as_int =
reinterpret_cast<uint32_t*
>(&val);
226 return (val == 0) ?
static_cast<size_t>(0) :
static_cast<size_t>(*as_int);
234 uint64_t* as_int =
reinterpret_cast<uint64_t*
>(&val);
235 return (val == 0) ?
static_cast<size_t>(0) :
fold_if_needed<
sizeof(
size_t)>()(*as_int);
241struct Hash<
nstd::string> :
public phmap_unary_function<nstd::string, size_t> {
243 return (val.empty() ?
static_cast<size_t>(0) : std::hash<std::string>{}(val.c_str()));
251#define PHMAP_HASH_ROTL32(x, r) _rotl(x, r)
253#define PHMAP_HASH_ROTL32(x, r) (x << r) | (x >> (32 - r))
256template <
class H,
int sz>
269 const uint32_t c1 = 0xcc9e2d51;
270 const uint32_t c2 = 0x1b873593;
278 h1 = h1 * 5 + 0xe6546b64;
282 return h1 ^ (k1 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
294 const uint64_t m = (uint64_t(0xc6a4a793) << 32) + 0x5bd1e995;
310 return h ^ (k + size_t(0xc6a4a7935bd1e995) + (h << 6) + (h >> 2));
320 template <
typename T,
typename... Ts>
321 static H
combine(H state,
const T& value,
const Ts&... values);
327template <
typename T,
typename... Ts>
336#if !defined(PHMAP_USE_ABSL_HASH)
340template <
class T1,
class T2>
349 size_t operator()(std::tuple<T...>
const& t)
const noexcept {
351 return _hash_helper(seed, t);
355 template <
size_t I = 0,
class TUP>
356 typename std::enable_if<I == std::tuple_size<TUP>::value,
size_t>::type
_hash_helper(
size_t seed,
const TUP&)
const noexcept {
360 template <
size_t I = 0,
class TUP>
361 typename std::enable_if < I<std::tuple_size<TUP>::value,
size_t>::type _hash_helper(
size_t seed,
const TUP& t)
const noexcept {
362 const auto& el = std::get<I>(t);
363 using el_type =
typename std::remove_cv<
typename std::remove_reference<
decltype(el)>::type>::type;
365 return _hash_helper<I + 1>(seed, t);
Definition: ne_stl_string.h:19
Definition: phmap_utils.h:318
static H combine(H state)
Definition: phmap_utils.h:323
static H combine(H state, const T &value, const Ts &... values)
Definition: phmap_utils.h:328
Definition: ne_stl_any.h:7
HashStateBase< size_t > HashState
Definition: phmap_utils.h:332
#define PHMAP_HASH_ROTL32(x, r)
Definition: phmap_utils.h:253
unsigned char bool
Definition: stdbool.h:25
H operator()(H h1, size_t k1)
Definition: phmap_utils.h:263
H operator()(H h, size_t k)
Definition: phmap_utils.h:289
Definition: phmap_utils.h:257
H operator()(H seed, size_t value)
size_t operator()(const T *val) const noexcept
Definition: phmap_utils.h:155
size_t operator()(bool val) const noexcept
Definition: phmap_utils.h:166
size_t operator()(char val) const noexcept
Definition: phmap_utils.h:171
size_t operator()(double val) const noexcept
Definition: phmap_utils.h:232
size_t operator()(float val) const noexcept
Definition: phmap_utils.h:223
size_t operator()(int16_t val) const noexcept
Definition: phmap_utils.h:193
size_t operator()(int32_t val) const noexcept
Definition: phmap_utils.h:203
size_t operator()(int64_t val) const noexcept
Definition: phmap_utils.h:213
size_t operator()(signed char val) const noexcept
Definition: phmap_utils.h:176
size_t operator()(std::pair< T1, T2 > const &p) const noexcept
Definition: phmap_utils.h:342
size_t operator()(std::tuple< T... > const &t) const noexcept
Definition: phmap_utils.h:349
std::enable_if< I==std::tuple_size< TUP >::value, size_t >::type _hash_helper(size_t seed, const TUP &) const noexcept
Definition: phmap_utils.h:356
size_t operator()(uint16_t val) const noexcept
Definition: phmap_utils.h:198
size_t operator()(uint32_t val) const noexcept
Definition: phmap_utils.h:208
size_t operator()(uint64_t val) const noexcept
Definition: phmap_utils.h:218
size_t operator()(unsigned char val) const noexcept
Definition: phmap_utils.h:181
size_t operator()(wchar_t val) const noexcept
Definition: phmap_utils.h:187
Definition: phmap_utils.h:139
size_t operator()(const T &val) const
Definition: phmap_utils.h:150
size_t _hash(const T &val) const
Definition: phmap_utils.h:141
size_t operator()(uint64_t a) const
Definition: phmap_utils.h:104
size_t operator()(uint64_t a) const
Definition: phmap_utils.h:109
Definition: phmap_utils.h:98
size_t operator()(uint64_t) const
Definition: phmap_utils.h:116
static auto test(int) -> decltype(hash_value(std::declval< const U & >())==1, yes())
std::true_type yes
Definition: phmap_utils.h:118
std::false_type no
Definition: phmap_utils.h:119
static constexpr bool value
Definition: phmap_utils.h:128
size_t operator()(size_t a) const
Definition: phmap_utils.h:60
size_t operator()(size_t a) const
Definition: phmap_utils.h:83
Definition: phmap_utils.h:54
size_t operator()(size_t) const
Definition: phmap_utils.h:159
ArgumentType argument_type
Definition: phmap_utils.h:160
ResultType result_type
Definition: phmap_utils.h:161