Coverage Report

Created: 2025-12-12 07:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hermes/external/llvh/include/llvh/ADT/Hashing.h
Line
Count
Source
1
//===-- llvm/ADT/Hashing.h - Utilities for hashing --------------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file implements the newly proposed standard C++ interfaces for hashing
11
// arbitrary data and building hash functions for user-defined types. This
12
// interface was originally proposed in N3333[1] and is currently under review
13
// for inclusion in a future TR and/or standard.
14
//
15
// The primary interfaces provide are comprised of one type and three functions:
16
//
17
//  -- 'hash_code' class is an opaque type representing the hash code for some
18
//     data. It is the intended product of hashing, and can be used to implement
19
//     hash tables, checksumming, and other common uses of hashes. It is not an
20
//     integer type (although it can be converted to one) because it is risky
21
//     to assume much about the internals of a hash_code. In particular, each
22
//     execution of the program has a high probability of producing a different
23
//     hash_code for a given input. Thus their values are not stable to save or
24
//     persist, and should only be used during the execution for the
25
//     construction of hashing datastructures.
26
//
27
//  -- 'hash_value' is a function designed to be overloaded for each
28
//     user-defined type which wishes to be used within a hashing context. It
29
//     should be overloaded within the user-defined type's namespace and found
30
//     via ADL. Overloads for primitive types are provided by this library.
31
//
32
//  -- 'hash_combine' and 'hash_combine_range' are functions designed to aid
33
//      programmers in easily and intuitively combining a set of data into
34
//      a single hash_code for their object. They should only logically be used
35
//      within the implementation of a 'hash_value' routine or similar context.
36
//
37
// Note that 'hash_combine_range' contains very special logic for hashing
38
// a contiguous array of integers or pointers. This logic is *extremely* fast,
39
// on a modern Intel "Gainestown" Xeon (Nehalem uarch) @2.2 GHz, these were
40
// benchmarked at over 6.5 GiB/s for large keys, and <20 cycles/hash for keys
41
// under 32-bytes.
42
//
43
//===----------------------------------------------------------------------===//
44
#ifndef LLVM_ADT_HASHING_H
45
#define LLVM_ADT_HASHING_H
46
47
#include "llvh/Support/DataTypes.h"
48
#include "llvh/Support/Host.h"
49
#include "llvh/Support/SwapByteOrder.h"
50
#include "llvh/Support/type_traits.h"
51
#include <algorithm>
52
#include <cassert>
53
#include <cstring>
54
#include <string>
55
#include <utility>
56
57
#pragma GCC diagnostic push
58
59
#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
60
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
61
#endif
62
63
namespace llvh {
64
65
/// An opaque object representing a hash code.
66
///
67
/// This object represents the result of hashing some entity. It is intended to
68
/// be used to implement hashtables or other hashing-based data structures.
69
/// While it wraps and exposes a numeric value, this value should not be
70
/// trusted to be stable or predictable across processes or executions.
71
///
72
/// In order to obtain the hash_code for an object 'x':
73
/// \code
74
///   using llvh::hash_value;
75
///   llvh::hash_code code = hash_value(x);
76
/// \endcode
77
class hash_code {
78
  size_t value;
79
80
public:
81
  /// Default construct a hash_code.
82
  /// Note that this leaves the value uninitialized.
83
  hash_code() = default;
84
85
  /// Form a hash code directly from a numerical value.
86
8.60M
  hash_code(size_t value) : value(value) {}
87
88
  /// Convert the hash code to its numerical value for use.
89
8.60M
  /*explicit*/ operator size_t() const { return value; }
90
91
0
  friend bool operator==(const hash_code &lhs, const hash_code &rhs) {
92
0
    return lhs.value == rhs.value;
93
0
  }
94
0
  friend bool operator!=(const hash_code &lhs, const hash_code &rhs) {
95
0
    return lhs.value != rhs.value;
96
0
  }
97
98
  /// Allow a hash_code to be directly run through hash_value.
99
0
  friend size_t hash_value(const hash_code &code) { return code.value; }
100
};
101
102
/// Compute a hash_code for any integer value.
103
///
104
/// Note that this function is intended to compute the same hash_code for
105
/// a particular value without regard to the pre-promotion type. This is in
106
/// contrast to hash_combine which may produce different hash_codes for
107
/// differing argument types even if they would implicit promote to a common
108
/// type without changing the value.
109
template <typename T>
110
typename std::enable_if<is_integral_or_enum<T>::value, hash_code>::type
111
hash_value(T value);
112
113
/// Compute a hash_code for a pointer's address.
114
///
115
/// N.B.: This hashes the *address*. Not the value and not the type.
116
template <typename T> hash_code hash_value(const T *ptr);
117
118
/// Compute a hash_code for a pair of objects.
119
template <typename T, typename U>
120
hash_code hash_value(const std::pair<T, U> &arg);
121
122
/// Compute a hash_code for a standard string.
123
template <typename T>
124
hash_code hash_value(const std::basic_string<T> &arg);
125
126
127
/// Override the execution seed with a fixed value.
128
///
129
/// This hashing library uses a per-execution seed designed to change on each
130
/// run with high probability in order to ensure that the hash codes are not
131
/// attackable and to ensure that output which is intended to be stable does
132
/// not rely on the particulars of the hash codes produced.
133
///
134
/// That said, there are use cases where it is important to be able to
135
/// reproduce *exactly* a specific behavior. To that end, we provide a function
136
/// which will forcibly set the seed to a fixed value. This must be done at the
137
/// start of the program, before any hashes are computed. Also, it cannot be
138
/// undone. This makes it thread-hostile and very hard to use outside of
139
/// immediately on start of a simple program designed for reproducible
140
/// behavior.
141
void set_fixed_execution_hash_seed(uint64_t fixed_value);
142
143
144
// All of the implementation details of actually computing the various hash
145
// code values are held within this namespace. These routines are included in
146
// the header file mainly to allow inlining and constant propagation.
147
namespace hashing {
148
namespace detail {
149
150
13.2M
inline uint64_t fetch64(const char *p) {
151
13.2M
  uint64_t result;
152
13.2M
  memcpy(&result, p, sizeof(result));
153
13.2M
  if (sys::IsBigEndianHost)
154
0
    sys::swapByteOrder(result);
155
13.2M
  return result;
156
13.2M
}
157
158
5.03M
inline uint32_t fetch32(const char *p) {
159
5.03M
  uint32_t result;
160
5.03M
  memcpy(&result, p, sizeof(result));
161
5.03M
  if (sys::IsBigEndianHost)
162
0
    sys::swapByteOrder(result);
163
5.03M
  return result;
164
5.03M
}
165
166
/// Some primes between 2^63 and 2^64 for various uses.
167
static const uint64_t k0 = 0xc3a5c85c97cb3127ULL;
168
static const uint64_t k1 = 0xb492b66fbe98f273ULL;
169
static const uint64_t k2 = 0x9ae16a3b2f90404fULL;
170
static const uint64_t k3 = 0xc949d7c7509e6557ULL;
171
172
/// Bitwise right rotate.
173
/// Normally this will compile to a single instruction, especially if the
174
/// shift is a manifest constant.
175
7.78M
inline uint64_t rotate(uint64_t val, size_t shift) {
176
  // Avoid shifting by 64: doing so yields an undefined result.
177
7.78M
  return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
178
7.78M
}
179
180
4.93M
inline uint64_t shift_mix(uint64_t val) {
181
4.93M
  return val ^ (val >> 47);
182
4.93M
}
183
184
3.19M
inline uint64_t hash_16_bytes(uint64_t low, uint64_t high) {
185
  // Murmur-inspired hashing.
186
3.19M
  const uint64_t kMul = 0x9ddfea08eb382d69ULL;
187
3.19M
  uint64_t a = (low ^ high) * kMul;
188
3.19M
  a ^= (a >> 47);
189
3.19M
  uint64_t b = (high ^ a) * kMul;
190
3.19M
  b ^= (b >> 47);
191
3.19M
  b *= kMul;
192
3.19M
  return b;
193
3.19M
}
194
195
4.77M
inline uint64_t hash_1to3_bytes(const char *s, size_t len, uint64_t seed) {
196
4.77M
  uint8_t a = s[0];
197
4.77M
  uint8_t b = s[len >> 1];
198
4.77M
  uint8_t c = s[len - 1];
199
4.77M
  uint32_t y = static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8);
200
4.77M
  uint32_t z = len + (static_cast<uint32_t>(c) << 2);
201
4.77M
  return shift_mix(y * k2 ^ z * k3 ^ seed) * k2;
202
4.77M
}
203
204
2.51M
inline uint64_t hash_4to8_bytes(const char *s, size_t len, uint64_t seed) {
205
2.51M
  uint64_t a = fetch32(s);
206
2.51M
  return hash_16_bytes(len + (a << 3), seed ^ fetch32(s + len - 4));
207
2.51M
}
208
209
419k
inline uint64_t hash_9to16_bytes(const char *s, size_t len, uint64_t seed) {
210
419k
  uint64_t a = fetch64(s);
211
419k
  uint64_t b = fetch64(s + len - 8);
212
419k
  return hash_16_bytes(seed ^ a, rotate(b + len, len)) ^ b;
213
419k
}
214
215
52.1k
inline uint64_t hash_17to32_bytes(const char *s, size_t len, uint64_t seed) {
216
52.1k
  uint64_t a = fetch64(s) * k1;
217
52.1k
  uint64_t b = fetch64(s + 8);
218
52.1k
  uint64_t c = fetch64(s + len - 8) * k2;
219
52.1k
  uint64_t d = fetch64(s + len - 16) * k0;
220
52.1k
  return hash_16_bytes(rotate(a - b, 43) + rotate(c ^ seed, 30) + d,
221
52.1k
                       a + rotate(b ^ k3, 20) - c + len + seed);
222
52.1k
}
223
224
15.5k
inline uint64_t hash_33to64_bytes(const char *s, size_t len, uint64_t seed) {
225
15.5k
  uint64_t z = fetch64(s + 24);
226
15.5k
  uint64_t a = fetch64(s) + (len + fetch64(s + len - 16)) * k0;
227
15.5k
  uint64_t b = rotate(a + z, 52);
228
15.5k
  uint64_t c = rotate(a, 37);
229
15.5k
  a += fetch64(s + 8);
230
15.5k
  c += rotate(a, 7);
231
15.5k
  a += fetch64(s + 16);
232
15.5k
  uint64_t vf = a + z;
233
15.5k
  uint64_t vs = b + rotate(a, 31) + c;
234
15.5k
  a = fetch64(s + 16) + fetch64(s + len - 32);
235
15.5k
  z = fetch64(s + len - 8);
236
15.5k
  b = rotate(a + z, 52);
237
15.5k
  c = rotate(a, 37);
238
15.5k
  a += fetch64(s + len - 24);
239
15.5k
  c += rotate(a, 7);
240
15.5k
  a += fetch64(s + len - 16);
241
15.5k
  uint64_t wf = a + z;
242
15.5k
  uint64_t ws = b + rotate(a, 31) + c;
243
15.5k
  uint64_t r = shift_mix((vf + ws) * k2 + (wf + vs) * k0);
244
15.5k
  return shift_mix((seed ^ (r * k0)) + vs) * k2;
245
15.5k
}
246
247
8.56M
inline uint64_t hash_short(const char *s, size_t length, uint64_t seed) {
248
8.56M
  if (length >= 4 && length <= 8)
249
2.51M
    return hash_4to8_bytes(s, length, seed);
250
6.04M
  if (length > 8 && length <= 16)
251
419k
    return hash_9to16_bytes(s, length, seed);
252
5.62M
  if (length > 16 && length <= 32)
253
52.1k
    return hash_17to32_bytes(s, length, seed);
254
5.57M
  if (length > 32)
255
15.5k
    return hash_33to64_bytes(s, length, seed);
256
5.55M
  if (length != 0)
257
4.77M
    return hash_1to3_bytes(s, length, seed);
258
259
780k
  return k2 ^ seed;
260
5.55M
}
261
262
/// The intermediate state used during hashing.
263
/// Currently, the algorithm for computing hash codes is based on CityHash and
264
/// keeps 56 bytes of arbitrary state.
265
struct hash_state {
266
  uint64_t h0, h1, h2, h3, h4, h5, h6;
267
268
  /// Create a new hash_state structure and initialize it based on the
269
  /// seed and the first 64-byte chunk.
270
  /// This effectively performs the initial mix.
271
42.4k
  static hash_state create(const char *s, uint64_t seed) {
272
42.4k
    hash_state state = {
273
42.4k
      0, seed, hash_16_bytes(seed, k1), rotate(seed ^ k1, 49),
274
42.4k
      seed * k1, shift_mix(seed), 0 };
275
42.4k
    state.h6 = hash_16_bytes(state.h4, state.h5);
276
42.4k
    state.mix(s);
277
42.4k
    return state;
278
42.4k
  }
279
280
  /// Mix 32-bytes from the input sequence into the 16-bytes of 'a'
281
  /// and 'b', including whatever is already in 'a' and 'b'.
282
2.01M
  static void mix_32_bytes(const char *s, uint64_t &a, uint64_t &b) {
283
2.01M
    a += fetch64(s);
284
2.01M
    uint64_t c = fetch64(s + 24);
285
2.01M
    b = rotate(b + a + c, 21);
286
2.01M
    uint64_t d = a;
287
2.01M
    a += fetch64(s + 8) + fetch64(s + 16);
288
2.01M
    b += rotate(a, 44) + d;
289
2.01M
    a += c;
290
2.01M
  }
291
292
  /// Mix in a 64-byte buffer of data.
293
  /// We mix all 64 bytes even when the chunk length is smaller, but we
294
  /// record the actual length.
295
1.00M
  void mix(const char *s) {
296
1.00M
    h0 = rotate(h0 + h1 + h3 + fetch64(s + 8), 37) * k1;
297
1.00M
    h1 = rotate(h1 + h4 + fetch64(s + 48), 42) * k1;
298
1.00M
    h0 ^= h6;
299
1.00M
    h1 += h3 + fetch64(s + 40);
300
1.00M
    h2 = rotate(h2 + h5, 33) * k1;
301
1.00M
    h3 = h4 * k1;
302
1.00M
    h4 = h0 + h5;
303
1.00M
    mix_32_bytes(s, h3, h4);
304
1.00M
    h5 = h2 + h6;
305
1.00M
    h6 = h1 + fetch64(s + 16);
306
1.00M
    mix_32_bytes(s + 32, h5, h6);
307
1.00M
    std::swap(h2, h0);
308
1.00M
  }
309
310
  /// Compute the final 64-bit hash code value based on the current
311
  /// state and the length of bytes hashed.
312
42.4k
  uint64_t finalize(size_t length) {
313
42.4k
    return hash_16_bytes(hash_16_bytes(h3, h5) + shift_mix(h1) * k1 + h2,
314
42.4k
                         hash_16_bytes(h4, h6) + shift_mix(length) * k1 + h0);
315
42.4k
  }
316
};
317
318
319
/// A global, fixed seed-override variable.
320
///
321
/// This variable can be set using the \see llvh::set_fixed_execution_seed
322
/// function. See that function for details. Do not, under any circumstances,
323
/// set or read this variable.
324
extern uint64_t fixed_seed_override;
325
326
8.60M
inline uint64_t get_execution_seed() {
327
  // FIXME: This needs to be a per-execution seed. This is just a placeholder
328
  // implementation. Switching to a per-execution seed is likely to flush out
329
  // instability bugs and so will happen as its own commit.
330
  //
331
  // However, if there is a fixed seed override set the first time this is
332
  // called, return that instead of the per-execution seed.
333
8.60M
  const uint64_t seed_prime = 0xff51afd7ed558ccdULL;
334
8.60M
  static uint64_t seed = fixed_seed_override ? fixed_seed_override : seed_prime;
335
8.60M
  return seed;
336
8.60M
}
337
338
339
/// Trait to indicate whether a type's bits can be hashed directly.
340
///
341
/// A type trait which is true if we want to combine values for hashing by
342
/// reading the underlying data. It is false if values of this type must
343
/// first be passed to hash_value, and the resulting hash_codes combined.
344
//
345
// FIXME: We want to replace is_integral_or_enum and is_pointer here with
346
// a predicate which asserts that comparing the underlying storage of two
347
// values of the type for equality is equivalent to comparing the two values
348
// for equality. For all the platforms we care about, this holds for integers
349
// and pointers, but there are platforms where it doesn't and we would like to
350
// support user-defined types which happen to satisfy this property.
351
template <typename T> struct is_hashable_data
352
  : std::integral_constant<bool, ((is_integral_or_enum<T>::value ||
353
                                   std::is_pointer<T>::value) &&
354
                                  64 % sizeof(T) == 0)> {};
355
356
// Special case std::pair to detect when both types are viable and when there
357
// is no alignment-derived padding in the pair. This is a bit of a lie because
358
// std::pair isn't truly POD, but it's close enough in all reasonable
359
// implementations for our use case of hashing the underlying data.
360
template <typename T, typename U> struct is_hashable_data<std::pair<T, U> >
361
  : std::integral_constant<bool, (is_hashable_data<T>::value &&
362
                                  is_hashable_data<U>::value &&
363
                                  (sizeof(T) + sizeof(U)) ==
364
                                   sizeof(std::pair<T, U>))> {};
365
366
/// Helper to get the hashable data representation for a type.
367
/// This variant is enabled when the type itself can be used.
368
template <typename T>
369
typename std::enable_if<is_hashable_data<T>::value, T>::type
370
122k
get_hashable_data(const T &value) {
371
122k
  return value;
372
122k
}
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataIjEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueES5_E4typeERKS5_
_ZN4llvh7hashing6detail17get_hashable_dataIPN6hermes13LiteralStringEEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueES8_E4typeERKS8_
Line
Count
Source
370
122k
get_hashable_data(const T &value) {
371
122k
  return value;
372
122k
}
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataIDsEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueES5_E4typeERKS5_
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataIPN6hermes5ValueEEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueES8_E4typeERKS8_
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataImEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueES5_E4typeERKS5_
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataIxEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueES5_E4typeERKS5_
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataIiEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueES5_E4typeERKS5_
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataIhEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueES5_E4typeERKS5_
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataIsEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueES5_E4typeERKS5_
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataIPKNS_12fltSemanticsEEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueES8_E4typeERKS8_
373
/// Helper to get the hashable data representation for a type.
374
/// This variant is enabled when we must first call hash_value and use the
375
/// result as our data.
376
template <typename T>
377
typename std::enable_if<!is_hashable_data<T>::value, size_t>::type
378
0
get_hashable_data(const T &value) {
379
0
  using ::llvh::hash_value;
380
0
  return hash_value(value);
381
0
}
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataIN6hermes11Instruction7VarietyEEENSt3__19enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS8_
Unexecuted instantiation: _ZN4llvh7hashing6detail17get_hashable_dataINS_9hash_codeEEENSt3__19enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_
382
383
/// Helper to store data from a value into a buffer and advance the
384
/// pointer into that buffer.
385
///
386
/// This routine first checks whether there is enough space in the provided
387
/// buffer, and if not immediately returns false. If there is space, it
388
/// copies the underlying bytes of value into the buffer, advances the
389
/// buffer_ptr past the copied bytes, and returns true.
390
template <typename T>
391
bool store_and_advance(char *&buffer_ptr, char *buffer_end, const T& value,
392
122k
                       size_t offset = 0) {
393
122k
  size_t store_size = sizeof(value) - offset;
394
122k
  if (buffer_ptr + store_size > buffer_end)
395
13.1k
    return false;
396
109k
  const char *value_data = reinterpret_cast<const char *>(&value);
397
109k
  memcpy(buffer_ptr, value_data + offset, store_size);
398
109k
  buffer_ptr += store_size;
399
109k
  return true;
400
122k
}
Unexecuted instantiation: bool llvh::hashing::detail::store_and_advance<unsigned int>(char*&, char*, unsigned int const&, unsigned long)
bool llvh::hashing::detail::store_and_advance<hermes::LiteralString*>(char*&, char*, hermes::LiteralString* const&, unsigned long)
Line
Count
Source
392
122k
                       size_t offset = 0) {
393
122k
  size_t store_size = sizeof(value) - offset;
394
122k
  if (buffer_ptr + store_size > buffer_end)
395
13.1k
    return false;
396
109k
  const char *value_data = reinterpret_cast<const char *>(&value);
397
109k
  memcpy(buffer_ptr, value_data + offset, store_size);
398
109k
  buffer_ptr += store_size;
399
109k
  return true;
400
122k
}
Unexecuted instantiation: bool llvh::hashing::detail::store_and_advance<char16_t>(char*&, char*, char16_t const&, unsigned long)
Unexecuted instantiation: bool llvh::hashing::detail::store_and_advance<unsigned long>(char*&, char*, unsigned long const&, unsigned long)
Unexecuted instantiation: bool llvh::hashing::detail::store_and_advance<hermes::Value*>(char*&, char*, hermes::Value* const&, unsigned long)
Unexecuted instantiation: bool llvh::hashing::detail::store_and_advance<long long>(char*&, char*, long long const&, unsigned long)
Unexecuted instantiation: bool llvh::hashing::detail::store_and_advance<int>(char*&, char*, int const&, unsigned long)
Unexecuted instantiation: bool llvh::hashing::detail::store_and_advance<unsigned char>(char*&, char*, unsigned char const&, unsigned long)
Unexecuted instantiation: bool llvh::hashing::detail::store_and_advance<short>(char*&, char*, short const&, unsigned long)
Unexecuted instantiation: bool llvh::hashing::detail::store_and_advance<llvh::fltSemantics const*>(char*&, char*, llvh::fltSemantics const* const&, unsigned long)
401
402
/// Implement the combining of integral values into a hash_code.
403
///
404
/// This overload is selected when the value type of the iterator is
405
/// integral. Rather than computing a hash_code for each object and then
406
/// combining them, this (as an optimization) directly combines the integers.
407
template <typename InputIteratorT>
408
4.38k
hash_code hash_combine_range_impl(InputIteratorT first, InputIteratorT last) {
409
4.38k
  const uint64_t seed = get_execution_seed();
410
4.38k
  char buffer[64], *buffer_ptr = buffer;
411
4.38k
  char *const buffer_end = std::end(buffer);
412
8.80k
  while (first != last && store_and_advance(buffer_ptr, buffer_end,
413
4.43k
                                            get_hashable_data(*first)))
414
4.42k
    ++first;
415
4.38k
  if (first == last)
416
4.37k
    return hash_short(buffer, buffer_ptr - buffer, seed);
417
4.38k
  assert(buffer_ptr == buffer_end);
418
419
6
  hash_state state = state.create(buffer, seed);
420
6
  size_t length = 64;
421
13.1k
  while (first != last) {
422
    // Fill up the buffer. We don't clear it, which re-mixes the last round
423
    // when only a partial 64-byte chunk is left.
424
13.1k
    buffer_ptr = buffer;
425
117k
    while (first != last && store_and_advance(buffer_ptr, buffer_end,
426
117k
                                              get_hashable_data(*first)))
427
104k
      ++first;
428
429
    // Rotate the buffer if we did a partial fill in order to simulate doing
430
    // a mix of the last 64-bytes. That is how the algorithm works when we
431
    // have a contiguous byte sequence, and we want to emulate that here.
432
13.1k
    std::rotate(buffer, buffer_ptr, buffer_end);
433
434
    // Mix this chunk into the current state.
435
13.1k
    state.mix(buffer);
436
13.1k
    length += buffer_ptr - buffer;
437
13.1k
  };
438
439
6
  return state.finalize(length);
440
6
}
llvh::hash_code llvh::hashing::detail::hash_combine_range_impl<std::__1::__wrap_iter<hermes::LiteralString* const*> >(std::__1::__wrap_iter<hermes::LiteralString* const*>, std::__1::__wrap_iter<hermes::LiteralString* const*>)
Line
Count
Source
408
4.38k
hash_code hash_combine_range_impl(InputIteratorT first, InputIteratorT last) {
409
4.38k
  const uint64_t seed = get_execution_seed();
410
4.38k
  char buffer[64], *buffer_ptr = buffer;
411
4.38k
  char *const buffer_end = std::end(buffer);
412
8.80k
  while (first != last && store_and_advance(buffer_ptr, buffer_end,
413
4.43k
                                            get_hashable_data(*first)))
414
4.42k
    ++first;
415
4.38k
  if (first == last)
416
4.37k
    return hash_short(buffer, buffer_ptr - buffer, seed);
417
4.38k
  assert(buffer_ptr == buffer_end);
418
419
6
  hash_state state = state.create(buffer, seed);
420
6
  size_t length = 64;
421
13.1k
  while (first != last) {
422
    // Fill up the buffer. We don't clear it, which re-mixes the last round
423
    // when only a partial 64-byte chunk is left.
424
13.1k
    buffer_ptr = buffer;
425
117k
    while (first != last && store_and_advance(buffer_ptr, buffer_end,
426
117k
                                              get_hashable_data(*first)))
427
104k
      ++first;
428
429
    // Rotate the buffer if we did a partial fill in order to simulate doing
430
    // a mix of the last 64-bytes. That is how the algorithm works when we
431
    // have a contiguous byte sequence, and we want to emulate that here.
432
13.1k
    std::rotate(buffer, buffer_ptr, buffer_end);
433
434
    // Mix this chunk into the current state.
435
13.1k
    state.mix(buffer);
436
13.1k
    length += buffer_ptr - buffer;
437
13.1k
  };
438
439
6
  return state.finalize(length);
440
6
}
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_range_impl<hermes::vm::StringView::const_iterator>(hermes::vm::StringView::const_iterator, hermes::vm::StringView::const_iterator)
441
442
/// Implement the combining of integral values into a hash_code.
443
///
444
/// This overload is selected when the value type of the iterator is integral
445
/// and when the input iterator is actually a pointer. Rather than computing
446
/// a hash_code for each object and then combining them, this (as an
447
/// optimization) directly combines the integers. Also, because the integers
448
/// are stored in contiguous memory, this routine avoids copying each value
449
/// and directly reads from the underlying memory.
450
template <typename ValueT>
451
typename std::enable_if<is_hashable_data<ValueT>::value, hash_code>::type
452
8.60M
hash_combine_range_impl(ValueT *first, ValueT *last) {
453
8.60M
  const uint64_t seed = get_execution_seed();
454
8.60M
  const char *s_begin = reinterpret_cast<const char *>(first);
455
8.60M
  const char *s_end = reinterpret_cast<const char *>(last);
456
8.60M
  const size_t length = std::distance(s_begin, s_end);
457
8.60M
  if (length <= 64)
458
8.55M
    return hash_short(s_begin, length, seed);
459
460
42.4k
  const char *s_aligned_end = s_begin + (length & ~63);
461
42.4k
  hash_state state = state.create(s_begin, seed);
462
42.4k
  s_begin += 64;
463
951k
  while (s_begin != s_aligned_end) {
464
908k
    state.mix(s_begin);
465
908k
    s_begin += 64;
466
908k
  }
467
42.4k
  if (length & 63)
468
42.2k
    state.mix(s_end - 64);
469
470
42.4k
  return state.finalize(length);
471
8.60M
}
_ZN4llvh7hashing6detail23hash_combine_range_implIKhEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS6_SA_
Line
Count
Source
452
121
hash_combine_range_impl(ValueT *first, ValueT *last) {
453
121
  const uint64_t seed = get_execution_seed();
454
121
  const char *s_begin = reinterpret_cast<const char *>(first);
455
121
  const char *s_end = reinterpret_cast<const char *>(last);
456
121
  const size_t length = std::distance(s_begin, s_end);
457
121
  if (length <= 64)
458
121
    return hash_short(s_begin, length, seed);
459
460
0
  const char *s_aligned_end = s_begin + (length & ~63);
461
0
  hash_state state = state.create(s_begin, seed);
462
0
  s_begin += 64;
463
0
  while (s_begin != s_aligned_end) {
464
0
    state.mix(s_begin);
465
0
    s_begin += 64;
466
0
  }
467
0
  if (length & 63)
468
0
    state.mix(s_end - 64);
469
470
0
  return state.finalize(length);
471
121
}
Unexecuted instantiation: _ZN4llvh7hashing6detail23hash_combine_range_implIKDsEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS6_SA_
Unexecuted instantiation: _ZN4llvh7hashing6detail23hash_combine_range_implImEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS5_S9_
_ZN4llvh7hashing6detail23hash_combine_range_implIKjEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS6_SA_
Line
Count
Source
452
1.47M
hash_combine_range_impl(ValueT *first, ValueT *last) {
453
1.47M
  const uint64_t seed = get_execution_seed();
454
1.47M
  const char *s_begin = reinterpret_cast<const char *>(first);
455
1.47M
  const char *s_end = reinterpret_cast<const char *>(last);
456
1.47M
  const size_t length = std::distance(s_begin, s_end);
457
1.47M
  if (length <= 64)
458
1.47M
    return hash_short(s_begin, length, seed);
459
460
0
  const char *s_aligned_end = s_begin + (length & ~63);
461
0
  hash_state state = state.create(s_begin, seed);
462
0
  s_begin += 64;
463
0
  while (s_begin != s_aligned_end) {
464
0
    state.mix(s_begin);
465
0
    s_begin += 64;
466
0
  }
467
0
  if (length & 63)
468
0
    state.mix(s_end - 64);
469
470
0
  return state.finalize(length);
471
1.47M
}
_ZN4llvh7hashing6detail23hash_combine_range_implIKcEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS6_SA_
Line
Count
Source
452
7.12M
hash_combine_range_impl(ValueT *first, ValueT *last) {
453
7.12M
  const uint64_t seed = get_execution_seed();
454
7.12M
  const char *s_begin = reinterpret_cast<const char *>(first);
455
7.12M
  const char *s_end = reinterpret_cast<const char *>(last);
456
7.12M
  const size_t length = std::distance(s_begin, s_end);
457
7.12M
  if (length <= 64)
458
7.08M
    return hash_short(s_begin, length, seed);
459
460
42.4k
  const char *s_aligned_end = s_begin + (length & ~63);
461
42.4k
  hash_state state = state.create(s_begin, seed);
462
42.4k
  s_begin += 64;
463
951k
  while (s_begin != s_aligned_end) {
464
908k
    state.mix(s_begin);
465
908k
    s_begin += 64;
466
908k
  }
467
42.4k
  if (length & 63)
468
42.2k
    state.mix(s_end - 64);
469
470
42.4k
  return state.finalize(length);
471
7.12M
}
Unexecuted instantiation: _ZN4llvh7hashing6detail23hash_combine_range_implIKmEENSt3__19enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS6_SA_
472
473
} // namespace detail
474
} // namespace hashing
475
476
477
/// Compute a hash_code for a sequence of values.
478
///
479
/// This hashes a sequence of values. It produces the same hash_code as
480
/// 'hash_combine(a, b, c, ...)', but can run over arbitrary sized sequences
481
/// and is significantly faster given pointers and types which can be hashed as
482
/// a sequence of bytes.
483
template <typename InputIteratorT>
484
8.60M
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last) {
485
8.60M
  return ::llvh::hashing::detail::hash_combine_range_impl(first, last);
486
8.60M
}
llvh::hash_code llvh::hash_combine_range<unsigned char const*>(unsigned char const*, unsigned char const*)
Line
Count
Source
484
121
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last) {
485
121
  return ::llvh::hashing::detail::hash_combine_range_impl(first, last);
486
121
}
llvh::hash_code llvh::hash_combine_range<std::__1::__wrap_iter<hermes::LiteralString* const*> >(std::__1::__wrap_iter<hermes::LiteralString* const*>, std::__1::__wrap_iter<hermes::LiteralString* const*>)
Line
Count
Source
484
4.38k
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last) {
485
4.38k
  return ::llvh::hashing::detail::hash_combine_range_impl(first, last);
486
4.38k
}
Unexecuted instantiation: llvh::hash_code llvh::hash_combine_range<char16_t const*>(char16_t const*, char16_t const*)
Unexecuted instantiation: llvh::hash_code llvh::hash_combine_range<hermes::vm::StringView::const_iterator>(hermes::vm::StringView::const_iterator, hermes::vm::StringView::const_iterator)
Unexecuted instantiation: llvh::hash_code llvh::hash_combine_range<unsigned long*>(unsigned long*, unsigned long*)
llvh::hash_code llvh::hash_combine_range<unsigned int const*>(unsigned int const*, unsigned int const*)
Line
Count
Source
484
1.47M
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last) {
485
1.47M
  return ::llvh::hashing::detail::hash_combine_range_impl(first, last);
486
1.47M
}
llvh::hash_code llvh::hash_combine_range<char const*>(char const*, char const*)
Line
Count
Source
484
7.12M
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last) {
485
7.12M
  return ::llvh::hashing::detail::hash_combine_range_impl(first, last);
486
7.12M
}
Unexecuted instantiation: llvh::hash_code llvh::hash_combine_range<unsigned long const*>(unsigned long const*, unsigned long const*)
487
488
489
// Implementation details for hash_combine.
490
namespace hashing {
491
namespace detail {
492
493
/// Helper class to manage the recursive combining of hash_combine
494
/// arguments.
495
///
496
/// This class exists to manage the state and various calls involved in the
497
/// recursive combining of arguments used in hash_combine. It is particularly
498
/// useful at minimizing the code in the recursive calls to ease the pain
499
/// caused by a lack of variadic functions.
500
struct hash_combine_recursive_helper {
501
  char buffer[64];
502
  hash_state state;
503
  const uint64_t seed;
504
505
public:
506
  /// Construct a recursive hash combining helper.
507
  ///
508
  /// This sets up the state for a recursive hash combine, including getting
509
  /// the seed and buffer setup.
510
  hash_combine_recursive_helper()
511
0
    : seed(get_execution_seed()) {}
512
513
  /// Combine one chunk of data into the current in-flight hash.
514
  ///
515
  /// This merges one chunk of data into the hash. First it tries to buffer
516
  /// the data. If the buffer is full, it hashes the buffer into its
517
  /// hash_state, empties it, and then merges the new chunk in. This also
518
  /// handles cases where the data straddles the end of the buffer.
519
  template <typename T>
520
0
  char *combine_data(size_t &length, char *buffer_ptr, char *buffer_end, T data) {
521
0
    if (!store_and_advance(buffer_ptr, buffer_end, data)) {
522
      // Check for skew which prevents the buffer from being packed, and do
523
      // a partial store into the buffer to fill it. This is only a concern
524
      // with the variadic combine because that formation can have varying
525
      // argument types.
526
0
      size_t partial_store_size = buffer_end - buffer_ptr;
527
0
      memcpy(buffer_ptr, &data, partial_store_size);
528
529
      // If the store fails, our buffer is full and ready to hash. We have to
530
      // either initialize the hash state (on the first full buffer) or mix
531
      // this buffer into the existing hash state. Length tracks the *hashed*
532
      // length, not the buffered length.
533
0
      if (length == 0) {
534
0
        state = state.create(buffer, seed);
535
0
        length = 64;
536
0
      } else {
537
        // Mix this chunk into the current state and bump length up by 64.
538
0
        state.mix(buffer);
539
0
        length += 64;
540
0
      }
541
      // Reset the buffer_ptr to the head of the buffer for the next chunk of
542
      // data.
543
0
      buffer_ptr = buffer;
544
545
      // Try again to store into the buffer -- this cannot fail as we only
546
      // store types smaller than the buffer.
547
0
      if (!store_and_advance(buffer_ptr, buffer_end, data,
548
0
                             partial_store_size))
549
0
        abort();
550
0
    }
551
0
    return buffer_ptr;
552
0
  }
Unexecuted instantiation: char* llvh::hashing::detail::hash_combine_recursive_helper::combine_data<unsigned int>(unsigned long&, char*, char*, unsigned int)
Unexecuted instantiation: char* llvh::hashing::detail::hash_combine_recursive_helper::combine_data<unsigned long>(unsigned long&, char*, char*, unsigned long)
Unexecuted instantiation: char* llvh::hashing::detail::hash_combine_recursive_helper::combine_data<hermes::Value*>(unsigned long&, char*, char*, hermes::Value*)
Unexecuted instantiation: char* llvh::hashing::detail::hash_combine_recursive_helper::combine_data<long long>(unsigned long&, char*, char*, long long)
Unexecuted instantiation: char* llvh::hashing::detail::hash_combine_recursive_helper::combine_data<int>(unsigned long&, char*, char*, int)
Unexecuted instantiation: char* llvh::hashing::detail::hash_combine_recursive_helper::combine_data<unsigned char>(unsigned long&, char*, char*, unsigned char)
Unexecuted instantiation: char* llvh::hashing::detail::hash_combine_recursive_helper::combine_data<short>(unsigned long&, char*, char*, short)
Unexecuted instantiation: char* llvh::hashing::detail::hash_combine_recursive_helper::combine_data<llvh::fltSemantics const*>(unsigned long&, char*, char*, llvh::fltSemantics const*)
553
554
  /// Recursive, variadic combining method.
555
  ///
556
  /// This function recurses through each argument, combining that argument
557
  /// into a single hash.
558
  template <typename T, typename ...Ts>
559
  hash_code combine(size_t length, char *buffer_ptr, char *buffer_end,
560
0
                    const T &arg, const Ts &...args) {
561
0
    buffer_ptr = combine_data(length, buffer_ptr, buffer_end, get_hashable_data(arg));
562
563
    // Recurse to the next argument.
564
0
    return combine(length, buffer_ptr, buffer_end, args...);
565
0
  }
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<unsigned int, unsigned int>(unsigned long, char*, char*, unsigned int const&, unsigned int const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<unsigned int>(unsigned long, char*, char*, unsigned int const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<hermes::Instruction::Variety, unsigned int>(unsigned long, char*, char*, hermes::Instruction::Variety const&, unsigned int const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<llvh::hash_code, hermes::Value*>(unsigned long, char*, char*, llvh::hash_code const&, hermes::Value* const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<hermes::Value*>(unsigned long, char*, char*, hermes::Value* const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<llvh::hash_code, llvh::hash_code>(unsigned long, char*, char*, llvh::hash_code const&, llvh::hash_code const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<llvh::hash_code>(unsigned long, char*, char*, llvh::hash_code const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<unsigned long>(unsigned long, char*, char*, unsigned long const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<long long, int>(unsigned long, char*, char*, long long const&, int const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<int>(unsigned long, char*, char*, int const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<unsigned char, unsigned char, unsigned int>(unsigned long, char*, char*, unsigned char const&, unsigned char const&, unsigned int const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<unsigned char, unsigned int>(unsigned long, char*, char*, unsigned char const&, unsigned int const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<unsigned char, unsigned char, unsigned int, short, llvh::hash_code>(unsigned long, char*, char*, unsigned char const&, unsigned char const&, unsigned int const&, short const&, llvh::hash_code const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<unsigned char, unsigned int, short, llvh::hash_code>(unsigned long, char*, char*, unsigned char const&, unsigned int const&, short const&, llvh::hash_code const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<unsigned int, short, llvh::hash_code>(unsigned long, char*, char*, unsigned int const&, short const&, llvh::hash_code const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<short, llvh::hash_code>(unsigned long, char*, char*, short const&, llvh::hash_code const&)
Unexecuted instantiation: llvh::hash_code llvh::hashing::detail::hash_combine_recursive_helper::combine<llvh::fltSemantics const*>(unsigned long, char*, char*, llvh::fltSemantics const* const&)
566
567
  /// Base case for recursive, variadic combining.
568
  ///
569
  /// The base case when combining arguments recursively is reached when all
570
  /// arguments have been handled. It flushes the remaining buffer and
571
  /// constructs a hash_code.
572
0
  hash_code combine(size_t length, char *buffer_ptr, char *buffer_end) {
573
    // Check whether the entire set of values fit in the buffer. If so, we'll
574
    // use the optimized short hashing routine and skip state entirely.
575
0
    if (length == 0)
576
0
      return hash_short(buffer, buffer_ptr - buffer, seed);
577
578
    // Mix the final buffer, rotating it if we did a partial fill in order to
579
    // simulate doing a mix of the last 64-bytes. That is how the algorithm
580
    // works when we have a contiguous byte sequence, and we want to emulate
581
    // that here.
582
0
    std::rotate(buffer, buffer_ptr, buffer_end);
583
584
    // Mix this chunk into the current state.
585
0
    state.mix(buffer);
586
0
    length += buffer_ptr - buffer;
587
588
0
    return state.finalize(length);
589
0
  }
590
};
591
592
} // namespace detail
593
} // namespace hashing
594
595
/// Combine values into a single hash_code.
596
///
597
/// This routine accepts a varying number of arguments of any type. It will
598
/// attempt to combine them into a single hash_code. For user-defined types it
599
/// attempts to call a \see hash_value overload (via ADL) for the type. For
600
/// integer and pointer types it directly combines their data into the
601
/// resulting hash_code.
602
///
603
/// The result is suitable for returning from a user's hash_value
604
/// *implementation* for their user-defined type. Consumers of a type should
605
/// *not* call this routine, they should instead call 'hash_value'.
606
0
template <typename ...Ts> hash_code hash_combine(const Ts &...args) {
607
  // Recursively hash each argument using a helper class.
608
0
  ::llvh::hashing::detail::hash_combine_recursive_helper helper;
609
0
  return helper.combine(0, helper.buffer, helper.buffer + 64, args...);
610
0
}
Unexecuted instantiation: llvh::hash_code llvh::hash_combine<unsigned int, unsigned int>(unsigned int const&, unsigned int const&)
Unexecuted instantiation: llvh::hash_code llvh::hash_combine<hermes::Instruction::Variety, unsigned int>(hermes::Instruction::Variety const&, unsigned int const&)
Unexecuted instantiation: llvh::hash_code llvh::hash_combine<llvh::hash_code, hermes::Value*>(llvh::hash_code const&, hermes::Value* const&)
Unexecuted instantiation: llvh::hash_code llvh::hash_combine<llvh::hash_code, llvh::hash_code>(llvh::hash_code const&, llvh::hash_code const&)
Unexecuted instantiation: llvh::hash_code llvh::hash_combine<unsigned long>(unsigned long const&)
Unexecuted instantiation: llvh::hash_code llvh::hash_combine<long long, int>(long long const&, int const&)
Unexecuted instantiation: llvh::hash_code llvh::hash_combine<unsigned char, unsigned char, unsigned int>(unsigned char const&, unsigned char const&, unsigned int const&)
Unexecuted instantiation: llvh::hash_code llvh::hash_combine<unsigned char, unsigned char, unsigned int, short, llvh::hash_code>(unsigned char const&, unsigned char const&, unsigned int const&, short const&, llvh::hash_code const&)
Unexecuted instantiation: llvh::hash_code llvh::hash_combine<llvh::fltSemantics const*>(llvh::fltSemantics const* const&)
611
612
// Implementation details for implementations of hash_value overloads provided
613
// here.
614
namespace hashing {
615
namespace detail {
616
617
/// Helper to hash the value of a single integer.
618
///
619
/// Overloads for smaller integer types are not provided to ensure consistent
620
/// behavior in the presence of integral promotions. Essentially,
621
/// "hash_value('4')" and "hash_value('0' + 4)" should be the same.
622
0
inline hash_code hash_integer_value(uint64_t value) {
623
  // Similar to hash_4to8_bytes but using a seed instead of length.
624
0
  const uint64_t seed = get_execution_seed();
625
0
  const char *s = reinterpret_cast<const char *>(&value);
626
0
  const uint64_t a = fetch32(s);
627
0
  return hash_16_bytes(seed + (a << 3), fetch32(s + 4));
628
0
}
629
630
} // namespace detail
631
} // namespace hashing
632
633
// Declared and documented above, but defined here so that any of the hashing
634
// infrastructure is available.
635
template <typename T>
636
typename std::enable_if<is_integral_or_enum<T>::value, hash_code>::type
637
0
hash_value(T value) {
638
0
  return ::llvh::hashing::detail::hash_integer_value(
639
0
      static_cast<uint64_t>(value));
640
0
}
Unexecuted instantiation: _ZN4llvh10hash_valueItEENSt3__19enable_ifIXsr19is_integral_or_enumIT_EE5valueENS_9hash_codeEE4typeES3_
Unexecuted instantiation: _ZN4llvh10hash_valueImEENSt3__19enable_ifIXsr19is_integral_or_enumIT_EE5valueENS_9hash_codeEE4typeES3_
Unexecuted instantiation: _ZN4llvh10hash_valueIjEENSt3__19enable_ifIXsr19is_integral_or_enumIT_EE5valueENS_9hash_codeEE4typeES3_
641
642
// Declared and documented above, but defined here so that any of the hashing
643
// infrastructure is available.
644
template <typename T> hash_code hash_value(const T *ptr) {
645
  return ::llvh::hashing::detail::hash_integer_value(
646
    reinterpret_cast<uintptr_t>(ptr));
647
}
648
649
// Declared and documented above, but defined here so that any of the hashing
650
// infrastructure is available.
651
template <typename T, typename U>
652
0
hash_code hash_value(const std::pair<T, U> &arg) {
653
0
  return hash_combine(arg.first, arg.second);
654
0
}
655
656
// Declared and documented above, but defined here so that any of the hashing
657
// infrastructure is available.
658
template <typename T>
659
hash_code hash_value(const std::basic_string<T> &arg) {
660
  return hash_combine_range(arg.begin(), arg.end());
661
}
662
663
} // namespace llvh
664
665
#pragma GCC diagnostic pop
666
667
#endif