| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#ifndef ROBIN_HOOD_H_INCLUDED |
| 34 |
#define ROBIN_HOOD_H_INCLUDED |
| 35 |
|
| 36 |
|
| 37 |
#define ROBIN_HOOD_VERSION_MAJOR 3 // for incompatible API changes |
| 38 |
#define ROBIN_HOOD_VERSION_MINOR 11 // for adding functionality in a backwards-compatible manner |
| 39 |
#define ROBIN_HOOD_VERSION_PATCH 5 // for backwards-compatible bug fixes |
| 40 |
|
| 41 |
#include <algorithm> |
| 42 |
#include <cstdlib> |
| 43 |
#include <cstring> |
| 44 |
#include <functional> |
| 45 |
#include <limits> |
| 46 |
#include <memory> |
| 47 |
#include <stdexcept> |
| 48 |
#include <string> |
| 49 |
#include <type_traits> |
| 50 |
#include <utility> |
| 51 |
#if __cplusplus >= 201703L |
| 52 |
# include <string_view> |
| 53 |
#endif |
| 54 |
|
| 55 |
|
| 56 |
#ifdef ROBIN_HOOD_LOG_ENABLED |
| 57 |
# include <iostream> |
| 58 |
# define ROBIN_HOOD_LOG(...) \ |
| 59 |
std::cout << __FUNCTION__ << "@" << __LINE__ << ": " << __VA_ARGS__ << std::endl; |
| 60 |
#else |
| 61 |
# define ROBIN_HOOD_LOG(x) |
| 62 |
#endif |
| 63 |
|
| 64 |
|
| 65 |
#ifdef ROBIN_HOOD_TRACE_ENABLED |
| 66 |
# include <iostream> |
| 67 |
# define ROBIN_HOOD_TRACE(...) \ |
| 68 |
std::cout << __FUNCTION__ << "@" << __LINE__ << ": " << __VA_ARGS__ << std::endl; |
| 69 |
#else |
| 70 |
# define ROBIN_HOOD_TRACE(x) |
| 71 |
#endif |
| 72 |
|
| 73 |
|
| 74 |
#ifdef ROBIN_HOOD_COUNT_ENABLED |
| 75 |
# include <iostream> |
| 76 |
# define ROBIN_HOOD_COUNT(x) ++counts().x; |
| 77 |
namespace robin_hood { |
| 78 |
struct Counts { |
| 79 |
uint64_t shiftUp{}; |
| 80 |
uint64_t shiftDown{}; |
| 81 |
}; |
| 82 |
inline std::ostream& operator<<(std::ostream& os, Counts const& c) { |
| 83 |
return os << c.shiftUp << " shiftUp" << std::endl << c.shiftDown << " shiftDown" << std::endl; |
| 84 |
} |
| 85 |
|
| 86 |
static Counts& counts() { |
| 87 |
static Counts counts{}; |
| 88 |
return counts; |
| 89 |
} |
| 90 |
} |
| 91 |
#else |
| 92 |
# define ROBIN_HOOD_COUNT(x) |
| 93 |
#endif |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
#define ROBIN_HOOD(x) ROBIN_HOOD_PRIVATE_DEFINITION_##x() |
| 98 |
|
| 99 |
|
| 100 |
#define ROBIN_HOOD_UNUSED(identifier) |
| 101 |
|
| 102 |
|
| 103 |
#if SIZE_MAX == UINT32_MAX |
| 104 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_BITNESS() 32 |
| 105 |
#elif SIZE_MAX == UINT64_MAX |
| 106 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_BITNESS() 64 |
| 107 |
#else |
| 108 |
# error Unsupported bitness |
| 109 |
#endif |
| 110 |
|
| 111 |
|
| 112 |
#ifdef _MSC_VER |
| 113 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_LITTLE_ENDIAN() 1 |
| 114 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_BIG_ENDIAN() 0 |
| 115 |
#else |
| 116 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_LITTLE_ENDIAN() \ |
| 117 |
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
| 118 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_BIG_ENDIAN() (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) |
| 119 |
#endif |
| 120 |
|
| 121 |
|
| 122 |
#ifdef _MSC_VER |
| 123 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_NOINLINE() __declspec(noinline) |
| 124 |
#else |
| 125 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_NOINLINE() __attribute__((noinline)) |
| 126 |
#endif |
| 127 |
|
| 128 |
|
| 129 |
#if !defined(__cpp_exceptions) && !defined(__EXCEPTIONS) && !defined(_CPPUNWIND) |
| 130 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_EXCEPTIONS() 0 |
| 131 |
#else |
| 132 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_EXCEPTIONS() 1 |
| 133 |
#endif |
| 134 |
|
| 135 |
|
| 136 |
#if !defined(ROBIN_HOOD_DISABLE_INTRINSICS) |
| 137 |
# ifdef _MSC_VER |
| 138 |
# if ROBIN_HOOD(BITNESS) == 32 |
| 139 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_BITSCANFORWARD() _BitScanForward |
| 140 |
# else |
| 141 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_BITSCANFORWARD() _BitScanForward64 |
| 142 |
# endif |
| 143 |
# include <intrin.h> |
| 144 |
# pragma intrinsic(ROBIN_HOOD(BITSCANFORWARD)) |
| 145 |
# define ROBIN_HOOD_COUNT_TRAILING_ZEROES(x) \ |
| 146 |
[](size_t mask) noexcept -> int { \ |
| 147 |
unsigned long index; \ |
| 148 |
return ROBIN_HOOD(BITSCANFORWARD)(&index, mask) ? static_cast<int>(index) \ |
| 149 |
: ROBIN_HOOD(BITNESS); \ |
| 150 |
}(x) |
| 151 |
# else |
| 152 |
# if ROBIN_HOOD(BITNESS) == 32 |
| 153 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_CTZ() __builtin_ctzl |
| 154 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_CLZ() __builtin_clzl |
| 155 |
# else |
| 156 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_CTZ() __builtin_ctzll |
| 157 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_CLZ() __builtin_clzll |
| 158 |
# endif |
| 159 |
# define ROBIN_HOOD_COUNT_LEADING_ZEROES(x) ((x) ? ROBIN_HOOD(CLZ)(x) : ROBIN_HOOD(BITNESS)) |
| 160 |
# define ROBIN_HOOD_COUNT_TRAILING_ZEROES(x) ((x) ? ROBIN_HOOD(CTZ)(x) : ROBIN_HOOD(BITNESS)) |
| 161 |
# endif |
| 162 |
#endif |
| 163 |
|
| 164 |
|
| 165 |
#ifndef __has_cpp_attribute |
| 166 |
# define __has_cpp_attribute(x) 0 |
| 167 |
#endif |
| 168 |
#if __has_cpp_attribute(clang::fallthrough) |
| 169 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_FALLTHROUGH() [[clang::fallthrough]] |
| 170 |
#elif __has_cpp_attribute(gnu::fallthrough) |
| 171 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_FALLTHROUGH() [[gnu::fallthrough]] |
| 172 |
#else |
| 173 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_FALLTHROUGH() |
| 174 |
#endif |
| 175 |
|
| 176 |
|
| 177 |
#ifdef _MSC_VER |
| 178 |
# define ROBIN_HOOD_LIKELY(condition) condition |
| 179 |
# define ROBIN_HOOD_UNLIKELY(condition) condition |
| 180 |
#else |
| 181 |
# define ROBIN_HOOD_LIKELY(condition) __builtin_expect(condition, 1) |
| 182 |
# define ROBIN_HOOD_UNLIKELY(condition) __builtin_expect(condition, 0) |
| 183 |
#endif |
| 184 |
|
| 185 |
|
| 186 |
#ifdef _MSC_VER |
| 187 |
# ifdef _NATIVE_WCHAR_T_DEFINED |
| 188 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_NATIVE_WCHART() 1 |
| 189 |
# else |
| 190 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_NATIVE_WCHART() 0 |
| 191 |
# endif |
| 192 |
#else |
| 193 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_NATIVE_WCHART() 1 |
| 194 |
#endif |
| 195 |
|
| 196 |
|
| 197 |
#ifdef _MSC_VER |
| 198 |
# if _MSC_VER <= 1900 |
| 199 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_BROKEN_CONSTEXPR() 1 |
| 200 |
# else |
| 201 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_BROKEN_CONSTEXPR() 0 |
| 202 |
# endif |
| 203 |
#else |
| 204 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_BROKEN_CONSTEXPR() 0 |
| 205 |
#endif |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
#if defined(__GNUC__) && __GNUC__ < 5 |
| 210 |
# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) __has_trivial_copy(__VA_ARGS__) |
| 211 |
#else |
| 212 |
# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) std::is_trivially_copyable<__VA_ARGS__>::value |
| 213 |
#endif |
| 214 |
|
| 215 |
|
| 216 |
#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX() __cplusplus |
| 217 |
#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX98() 199711L |
| 218 |
#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX11() 201103L |
| 219 |
#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX14() 201402L |
| 220 |
#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX17() 201703L |
| 221 |
|
| 222 |
#if ROBIN_HOOD(CXX) >= ROBIN_HOOD(CXX17) |
| 223 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_NODISCARD() [[nodiscard]] |
| 224 |
#else |
| 225 |
# define ROBIN_HOOD_PRIVATE_DEFINITION_NODISCARD() |
| 226 |
#endif |
| 227 |
|
| 228 |
namespace robin_hood { |
| 229 |
|
| 230 |
#if ROBIN_HOOD(CXX) >= ROBIN_HOOD(CXX14) |
| 231 |
# define ROBIN_HOOD_STD std |
| 232 |
#else |
| 233 |
|
| 234 |
|
| 235 |
namespace ROBIN_HOOD_STD { |
| 236 |
template <class T> |
| 237 |
struct alignment_of |
| 238 |
: std::integral_constant<std::size_t, alignof(typename std::remove_all_extents<T>::type)> {}; |
| 239 |
|
| 240 |
template <class T, T... Ints> |
| 241 |
class integer_sequence { |
| 242 |
public: |
| 243 |
using value_type = T; |
| 244 |
static_assert(std::is_integral<value_type>::value, "not integral type"); |
| 245 |
static constexpr std::size_t size() noexcept { |
| 246 |
return sizeof...(Ints); |
| 247 |
} |
| 248 |
}; |
| 249 |
template <std::size_t... Inds> |
| 250 |
using index_sequence = integer_sequence<std::size_t, Inds...>; |
| 251 |
|
| 252 |
namespace detail_ { |
| 253 |
template <class T, T Begin, T End, bool> |
| 254 |
struct IntSeqImpl { |
| 255 |
using TValue = T; |
| 256 |
static_assert(std::is_integral<TValue>::value, "not integral type"); |
| 257 |
static_assert(Begin >= 0 && Begin < End, "unexpected argument (Begin<0 || Begin<=End)"); |
| 258 |
|
| 259 |
template <class, class> |
| 260 |
struct IntSeqCombiner; |
| 261 |
|
| 262 |
template <TValue... Inds0, TValue... Inds1> |
| 263 |
struct IntSeqCombiner<integer_sequence<TValue, Inds0...>, integer_sequence<TValue, Inds1...>> { |
| 264 |
using TResult = integer_sequence<TValue, Inds0..., Inds1...>; |
| 265 |
}; |
| 266 |
|
| 267 |
using TResult = |
| 268 |
typename IntSeqCombiner<typename IntSeqImpl<TValue, Begin, Begin + (End - Begin) / 2, |
| 269 |
(End - Begin) / 2 == 1>::TResult, |
| 270 |
typename IntSeqImpl<TValue, Begin + (End - Begin) / 2, End, |
| 271 |
(End - Begin + 1) / 2 == 1>::TResult>::TResult; |
| 272 |
}; |
| 273 |
|
| 274 |
template <class T, T Begin> |
| 275 |
struct IntSeqImpl<T, Begin, Begin, false> { |
| 276 |
using TValue = T; |
| 277 |
static_assert(std::is_integral<TValue>::value, "not integral type"); |
| 278 |
static_assert(Begin >= 0, "unexpected argument (Begin<0)"); |
| 279 |
using TResult = integer_sequence<TValue>; |
| 280 |
}; |
| 281 |
|
| 282 |
template <class T, T Begin, T End> |
| 283 |
struct IntSeqImpl<T, Begin, End, true> { |
| 284 |
using TValue = T; |
| 285 |
static_assert(std::is_integral<TValue>::value, "not integral type"); |
| 286 |
static_assert(Begin >= 0, "unexpected argument (Begin<0)"); |
| 287 |
using TResult = integer_sequence<TValue, Begin>; |
| 288 |
}; |
| 289 |
} |
| 290 |
|
| 291 |
template <class T, T N> |
| 292 |
using make_integer_sequence = typename detail_::IntSeqImpl<T, 0, N, (N - 0) == 1>::TResult; |
| 293 |
|
| 294 |
template <std::size_t N> |
| 295 |
using make_index_sequence = make_integer_sequence<std::size_t, N>; |
| 296 |
|
| 297 |
template <class... T> |
| 298 |
using index_sequence_for = make_index_sequence<sizeof...(T)>; |
| 299 |
|
| 300 |
} |
| 301 |
|
| 302 |
#endif |
| 303 |
|
| 304 |
namespace detail { |
| 305 |
|
| 306 |
|
| 307 |
#if ROBIN_HOOD(BITNESS) == 64 |
| 308 |
using SizeT = uint64_t; |
| 309 |
#else |
| 310 |
using SizeT = uint32_t; |
| 311 |
#endif |
| 312 |
|
| 313 |
template <typename T> |
| 314 |
T rotr(T x, unsigned k) { |
| 315 |
return (x >> k) | (x << (8U * sizeof(T) - k)); |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
template <typename T> |
| 322 |
inline T reinterpret_cast_no_cast_align_warning(void* ptr) noexcept { |
| 323 |
return reinterpret_cast<T>(ptr); |
| 324 |
} |
| 325 |
|
| 326 |
template <typename T> |
| 327 |
inline T reinterpret_cast_no_cast_align_warning(void const* ptr) noexcept { |
| 328 |
return reinterpret_cast<T>(ptr); |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
template <typename E, typename... Args> |
| 334 |
[[noreturn]] ROBIN_HOOD(NOINLINE) |
| 335 |
#if ROBIN_HOOD(HAS_EXCEPTIONS) |
| 336 |
void doThrow(Args&&... args) { |
| 337 |
|
| 338 |
throw E(std::forward<Args>(args)...); |
| 339 |
} |
| 340 |
#else |
| 341 |
void doThrow(Args&&... ROBIN_HOOD_UNUSED(args) ) { |
| 342 |
abort(); |
| 343 |
} |
| 344 |
#endif |
| 345 |
|
| 346 |
template <typename E, typename T, typename... Args> |
| 347 |
T* assertNotNull(T* t, Args&&... args) { |
| 348 |
if (ROBIN_HOOD_UNLIKELY(nullptr == t)) { |
| 349 |
doThrow<E>(std::forward<Args>(args)...); |
| 350 |
} |
| 351 |
return t; |
| 352 |
} |
| 353 |
|
| 354 |
template <typename T> |
| 355 |
inline T unaligned_load(void const* ptr) noexcept { |
| 356 |
|
| 357 |
|
| 358 |
T t; |
| 359 |
std::memcpy(&t, ptr, sizeof(T)); |
| 360 |
return t; |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
template <typename T, size_t MinNumAllocs = 4, size_t MaxNumAllocs = 256> |
| 367 |
class BulkPoolAllocator { |
| 368 |
public: |
| 369 |
BulkPoolAllocator() noexcept = default; |
| 370 |
|
| 371 |
|
| 372 |
BulkPoolAllocator(const BulkPoolAllocator& ROBIN_HOOD_UNUSED(o) ) noexcept |
| 373 |
: mHead(nullptr) |
| 374 |
, mListForFree(nullptr) {} |
| 375 |
|
| 376 |
BulkPoolAllocator(BulkPoolAllocator&& o) noexcept |
| 377 |
: mHead(o.mHead) |
| 378 |
, mListForFree(o.mListForFree) { |
| 379 |
o.mListForFree = nullptr; |
| 380 |
o.mHead = nullptr; |
| 381 |
} |
| 382 |
|
| 383 |
BulkPoolAllocator& operator=(BulkPoolAllocator&& o) noexcept { |
| 384 |
reset(); |
| 385 |
mHead = o.mHead; |
| 386 |
mListForFree = o.mListForFree; |
| 387 |
o.mListForFree = nullptr; |
| 388 |
o.mHead = nullptr; |
| 389 |
return *this; |
| 390 |
} |
| 391 |
|
| 392 |
BulkPoolAllocator& |
| 393 |
|
| 394 |
operator=(const BulkPoolAllocator& ROBIN_HOOD_UNUSED(o) ) noexcept { |
| 395 |
|
| 396 |
return *this; |
| 397 |
} |
| 398 |
|
| 399 |
~BulkPoolAllocator() noexcept { |
| 400 |
reset(); |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
void reset() noexcept { |
| 405 |
while (mListForFree) { |
| 406 |
T* tmp = *mListForFree; |
| 407 |
ROBIN_HOOD_LOG("std::free") |
| 408 |
std::free(mListForFree); |
| 409 |
mListForFree = reinterpret_cast_no_cast_align_warning<T**>(tmp); |
| 410 |
} |
| 411 |
mHead = nullptr; |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
T* allocate() { |
| 418 |
T* tmp = mHead; |
| 419 |
if (!tmp) { |
| 420 |
tmp = performAllocation(); |
| 421 |
} |
| 422 |
|
| 423 |
mHead = *reinterpret_cast_no_cast_align_warning<T**>(tmp); |
| 424 |
return tmp; |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
void deallocate(T* obj) noexcept { |
| 432 |
*reinterpret_cast_no_cast_align_warning<T**>(obj) = mHead; |
| 433 |
mHead = obj; |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
void addOrFree(void* ptr, const size_t numBytes) noexcept { |
| 440 |
|
| 441 |
if (numBytes < ALIGNMENT + ALIGNED_SIZE) { |
| 442 |
|
| 443 |
ROBIN_HOOD_LOG("std::free") |
| 444 |
std::free(ptr); |
| 445 |
} else { |
| 446 |
ROBIN_HOOD_LOG("add to buffer") |
| 447 |
add(ptr, numBytes); |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
void swap(BulkPoolAllocator<T, MinNumAllocs, MaxNumAllocs>& other) noexcept { |
| 452 |
using std::swap; |
| 453 |
swap(mHead, other.mHead); |
| 454 |
swap(mListForFree, other.mListForFree); |
| 455 |
} |
| 456 |
|
| 457 |
private: |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
ROBIN_HOOD(NODISCARD) size_t calcNumElementsToAlloc() const noexcept { |
| 463 |
auto tmp = mListForFree; |
| 464 |
size_t numAllocs = MinNumAllocs; |
| 465 |
|
| 466 |
while (numAllocs * 2 <= MaxNumAllocs && tmp) { |
| 467 |
auto x = reinterpret_cast<T***>(tmp); |
| 468 |
tmp = *x; |
| 469 |
numAllocs *= 2; |
| 470 |
} |
| 471 |
|
| 472 |
return numAllocs; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
void add(void* ptr, const size_t numBytes) noexcept { |
| 477 |
const size_t numElements = (numBytes - ALIGNMENT) / ALIGNED_SIZE; |
| 478 |
|
| 479 |
auto data = reinterpret_cast<T**>(ptr); |
| 480 |
|
| 481 |
|
| 482 |
auto x = reinterpret_cast<T***>(data); |
| 483 |
*x = mListForFree; |
| 484 |
mListForFree = data; |
| 485 |
|
| 486 |
|
| 487 |
auto* const headT = |
| 488 |
reinterpret_cast_no_cast_align_warning<T*>(reinterpret_cast<char*>(ptr) + ALIGNMENT); |
| 489 |
|
| 490 |
auto* const head = reinterpret_cast<char*>(headT); |
| 491 |
|
| 492 |
|
| 493 |
for (size_t i = 0; i < numElements; ++i) { |
| 494 |
*reinterpret_cast_no_cast_align_warning<char**>(head + i * ALIGNED_SIZE) = |
| 495 |
head + (i + 1) * ALIGNED_SIZE; |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
*reinterpret_cast_no_cast_align_warning<T**>(head + (numElements - 1) * ALIGNED_SIZE) = |
| 500 |
mHead; |
| 501 |
mHead = headT; |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
ROBIN_HOOD(NOINLINE) T* performAllocation() { |
| 507 |
size_t const numElementsToAlloc = calcNumElementsToAlloc(); |
| 508 |
|
| 509 |
|
| 510 |
size_t const bytes = ALIGNMENT + ALIGNED_SIZE * numElementsToAlloc; |
| 511 |
ROBIN_HOOD_LOG("std::malloc " << bytes << " = " << ALIGNMENT << " + " << ALIGNED_SIZE |
| 512 |
<< " * " << numElementsToAlloc) |
| 513 |
add(assertNotNull<std::bad_alloc>(std::malloc(bytes)), bytes); |
| 514 |
return mHead; |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
#if ROBIN_HOOD(CXX) >= ROBIN_HOOD(CXX14) |
| 519 |
static constexpr size_t ALIGNMENT = |
| 520 |
(std::max)(std::alignment_of<T>::value, std::alignment_of<T*>::value); |
| 521 |
#else |
| 522 |
static const size_t ALIGNMENT = |
| 523 |
(ROBIN_HOOD_STD::alignment_of<T>::value > ROBIN_HOOD_STD::alignment_of<T*>::value) |
| 524 |
? ROBIN_HOOD_STD::alignment_of<T>::value |
| 525 |
: +ROBIN_HOOD_STD::alignment_of<T*>::value; |
| 526 |
#endif |
| 527 |
|
| 528 |
static constexpr size_t ALIGNED_SIZE = ((sizeof(T) - 1) / ALIGNMENT + 1) * ALIGNMENT; |
| 529 |
|
| 530 |
static_assert(MinNumAllocs >= 1, "MinNumAllocs"); |
| 531 |
static_assert(MaxNumAllocs >= MinNumAllocs, "MaxNumAllocs"); |
| 532 |
static_assert(ALIGNED_SIZE >= sizeof(T*), "ALIGNED_SIZE"); |
| 533 |
static_assert(0 == (ALIGNED_SIZE % sizeof(T*)), "ALIGNED_SIZE mod"); |
| 534 |
static_assert(ALIGNMENT >= sizeof(T*), "ALIGNMENT"); |
| 535 |
|
| 536 |
T* mHead{nullptr}; |
| 537 |
T** mListForFree{nullptr}; |
| 538 |
}; |
| 539 |
|
| 540 |
template <typename T, size_t MinSize, size_t MaxSize, bool IsFlat> |
| 541 |
struct NodeAllocator; |
| 542 |
|
| 543 |
|
| 544 |
template <typename T, size_t MinSize, size_t MaxSize> |
| 545 |
struct NodeAllocator<T, MinSize, MaxSize, true> { |
| 546 |
|
| 547 |
|
| 548 |
void addOrFree(void* ptr, size_t ROBIN_HOOD_UNUSED(numBytes) ) noexcept { |
| 549 |
ROBIN_HOOD_LOG("std::free") |
| 550 |
std::free(ptr); |
| 551 |
} |
| 552 |
}; |
| 553 |
|
| 554 |
template <typename T, size_t MinSize, size_t MaxSize> |
| 555 |
struct NodeAllocator<T, MinSize, MaxSize, false> : public BulkPoolAllocator<T, MinSize, MaxSize> {}; |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
namespace swappable { |
| 560 |
#if ROBIN_HOOD(CXX) < ROBIN_HOOD(CXX17) |
| 561 |
using std::swap; |
| 562 |
template <typename T> |
| 563 |
struct nothrow { |
| 564 |
static const bool value = noexcept(swap(std::declval<T&>(), std::declval<T&>())); |
| 565 |
}; |
| 566 |
#else |
| 567 |
template <typename T> |
| 568 |
struct nothrow { |
| 569 |
static const bool value = std::is_nothrow_swappable<T>::value; |
| 570 |
}; |
| 571 |
#endif |
| 572 |
} |
| 573 |
|
| 574 |
} |
| 575 |
|
| 576 |
struct is_transparent_tag {}; |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
template <typename T1, typename T2> |
| 582 |
struct pair { |
| 583 |
using first_type = T1; |
| 584 |
using second_type = T2; |
| 585 |
|
| 586 |
template <typename U1 = T1, typename U2 = T2, |
| 587 |
typename = typename std::enable_if<std::is_default_constructible<U1>::value && |
| 588 |
std::is_default_constructible<U2>::value>::type> |
| 589 |
constexpr pair() noexcept(noexcept(U1()) && noexcept(U2())) |
| 590 |
: first() |
| 591 |
, second() {} |
| 592 |
|
| 593 |
|
| 594 |
explicit constexpr pair(std::pair<T1, T2> const& o) noexcept( |
| 595 |
noexcept(T1(std::declval<T1 const&>())) && noexcept(T2(std::declval<T2 const&>()))) |
| 596 |
: first(o.first) |
| 597 |
, second(o.second) {} |
| 598 |
|
| 599 |
|
| 600 |
explicit constexpr pair(std::pair<T1, T2>&& o) noexcept(noexcept( |
| 601 |
T1(std::move(std::declval<T1&&>()))) && noexcept(T2(std::move(std::declval<T2&&>())))) |
| 602 |
: first(std::move(o.first)) |
| 603 |
, second(std::move(o.second)) {} |
| 604 |
|
| 605 |
constexpr pair(T1&& a, T2&& b) noexcept(noexcept( |
| 606 |
T1(std::move(std::declval<T1&&>()))) && noexcept(T2(std::move(std::declval<T2&&>())))) |
| 607 |
: first(std::move(a)) |
| 608 |
, second(std::move(b)) {} |
| 609 |
|
| 610 |
template <typename U1, typename U2> |
| 611 |
constexpr pair(U1&& a, U2&& b) noexcept(noexcept(T1(std::forward<U1>( |
| 612 |
std::declval<U1&&>()))) && noexcept(T2(std::forward<U2>(std::declval<U2&&>())))) |
| 613 |
: first(std::forward<U1>(a)) |
| 614 |
, second(std::forward<U2>(b)) {} |
| 615 |
|
| 616 |
template <typename... U1, typename... U2> |
| 617 |
ers" |
| 618 |
|
| 619 |
#if !ROBIN_HOOD(BROKEN_CONSTEXPR) |
| 620 |
constexpr |
| 621 |
#endif |
| 622 |
pair(std::piecewise_construct_t , std::tuple<U1...> a, |
| 623 |
std::tuple<U2...> |
| 624 |
b) noexcept(noexcept(pair(std::declval<std::tuple<U1...>&>(), |
| 625 |
std::declval<std::tuple<U2...>&>(), |
| 626 |
ROBIN_HOOD_STD::index_sequence_for<U1...>(), |
| 627 |
ROBIN_HOOD_STD::index_sequence_for<U2...>()))) |
| 628 |
: pair(a, b, ROBIN_HOOD_STD::index_sequence_for<U1...>(), |
| 629 |
ROBIN_HOOD_STD::index_sequence_for<U2...>()) { |
| 630 |
} |
| 631 |
|
| 632 |
|
| 633 |
template <typename... U1, size_t... I1, typename... U2, size_t... I2> |
| 634 |
pair(std::tuple<U1...>& a, std::tuple<U2...>& b, ROBIN_HOOD_STD::index_sequence<I1...> , ROBIN_HOOD_STD::index_sequence<I2...> ) noexcept( |
| 635 |
noexcept(T1(std::forward<U1>(std::get<I1>( |
| 636 |
std::declval<std::tuple< |
| 637 |
U1...>&>()))...)) && noexcept(T2(std:: |
| 638 |
forward<U2>(std::get<I2>( |
| 639 |
std::declval<std::tuple<U2...>&>()))...))) |
| 640 |
: first(std::forward<U1>(std::get<I1>(a))...) |
| 641 |
, second(std::forward<U2>(std::get<I2>(b))...) { |
| 642 |
|
| 643 |
|
| 644 |
(void)a; |
| 645 |
(void)b; |
| 646 |
} |
| 647 |
|
| 648 |
void swap(pair<T1, T2>& o) noexcept((detail::swappable::nothrow<T1>::value) && |
| 649 |
(detail::swappable::nothrow<T2>::value)) { |
| 650 |
using std::swap; |
| 651 |
swap(first, o.first); |
| 652 |
swap(second, o.second); |
| 653 |
} |
| 654 |
|
| 655 |
T1 first; |
| 656 |
T2 second; |
| 657 |
}; |
| 658 |
|
| 659 |
template <typename A, typename B> |
| 660 |
inline void swap(pair<A, B>& a, pair<A, B>& b) noexcept( |
| 661 |
noexcept(std::declval<pair<A, B>&>().swap(std::declval<pair<A, B>&>()))) { |
| 662 |
a.swap(b); |
| 663 |
} |
| 664 |
|
| 665 |
template <typename A, typename B> |
| 666 |
inline constexpr bool operator==(pair<A, B> const& x, pair<A, B> const& y) { |
| 667 |
return (x.first == y.first) && (x.second == y.second); |
| 668 |
} |
| 669 |
template <typename A, typename B> |
| 670 |
inline constexpr bool operator!=(pair<A, B> const& x, pair<A, B> const& y) { |
| 671 |
return !(x == y); |
| 672 |
} |
| 673 |
template <typename A, typename B> |
| 674 |
inline constexpr bool operator<(pair<A, B> const& x, pair<A, B> const& y) noexcept(noexcept( |
| 675 |
std::declval<A const&>() < std::declval<A const&>()) && noexcept(std::declval<B const&>() < |
| 676 |
std::declval<B const&>())) { |
| 677 |
return x.first < y.first || (!(y.first < x.first) && x.second < y.second); |
| 678 |
} |
| 679 |
template <typename A, typename B> |
| 680 |
inline constexpr bool operator>(pair<A, B> const& x, pair<A, B> const& y) { |
| 681 |
return y < x; |
| 682 |
} |
| 683 |
template <typename A, typename B> |
| 684 |
inline constexpr bool operator<=(pair<A, B> const& x, pair<A, B> const& y) { |
| 685 |
return !(x > y); |
| 686 |
} |
| 687 |
template <typename A, typename B> |
| 688 |
inline constexpr bool operator>=(pair<A, B> const& x, pair<A, B> const& y) { |
| 689 |
return !(x < y); |
| 690 |
} |
| 691 |
|
| 692 |
inline size_t hash_bytes(void const* ptr, size_t len) noexcept { |
| 693 |
static constexpr uint64_t m = UINT64_C(0xc6a4a7935bd1e995); |
| 694 |
static constexpr uint64_t seed = UINT64_C(0xe17a1465); |
| 695 |
static constexpr unsigned int r = 47; |
| 696 |
|
| 697 |
auto const* const data64 = static_cast<uint64_t const*>(ptr); |
| 698 |
uint64_t h = seed ^ (len * m); |
| 699 |
|
| 700 |
size_t const n_blocks = len / 8; |
| 701 |
for (size_t i = 0; i < n_blocks; ++i) { |
| 702 |
auto k = detail::unaligned_load<uint64_t>(data64 + i); |
| 703 |
|
| 704 |
k *= m; |
| 705 |
k ^= k >> r; |
| 706 |
k *= m; |
| 707 |
|
| 708 |
h ^= k; |
| 709 |
h *= m; |
| 710 |
} |
| 711 |
|
| 712 |
auto const* const data8 = reinterpret_cast<uint8_t const*>(data64 + n_blocks); |
| 713 |
switch (len & 7U) { |
| 714 |
case 7: |
| 715 |
h ^= static_cast<uint64_t>(data8[6]) << 48U; |
| 716 |
ROBIN_HOOD(FALLTHROUGH); |
| 717 |
case 6: |
| 718 |
h ^= static_cast<uint64_t>(data8[5]) << 40U; |
| 719 |
ROBIN_HOOD(FALLTHROUGH); |
| 720 |
case 5: |
| 721 |
h ^= static_cast<uint64_t>(data8[4]) << 32U; |
| 722 |
ROBIN_HOOD(FALLTHROUGH); |
| 723 |
case 4: |
| 724 |
h ^= static_cast<uint64_t>(data8[3]) << 24U; |
| 725 |
ROBIN_HOOD(FALLTHROUGH); |
| 726 |
case 3: |
| 727 |
h ^= static_cast<uint64_t>(data8[2]) << 16U; |
| 728 |
ROBIN_HOOD(FALLTHROUGH); |
| 729 |
case 2: |
| 730 |
h ^= static_cast<uint64_t>(data8[1]) << 8U; |
| 731 |
ROBIN_HOOD(FALLTHROUGH); |
| 732 |
case 1: |
| 733 |
h ^= static_cast<uint64_t>(data8[0]); |
| 734 |
h *= m; |
| 735 |
ROBIN_HOOD(FALLTHROUGH); |
| 736 |
default: |
| 737 |
break; |
| 738 |
} |
| 739 |
|
| 740 |
h ^= h >> r; |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
return static_cast<size_t>(h); |
| 746 |
} |
| 747 |
|
| 748 |
inline size_t hash_int(uint64_t x) noexcept { |
| 749 |
|
| 750 |
|
| 751 |
x ^= x >> 33U; |
| 752 |
x *= UINT64_C(0xff51afd7ed558ccd); |
| 753 |
x ^= x >> 33U; |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
return static_cast<size_t>(x); |
| 759 |
} |
| 760 |
|
| 761 |
|
| 762 |
template <typename T, typename Enable = void> |
| 763 |
struct hash : public std::hash<T> { |
| 764 |
size_t operator()(T const& obj) const |
| 765 |
noexcept(noexcept(std::declval<std::hash<T>>().operator()(std::declval<T const&>()))) { |
| 766 |
|
| 767 |
auto result = std::hash<T>::operator()(obj); |
| 768 |
|
| 769 |
return hash_int(static_cast<detail::SizeT>(result)); |
| 770 |
} |
| 771 |
}; |
| 772 |
|
| 773 |
template <typename CharT> |
| 774 |
struct hash<std::basic_string<CharT>> { |
| 775 |
size_t operator()(std::basic_string<CharT> const& str) const noexcept { |
| 776 |
return hash_bytes(str.data(), sizeof(CharT) * str.size()); |
| 777 |
} |
| 778 |
}; |
| 779 |
|
| 780 |
#if ROBIN_HOOD(CXX) >= ROBIN_HOOD(CXX17) |
| 781 |
template <typename CharT> |
| 782 |
struct hash<std::basic_string_view<CharT>> { |
| 783 |
size_t operator()(std::basic_string_view<CharT> const& sv) const noexcept { |
| 784 |
return hash_bytes(sv.data(), sizeof(CharT) * sv.size()); |
| 785 |
} |
| 786 |
}; |
| 787 |
#endif |
| 788 |
|
| 789 |
template <class T> |
| 790 |
struct hash<T*> { |
| 791 |
size_t operator()(T* ptr) const noexcept { |
| 792 |
return hash_int(reinterpret_cast<detail::SizeT>(ptr)); |
| 793 |
} |
| 794 |
}; |
| 795 |
|
| 796 |
template <class T> |
| 797 |
struct hash<std::unique_ptr<T>> { |
| 798 |
size_t operator()(std::unique_ptr<T> const& ptr) const noexcept { |
| 799 |
return hash_int(reinterpret_cast<detail::SizeT>(ptr.get())); |
| 800 |
} |
| 801 |
}; |
| 802 |
|
| 803 |
template <class T> |
| 804 |
struct hash<std::shared_ptr<T>> { |
| 805 |
size_t operator()(std::shared_ptr<T> const& ptr) const noexcept { |
| 806 |
return hash_int(reinterpret_cast<detail::SizeT>(ptr.get())); |
| 807 |
} |
| 808 |
}; |
| 809 |
|
| 810 |
template <typename Enum> |
| 811 |
struct hash<Enum, typename std::enable_if<std::is_enum<Enum>::value>::type> { |
| 812 |
size_t operator()(Enum e) const noexcept { |
| 813 |
using Underlying = typename std::underlying_type<Enum>::type; |
| 814 |
return hash<Underlying>{}(static_cast<Underlying>(e)); |
| 815 |
} |
| 816 |
}; |
| 817 |
|
| 818 |
#define ROBIN_HOOD_HASH_INT(T) \ |
| 819 |
template <> \ |
| 820 |
struct hash<T> { \ |
| 821 |
size_t operator()(T const& obj) const noexcept { \ |
| 822 |
return hash_int(static_cast<uint64_t>(obj)); \ |
| 823 |
} \ |
| 824 |
} |
| 825 |
|
| 826 |
#if defined(__GNUC__) && !defined(__clang__) |
| 827 |
# pragma GCC diagnostic push |
| 828 |
# pragma GCC diagnostic ignored "-Wuseless-cast" |
| 829 |
#endif |
| 830 |
|
| 831 |
ROBIN_HOOD_HASH_INT(bool); |
| 832 |
ROBIN_HOOD_HASH_INT(char); |
| 833 |
ROBIN_HOOD_HASH_INT(signed char); |
| 834 |
ROBIN_HOOD_HASH_INT(unsigned char); |
| 835 |
ROBIN_HOOD_HASH_INT(char16_t); |
| 836 |
ROBIN_HOOD_HASH_INT(char32_t); |
| 837 |
#if ROBIN_HOOD(HAS_NATIVE_WCHART) |
| 838 |
ROBIN_HOOD_HASH_INT(wchar_t); |
| 839 |
#endif |
| 840 |
ROBIN_HOOD_HASH_INT(short); |
| 841 |
ROBIN_HOOD_HASH_INT(unsigned short); |
| 842 |
ROBIN_HOOD_HASH_INT(int); |
| 843 |
ROBIN_HOOD_HASH_INT(unsigned int); |
| 844 |
ROBIN_HOOD_HASH_INT(long); |
| 845 |
ROBIN_HOOD_HASH_INT(long long); |
| 846 |
ROBIN_HOOD_HASH_INT(unsigned long); |
| 847 |
ROBIN_HOOD_HASH_INT(unsigned long long); |
| 848 |
#if defined(__GNUC__) && !defined(__clang__) |
| 849 |
# pragma GCC diagnostic pop |
| 850 |
#endif |
| 851 |
namespace detail { |
| 852 |
|
| 853 |
template <typename T> |
| 854 |
struct void_type { |
| 855 |
using type = void; |
| 856 |
}; |
| 857 |
|
| 858 |
template <typename T, typename = void> |
| 859 |
struct has_is_transparent : public std::false_type {}; |
| 860 |
|
| 861 |
template <typename T> |
| 862 |
struct has_is_transparent<T, typename void_type<typename T::is_transparent>::type> |
| 863 |
: public std::true_type {}; |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
template <typename T> |
| 868 |
struct WrapHash : public T { |
| 869 |
WrapHash() = default; |
| 870 |
explicit WrapHash(T const& o) noexcept(noexcept(T(std::declval<T const&>()))) |
| 871 |
: T(o) {} |
| 872 |
}; |
| 873 |
|
| 874 |
template <typename T> |
| 875 |
struct WrapKeyEqual : public T { |
| 876 |
WrapKeyEqual() = default; |
| 877 |
explicit WrapKeyEqual(T const& o) noexcept(noexcept(T(std::declval<T const&>()))) |
| 878 |
: T(o) {} |
| 879 |
}; |
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
template <bool IsFlat, size_t MaxLoadFactor100, typename Key, typename T, typename Hash, |
| 908 |
typename KeyEqual> |
| 909 |
class Table |
| 910 |
: public WrapHash<Hash>, |
| 911 |
public WrapKeyEqual<KeyEqual>, |
| 912 |
detail::NodeAllocator< |
| 913 |
typename std::conditional< |
| 914 |
std::is_void<T>::value, Key, |
| 915 |
robin_hood::pair<typename std::conditional<IsFlat, Key, Key const>::type, T>>::type, |
| 916 |
4, 16384, IsFlat> { |
| 917 |
public: |
| 918 |
static constexpr bool is_flat = IsFlat; |
| 919 |
static constexpr bool is_map = !std::is_void<T>::value; |
| 920 |
static constexpr bool is_set = !is_map; |
| 921 |
static constexpr bool is_transparent = |
| 922 |
has_is_transparent<Hash>::value && has_is_transparent<KeyEqual>::value; |
| 923 |
|
| 924 |
using key_type = Key; |
| 925 |
using mapped_type = T; |
| 926 |
using value_type = typename std::conditional< |
| 927 |
is_set, Key, |
| 928 |
robin_hood::pair<typename std::conditional<is_flat, Key, Key const>::type, T>>::type; |
| 929 |
using size_type = size_t; |
| 930 |
using hasher = Hash; |
| 931 |
using key_equal = KeyEqual; |
| 932 |
using Self = Table<IsFlat, MaxLoadFactor100, key_type, mapped_type, hasher, key_equal>; |
| 933 |
|
| 934 |
private: |
| 935 |
static_assert(MaxLoadFactor100 > 10 && MaxLoadFactor100 < 100, |
| 936 |
"MaxLoadFactor100 needs to be >10 && < 100"); |
| 937 |
|
| 938 |
using WHash = WrapHash<Hash>; |
| 939 |
using WKeyEqual = WrapKeyEqual<KeyEqual>; |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
static constexpr size_t InitialNumElements = sizeof(uint64_t); |
| 945 |
static constexpr uint32_t InitialInfoNumBits = 5; |
| 946 |
static constexpr uint8_t InitialInfoInc = 1U << InitialInfoNumBits; |
| 947 |
static constexpr size_t InfoMask = InitialInfoInc - 1U; |
| 948 |
static constexpr uint8_t InitialInfoHashShift = 0; |
| 949 |
using DataPool = detail::NodeAllocator<value_type, 4, 16384, IsFlat>; |
| 950 |
|
| 951 |
|
| 952 |
using InfoType = uint32_t; |
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
template <typename M, bool> |
| 960 |
class DataNode {}; |
| 961 |
|
| 962 |
|
| 963 |
template <typename M> |
| 964 |
class DataNode<M, true> final { |
| 965 |
public: |
| 966 |
template <typename... Args> |
| 967 |
explicit DataNode(M& ROBIN_HOOD_UNUSED(map) , Args&&... args) noexcept( |
| 968 |
noexcept(value_type(std::forward<Args>(args)...))) |
| 969 |
: mData(std::forward<Args>(args)...) {} |
| 970 |
|
| 971 |
DataNode(M& ROBIN_HOOD_UNUSED(map) , DataNode<M, true>&& n) noexcept( |
| 972 |
std::is_nothrow_move_constructible<value_type>::value) |
| 973 |
: mData(std::move(n.mData)) {} |
| 974 |
|
| 975 |
|
| 976 |
void destroy(M& ROBIN_HOOD_UNUSED(map) ) noexcept {} |
| 977 |
void destroyDoNotDeallocate() noexcept {} |
| 978 |
|
| 979 |
value_type const* operator->() const noexcept { |
| 980 |
return &mData; |
| 981 |
} |
| 982 |
value_type* operator->() noexcept { |
| 983 |
return &mData; |
| 984 |
} |
| 985 |
|
| 986 |
const value_type& operator*() const noexcept { |
| 987 |
return mData; |
| 988 |
} |
| 989 |
|
| 990 |
value_type& operator*() noexcept { |
| 991 |
return mData; |
| 992 |
} |
| 993 |
|
| 994 |
template <typename VT = value_type> |
| 995 |
ROBIN_HOOD(NODISCARD) |
| 996 |
typename std::enable_if<is_map, typename VT::first_type&>::type getFirst() noexcept { |
| 997 |
return mData.first; |
| 998 |
} |
| 999 |
template <typename VT = value_type> |
| 1000 |
ROBIN_HOOD(NODISCARD) |
| 1001 |
typename std::enable_if<is_set, VT&>::type getFirst() noexcept { |
| 1002 |
return mData; |
| 1003 |
} |
| 1004 |
|
| 1005 |
template <typename VT = value_type> |
| 1006 |
ROBIN_HOOD(NODISCARD) |
| 1007 |
typename std::enable_if<is_map, typename VT::first_type const&>::type |
| 1008 |
getFirst() const noexcept { |
| 1009 |
return mData.first; |
| 1010 |
} |
| 1011 |
template <typename VT = value_type> |
| 1012 |
ROBIN_HOOD(NODISCARD) |
| 1013 |
typename std::enable_if<is_set, VT const&>::type getFirst() const noexcept { |
| 1014 |
return mData; |
| 1015 |
} |
| 1016 |
|
| 1017 |
template <typename MT = mapped_type> |
| 1018 |
ROBIN_HOOD(NODISCARD) |
| 1019 |
typename std::enable_if<is_map, MT&>::type getSecond() noexcept { |
| 1020 |
return mData.second; |
| 1021 |
} |
| 1022 |
|
| 1023 |
template <typename MT = mapped_type> |
| 1024 |
ROBIN_HOOD(NODISCARD) |
| 1025 |
typename std::enable_if<is_set, MT const&>::type getSecond() const noexcept { |
| 1026 |
return mData.second; |
| 1027 |
} |
| 1028 |
|
| 1029 |
void swap(DataNode<M, true>& o) noexcept( |
| 1030 |
noexcept(std::declval<value_type>().swap(std::declval<value_type>()))) { |
| 1031 |
mData.swap(o.mData); |
| 1032 |
} |
| 1033 |
|
| 1034 |
private: |
| 1035 |
value_type mData; |
| 1036 |
}; |
| 1037 |
|
| 1038 |
|
| 1039 |
template <typename M> |
| 1040 |
class DataNode<M, false> { |
| 1041 |
public: |
| 1042 |
template <typename... Args> |
| 1043 |
explicit DataNode(M& map, Args&&... args) |
| 1044 |
: mData(map.allocate()) { |
| 1045 |
::new (static_cast<void*>(mData)) value_type(std::forward<Args>(args)...); |
| 1046 |
} |
| 1047 |
|
| 1048 |
DataNode(M& ROBIN_HOOD_UNUSED(map) , DataNode<M, false>&& n) noexcept |
| 1049 |
: mData(std::move(n.mData)) {} |
| 1050 |
|
| 1051 |
void destroy(M& map) noexcept { |
| 1052 |
|
| 1053 |
mData->~value_type(); |
| 1054 |
map.deallocate(mData); |
| 1055 |
} |
| 1056 |
|
| 1057 |
void destroyDoNotDeallocate() noexcept { |
| 1058 |
mData->~value_type(); |
| 1059 |
} |
| 1060 |
|
| 1061 |
value_type const* operator->() const noexcept { |
| 1062 |
return mData; |
| 1063 |
} |
| 1064 |
|
| 1065 |
value_type* operator->() noexcept { |
| 1066 |
return mData; |
| 1067 |
} |
| 1068 |
|
| 1069 |
const value_type& operator*() const { |
| 1070 |
return *mData; |
| 1071 |
} |
| 1072 |
|
| 1073 |
value_type& operator*() { |
| 1074 |
return *mData; |
| 1075 |
} |
| 1076 |
|
| 1077 |
template <typename VT = value_type> |
| 1078 |
ROBIN_HOOD(NODISCARD) |
| 1079 |
typename std::enable_if<is_map, typename VT::first_type&>::type getFirst() noexcept { |
| 1080 |
return mData->first; |
| 1081 |
} |
| 1082 |
template <typename VT = value_type> |
| 1083 |
ROBIN_HOOD(NODISCARD) |
| 1084 |
typename std::enable_if<is_set, VT&>::type getFirst() noexcept { |
| 1085 |
return *mData; |
| 1086 |
} |
| 1087 |
|
| 1088 |
template <typename VT = value_type> |
| 1089 |
ROBIN_HOOD(NODISCARD) |
| 1090 |
typename std::enable_if<is_map, typename VT::first_type const&>::type |
| 1091 |
getFirst() const noexcept { |
| 1092 |
return mData->first; |
| 1093 |
} |
| 1094 |
template <typename VT = value_type> |
| 1095 |
ROBIN_HOOD(NODISCARD) |
| 1096 |
typename std::enable_if<is_set, VT const&>::type getFirst() const noexcept { |
| 1097 |
return *mData; |
| 1098 |
} |
| 1099 |
|
| 1100 |
template <typename MT = mapped_type> |
| 1101 |
ROBIN_HOOD(NODISCARD) |
| 1102 |
typename std::enable_if<is_map, MT&>::type getSecond() noexcept { |
| 1103 |
return mData->second; |
| 1104 |
} |
| 1105 |
|
| 1106 |
template <typename MT = mapped_type> |
| 1107 |
ROBIN_HOOD(NODISCARD) |
| 1108 |
typename std::enable_if<is_map, MT const&>::type getSecond() const noexcept { |
| 1109 |
return mData->second; |
| 1110 |
} |
| 1111 |
|
| 1112 |
void swap(DataNode<M, false>& o) noexcept { |
| 1113 |
using std::swap; |
| 1114 |
swap(mData, o.mData); |
| 1115 |
} |
| 1116 |
|
| 1117 |
private: |
| 1118 |
value_type* mData; |
| 1119 |
}; |
| 1120 |
|
| 1121 |
using Node = DataNode<Self, IsFlat>; |
| 1122 |
|
| 1123 |
|
| 1124 |
ROBIN_HOOD(NODISCARD) key_type const& getFirstConst(Node const& n) const noexcept { |
| 1125 |
return n.getFirst(); |
| 1126 |
} |
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
ROBIN_HOOD(NODISCARD) key_type const& getFirstConst(key_type const& k) const noexcept { |
| 1131 |
return k; |
| 1132 |
} |
| 1133 |
|
| 1134 |
|
| 1135 |
template <typename Q = mapped_type> |
| 1136 |
ROBIN_HOOD(NODISCARD) |
| 1137 |
typename std::enable_if<!std::is_void<Q>::value, key_type const&>::type |
| 1138 |
getFirstConst(value_type const& vt) const noexcept { |
| 1139 |
return vt.first; |
| 1140 |
} |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
template <typename M, bool UseMemcpy> |
| 1145 |
struct Cloner; |
| 1146 |
|
| 1147 |
|
| 1148 |
template <typename M> |
| 1149 |
struct Cloner<M, true> { |
| 1150 |
void operator()(M const& source, M& target) const { |
| 1151 |
auto const* const src = reinterpret_cast<char const*>(source.mKeyVals); |
| 1152 |
auto* tgt = reinterpret_cast<char*>(target.mKeyVals); |
| 1153 |
auto const numElementsWithBuffer = target.calcNumElementsWithBuffer(target.mMask + 1); |
| 1154 |
std::copy(src, src + target.calcNumBytesTotal(numElementsWithBuffer), tgt); |
| 1155 |
} |
| 1156 |
}; |
| 1157 |
|
| 1158 |
template <typename M> |
| 1159 |
struct Cloner<M, false> { |
| 1160 |
void operator()(M const& s, M& t) const { |
| 1161 |
auto const numElementsWithBuffer = t.calcNumElementsWithBuffer(t.mMask + 1); |
| 1162 |
std::copy(s.mInfo, s.mInfo + t.calcNumBytesInfo(numElementsWithBuffer), t.mInfo); |
| 1163 |
|
| 1164 |
for (size_t i = 0; i < numElementsWithBuffer; ++i) { |
| 1165 |
if (t.mInfo[i]) { |
| 1166 |
::new (static_cast<void*>(t.mKeyVals + i)) Node(t, *s.mKeyVals[i]); |
| 1167 |
} |
| 1168 |
} |
| 1169 |
} |
| 1170 |
}; |
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
template <typename M, bool IsFlatAndTrivial> |
| 1175 |
struct Destroyer {}; |
| 1176 |
|
| 1177 |
template <typename M> |
| 1178 |
struct Destroyer<M, true> { |
| 1179 |
void nodes(M& m) const noexcept { |
| 1180 |
m.mNumElements = 0; |
| 1181 |
} |
| 1182 |
|
| 1183 |
void nodesDoNotDeallocate(M& m) const noexcept { |
| 1184 |
m.mNumElements = 0; |
| 1185 |
} |
| 1186 |
}; |
| 1187 |
|
| 1188 |
template <typename M> |
| 1189 |
struct Destroyer<M, false> { |
| 1190 |
void nodes(M& m) const noexcept { |
| 1191 |
m.mNumElements = 0; |
| 1192 |
|
| 1193 |
auto const numElementsWithBuffer = m.calcNumElementsWithBuffer(m.mMask + 1); |
| 1194 |
|
| 1195 |
for (size_t idx = 0; idx < numElementsWithBuffer; ++idx) { |
| 1196 |
if (0 != m.mInfo[idx]) { |
| 1197 |
Node& n = m.mKeyVals[idx]; |
| 1198 |
n.destroy(m); |
| 1199 |
n.~Node(); |
| 1200 |
} |
| 1201 |
} |
| 1202 |
} |
| 1203 |
|
| 1204 |
void nodesDoNotDeallocate(M& m) const noexcept { |
| 1205 |
m.mNumElements = 0; |
| 1206 |
|
| 1207 |
auto const numElementsWithBuffer = m.calcNumElementsWithBuffer(m.mMask + 1); |
| 1208 |
for (size_t idx = 0; idx < numElementsWithBuffer; ++idx) { |
| 1209 |
if (0 != m.mInfo[idx]) { |
| 1210 |
Node& n = m.mKeyVals[idx]; |
| 1211 |
n.destroyDoNotDeallocate(); |
| 1212 |
n.~Node(); |
| 1213 |
} |
| 1214 |
} |
| 1215 |
} |
| 1216 |
}; |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
struct fast_forward_tag {}; |
| 1221 |
|
| 1222 |
|
| 1223 |
template <bool IsConst> |
| 1224 |
|
| 1225 |
class Iter { |
| 1226 |
private: |
| 1227 |
using NodePtr = typename std::conditional<IsConst, Node const*, Node*>::type; |
| 1228 |
|
| 1229 |
public: |
| 1230 |
using difference_type = std::ptrdiff_t; |
| 1231 |
using value_type = typename Self::value_type; |
| 1232 |
using reference = typename std::conditional<IsConst, value_type const&, value_type&>::type; |
| 1233 |
using pointer = typename std::conditional<IsConst, value_type const*, value_type*>::type; |
| 1234 |
using iterator_category = std::forward_iterator_tag; |
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
Iter() = default; |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
template <bool OtherIsConst, |
| 1245 |
typename = typename std::enable_if<IsConst && !OtherIsConst>::type> |
| 1246 |
|
| 1247 |
Iter(Iter<OtherIsConst> const& other) noexcept |
| 1248 |
: mKeyVals(other.mKeyVals) |
| 1249 |
, mInfo(other.mInfo) {} |
| 1250 |
|
| 1251 |
Iter(NodePtr valPtr, uint8_t const* infoPtr) noexcept |
| 1252 |
: mKeyVals(valPtr) |
| 1253 |
, mInfo(infoPtr) {} |
| 1254 |
|
| 1255 |
Iter(NodePtr valPtr, uint8_t const* infoPtr, |
| 1256 |
fast_forward_tag ROBIN_HOOD_UNUSED(tag) ) noexcept |
| 1257 |
: mKeyVals(valPtr) |
| 1258 |
, mInfo(infoPtr) { |
| 1259 |
fastForward(); |
| 1260 |
} |
| 1261 |
|
| 1262 |
template <bool OtherIsConst, |
| 1263 |
typename = typename std::enable_if<IsConst && !OtherIsConst>::type> |
| 1264 |
Iter& operator=(Iter<OtherIsConst> const& other) noexcept { |
| 1265 |
mKeyVals = other.mKeyVals; |
| 1266 |
mInfo = other.mInfo; |
| 1267 |
return *this; |
| 1268 |
} |
| 1269 |
|
| 1270 |
|
| 1271 |
Iter& operator++() noexcept { |
| 1272 |
mInfo++; |
| 1273 |
mKeyVals++; |
| 1274 |
fastForward(); |
| 1275 |
return *this; |
| 1276 |
} |
| 1277 |
|
| 1278 |
Iter operator++(int) noexcept { |
| 1279 |
Iter tmp = *this; |
| 1280 |
++(*this); |
| 1281 |
return tmp; |
| 1282 |
} |
| 1283 |
|
| 1284 |
reference operator*() const { |
| 1285 |
return **mKeyVals; |
| 1286 |
} |
| 1287 |
|
| 1288 |
pointer operator->() const { |
| 1289 |
return &**mKeyVals; |
| 1290 |
} |
| 1291 |
|
| 1292 |
template <bool O> |
| 1293 |
bool operator==(Iter<O> const& o) const noexcept { |
| 1294 |
return mKeyVals == o.mKeyVals; |
| 1295 |
} |
| 1296 |
|
| 1297 |
template <bool O> |
| 1298 |
bool operator!=(Iter<O> const& o) const noexcept { |
| 1299 |
return mKeyVals != o.mKeyVals; |
| 1300 |
} |
| 1301 |
|
| 1302 |
private: |
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
void fastForward() noexcept { |
| 1307 |
size_t n = 0; |
| 1308 |
while (0U == (n = detail::unaligned_load<size_t>(mInfo))) { |
| 1309 |
mInfo += sizeof(size_t); |
| 1310 |
mKeyVals += sizeof(size_t); |
| 1311 |
} |
| 1312 |
#if defined(ROBIN_HOOD_DISABLE_INTRINSICS) |
| 1313 |
|
| 1314 |
if (ROBIN_HOOD_UNLIKELY(0U == detail::unaligned_load<uint32_t>(mInfo))) { |
| 1315 |
mInfo += 4; |
| 1316 |
mKeyVals += 4; |
| 1317 |
} |
| 1318 |
if (ROBIN_HOOD_UNLIKELY(0U == detail::unaligned_load<uint16_t>(mInfo))) { |
| 1319 |
mInfo += 2; |
| 1320 |
mKeyVals += 2; |
| 1321 |
} |
| 1322 |
if (ROBIN_HOOD_UNLIKELY(0U == *mInfo)) { |
| 1323 |
mInfo += 1; |
| 1324 |
mKeyVals += 1; |
| 1325 |
} |
| 1326 |
#else |
| 1327 |
# if ROBIN_HOOD(LITTLE_ENDIAN) |
| 1328 |
auto inc = ROBIN_HOOD_COUNT_TRAILING_ZEROES(n) / 8; |
| 1329 |
# else |
| 1330 |
auto inc = ROBIN_HOOD_COUNT_LEADING_ZEROES(n) / 8; |
| 1331 |
# endif |
| 1332 |
mInfo += inc; |
| 1333 |
mKeyVals += inc; |
| 1334 |
#endif |
| 1335 |
} |
| 1336 |
|
| 1337 |
friend class Table<IsFlat, MaxLoadFactor100, key_type, mapped_type, hasher, key_equal>; |
| 1338 |
NodePtr mKeyVals{nullptr}; |
| 1339 |
uint8_t const* mInfo{nullptr}; |
| 1340 |
}; |
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
template <typename HashKey> |
| 1348 |
void keyToIdx(HashKey&& key, size_t* idx, InfoType* info) const { |
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
auto h = static_cast<uint64_t>(WHash::operator()(key)); |
| 1353 |
|
| 1354 |
h *= mHashMultiplier; |
| 1355 |
h ^= h >> 33U; |
| 1356 |
|
| 1357 |
|
| 1358 |
*info = mInfoInc + static_cast<InfoType>((h & InfoMask) >> mInfoHashShift); |
| 1359 |
*idx = (static_cast<size_t>(h) >> InitialInfoNumBits) & mMask; |
| 1360 |
} |
| 1361 |
|
| 1362 |
|
| 1363 |
void next(InfoType* info, size_t* idx) const noexcept { |
| 1364 |
*idx = *idx + 1; |
| 1365 |
*info += mInfoInc; |
| 1366 |
} |
| 1367 |
|
| 1368 |
void nextWhileLess(InfoType* info, size_t* idx) const noexcept { |
| 1369 |
|
| 1370 |
while (*info < mInfo[*idx]) { |
| 1371 |
next(info, idx); |
| 1372 |
} |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
void |
| 1377 |
shiftUp(size_t startIdx, |
| 1378 |
size_t const insertion_idx) noexcept(std::is_nothrow_move_assignable<Node>::value) { |
| 1379 |
auto idx = startIdx; |
| 1380 |
::new (static_cast<void*>(mKeyVals + idx)) Node(std::move(mKeyVals[idx - 1])); |
| 1381 |
while (--idx != insertion_idx) { |
| 1382 |
mKeyVals[idx] = std::move(mKeyVals[idx - 1]); |
| 1383 |
} |
| 1384 |
|
| 1385 |
idx = startIdx; |
| 1386 |
while (idx != insertion_idx) { |
| 1387 |
ROBIN_HOOD_COUNT(shiftUp) |
| 1388 |
mInfo[idx] = static_cast<uint8_t>(mInfo[idx - 1] + mInfoInc); |
| 1389 |
if (ROBIN_HOOD_UNLIKELY(mInfo[idx] + mInfoInc > 0xFF)) { |
| 1390 |
mMaxNumElementsAllowed = 0; |
| 1391 |
} |
| 1392 |
--idx; |
| 1393 |
} |
| 1394 |
} |
| 1395 |
|
| 1396 |
void shiftDown(size_t idx) noexcept(std::is_nothrow_move_assignable<Node>::value) { |
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
mKeyVals[idx].destroy(*this); |
| 1401 |
|
| 1402 |
|
| 1403 |
while (mInfo[idx + 1] >= 2 * mInfoInc) { |
| 1404 |
ROBIN_HOOD_COUNT(shiftDown) |
| 1405 |
mInfo[idx] = static_cast<uint8_t>(mInfo[idx + 1] - mInfoInc); |
| 1406 |
mKeyVals[idx] = std::move(mKeyVals[idx + 1]); |
| 1407 |
++idx; |
| 1408 |
} |
| 1409 |
|
| 1410 |
mInfo[idx] = 0; |
| 1411 |
|
| 1412 |
|
| 1413 |
mKeyVals[idx].~Node(); |
| 1414 |
} |
| 1415 |
|
| 1416 |
|
| 1417 |
template <typename Other> |
| 1418 |
ROBIN_HOOD(NODISCARD) |
| 1419 |
size_t findIdx(Other const& key) const { |
| 1420 |
size_t idx{}; |
| 1421 |
InfoType info{}; |
| 1422 |
keyToIdx(key, &idx, &info); |
| 1423 |
|
| 1424 |
do { |
| 1425 |
|
| 1426 |
if (info == mInfo[idx] && |
| 1427 |
ROBIN_HOOD_LIKELY(WKeyEqual::operator()(key, mKeyVals[idx].getFirst()))) { |
| 1428 |
return idx; |
| 1429 |
} |
| 1430 |
next(&info, &idx); |
| 1431 |
if (info == mInfo[idx] && |
| 1432 |
ROBIN_HOOD_LIKELY(WKeyEqual::operator()(key, mKeyVals[idx].getFirst()))) { |
| 1433 |
return idx; |
| 1434 |
} |
| 1435 |
next(&info, &idx); |
| 1436 |
} while (info <= mInfo[idx]); |
| 1437 |
|
| 1438 |
|
| 1439 |
return mMask == 0 ? 0 |
| 1440 |
: static_cast<size_t>(std::distance( |
| 1441 |
mKeyVals, reinterpret_cast_no_cast_align_warning<Node*>(mInfo))); |
| 1442 |
} |
| 1443 |
|
| 1444 |
void cloneData(const Table& o) { |
| 1445 |
Cloner<Table, IsFlat && ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(Node)>()(o, *this); |
| 1446 |
} |
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
void insert_move(Node&& keyval) { |
| 1451 |
|
| 1452 |
|
| 1453 |
if (0 == mMaxNumElementsAllowed && !try_increase_info()) { |
| 1454 |
throwOverflowError(); |
| 1455 |
} |
| 1456 |
|
| 1457 |
size_t idx{}; |
| 1458 |
InfoType info{}; |
| 1459 |
keyToIdx(keyval.getFirst(), &idx, &info); |
| 1460 |
|
| 1461 |
|
| 1462 |
while (info <= mInfo[idx]) { |
| 1463 |
idx = idx + 1; |
| 1464 |
info += mInfoInc; |
| 1465 |
} |
| 1466 |
|
| 1467 |
|
| 1468 |
auto const insertion_idx = idx; |
| 1469 |
auto const insertion_info = static_cast<uint8_t>(info); |
| 1470 |
if (ROBIN_HOOD_UNLIKELY(insertion_info + mInfoInc > 0xFF)) { |
| 1471 |
mMaxNumElementsAllowed = 0; |
| 1472 |
} |
| 1473 |
|
| 1474 |
|
| 1475 |
while (0 != mInfo[idx]) { |
| 1476 |
next(&info, &idx); |
| 1477 |
} |
| 1478 |
|
| 1479 |
auto& l = mKeyVals[insertion_idx]; |
| 1480 |
if (idx == insertion_idx) { |
| 1481 |
::new (static_cast<void*>(&l)) Node(std::move(keyval)); |
| 1482 |
} else { |
| 1483 |
shiftUp(idx, insertion_idx); |
| 1484 |
l = std::move(keyval); |
| 1485 |
} |
| 1486 |
|
| 1487 |
|
| 1488 |
mInfo[insertion_idx] = insertion_info; |
| 1489 |
|
| 1490 |
++mNumElements; |
| 1491 |
} |
| 1492 |
|
| 1493 |
public: |
| 1494 |
using iterator = Iter<false>; |
| 1495 |
using const_iterator = Iter<true>; |
| 1496 |
|
| 1497 |
Table() noexcept(noexcept(Hash()) && noexcept(KeyEqual())) |
| 1498 |
: WHash() |
| 1499 |
, WKeyEqual() { |
| 1500 |
ROBIN_HOOD_TRACE(this) |
| 1501 |
} |
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
explicit Table( |
| 1509 |
size_t ROBIN_HOOD_UNUSED(bucket_count) , const Hash& h = Hash{}, |
| 1510 |
const KeyEqual& equal = KeyEqual{}) noexcept(noexcept(Hash(h)) && noexcept(KeyEqual(equal))) |
| 1511 |
: WHash(h) |
| 1512 |
, WKeyEqual(equal) { |
| 1513 |
ROBIN_HOOD_TRACE(this) |
| 1514 |
} |
| 1515 |
|
| 1516 |
template <typename Iter> |
| 1517 |
Table(Iter first, Iter last, size_t ROBIN_HOOD_UNUSED(bucket_count) = 0, |
| 1518 |
const Hash& h = Hash{}, const KeyEqual& equal = KeyEqual{}) |
| 1519 |
: WHash(h) |
| 1520 |
, WKeyEqual(equal) { |
| 1521 |
ROBIN_HOOD_TRACE(this) |
| 1522 |
insert(first, last); |
| 1523 |
} |
| 1524 |
|
| 1525 |
Table(std::initializer_list<value_type> initlist, |
| 1526 |
size_t ROBIN_HOOD_UNUSED(bucket_count) = 0, const Hash& h = Hash{}, |
| 1527 |
const KeyEqual& equal = KeyEqual{}) |
| 1528 |
: WHash(h) |
| 1529 |
, WKeyEqual(equal) { |
| 1530 |
ROBIN_HOOD_TRACE(this) |
| 1531 |
insert(initlist.begin(), initlist.end()); |
| 1532 |
} |
| 1533 |
|
| 1534 |
Table(Table&& o) noexcept |
| 1535 |
: WHash(std::move(static_cast<WHash&>(o))) |
| 1536 |
, WKeyEqual(std::move(static_cast<WKeyEqual&>(o))) |
| 1537 |
, DataPool(std::move(static_cast<DataPool&>(o))) { |
| 1538 |
ROBIN_HOOD_TRACE(this) |
| 1539 |
if (o.mMask) { |
| 1540 |
mHashMultiplier = std::move(o.mHashMultiplier); |
| 1541 |
mKeyVals = std::move(o.mKeyVals); |
| 1542 |
mInfo = std::move(o.mInfo); |
| 1543 |
mNumElements = std::move(o.mNumElements); |
| 1544 |
mMask = std::move(o.mMask); |
| 1545 |
mMaxNumElementsAllowed = std::move(o.mMaxNumElementsAllowed); |
| 1546 |
mInfoInc = std::move(o.mInfoInc); |
| 1547 |
mInfoHashShift = std::move(o.mInfoHashShift); |
| 1548 |
|
| 1549 |
o.init(); |
| 1550 |
} |
| 1551 |
} |
| 1552 |
|
| 1553 |
Table& operator=(Table&& o) noexcept { |
| 1554 |
ROBIN_HOOD_TRACE(this) |
| 1555 |
if (&o != this) { |
| 1556 |
if (o.mMask) { |
| 1557 |
|
| 1558 |
destroy(); |
| 1559 |
mHashMultiplier = std::move(o.mHashMultiplier); |
| 1560 |
mKeyVals = std::move(o.mKeyVals); |
| 1561 |
mInfo = std::move(o.mInfo); |
| 1562 |
mNumElements = std::move(o.mNumElements); |
| 1563 |
mMask = std::move(o.mMask); |
| 1564 |
mMaxNumElementsAllowed = std::move(o.mMaxNumElementsAllowed); |
| 1565 |
mInfoInc = std::move(o.mInfoInc); |
| 1566 |
mInfoHashShift = std::move(o.mInfoHashShift); |
| 1567 |
WHash::operator=(std::move(static_cast<WHash&>(o))); |
| 1568 |
WKeyEqual::operator=(std::move(static_cast<WKeyEqual&>(o))); |
| 1569 |
DataPool::operator=(std::move(static_cast<DataPool&>(o))); |
| 1570 |
|
| 1571 |
o.init(); |
| 1572 |
|
| 1573 |
} else { |
| 1574 |
|
| 1575 |
clear(); |
| 1576 |
} |
| 1577 |
} |
| 1578 |
return *this; |
| 1579 |
} |
| 1580 |
|
| 1581 |
Table(const Table& o) |
| 1582 |
: WHash(static_cast<const WHash&>(o)) |
| 1583 |
, WKeyEqual(static_cast<const WKeyEqual&>(o)) |
| 1584 |
, DataPool(static_cast<const DataPool&>(o)) { |
| 1585 |
ROBIN_HOOD_TRACE(this) |
| 1586 |
if (!o.empty()) { |
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
auto const numElementsWithBuffer = calcNumElementsWithBuffer(o.mMask + 1); |
| 1591 |
auto const numBytesTotal = calcNumBytesTotal(numElementsWithBuffer); |
| 1592 |
|
| 1593 |
ROBIN_HOOD_LOG("std::malloc " << numBytesTotal << " = calcNumBytesTotal(" |
| 1594 |
<< numElementsWithBuffer << ")") |
| 1595 |
mHashMultiplier = o.mHashMultiplier; |
| 1596 |
mKeyVals = static_cast<Node*>( |
| 1597 |
detail::assertNotNull<std::bad_alloc>(std::malloc(numBytesTotal))); |
| 1598 |
|
| 1599 |
mInfo = reinterpret_cast<uint8_t*>(mKeyVals + numElementsWithBuffer); |
| 1600 |
mNumElements = o.mNumElements; |
| 1601 |
mMask = o.mMask; |
| 1602 |
mMaxNumElementsAllowed = o.mMaxNumElementsAllowed; |
| 1603 |
mInfoInc = o.mInfoInc; |
| 1604 |
mInfoHashShift = o.mInfoHashShift; |
| 1605 |
cloneData(o); |
| 1606 |
} |
| 1607 |
} |
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
Table& operator=(Table const& o) { |
| 1613 |
ROBIN_HOOD_TRACE(this) |
| 1614 |
if (&o == this) { |
| 1615 |
|
| 1616 |
return *this; |
| 1617 |
} |
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
if (o.empty()) { |
| 1622 |
if (0 == mMask) { |
| 1623 |
|
| 1624 |
return *this; |
| 1625 |
} |
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
destroy(); |
| 1630 |
init(); |
| 1631 |
WHash::operator=(static_cast<const WHash&>(o)); |
| 1632 |
WKeyEqual::operator=(static_cast<const WKeyEqual&>(o)); |
| 1633 |
DataPool::operator=(static_cast<DataPool const&>(o)); |
| 1634 |
|
| 1635 |
return *this; |
| 1636 |
} |
| 1637 |
|
| 1638 |
|
| 1639 |
Destroyer<Self, IsFlat && std::is_trivially_destructible<Node>::value>{}.nodes(*this); |
| 1640 |
|
| 1641 |
if (mMask != o.mMask) { |
| 1642 |
|
| 1643 |
if (0 != mMask) { |
| 1644 |
|
| 1645 |
ROBIN_HOOD_LOG("std::free") |
| 1646 |
std::free(mKeyVals); |
| 1647 |
} |
| 1648 |
|
| 1649 |
auto const numElementsWithBuffer = calcNumElementsWithBuffer(o.mMask + 1); |
| 1650 |
auto const numBytesTotal = calcNumBytesTotal(numElementsWithBuffer); |
| 1651 |
ROBIN_HOOD_LOG("std::malloc " << numBytesTotal << " = calcNumBytesTotal(" |
| 1652 |
<< numElementsWithBuffer << ")") |
| 1653 |
mKeyVals = static_cast<Node*>( |
| 1654 |
detail::assertNotNull<std::bad_alloc>(std::malloc(numBytesTotal))); |
| 1655 |
|
| 1656 |
|
| 1657 |
mInfo = reinterpret_cast<uint8_t*>(mKeyVals + numElementsWithBuffer); |
| 1658 |
|
| 1659 |
} |
| 1660 |
WHash::operator=(static_cast<const WHash&>(o)); |
| 1661 |
WKeyEqual::operator=(static_cast<const WKeyEqual&>(o)); |
| 1662 |
DataPool::operator=(static_cast<DataPool const&>(o)); |
| 1663 |
mHashMultiplier = o.mHashMultiplier; |
| 1664 |
mNumElements = o.mNumElements; |
| 1665 |
mMask = o.mMask; |
| 1666 |
mMaxNumElementsAllowed = o.mMaxNumElementsAllowed; |
| 1667 |
mInfoInc = o.mInfoInc; |
| 1668 |
mInfoHashShift = o.mInfoHashShift; |
| 1669 |
cloneData(o); |
| 1670 |
|
| 1671 |
return *this; |
| 1672 |
} |
| 1673 |
|
| 1674 |
|
| 1675 |
void swap(Table& o) { |
| 1676 |
ROBIN_HOOD_TRACE(this) |
| 1677 |
using std::swap; |
| 1678 |
swap(o, *this); |
| 1679 |
} |
| 1680 |
|
| 1681 |
|
| 1682 |
void clear() { |
| 1683 |
ROBIN_HOOD_TRACE(this) |
| 1684 |
if (empty()) { |
| 1685 |
|
| 1686 |
|
| 1687 |
return; |
| 1688 |
} |
| 1689 |
|
| 1690 |
Destroyer<Self, IsFlat && std::is_trivially_destructible<Node>::value>{}.nodes(*this); |
| 1691 |
|
| 1692 |
auto const numElementsWithBuffer = calcNumElementsWithBuffer(mMask + 1); |
| 1693 |
|
| 1694 |
uint8_t const z = 0; |
| 1695 |
std::fill(mInfo, mInfo + calcNumBytesInfo(numElementsWithBuffer), z); |
| 1696 |
mInfo[numElementsWithBuffer] = 1; |
| 1697 |
|
| 1698 |
mInfoInc = InitialInfoInc; |
| 1699 |
mInfoHashShift = InitialInfoHashShift; |
| 1700 |
} |
| 1701 |
|
| 1702 |
|
| 1703 |
~Table() { |
| 1704 |
ROBIN_HOOD_TRACE(this) |
| 1705 |
destroy(); |
| 1706 |
} |
| 1707 |
|
| 1708 |
|
| 1709 |
bool operator==(const Table& other) const { |
| 1710 |
ROBIN_HOOD_TRACE(this) |
| 1711 |
if (other.size() != size()) { |
| 1712 |
return false; |
| 1713 |
} |
| 1714 |
for (auto const& otherEntry : other) { |
| 1715 |
if (!has(otherEntry)) { |
| 1716 |
return false; |
| 1717 |
} |
| 1718 |
} |
| 1719 |
|
| 1720 |
return true; |
| 1721 |
} |
| 1722 |
|
| 1723 |
bool operator!=(const Table& other) const { |
| 1724 |
ROBIN_HOOD_TRACE(this) |
| 1725 |
return !operator==(other); |
| 1726 |
} |
| 1727 |
|
| 1728 |
template <typename Q = mapped_type> |
| 1729 |
typename std::enable_if<!std::is_void<Q>::value, Q&>::type operator[](const key_type& key) { |
| 1730 |
ROBIN_HOOD_TRACE(this) |
| 1731 |
auto idxAndState = insertKeyPrepareEmptySpot(key); |
| 1732 |
switch (idxAndState.second) { |
| 1733 |
case InsertionState::key_found: |
| 1734 |
break; |
| 1735 |
|
| 1736 |
case InsertionState::new_node: |
| 1737 |
::new (static_cast<void*>(&mKeyVals[idxAndState.first])) |
| 1738 |
Node(*this, std::piecewise_construct, std::forward_as_tuple(key), |
| 1739 |
std::forward_as_tuple()); |
| 1740 |
break; |
| 1741 |
|
| 1742 |
case InsertionState::overwrite_node: |
| 1743 |
mKeyVals[idxAndState.first] = Node(*this, std::piecewise_construct, |
| 1744 |
std::forward_as_tuple(key), std::forward_as_tuple()); |
| 1745 |
break; |
| 1746 |
|
| 1747 |
case InsertionState::overflow_error: |
| 1748 |
throwOverflowError(); |
| 1749 |
} |
| 1750 |
|
| 1751 |
return mKeyVals[idxAndState.first].getSecond(); |
| 1752 |
} |
| 1753 |
|
| 1754 |
template <typename Q = mapped_type> |
| 1755 |
typename std::enable_if<!std::is_void<Q>::value, Q&>::type operator[](key_type&& key) { |
| 1756 |
ROBIN_HOOD_TRACE(this) |
| 1757 |
auto idxAndState = insertKeyPrepareEmptySpot(key); |
| 1758 |
switch (idxAndState.second) { |
| 1759 |
case InsertionState::key_found: |
| 1760 |
break; |
| 1761 |
|
| 1762 |
case InsertionState::new_node: |
| 1763 |
::new (static_cast<void*>(&mKeyVals[idxAndState.first])) |
| 1764 |
Node(*this, std::piecewise_construct, std::forward_as_tuple(std::move(key)), |
| 1765 |
std::forward_as_tuple()); |
| 1766 |
break; |
| 1767 |
|
| 1768 |
case InsertionState::overwrite_node: |
| 1769 |
mKeyVals[idxAndState.first] = |
| 1770 |
Node(*this, std::piecewise_construct, std::forward_as_tuple(std::move(key)), |
| 1771 |
std::forward_as_tuple()); |
| 1772 |
break; |
| 1773 |
|
| 1774 |
case InsertionState::overflow_error: |
| 1775 |
throwOverflowError(); |
| 1776 |
} |
| 1777 |
|
| 1778 |
return mKeyVals[idxAndState.first].getSecond(); |
| 1779 |
} |
| 1780 |
|
| 1781 |
template <typename Iter> |
| 1782 |
void insert(Iter first, Iter last) { |
| 1783 |
for (; first != last; ++first) { |
| 1784 |
|
| 1785 |
insert(value_type(*first)); |
| 1786 |
} |
| 1787 |
} |
| 1788 |
|
| 1789 |
void insert(std::initializer_list<value_type> ilist) { |
| 1790 |
for (auto&& vt : ilist) { |
| 1791 |
insert(std::move(vt)); |
| 1792 |
} |
| 1793 |
} |
| 1794 |
|
| 1795 |
template <typename... Args> |
| 1796 |
std::pair<iterator, bool> emplace(Args&&... args) { |
| 1797 |
ROBIN_HOOD_TRACE(this) |
| 1798 |
Node n{*this, std::forward<Args>(args)...}; |
| 1799 |
auto idxAndState = insertKeyPrepareEmptySpot(getFirstConst(n)); |
| 1800 |
switch (idxAndState.second) { |
| 1801 |
case InsertionState::key_found: |
| 1802 |
n.destroy(*this); |
| 1803 |
break; |
| 1804 |
|
| 1805 |
case InsertionState::new_node: |
| 1806 |
::new (static_cast<void*>(&mKeyVals[idxAndState.first])) Node(*this, std::move(n)); |
| 1807 |
break; |
| 1808 |
|
| 1809 |
case InsertionState::overwrite_node: |
| 1810 |
mKeyVals[idxAndState.first] = std::move(n); |
| 1811 |
break; |
| 1812 |
|
| 1813 |
case InsertionState::overflow_error: |
| 1814 |
n.destroy(*this); |
| 1815 |
throwOverflowError(); |
| 1816 |
break; |
| 1817 |
} |
| 1818 |
|
| 1819 |
return std::make_pair(iterator(mKeyVals + idxAndState.first, mInfo + idxAndState.first), |
| 1820 |
InsertionState::key_found != idxAndState.second); |
| 1821 |
} |
| 1822 |
|
| 1823 |
template <typename... Args> |
| 1824 |
iterator emplace_hint(const_iterator position, Args&&... args) { |
| 1825 |
(void)position; |
| 1826 |
return emplace(std::forward<Args>(args)...).first; |
| 1827 |
} |
| 1828 |
|
| 1829 |
template <typename... Args> |
| 1830 |
std::pair<iterator, bool> try_emplace(const key_type& key, Args&&... args) { |
| 1831 |
return try_emplace_impl(key, std::forward<Args>(args)...); |
| 1832 |
} |
| 1833 |
|
| 1834 |
template <typename... Args> |
| 1835 |
std::pair<iterator, bool> try_emplace(key_type&& key, Args&&... args) { |
| 1836 |
return try_emplace_impl(std::move(key), std::forward<Args>(args)...); |
| 1837 |
} |
| 1838 |
|
| 1839 |
template <typename... Args> |
| 1840 |
iterator try_emplace(const_iterator hint, const key_type& key, Args&&... args) { |
| 1841 |
(void)hint; |
| 1842 |
return try_emplace_impl(key, std::forward<Args>(args)...).first; |
| 1843 |
} |
| 1844 |
|
| 1845 |
template <typename... Args> |
| 1846 |
iterator try_emplace(const_iterator hint, key_type&& key, Args&&... args) { |
| 1847 |
(void)hint; |
| 1848 |
return try_emplace_impl(std::move(key), std::forward<Args>(args)...).first; |
| 1849 |
} |
| 1850 |
|
| 1851 |
template <typename Mapped> |
| 1852 |
std::pair<iterator, bool> insert_or_assign(const key_type& key, Mapped&& obj) { |
| 1853 |
return insertOrAssignImpl(key, std::forward<Mapped>(obj)); |
| 1854 |
} |
| 1855 |
|
| 1856 |
template <typename Mapped> |
| 1857 |
std::pair<iterator, bool> insert_or_assign(key_type&& key, Mapped&& obj) { |
| 1858 |
return insertOrAssignImpl(std::move(key), std::forward<Mapped>(obj)); |
| 1859 |
} |
| 1860 |
|
| 1861 |
template <typename Mapped> |
| 1862 |
iterator insert_or_assign(const_iterator hint, const key_type& key, Mapped&& obj) { |
| 1863 |
(void)hint; |
| 1864 |
return insertOrAssignImpl(key, std::forward<Mapped>(obj)).first; |
| 1865 |
} |
| 1866 |
|
| 1867 |
template <typename Mapped> |
| 1868 |
iterator insert_or_assign(const_iterator hint, key_type&& key, Mapped&& obj) { |
| 1869 |
(void)hint; |
| 1870 |
return insertOrAssignImpl(std::move(key), std::forward<Mapped>(obj)).first; |
| 1871 |
} |
| 1872 |
|
| 1873 |
std::pair<iterator, bool> insert(const value_type& keyval) { |
| 1874 |
ROBIN_HOOD_TRACE(this) |
| 1875 |
return emplace(keyval); |
| 1876 |
} |
| 1877 |
|
| 1878 |
iterator insert(const_iterator hint, const value_type& keyval) { |
| 1879 |
(void)hint; |
| 1880 |
return emplace(keyval).first; |
| 1881 |
} |
| 1882 |
|
| 1883 |
std::pair<iterator, bool> insert(value_type&& keyval) { |
| 1884 |
return emplace(std::move(keyval)); |
| 1885 |
} |
| 1886 |
|
| 1887 |
iterator insert(const_iterator hint, value_type&& keyval) { |
| 1888 |
(void)hint; |
| 1889 |
return emplace(std::move(keyval)).first; |
| 1890 |
} |
| 1891 |
|
| 1892 |
|
| 1893 |
size_t count(const key_type& key) const { |
| 1894 |
ROBIN_HOOD_TRACE(this) |
| 1895 |
auto kv = mKeyVals + findIdx(key); |
| 1896 |
if (kv != reinterpret_cast_no_cast_align_warning<Node*>(mInfo)) { |
| 1897 |
return 1; |
| 1898 |
} |
| 1899 |
return 0; |
| 1900 |
} |
| 1901 |
|
| 1902 |
template <typename OtherKey, typename Self_ = Self> |
| 1903 |
|
| 1904 |
typename std::enable_if<Self_::is_transparent, size_t>::type count(const OtherKey& key) const { |
| 1905 |
ROBIN_HOOD_TRACE(this) |
| 1906 |
auto kv = mKeyVals + findIdx(key); |
| 1907 |
if (kv != reinterpret_cast_no_cast_align_warning<Node*>(mInfo)) { |
| 1908 |
return 1; |
| 1909 |
} |
| 1910 |
return 0; |
| 1911 |
} |
| 1912 |
|
| 1913 |
bool contains(const key_type& key) const { |
| 1914 |
return 1U == count(key); |
| 1915 |
} |
| 1916 |
|
| 1917 |
template <typename OtherKey, typename Self_ = Self> |
| 1918 |
|
| 1919 |
typename std::enable_if<Self_::is_transparent, bool>::type contains(const OtherKey& key) const { |
| 1920 |
return 1U == count(key); |
| 1921 |
} |
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
template <typename Q = mapped_type> |
| 1926 |
|
| 1927 |
typename std::enable_if<!std::is_void<Q>::value, Q&>::type at(key_type const& key) { |
| 1928 |
ROBIN_HOOD_TRACE(this) |
| 1929 |
auto kv = mKeyVals + findIdx(key); |
| 1930 |
if (kv == reinterpret_cast_no_cast_align_warning<Node*>(mInfo)) { |
| 1931 |
doThrow<std::out_of_range>("key not found"); |
| 1932 |
} |
| 1933 |
return kv->getSecond(); |
| 1934 |
} |
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
template <typename Q = mapped_type> |
| 1939 |
|
| 1940 |
typename std::enable_if<!std::is_void<Q>::value, Q const&>::type at(key_type const& key) const { |
| 1941 |
ROBIN_HOOD_TRACE(this) |
| 1942 |
auto kv = mKeyVals + findIdx(key); |
| 1943 |
if (kv == reinterpret_cast_no_cast_align_warning<Node*>(mInfo)) { |
| 1944 |
doThrow<std::out_of_range>("key not found"); |
| 1945 |
} |
| 1946 |
return kv->getSecond(); |
| 1947 |
} |
| 1948 |
|
| 1949 |
const_iterator find(const key_type& key) const { |
| 1950 |
ROBIN_HOOD_TRACE(this) |
| 1951 |
const size_t idx = findIdx(key); |
| 1952 |
return const_iterator{mKeyVals + idx, mInfo + idx}; |
| 1953 |
} |
| 1954 |
|
| 1955 |
template <typename OtherKey> |
| 1956 |
const_iterator find(const OtherKey& key, is_transparent_tag ) const { |
| 1957 |
ROBIN_HOOD_TRACE(this) |
| 1958 |
const size_t idx = findIdx(key); |
| 1959 |
return const_iterator{mKeyVals + idx, mInfo + idx}; |
| 1960 |
} |
| 1961 |
|
| 1962 |
template <typename OtherKey, typename Self_ = Self> |
| 1963 |
typename std::enable_if<Self_::is_transparent, |
| 1964 |
const_iterator>::type |
| 1965 |
find(const OtherKey& key) const { |
| 1966 |
ROBIN_HOOD_TRACE(this) |
| 1967 |
const size_t idx = findIdx(key); |
| 1968 |
return const_iterator{mKeyVals + idx, mInfo + idx}; |
| 1969 |
} |
| 1970 |
|
| 1971 |
iterator find(const key_type& key) { |
| 1972 |
ROBIN_HOOD_TRACE(this) |
| 1973 |
const size_t idx = findIdx(key); |
| 1974 |
return iterator{mKeyVals + idx, mInfo + idx}; |
| 1975 |
} |
| 1976 |
|
| 1977 |
template <typename OtherKey> |
| 1978 |
iterator find(const OtherKey& key, is_transparent_tag ) { |
| 1979 |
ROBIN_HOOD_TRACE(this) |
| 1980 |
const size_t idx = findIdx(key); |
| 1981 |
return iterator{mKeyVals + idx, mInfo + idx}; |
| 1982 |
} |
| 1983 |
|
| 1984 |
template <typename OtherKey, typename Self_ = Self> |
| 1985 |
typename std::enable_if<Self_::is_transparent, iterator>::type find(const OtherKey& key) { |
| 1986 |
ROBIN_HOOD_TRACE(this) |
| 1987 |
const size_t idx = findIdx(key); |
| 1988 |
return iterator{mKeyVals + idx, mInfo + idx}; |
| 1989 |
} |
| 1990 |
|
| 1991 |
iterator begin() { |
| 1992 |
ROBIN_HOOD_TRACE(this) |
| 1993 |
if (empty()) { |
| 1994 |
return end(); |
| 1995 |
} |
| 1996 |
return iterator(mKeyVals, mInfo, fast_forward_tag{}); |
| 1997 |
} |
| 1998 |
const_iterator begin() const { |
| 1999 |
ROBIN_HOOD_TRACE(this) |
| 2000 |
return cbegin(); |
| 2001 |
} |
| 2002 |
const_iterator cbegin() const { |
| 2003 |
ROBIN_HOOD_TRACE(this) |
| 2004 |
if (empty()) { |
| 2005 |
return cend(); |
| 2006 |
} |
| 2007 |
return const_iterator(mKeyVals, mInfo, fast_forward_tag{}); |
| 2008 |
} |
| 2009 |
|
| 2010 |
iterator end() { |
| 2011 |
ROBIN_HOOD_TRACE(this) |
| 2012 |
|
| 2013 |
|
| 2014 |
return iterator{reinterpret_cast_no_cast_align_warning<Node*>(mInfo), nullptr}; |
| 2015 |
} |
| 2016 |
const_iterator end() const { |
| 2017 |
ROBIN_HOOD_TRACE(this) |
| 2018 |
return cend(); |
| 2019 |
} |
| 2020 |
const_iterator cend() const { |
| 2021 |
ROBIN_HOOD_TRACE(this) |
| 2022 |
return const_iterator{reinterpret_cast_no_cast_align_warning<Node*>(mInfo), nullptr}; |
| 2023 |
} |
| 2024 |
|
| 2025 |
iterator erase(const_iterator pos) { |
| 2026 |
ROBIN_HOOD_TRACE(this) |
| 2027 |
|
| 2028 |
|
| 2029 |
return erase(iterator{const_cast<Node*>(pos.mKeyVals), const_cast<uint8_t*>(pos.mInfo)}); |
| 2030 |
} |
| 2031 |
|
| 2032 |
|
| 2033 |
iterator erase(iterator pos) { |
| 2034 |
ROBIN_HOOD_TRACE(this) |
| 2035 |
|
| 2036 |
auto const idx = static_cast<size_t>(pos.mKeyVals - mKeyVals); |
| 2037 |
|
| 2038 |
shiftDown(idx); |
| 2039 |
--mNumElements; |
| 2040 |
|
| 2041 |
if (*pos.mInfo) { |
| 2042 |
|
| 2043 |
return pos; |
| 2044 |
} |
| 2045 |
|
| 2046 |
|
| 2047 |
return ++pos; |
| 2048 |
} |
| 2049 |
|
| 2050 |
size_t erase(const key_type& key) { |
| 2051 |
ROBIN_HOOD_TRACE(this) |
| 2052 |
size_t idx{}; |
| 2053 |
InfoType info{}; |
| 2054 |
keyToIdx(key, &idx, &info); |
| 2055 |
|
| 2056 |
|
| 2057 |
do { |
| 2058 |
if (info == mInfo[idx] && WKeyEqual::operator()(key, mKeyVals[idx].getFirst())) { |
| 2059 |
shiftDown(idx); |
| 2060 |
--mNumElements; |
| 2061 |
return 1; |
| 2062 |
} |
| 2063 |
next(&info, &idx); |
| 2064 |
} while (info <= mInfo[idx]); |
| 2065 |
|
| 2066 |
|
| 2067 |
return 0; |
| 2068 |
} |
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
void rehash(size_t c) { |
| 2073 |
|
| 2074 |
reserve(c, true); |
| 2075 |
} |
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
void reserve(size_t c) { |
| 2080 |
|
| 2081 |
reserve(c, false); |
| 2082 |
} |
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
void compact() { |
| 2087 |
ROBIN_HOOD_TRACE(this) |
| 2088 |
auto newSize = InitialNumElements; |
| 2089 |
while (calcMaxNumElementsAllowed(newSize) < mNumElements && newSize != 0) { |
| 2090 |
newSize *= 2; |
| 2091 |
} |
| 2092 |
if (ROBIN_HOOD_UNLIKELY(newSize == 0)) { |
| 2093 |
throwOverflowError(); |
| 2094 |
} |
| 2095 |
|
| 2096 |
ROBIN_HOOD_LOG("newSize > mMask + 1: " << newSize << " > " << mMask << " + 1") |
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
if (newSize < mMask + 1) { |
| 2101 |
rehashPowerOfTwo(newSize, true); |
| 2102 |
} |
| 2103 |
} |
| 2104 |
|
| 2105 |
size_type size() const noexcept { |
| 2106 |
ROBIN_HOOD_TRACE(this) |
| 2107 |
return mNumElements; |
| 2108 |
} |
| 2109 |
|
| 2110 |
size_type max_size() const noexcept { |
| 2111 |
ROBIN_HOOD_TRACE(this) |
| 2112 |
return static_cast<size_type>(-1); |
| 2113 |
} |
| 2114 |
|
| 2115 |
ROBIN_HOOD(NODISCARD) bool empty() const noexcept { |
| 2116 |
ROBIN_HOOD_TRACE(this) |
| 2117 |
return 0 == mNumElements; |
| 2118 |
} |
| 2119 |
|
| 2120 |
float max_load_factor() const noexcept { |
| 2121 |
ROBIN_HOOD_TRACE(this) |
| 2122 |
return MaxLoadFactor100 / 100.0F; |
| 2123 |
} |
| 2124 |
|
| 2125 |
|
| 2126 |
float load_factor() const noexcept { |
| 2127 |
ROBIN_HOOD_TRACE(this) |
| 2128 |
return static_cast<float>(size()) / static_cast<float>(mMask + 1); |
| 2129 |
} |
| 2130 |
|
| 2131 |
ROBIN_HOOD(NODISCARD) size_t mask() const noexcept { |
| 2132 |
ROBIN_HOOD_TRACE(this) |
| 2133 |
return mMask; |
| 2134 |
} |
| 2135 |
|
| 2136 |
ROBIN_HOOD(NODISCARD) size_t calcMaxNumElementsAllowed(size_t maxElements) const noexcept { |
| 2137 |
if (ROBIN_HOOD_LIKELY(maxElements <= (std::numeric_limits<size_t>::max)() / 100)) { |
| 2138 |
return maxElements * MaxLoadFactor100 / 100; |
| 2139 |
} |
| 2140 |
|
| 2141 |
|
| 2142 |
return (maxElements / 100) * MaxLoadFactor100; |
| 2143 |
} |
| 2144 |
|
| 2145 |
ROBIN_HOOD(NODISCARD) size_t calcNumBytesInfo(size_t numElements) const noexcept { |
| 2146 |
|
| 2147 |
|
| 2148 |
return numElements + sizeof(uint64_t); |
| 2149 |
} |
| 2150 |
|
| 2151 |
ROBIN_HOOD(NODISCARD) |
| 2152 |
size_t calcNumElementsWithBuffer(size_t numElements) const noexcept { |
| 2153 |
auto maxNumElementsAllowed = calcMaxNumElementsAllowed(numElements); |
| 2154 |
return numElements + (std::min)(maxNumElementsAllowed, (static_cast<size_t>(0xFF))); |
| 2155 |
} |
| 2156 |
|
| 2157 |
|
| 2158 |
ROBIN_HOOD(NODISCARD) size_t calcNumBytesTotal(size_t numElements) const { |
| 2159 |
#if ROBIN_HOOD(BITNESS) == 64 |
| 2160 |
return numElements * sizeof(Node) + calcNumBytesInfo(numElements); |
| 2161 |
#else |
| 2162 |
|
| 2163 |
auto const ne = static_cast<uint64_t>(numElements); |
| 2164 |
auto const s = static_cast<uint64_t>(sizeof(Node)); |
| 2165 |
auto const infos = static_cast<uint64_t>(calcNumBytesInfo(numElements)); |
| 2166 |
|
| 2167 |
auto const total64 = ne * s + infos; |
| 2168 |
auto const total = static_cast<size_t>(total64); |
| 2169 |
|
| 2170 |
if (ROBIN_HOOD_UNLIKELY(static_cast<uint64_t>(total) != total64)) { |
| 2171 |
throwOverflowError(); |
| 2172 |
} |
| 2173 |
return total; |
| 2174 |
#endif |
| 2175 |
} |
| 2176 |
|
| 2177 |
private: |
| 2178 |
template <typename Q = mapped_type> |
| 2179 |
ROBIN_HOOD(NODISCARD) |
| 2180 |
typename std::enable_if<!std::is_void<Q>::value, bool>::type has(const value_type& e) const { |
| 2181 |
ROBIN_HOOD_TRACE(this) |
| 2182 |
auto it = find(e.first); |
| 2183 |
return it != end() && it->second == e.second; |
| 2184 |
} |
| 2185 |
|
| 2186 |
template <typename Q = mapped_type> |
| 2187 |
ROBIN_HOOD(NODISCARD) |
| 2188 |
typename std::enable_if<std::is_void<Q>::value, bool>::type has(const value_type& e) const { |
| 2189 |
ROBIN_HOOD_TRACE(this) |
| 2190 |
return find(e) != end(); |
| 2191 |
} |
| 2192 |
|
| 2193 |
void reserve(size_t c, bool forceRehash) { |
| 2194 |
ROBIN_HOOD_TRACE(this) |
| 2195 |
auto const minElementsAllowed = (std::max)(c, mNumElements); |
| 2196 |
auto newSize = InitialNumElements; |
| 2197 |
while (calcMaxNumElementsAllowed(newSize) < minElementsAllowed && newSize != 0) { |
| 2198 |
newSize *= 2; |
| 2199 |
} |
| 2200 |
if (ROBIN_HOOD_UNLIKELY(newSize == 0)) { |
| 2201 |
throwOverflowError(); |
| 2202 |
} |
| 2203 |
|
| 2204 |
ROBIN_HOOD_LOG("newSize > mMask + 1: " << newSize << " > " << mMask << " + 1") |
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
if (forceRehash || newSize > mMask + 1) { |
| 2209 |
rehashPowerOfTwo(newSize, false); |
| 2210 |
} |
| 2211 |
} |
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
void rehashPowerOfTwo(size_t numBuckets, bool forceFree) { |
| 2217 |
ROBIN_HOOD_TRACE(this) |
| 2218 |
|
| 2219 |
Node* const oldKeyVals = mKeyVals; |
| 2220 |
uint8_t const* const oldInfo = mInfo; |
| 2221 |
|
| 2222 |
const size_t oldMaxElementsWithBuffer = calcNumElementsWithBuffer(mMask + 1); |
| 2223 |
|
| 2224 |
|
| 2225 |
initData(numBuckets); |
| 2226 |
if (oldMaxElementsWithBuffer > 1) { |
| 2227 |
for (size_t i = 0; i < oldMaxElementsWithBuffer; ++i) { |
| 2228 |
if (oldInfo[i] != 0) { |
| 2229 |
|
| 2230 |
|
| 2231 |
insert_move(std::move(oldKeyVals[i])); |
| 2232 |
|
| 2233 |
oldKeyVals[i].~Node(); |
| 2234 |
} |
| 2235 |
} |
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
if (oldKeyVals != reinterpret_cast_no_cast_align_warning<Node*>(&mMask)) { |
| 2241 |
|
| 2242 |
if (forceFree) { |
| 2243 |
std::free(oldKeyVals); |
| 2244 |
} else { |
| 2245 |
DataPool::addOrFree(oldKeyVals, calcNumBytesTotal(oldMaxElementsWithBuffer)); |
| 2246 |
} |
| 2247 |
} |
| 2248 |
} |
| 2249 |
} |
| 2250 |
|
| 2251 |
ROBIN_HOOD(NOINLINE) void throwOverflowError() const { |
| 2252 |
#if ROBIN_HOOD(HAS_EXCEPTIONS) |
| 2253 |
throw std::overflow_error("robin_hood::map overflow"); |
| 2254 |
#else |
| 2255 |
abort(); |
| 2256 |
#endif |
| 2257 |
} |
| 2258 |
|
| 2259 |
template <typename OtherKey, typename... Args> |
| 2260 |
std::pair<iterator, bool> try_emplace_impl(OtherKey&& key, Args&&... args) { |
| 2261 |
ROBIN_HOOD_TRACE(this) |
| 2262 |
auto idxAndState = insertKeyPrepareEmptySpot(key); |
| 2263 |
switch (idxAndState.second) { |
| 2264 |
case InsertionState::key_found: |
| 2265 |
break; |
| 2266 |
|
| 2267 |
case InsertionState::new_node: |
| 2268 |
::new (static_cast<void*>(&mKeyVals[idxAndState.first])) Node( |
| 2269 |
*this, std::piecewise_construct, std::forward_as_tuple(std::forward<OtherKey>(key)), |
| 2270 |
std::forward_as_tuple(std::forward<Args>(args)...)); |
| 2271 |
break; |
| 2272 |
|
| 2273 |
case InsertionState::overwrite_node: |
| 2274 |
mKeyVals[idxAndState.first] = Node(*this, std::piecewise_construct, |
| 2275 |
std::forward_as_tuple(std::forward<OtherKey>(key)), |
| 2276 |
std::forward_as_tuple(std::forward<Args>(args)...)); |
| 2277 |
break; |
| 2278 |
|
| 2279 |
case InsertionState::overflow_error: |
| 2280 |
throwOverflowError(); |
| 2281 |
break; |
| 2282 |
} |
| 2283 |
|
| 2284 |
return std::make_pair(iterator(mKeyVals + idxAndState.first, mInfo + idxAndState.first), |
| 2285 |
InsertionState::key_found != idxAndState.second); |
| 2286 |
} |
| 2287 |
|
| 2288 |
template <typename OtherKey, typename Mapped> |
| 2289 |
std::pair<iterator, bool> insertOrAssignImpl(OtherKey&& key, Mapped&& obj) { |
| 2290 |
ROBIN_HOOD_TRACE(this) |
| 2291 |
auto idxAndState = insertKeyPrepareEmptySpot(key); |
| 2292 |
switch (idxAndState.second) { |
| 2293 |
case InsertionState::key_found: |
| 2294 |
mKeyVals[idxAndState.first].getSecond() = std::forward<Mapped>(obj); |
| 2295 |
break; |
| 2296 |
|
| 2297 |
case InsertionState::new_node: |
| 2298 |
::new (static_cast<void*>(&mKeyVals[idxAndState.first])) Node( |
| 2299 |
*this, std::piecewise_construct, std::forward_as_tuple(std::forward<OtherKey>(key)), |
| 2300 |
std::forward_as_tuple(std::forward<Mapped>(obj))); |
| 2301 |
break; |
| 2302 |
|
| 2303 |
case InsertionState::overwrite_node: |
| 2304 |
mKeyVals[idxAndState.first] = Node(*this, std::piecewise_construct, |
| 2305 |
std::forward_as_tuple(std::forward<OtherKey>(key)), |
| 2306 |
std::forward_as_tuple(std::forward<Mapped>(obj))); |
| 2307 |
break; |
| 2308 |
|
| 2309 |
case InsertionState::overflow_error: |
| 2310 |
throwOverflowError(); |
| 2311 |
break; |
| 2312 |
} |
| 2313 |
|
| 2314 |
return std::make_pair(iterator(mKeyVals + idxAndState.first, mInfo + idxAndState.first), |
| 2315 |
InsertionState::key_found != idxAndState.second); |
| 2316 |
} |
| 2317 |
|
| 2318 |
void initData(size_t max_elements) { |
| 2319 |
mNumElements = 0; |
| 2320 |
mMask = max_elements - 1; |
| 2321 |
mMaxNumElementsAllowed = calcMaxNumElementsAllowed(max_elements); |
| 2322 |
|
| 2323 |
auto const numElementsWithBuffer = calcNumElementsWithBuffer(max_elements); |
| 2324 |
|
| 2325 |
|
| 2326 |
auto const numBytesTotal = calcNumBytesTotal(numElementsWithBuffer); |
| 2327 |
ROBIN_HOOD_LOG("std::calloc " << numBytesTotal << " = calcNumBytesTotal(" |
| 2328 |
<< numElementsWithBuffer << ")") |
| 2329 |
mKeyVals = reinterpret_cast<Node*>( |
| 2330 |
detail::assertNotNull<std::bad_alloc>(std::malloc(numBytesTotal))); |
| 2331 |
mInfo = reinterpret_cast<uint8_t*>(mKeyVals + numElementsWithBuffer); |
| 2332 |
std::memset(mInfo, 0, numBytesTotal - numElementsWithBuffer * sizeof(Node)); |
| 2333 |
|
| 2334 |
|
| 2335 |
mInfo[numElementsWithBuffer] = 1; |
| 2336 |
|
| 2337 |
mInfoInc = InitialInfoInc; |
| 2338 |
mInfoHashShift = InitialInfoHashShift; |
| 2339 |
} |
| 2340 |
|
| 2341 |
enum class InsertionState { overflow_error, key_found, new_node, overwrite_node }; |
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
template <typename OtherKey> |
| 2347 |
std::pair<size_t, InsertionState> insertKeyPrepareEmptySpot(OtherKey&& key) { |
| 2348 |
for (int i = 0; i < 256; ++i) { |
| 2349 |
size_t idx{}; |
| 2350 |
InfoType info{}; |
| 2351 |
keyToIdx(key, &idx, &info); |
| 2352 |
nextWhileLess(&info, &idx); |
| 2353 |
|
| 2354 |
|
| 2355 |
while (info == mInfo[idx]) { |
| 2356 |
if (WKeyEqual::operator()(key, mKeyVals[idx].getFirst())) { |
| 2357 |
|
| 2358 |
|
| 2359 |
return std::make_pair(idx, InsertionState::key_found); |
| 2360 |
} |
| 2361 |
next(&info, &idx); |
| 2362 |
} |
| 2363 |
|
| 2364 |
|
| 2365 |
if (ROBIN_HOOD_UNLIKELY(mNumElements >= mMaxNumElementsAllowed)) { |
| 2366 |
if (!increase_size()) { |
| 2367 |
return std::make_pair(size_t(0), InsertionState::overflow_error); |
| 2368 |
} |
| 2369 |
continue; |
| 2370 |
} |
| 2371 |
|
| 2372 |
|
| 2373 |
auto const insertion_idx = idx; |
| 2374 |
auto const insertion_info = info; |
| 2375 |
if (ROBIN_HOOD_UNLIKELY(insertion_info + mInfoInc > 0xFF)) { |
| 2376 |
mMaxNumElementsAllowed = 0; |
| 2377 |
} |
| 2378 |
|
| 2379 |
|
| 2380 |
while (0 != mInfo[idx]) { |
| 2381 |
next(&info, &idx); |
| 2382 |
} |
| 2383 |
|
| 2384 |
if (idx != insertion_idx) { |
| 2385 |
shiftUp(idx, insertion_idx); |
| 2386 |
} |
| 2387 |
|
| 2388 |
mInfo[insertion_idx] = static_cast<uint8_t>(insertion_info); |
| 2389 |
++mNumElements; |
| 2390 |
return std::make_pair(insertion_idx, idx == insertion_idx |
| 2391 |
? InsertionState::new_node |
| 2392 |
: InsertionState::overwrite_node); |
| 2393 |
} |
| 2394 |
|
| 2395 |
|
| 2396 |
return std::make_pair(size_t(0), InsertionState::overflow_error); |
| 2397 |
} |
| 2398 |
|
| 2399 |
bool try_increase_info() { |
| 2400 |
ROBIN_HOOD_LOG("mInfoInc=" << mInfoInc << ", numElements=" << mNumElements |
| 2401 |
<< ", maxNumElementsAllowed=" |
| 2402 |
<< calcMaxNumElementsAllowed(mMask + 1)) |
| 2403 |
if (mInfoInc <= 2) { |
| 2404 |
|
| 2405 |
return false; |
| 2406 |
} |
| 2407 |
|
| 2408 |
mInfoInc = static_cast<uint8_t>(mInfoInc >> 1U); |
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
++mInfoHashShift; |
| 2413 |
auto const numElementsWithBuffer = calcNumElementsWithBuffer(mMask + 1); |
| 2414 |
|
| 2415 |
for (size_t i = 0; i < numElementsWithBuffer; i += 8) { |
| 2416 |
auto val = unaligned_load<uint64_t>(mInfo + i); |
| 2417 |
val = (val >> 1U) & UINT64_C(0x7f7f7f7f7f7f7f7f); |
| 2418 |
std::memcpy(mInfo + i, &val, sizeof(val)); |
| 2419 |
} |
| 2420 |
|
| 2421 |
mInfo[numElementsWithBuffer] = 1; |
| 2422 |
|
| 2423 |
mMaxNumElementsAllowed = calcMaxNumElementsAllowed(mMask + 1); |
| 2424 |
return true; |
| 2425 |
} |
| 2426 |
|
| 2427 |
|
| 2428 |
bool increase_size() { |
| 2429 |
|
| 2430 |
if (0 == mMask) { |
| 2431 |
initData(InitialNumElements); |
| 2432 |
return true; |
| 2433 |
} |
| 2434 |
|
| 2435 |
auto const maxNumElementsAllowed = calcMaxNumElementsAllowed(mMask + 1); |
| 2436 |
if (mNumElements < maxNumElementsAllowed && try_increase_info()) { |
| 2437 |
return true; |
| 2438 |
} |
| 2439 |
|
| 2440 |
ROBIN_HOOD_LOG("mNumElements=" << mNumElements << ", maxNumElementsAllowed=" |
| 2441 |
<< maxNumElementsAllowed << ", load=" |
| 2442 |
<< (static_cast<double>(mNumElements) * 100.0 / |
| 2443 |
(static_cast<double>(mMask) + 1))) |
| 2444 |
|
| 2445 |
if (mNumElements * 2 < calcMaxNumElementsAllowed(mMask + 1)) { |
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
nextHashMultiplier(); |
| 2450 |
rehashPowerOfTwo(mMask + 1, true); |
| 2451 |
} else { |
| 2452 |
|
| 2453 |
rehashPowerOfTwo((mMask + 1) * 2, false); |
| 2454 |
} |
| 2455 |
return true; |
| 2456 |
} |
| 2457 |
|
| 2458 |
void nextHashMultiplier() { |
| 2459 |
|
| 2460 |
|
| 2461 |
mHashMultiplier += UINT64_C(0xc4ceb9fe1a85ec54); |
| 2462 |
} |
| 2463 |
|
| 2464 |
void destroy() { |
| 2465 |
if (0 == mMask) { |
| 2466 |
|
| 2467 |
return; |
| 2468 |
} |
| 2469 |
|
| 2470 |
Destroyer<Self, IsFlat && std::is_trivially_destructible<Node>::value>{} |
| 2471 |
.nodesDoNotDeallocate(*this); |
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
if (mKeyVals != reinterpret_cast_no_cast_align_warning<Node*>(&mMask)) { |
| 2478 |
ROBIN_HOOD_LOG("std::free") |
| 2479 |
std::free(mKeyVals); |
| 2480 |
} |
| 2481 |
} |
| 2482 |
|
| 2483 |
void init() noexcept { |
| 2484 |
mKeyVals = reinterpret_cast_no_cast_align_warning<Node*>(&mMask); |
| 2485 |
mInfo = reinterpret_cast<uint8_t*>(&mMask); |
| 2486 |
mNumElements = 0; |
| 2487 |
mMask = 0; |
| 2488 |
mMaxNumElementsAllowed = 0; |
| 2489 |
mInfoInc = InitialInfoInc; |
| 2490 |
mInfoHashShift = InitialInfoHashShift; |
| 2491 |
} |
| 2492 |
|
| 2493 |
|
| 2494 |
uint64_t mHashMultiplier = UINT64_C(0xc4ceb9fe1a85ec53); |
| 2495 |
Node* mKeyVals = reinterpret_cast_no_cast_align_warning<Node*>(&mMask); |
| 2496 |
uint8_t* mInfo = reinterpret_cast<uint8_t*>(&mMask); |
| 2497 |
size_t mNumElements = 0; |
| 2498 |
size_t mMask = 0; |
| 2499 |
size_t mMaxNumElementsAllowed = 0; |
| 2500 |
InfoType mInfoInc = InitialInfoInc; |
| 2501 |
InfoType mInfoHashShift = InitialInfoHashShift; |
| 2502 |
|
| 2503 |
}; |
| 2504 |
|
| 2505 |
} |
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
template <typename Key, typename T, typename Hash = hash<Key>, |
| 2510 |
typename KeyEqual = std::equal_to<Key>, size_t MaxLoadFactor100 = 80> |
| 2511 |
using unordered_flat_map = detail::Table<true, MaxLoadFactor100, Key, T, Hash, KeyEqual>; |
| 2512 |
|
| 2513 |
template <typename Key, typename T, typename Hash = hash<Key>, |
| 2514 |
typename KeyEqual = std::equal_to<Key>, size_t MaxLoadFactor100 = 80> |
| 2515 |
using unordered_node_map = detail::Table<false, MaxLoadFactor100, Key, T, Hash, KeyEqual>; |
| 2516 |
|
| 2517 |
template <typename Key, typename T, typename Hash = hash<Key>, |
| 2518 |
typename KeyEqual = std::equal_to<Key>, size_t MaxLoadFactor100 = 80> |
| 2519 |
using unordered_map = |
| 2520 |
detail::Table<sizeof(robin_hood::pair<Key, T>) <= sizeof(size_t) * 6 && |
| 2521 |
std::is_nothrow_move_constructible<robin_hood::pair<Key, T>>::value && |
| 2522 |
std::is_nothrow_move_assignable<robin_hood::pair<Key, T>>::value, |
| 2523 |
MaxLoadFactor100, Key, T, Hash, KeyEqual>; |
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
template <typename Key, typename Hash = hash<Key>, typename KeyEqual = std::equal_to<Key>, |
| 2528 |
size_t MaxLoadFactor100 = 80> |
| 2529 |
using unordered_flat_set = detail::Table<true, MaxLoadFactor100, Key, void, Hash, KeyEqual>; |
| 2530 |
|
| 2531 |
template <typename Key, typename Hash = hash<Key>, typename KeyEqual = std::equal_to<Key>, |
| 2532 |
size_t MaxLoadFactor100 = 80> |
| 2533 |
using unordered_node_set = detail::Table<false, MaxLoadFactor100, Key, void, Hash, KeyEqual>; |
| 2534 |
|
| 2535 |
template <typename Key, typename Hash = hash<Key>, typename KeyEqual = std::equal_to<Key>, |
| 2536 |
size_t MaxLoadFactor100 = 80> |
| 2537 |
using unordered_set = detail::Table<sizeof(Key) <= sizeof(size_t) * 6 && |
| 2538 |
std::is_nothrow_move_constructible<Key>::value && |
| 2539 |
std::is_nothrow_move_assignable<Key>::value, |
| 2540 |
MaxLoadFactor100, Key, void, Hash, KeyEqual>; |
| 2541 |
|
| 2542 |
} |
| 2543 |
|
| 2544 |
#endif |