3086
#if _LIBCPP_STD_VER > 11
3091
typedef unique_ptr<_Tp> __unique_single;
3095
struct __unique_if<_Tp[]>
3097
typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3100
template<class _Tp, size_t _Np>
3101
struct __unique_if<_Tp[_Np]>
3103
typedef void __unique_array_known_bound;
3106
template<class _Tp, class... _Args>
3107
inline _LIBCPP_INLINE_VISIBILITY
3108
typename __unique_if<_Tp>::__unique_single
3109
make_unique(_Args&&... __args)
3111
return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3115
inline _LIBCPP_INLINE_VISIBILITY
3116
typename __unique_if<_Tp>::__unique_array_unknown_bound
3117
make_unique(size_t __n)
3119
typedef typename remove_extent<_Tp>::type _Up;
3120
return unique_ptr<_Tp>(new _Up[__n]());
3123
template<class _Tp, class... _Args>
3124
typename __unique_if<_Tp>::__unique_array_known_bound
3125
make_unique(_Args&&...) = delete;
3127
#endif // _LIBCPP_STD_VER > 11
3080
3129
template <class _Tp> struct hash;
3131
template <class _Size>
3132
inline _LIBCPP_INLINE_VISIBILITY
3134
__loadword(const void* __p)
3137
std::memcpy(&__r, __p, sizeof(__r));
3082
3141
// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3083
3142
// is 64 bits. This is because cityhash64 uses 64bit x 64bit
3084
3143
// multiplication, which can be very slow on 32-bit systems.
3162
3221
static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3163
3222
if (__len > 8) {
3164
const _Size __a = *(const _Size*)__s;
3165
const _Size __b = *(const _Size*)(__s + __len - 8);
3223
const _Size __a = __loadword<_Size>(__s);
3224
const _Size __b = __loadword<_Size>(__s + __len - 8);
3166
3225
return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3168
3227
if (__len >= 4) {
3169
const uint32_t __a = *(const uint32_t*)(__s);
3170
const uint32_t __b = *(const uint32_t*)(__s + __len - 4);
3228
const uint32_t __a = __loadword<uint32_t>(__s);
3229
const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
3171
3230
return __hash_len_16(__len + (__a << 3), __b);
3173
3232
if (__len > 0) {
3185
3244
static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3186
const _Size __a = *(const _Size*)(__s) * __k1;
3187
const _Size __b = *(const _Size*)(__s + 8);
3188
const _Size __c = *(const _Size*)(__s + __len - 8) * __k2;
3189
const _Size __d = *(const _Size*)(__s + __len - 16) * __k0;
3245
const _Size __a = __loadword<_Size>(__s) * __k1;
3246
const _Size __b = __loadword<_Size>(__s + 8);
3247
const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3248
const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
3190
3249
return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3191
3250
__a + __rotate(__b ^ __k3, 20) - __c + __len);
3207
3266
// Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3208
3267
static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3209
3268
const char* __s, _Size __a, _Size __b) {
3210
return __weak_hash_len_32_with_seeds(*(const _Size*)(__s),
3211
*(const _Size*)(__s + 8),
3212
*(const _Size*)(__s + 16),
3213
*(const _Size*)(__s + 24),
3269
return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3270
__loadword<_Size>(__s + 8),
3271
__loadword<_Size>(__s + 16),
3272
__loadword<_Size>(__s + 24),
3218
3277
// Return an 8-byte hash for 33 to 64 bytes.
3219
3278
static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3220
_Size __z = *(const _Size*)(__s + 24);
3221
_Size __a = *(const _Size*)(__s) +
3222
(__len + *(const _Size*)(__s + __len - 16)) * __k0;
3279
_Size __z = __loadword<_Size>(__s + 24);
3280
_Size __a = __loadword<_Size>(__s) +
3281
(__len + __loadword<_Size>(__s + __len - 16)) * __k0;
3223
3282
_Size __b = __rotate(__a + __z, 52);
3224
3283
_Size __c = __rotate(__a, 37);
3225
__a += *(const _Size*)(__s + 8);
3284
__a += __loadword<_Size>(__s + 8);
3226
3285
__c += __rotate(__a, 7);
3227
__a += *(const _Size*)(__s + 16);
3286
__a += __loadword<_Size>(__s + 16);
3228
3287
_Size __vf = __a + __z;
3229
3288
_Size __vs = __b + __rotate(__a, 31) + __c;
3230
__a = *(const _Size*)(__s + 16) + *(const _Size*)(__s + __len - 32);
3231
__z += *(const _Size*)(__s + __len - 8);
3289
__a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3290
__z += __loadword<_Size>(__s + __len - 8);
3232
3291
__b = __rotate(__a + __z, 52);
3233
3292
__c = __rotate(__a, 37);
3234
__a += *(const _Size*)(__s + __len - 24);
3293
__a += __loadword<_Size>(__s + __len - 24);
3235
3294
__c += __rotate(__a, 7);
3236
__a += *(const _Size*)(__s + __len - 16);
3295
__a += __loadword<_Size>(__s + __len - 16);
3237
3296
_Size __wf = __a + __z;
3238
3297
_Size __ws = __b + __rotate(__a, 31) + __c;
3239
3298
_Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3260
3319
// For strings over 64 bytes we hash the end first, and then as we
3261
3320
// loop we keep 56 bytes of state: v, w, x, y, and z.
3262
_Size __x = *(const _Size*)(__s + __len - 40);
3263
_Size __y = *(const _Size*)(__s + __len - 16) +
3264
*(const _Size*)(__s + __len - 56);
3265
_Size __z = __hash_len_16(*(const _Size*)(__s + __len - 48) + __len,
3266
*(const _Size*)(__s + __len - 24));
3321
_Size __x = __loadword<_Size>(__s + __len - 40);
3322
_Size __y = __loadword<_Size>(__s + __len - 16) +
3323
__loadword<_Size>(__s + __len - 56);
3324
_Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3325
__loadword<_Size>(__s + __len - 24));
3267
3326
pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3268
3327
pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3269
__x = __x * __k1 + *(const _Size*)(__s);
3328
__x = __x * __k1 + __loadword<_Size>(__s);
3271
3330
// Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3272
3331
__len = (__len - 1) & ~static_cast<_Size>(63);
3274
__x = __rotate(__x + __y + __v.first + *(const _Size*)(__s + 8), 37) * __k1;
3275
__y = __rotate(__y + __v.second + *(const _Size*)(__s + 48), 42) * __k1;
3333
__x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3334
__y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
3276
3335
__x ^= __w.second;
3277
__y += __v.first + *(const _Size*)(__s + 40);
3336
__y += __v.first + __loadword<_Size>(__s + 40);
3278
3337
__z = __rotate(__z + __w.first, 33) * __k1;
3279
3338
__v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3280
3339
__w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3281
__y + *(const _Size*)(__s + 16));
3340
__y + __loadword<_Size>(__s + 16));
3282
3341
std::swap(__z, __x);