24#ifndef TSL_HOPSCOTCH_HASH_H
25#define TSL_HOPSCOTCH_HASH_H
34#include <initializer_list>
46#if (defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 9))
47#define TSL_HH_NO_RANGE_ERASE_WITH_CONST_ITERATOR
52 namespace detail_hopscotch_hash {
82 template <std::
size_t GrowthFactor>
88 template <
typename T,
typename U>
89 T
numeric_cast(U value,
const char *error_message =
"numeric_cast() failed.")
91 T ret =
static_cast<T
>(value);
92 if (
static_cast<U
>(ret) != value) {
96 const bool is_same_signedness = (std::is_unsigned<T>::value && std::is_unsigned<U>::value) ||
97 (std::is_signed<T>::value && std::is_signed<U>::value);
98 if (!is_same_signedness && (ret < T{}) != (value < U{})) {
114 template <
unsigned int MinBits>
116 typename std::enable_if<(MinBits > 0) && (MinBits <= 8)>::type>
119 using type = std::uint_least8_t;
122 template <
unsigned int MinBits>
124 MinBits, typename std::enable_if<(MinBits > 8) && (MinBits <= 16)>::type>
127 using type = std::uint_least16_t;
130 template <
unsigned int MinBits>
132 MinBits, typename std::enable_if<(MinBits > 16) && (MinBits <= 32)>::type>
135 using type = std::uint_least32_t;
138 template <
unsigned int MinBits>
140 MinBits, typename std::enable_if<(MinBits > 32) && (MinBits <= 64)>::type>
143 using type = std::uint_least64_t;
208 template <
typename ValueType,
unsigned int NeighborhoodSize,
bool StoreHash>
216 static_assert(NeighborhoodSize >= 4,
"NeighborhoodSize should be >= 4.");
220 static_assert(NeighborhoodSize <= 62,
"NeighborhoodSize should be <= 62.");
224 static_assert(!StoreHash || NeighborhoodSize <= 30,
225 "NeighborhoodSize should be <= 30 if StoreHash is true.");
243 std::is_nothrow_copy_constructible<value_type>::value)
246 if (!bucket.empty()) {
247 ::new (static_cast<void *>(std::addressof(m_value))) value_type(bucket.value());
254 std::is_nothrow_move_constructible<value_type>::value)
257 if (!bucket.empty()) {
258 ::new (static_cast<void *>(std::addressof(m_value)))
259 value_type(std::move(bucket.value()));
266 std::is_nothrow_copy_constructible<value_type>::value)
268 if (
this != &bucket) {
271 bucket_hash::operator=(bucket);
272 if (!bucket.empty()) {
339 template <
typename... Args>
344 ::new (
static_cast<void *
>(std::addressof(
m_value)))
345 value_type(std::forward<Args>(value_type_args)...);
354 ::new (
static_cast<void *
>(std::addressof(empty_bucket.
m_value)))
401 value().~value_type();
427 template <
class ValueType,
class KeySelect,
class ValueSelect,
class Hash,
class KeyEqual,
428 class Allocator,
unsigned int NeighborhoodSize,
bool StoreHash,
class GrowthPolicy,
429 class OverflowContainer>
433 template <
typename U>
434 using has_mapped_type =
typename std::integral_constant<bool, !std::is_same<U, void>::value>;
436 static_assert(
noexcept(std::declval<GrowthPolicy>().bucket_for_hash(std::size_t(0))),
437 "GrowthPolicy::bucket_for_hash must be noexcept.");
438 static_assert(
noexcept(std::declval<GrowthPolicy>().clear()),
439 "GrowthPolicy::clear must be noexcept.");
464 typename std::allocator_traits<allocator_type>::template rebind_alloc<hopscotch_bucket>;
469 static_assert(std::is_same<typename overflow_container_type::value_type, ValueType>::value,
470 "OverflowContainer should have ValueType as type.");
473 std::is_same<typename overflow_container_type::allocator_type, Allocator>::value,
474 "Invalid allocator, not the same type as the value_type.");
519 template <bool TIsConst = IsConst, typename std::enable_if<TIsConst>::type * =
nullptr>
538 return KeySelect()(*m_overflow_iterator);
541 template <
class U = ValueSelect,
542 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
543 typename std::conditional<IsConst,
const typename U::value_type &,
544 typename U::value_type &>::type
551 return U()(*m_overflow_iterator);
602 return !(lhs == rhs);
612 template <
class OC = OverflowContainer,
613 typename std::enable_if<!has_key_compare<OC>::value>::type * =
nullptr>
624 static_assert(NeighborhoodSize - 1 > 0,
"");
636 static_assert(std::is_nothrow_move_constructible<value_type>::value ||
637 std::is_copy_constructible<value_type>::value,
638 "value_type must be either copy constructible or nothrow "
639 "move constructible.");
642 template <
class OC = OverflowContainer,
643 typename std::enable_if<has_key_compare<OC>::value>::type * =
nullptr>
646 const typename OC::key_compare &comp)
655 static_assert(NeighborhoodSize - 1 > 0,
"");
667 static_assert(std::is_nothrow_move_constructible<value_type>::value ||
668 std::is_copy_constructible<value_type>::value,
669 "value_type must be either copy constructible or nothrow "
670 "move constructible.");
685 std::is_nothrow_move_constructible<Hash>::value &&
686 std::is_nothrow_move_constructible<KeyEqual>::value &&
687 std::is_nothrow_move_constructible<GrowthPolicy>::value &&
688 std::is_nothrow_move_constructible<buckets_container_type>::value &&
689 std::is_nothrow_move_constructible<overflow_container_type>::value)
690 : Hash(std::move(static_cast<Hash &>(other))),
691 KeyEqual(std::move(static_cast<KeyEqual &>(other))),
692 GrowthPolicy(std::move(static_cast<GrowthPolicy &>(other))),
701 other.GrowthPolicy::clear();
702 other.m_buckets_data.
clear();
703 other.m_overflow_elements.clear();
705 other.m_nb_elements = 0;
706 other.m_min_load_threshold_rehash = 0;
707 other.m_max_load_threshold_rehash = 0;
712 if (&other !=
this) {
713 Hash::operator=(other);
714 KeyEqual::operator=(other);
715 GrowthPolicy::operator=(other);
802 template <
class P,
typename std::enable_if<
803 std::is_constructible<value_type, P &&>::value>::type * =
nullptr>
804 std::pair<iterator, bool>
insert(P &&value)
813 if (hint !=
cend() &&
compare_keys(KeySelect()(*hint), KeySelect()(value))) {
817 return insert(value).first;
820 template <
class P,
typename std::enable_if<
821 std::is_constructible<value_type, P &&>::value>::type * =
nullptr>
829 if (hint !=
cend() &&
compare_keys(KeySelect()(*hint), KeySelect()(value))) {
833 return insert(std::move(value)).first;
836 template <
class InputIt>
void insert(InputIt first, InputIt last)
838 if (std::is_base_of<std::forward_iterator_tag,
839 typename std::iterator_traits<InputIt>::iterator_category>::value) {
840 const auto nb_elements_insert = std::distance(first, last);
846 if (nb_elements_insert > 0 && nb_free_buckets < std::size_t(nb_elements_insert)) {
847 reserve(nb_elements_in_buckets + std::size_t(nb_elements_insert));
851 for (; first != last; ++first) {
870 it.value() = std::forward<M>(obj);
882 it.value() = std::forward<M>(obj);
890 template <
class... Args> std::pair<iterator, bool>
emplace(Args &&...args)
900 template <
class... Args>
911 template <
class... Args>
918 return try_emplace(k, std::forward<Args>(args)...).first;
921 template <
class... Args>
928 return try_emplace(std::move(k), std::forward<Args>(args)...).first;
960 auto to_delete =
erase(first);
961 while (to_delete != last) {
962 to_delete =
erase(to_delete);
976 if (bucket_found !=
nullptr) {
982 if (
m_buckets[ibucket_for_hash].has_overflow()) {
998 swap(
static_cast<Hash &
>(*
this),
static_cast<Hash &
>(other));
999 swap(
static_cast<KeyEqual &
>(*
this),
static_cast<KeyEqual &
>(other));
1000 swap(
static_cast<GrowthPolicy &
>(*
this),
static_cast<GrowthPolicy &
>(other));
1013 template <
class K,
class U = ValueSelect,
1014 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1015 typename U::value_type &
at(
const K &key)
1020 template <
class K,
class U = ValueSelect,
1021 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1022 typename U::value_type &
at(
const K &key, std::size_t my_hash)
1024 return const_cast<typename U::value_type &
>(
1028 template <
class K,
class U = ValueSelect,
1029 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1030 const typename U::value_type &
at(
const K &key)
const
1035 template <
class K,
class U = ValueSelect,
1036 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1037 const typename U::value_type &
at(
const K &key, std::size_t my_hash)
const
1039 using T =
typename U::value_type;
1042 if (value ==
nullptr) {
1050 template <
class K,
class U = ValueSelect,
1051 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1054 using T =
typename U::value_type;
1056 const std::size_t my_hash =
hash_key(key);
1060 if (value !=
nullptr) {
1064 return insert_value(ibucket_for_hash, my_hash, std::piecewise_construct,
1065 std::forward_as_tuple(std::forward<K>(key)), std::forward_as_tuple())
1096 template <
class K>
bool contains(
const K &key, std::size_t my_hash)
const
1098 return count(key, my_hash) != 0;
1101 template <
class K> std::pair<iterator, iterator>
equal_range(
const K &key)
1107 std::pair<iterator, iterator>
equal_range(
const K &key, std::size_t my_hash)
1110 return std::make_pair(it, (it ==
end()) ? it : std::next(it));
1113 template <
class K> std::pair<const_iterator, const_iterator>
equal_range(
const K &key)
const
1119 std::pair<const_iterator, const_iterator>
equal_range(
const K &key, std::size_t my_hash)
const
1122 return std::make_pair(it, (it ==
cend()) ? it : std::next(it));
1146 std::min(GrowthPolicy::max_bucket_count(),
m_buckets_data.max_size());
1209 template <
class U = OverflowContainer,
1210 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1217 template <
class K> std::size_t
hash_key(
const K &key)
const {
return Hash::operator()(key); }
1219 template <
class K1,
class K2>
bool compare_keys(
const K1 &key1,
const K2 &key2)
const
1221 return KeyEqual::operator()(key1, key2);
1226 const std::size_t bucket = GrowthPolicy::bucket_for_hash(my_hash);
1234 typename std::enable_if<std::is_nothrow_move_constructible<U>::value>::type * =
nullptr>
1244 const std::size_t ibucket_for_hash =
1250#ifndef TSL_HH_NO_EXCEPTIONS
1256 if (it_bucket->empty()) {
1260 const std::size_t my_hash = use_stored_hash
1261 ? it_bucket->truncated_bucket_hash()
1262 : new_map.
hash_key(KeySelect()(it_bucket->value()));
1263 const std::size_t ibucket_for_hash = new_map.
bucket_for_hash(my_hash);
1265 new_map.
insert_value(ibucket_for_hash, my_hash, std::move(it_bucket->value()));
1269#ifndef TSL_HH_NO_EXCEPTIONS
1282 if (it_bucket->empty()) {
1286 const std::size_t my_hash = use_stored_hash ? it_bucket->truncated_bucket_hash()
1287 :
hash_key(KeySelect()(it_bucket->value()));
1293 insert_value(ibucket_for_hash, my_hash, std::move(it_bucket->value()));
1300 new_map.
swap(*
this);
1305 typename std::enable_if<std::is_copy_constructible<U>::value &&
1306 !std::is_nothrow_move_constructible<U>::value>::type * =
nullptr>
1313 if (bucket.empty()) {
1317 const std::size_t my_hash = use_stored_hash
1318 ? bucket.truncated_bucket_hash()
1319 : new_map.
hash_key(KeySelect()(bucket.value()));
1320 const std::size_t ibucket_for_hash = new_map.
bucket_for_hash(my_hash);
1322 new_map.
insert_value(ibucket_for_hash, my_hash, bucket.value());
1326 const std::size_t my_hash = new_map.
hash_key(KeySelect()(value));
1327 const std::size_t ibucket_for_hash = new_map.
bucket_for_hash(my_hash);
1329 new_map.
insert_value(ibucket_for_hash, my_hash, value);
1332 new_map.
swap(*
this);
1335#ifdef TSL_HH_NO_RANGE_ERASE_WITH_CONST_ITERATOR
1350 std::size_t ibucket_for_hash)
1352#ifdef TSL_HH_NO_RANGE_ERASE_WITH_CONST_ITERATOR
1363 if (bucket_for_value == ibucket_for_hash) {
1377 std::size_t ibucket_for_hash)
noexcept
1379 const std::size_t ibucket_for_value =
1383 bucket_for_value.remove_value();
1392 it.first.value() = std::forward<M>(obj);
1398 template <
typename P,
class... Args>
1401 const std::size_t my_hash =
hash_key(key);
1406 if (it_find !=
end()) {
1407 return std::make_pair(it_find,
false);
1410 return insert_value(ibucket_for_hash, my_hash, std::piecewise_construct,
1411 std::forward_as_tuple(std::forward<P>(key)),
1412 std::forward_as_tuple(std::forward<Args>(args_value)...));
1415 template <
typename P> std::pair<iterator, bool>
insert_impl(P &&value)
1417 const std::size_t my_hash =
hash_key(KeySelect()(value));
1422 if (it_find !=
end()) {
1423 return std::make_pair(it_find,
false);
1426 return insert_value(ibucket_for_hash, my_hash, std::forward<P>(value));
1429 template <
typename... Args>
1430 std::pair<iterator, bool>
insert_value(std::size_t ibucket_for_hash, std::size_t my_hash,
1431 Args &&...value_type_args)
1434 rehash(GrowthPolicy::next_bucket_count());
1444 if (ibucket_empty - ibucket_for_hash < NeighborhoodSize) {
1446 std::forward<Args>(value_type_args)...);
1459 auto it =
insert_in_overflow(ibucket_for_hash, std::forward<Args>(value_type_args)...);
1463 rehash(GrowthPolicy::next_bucket_count());
1466 return insert_value(ibucket_for_hash, my_hash, std::forward<Args>(value_type_args)...);
1476 std::size_t expand_bucket_count = GrowthPolicy::next_bucket_count();
1477 GrowthPolicy expand_growth_policy(expand_bucket_count);
1480 for (
size_t ibucket = ibucket_neighborhood_check;
1482 (ibucket - ibucket_neighborhood_check) < NeighborhoodSize;
1486 const size_t my_hash = use_stored_hash
1489 if (
bucket_for_hash(my_hash) != expand_growth_policy.bucket_for_hash(my_hash)) {
1503 const std::size_t limit =
1505 for (; ibucket_start < limit; ibucket_start++) {
1507 return ibucket_start;
1520 template <
typename... Args>
1522 std::size_t my_hash, Args &&...value_type_args)
1527 std::forward<Args>(value_type_args)...);
1536 template <
class... Args,
class U = OverflowContainer,
1537 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1541 std::forward<Args>(value_type_args)...);
1549 template <
class... Args,
class U = OverflowContainer,
1550 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1571 const std::size_t neighborhood_start = ibucket_empty_in_out - NeighborhoodSize + 1;
1573 for (std::size_t to_check = neighborhood_start; to_check < ibucket_empty_in_out;
1576 std::size_t to_swap = to_check;
1578 while (neighborhood_infos != 0 && to_swap < ibucket_empty_in_out) {
1579 if ((neighborhood_infos & 1) == 1) {
1586 !
m_buckets[to_check].check_neighbor_presence(ibucket_empty_in_out - to_check));
1592 ibucket_empty_in_out = to_swap;
1605 template <
class K,
class U = ValueSelect,
1606 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1610 return const_cast<typename U::value_type *
>(
1622 template <
class K,
class U = ValueSelect,
1623 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1628 if (bucket_found !=
nullptr) {
1629 return std::addressof(ValueSelect()(bucket_found->
value()));
1635 return std::addressof(ValueSelect()(*it_overflow));
1662 if (bucket_found !=
nullptr) {
1680 if (bucket_found !=
nullptr) {
1717 while (neighborhood_infos != 0) {
1718 if ((neighborhood_infos & 1) == 1) {
1736 template <
class K,
class U = OverflowContainer,
1737 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1740 return std::find_if(
1742 [&](
const value_type &value) { return compare_keys(key, KeySelect()(value)); });
1745 template <
class K,
class U = OverflowContainer,
1746 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1749 return std::find_if(
1751 [&](
const value_type &value) { return compare_keys(key, KeySelect()(value)); });
1754 template <
class K,
class U = OverflowContainer,
1755 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1761 template <
class K,
class U = OverflowContainer,
1762 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1768 template <
class U = OverflowContainer,
1769 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1776 template <
class U = OverflowContainer,
1777 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1801 typename std::enable_if<std::is_same<T, truncated_hash_type>::value>::type * =
nullptr>
1809 typename std::enable_if<!std::is_same<T, truncated_hash_type>::value>::type * =
nullptr>
1815 return (
bucket_count - 1) <= std::numeric_limits<truncated_hash_type>::max();
1828 return &empty_bucket;
void set_hash(truncated_hash_type my_hash) noexcept
Definition hopscotch_hash.h:202
bool bucket_hash_equal(std::size_t my_hash) const noexcept
Definition hopscotch_hash.h:192
truncated_hash_type m_hash
Definition hopscotch_hash.h:205
truncated_hash_type truncated_bucket_hash() const noexcept
Definition hopscotch_hash.h:197
void copy_hash(const hopscotch_bucket_hash &bucket) noexcept
Definition hopscotch_hash.h:200
Definition hopscotch_hash.h:177
truncated_hash_type truncated_bucket_hash() const noexcept
Definition hopscotch_hash.h:181
void set_hash(truncated_hash_type) noexcept
Definition hopscotch_hash.h:186
bool bucket_hash_equal(std::size_t) const noexcept
Definition hopscotch_hash.h:179
void copy_hash(const hopscotch_bucket_hash &) noexcept
Definition hopscotch_hash.h:184
Definition hopscotch_hash.h:210
const value_type & value() const noexcept
Definition hopscotch_hash.h:333
static truncated_hash_type truncate_hash(std::size_t my_hash) noexcept
Definition hopscotch_hash.h:382
value_type & value() noexcept
Definition hopscotch_hash.h:327
hopscotch_bucket(const hopscotch_bucket &bucket) noexcept(std::is_nothrow_copy_constructible< value_type >::value)
Definition hopscotch_hash.h:242
void clear() noexcept
Definition hopscotch_hash.h:372
~hopscotch_bucket() noexcept
Definition hopscotch_hash.h:284
neighborhood_bitmap m_neighborhood_infos
Definition hopscotch_hash.h:407
hopscotch_bucket(hopscotch_bucket &&bucket) noexcept(std::is_nothrow_move_constructible< value_type >::value)
Definition hopscotch_hash.h:253
void destroy_value() noexcept
Definition hopscotch_hash.h:398
static const std::size_t MAX_NEIGHBORHOOD_SIZE
Definition hopscotch_hash.h:213
typename std::aligned_storage< sizeof(value_type), alignof(value_type)>::type storage
Definition hopscotch_hash.h:405
bool check_neighbor_presence(std::size_t ineighbor) const noexcept
Definition hopscotch_hash.h:317
ValueType value_type
Definition hopscotch_hash.h:232
typename smallest_type_for_min_bits< NeighborhoodSize+ NB_RESERVED_BITS_IN_NEIGHBORHOOD >::type neighborhood_bitmap
Definition hopscotch_hash.h:233
storage m_value
Definition hopscotch_hash.h:408
static const std::size_t MIN_NEIGHBORHOOD_SIZE
Definition hopscotch_hash.h:212
void set_value_of_empty_bucket(truncated_hash_type my_hash, Args &&...value_type_args)
Definition hopscotch_hash.h:340
void swap_value_into_empty_bucket(hopscotch_bucket &empty_bucket)
Definition hopscotch_hash.h:350
void toggle_neighbor_presence(std::size_t ineighbor) noexcept
Definition hopscotch_hash.h:310
hopscotch_bucket() noexcept
Definition hopscotch_hash.h:237
hopscotch_bucket & operator=(const hopscotch_bucket &bucket) noexcept(std::is_nothrow_copy_constructible< value_type >::value)
Definition hopscotch_hash.h:265
bool empty() const noexcept
Definition hopscotch_hash.h:308
void set_empty(bool is_empty) noexcept
Definition hopscotch_hash.h:388
neighborhood_bitmap neighborhood_infos() const noexcept
Definition hopscotch_hash.h:291
bool has_overflow() const noexcept
Definition hopscotch_hash.h:306
void remove_value() noexcept
Definition hopscotch_hash.h:364
hopscotch_bucket & operator=(hopscotch_bucket &&)=delete
void set_overflow(bool has_overflow) noexcept
Definition hopscotch_hash.h:296
Definition hopscotch_hash.h:491
hopscotch_iterator(const hopscotch_iterator<!TIsConst > &other) noexcept
Definition hopscotch_hash.h:520
const hopscotch_hash::key_type & key() const
Definition hopscotch_hash.h:532
typename std::conditional< IsConst, typename hopscotch_hash::const_iterator_overflow, typename hopscotch_hash::iterator_overflow >::type iterator_overflow
Definition hopscotch_hash.h:498
typename std::conditional< IsConst, typename hopscotch_hash::const_iterator_buckets, typename hopscotch_hash::iterator_buckets >::type iterator_bucket
Definition hopscotch_hash.h:495
hopscotch_iterator() noexcept
Definition hopscotch_hash.h:516
value_type & reference
Definition hopscotch_hash.h:513
hopscotch_iterator(iterator_bucket buckets_iterator, iterator_bucket buckets_end_iterator, iterator_overflow overflow_iterator) noexcept
Definition hopscotch_hash.h:502
std::conditional< IsConst, consttypenameU::value_type &, typenameU::value_type & >::type value() const
Definition hopscotch_hash.h:545
iterator_bucket m_buckets_iterator
Definition hopscotch_hash.h:606
friend bool operator!=(const hopscotch_iterator &lhs, const hopscotch_iterator &rhs)
Definition hopscotch_hash.h:600
hopscotch_iterator operator++(int)
Definition hopscotch_hash.h:586
hopscotch_iterator(hopscotch_iterator &&other)=default
hopscotch_iterator & operator=(const hopscotch_iterator &other)=default
hopscotch_iterator(const hopscotch_iterator &other)=default
std::forward_iterator_tag iterator_category
Definition hopscotch_hash.h:510
std::ptrdiff_t difference_type
Definition hopscotch_hash.h:512
reference operator*() const
Definition hopscotch_hash.h:554
pointer operator->() const
Definition hopscotch_hash.h:563
iterator_overflow m_overflow_iterator
Definition hopscotch_hash.h:608
value_type * pointer
Definition hopscotch_hash.h:514
hopscotch_iterator & operator++()
Definition hopscotch_hash.h:572
hopscotch_iterator & operator=(hopscotch_iterator &&other)=default
const typename hopscotch_hash::value_type value_type
Definition hopscotch_hash.h:511
iterator_bucket m_buckets_end_iterator
Definition hopscotch_hash.h:607
friend bool operator==(const hopscotch_iterator &lhs, const hopscotch_iterator &rhs)
Definition hopscotch_hash.h:594
Definition hopscotch_hash.h:431
const_iterator begin() const noexcept
Definition hopscotch_hash.h:753
size_type erase(const K &key)
Definition hopscotch_hash.h:968
iterator_buckets insert_in_bucket(std::size_t ibucket_empty, std::size_t ibucket_for_hash, std::size_t my_hash, Args &&...value_type_args)
Definition hopscotch_hash.h:1521
const_iterator cend() const noexcept
Definition hopscotch_hash.h:772
std::pair< iterator, bool > emplace(Args &&...args)
Definition hopscotch_hash.h:890
const_iterator find_impl(const K &key, std::size_t my_hash, const hopscotch_bucket *bucket_for_hash) const
Definition hopscotch_hash.h:1676
typename overflow_container_type::const_iterator const_iterator_overflow
Definition hopscotch_hash.h:480
hopscotch_bucket * static_empty_bucket_ptr()
Definition hopscotch_hash.h:1825
void swap(hopscotch_hash &other)
Definition hopscotch_hash.h:994
buckets_container_type m_buckets_data
Definition hopscotch_hash.h:1832
size_type m_min_load_threshold_rehash
Definition hopscotch_hash.h:1853
std::size_t size_type
Definition hopscotch_hash.h:446
Hash hasher
Definition hopscotch_hash.h:448
std::pair< iterator, bool > insert_impl(P &&value)
Definition hopscotch_hash.h:1415
iterator_overflow mutable_overflow_iterator(const_iterator_overflow it)
Definition hopscotch_hash.h:1342
static const std::size_t MAX_PROBES_FOR_EMPTY_BUCKET
Definition hopscotch_hash.h:1790
std::pair< iterator, bool > insert(P &&value)
Definition hopscotch_hash.h:804
const U::value_type * find_value_impl(const K &key, std::size_t my_hash, const hopscotch_bucket *bucket_for_hash) const
Definition hopscotch_hash.h:1624
std::vector< hopscotch_bucket, buckets_allocator > buckets_container_type
Definition hopscotch_hash.h:465
typename std::allocator_traits< allocator_type >::template rebind_alloc< hopscotch_bucket > buckets_allocator
Definition hopscotch_hash.h:463
iterator insert_or_assign(const_iterator hint, const key_type &k, M &&obj)
Definition hopscotch_hash.h:866
size_type count_impl(const K &key, std::size_t my_hash, const hopscotch_bucket *bucket_for_hash) const
Definition hopscotch_hash.h:1643
hopscotch_bucket * m_buckets
Definition hopscotch_hash.h:1843
const_iterator find(const K &key) const
Definition hopscotch_hash.h:1084
value_type & reference
Definition hopscotch_hash.h:451
bool contains(const K &key) const
Definition hopscotch_hash.h:1094
const_iterator cbegin() const noexcept
Definition hopscotch_hash.h:755
size_type max_size() const noexcept
Definition hopscotch_hash.h:785
OverflowContainer overflow_container_type
Definition hopscotch_hash.h:467
hopscotch_iterator< true > const_iterator
Definition hopscotch_hash.h:456
float max_load_factor() const
Definition hopscotch_hash.h:1162
value_type * pointer
Definition hopscotch_hash.h:453
size_type count(const K &key) const
Definition hopscotch_hash.h:1070
U::key_compare key_comp() const
Definition hopscotch_hash.h:1211
const_iterator end() const noexcept
Definition hopscotch_hash.h:770
overflow_container_type m_overflow_elements
Definition hopscotch_hash.h:1833
std::pair< iterator, bool > insert(const value_type &value)
Definition hopscotch_hash.h:800
typename buckets_container_type::iterator iterator_buckets
Definition hopscotch_hash.h:476
key_equal key_eq() const
Definition hopscotch_hash.h:1187
std::ptrdiff_t difference_type
Definition hopscotch_hash.h:447
static const size_type DEFAULT_INIT_BUCKETS_SIZE
Definition hopscotch_hash.h:1786
size_type count(const K &key, std::size_t my_hash) const
Definition hopscotch_hash.h:1072
iterator_overflow erase_from_overflow(const_iterator_overflow pos, std::size_t ibucket_for_hash)
Definition hopscotch_hash.h:1349
static bool USE_STORED_HASH_ON_REHASH(size_type bucket_count)
Definition hopscotch_hash.h:1810
hopscotch_hash(const hopscotch_hash &other)
Definition hopscotch_hash.h:673
hopscotch_hash(hopscotch_hash &&other) noexcept(std::is_nothrow_move_constructible< Hash >::value &&std::is_nothrow_move_constructible< KeyEqual >::value &&std::is_nothrow_move_constructible< GrowthPolicy >::value &&std::is_nothrow_move_constructible< buckets_container_type >::value &&std::is_nothrow_move_constructible< overflow_container_type >::value)
Definition hopscotch_hash.h:684
typename hopscotch_bucket::neighborhood_bitmap neighborhood_bitmap
Definition hopscotch_hash.h:461
std::pair< iterator, bool > try_emplace_impl(P &&key, Args &&...args_value)
Definition hopscotch_hash.h:1399
U::value_type & at(const K &key, std::size_t my_hash)
Definition hopscotch_hash.h:1022
size_type erase(const K &key, std::size_t my_hash)
Definition hopscotch_hash.h:970
float load_factor() const
Definition hopscotch_hash.h:1153
static constexpr float MIN_LOAD_FACTOR_FOR_REHASH
Definition hopscotch_hash.h:1791
typename buckets_container_type::const_iterator const_iterator_buckets
Definition hopscotch_hash.h:477
hopscotch_bucket * find_in_buckets(const K &key, std::size_t my_hash, hopscotch_bucket *bucket_for_hash)
Definition hopscotch_hash.h:1694
allocator_type get_allocator() const
Definition hopscotch_hash.h:738
bool empty() const noexcept
Definition hopscotch_hash.h:781
KeyEqual key_equal
Definition hopscotch_hash.h:449
iterator insert(const_iterator hint, const value_type &value)
Definition hopscotch_hash.h:811
typename overflow_container_type::iterator iterator_overflow
Definition hopscotch_hash.h:479
iterator erase(iterator pos)
Definition hopscotch_hash.h:935
typename std::integral_constant< bool, !std::is_same< U, void >::value > has_mapped_type
Definition hopscotch_hash.h:434
static constexpr float DEFAULT_MAX_LOAD_FACTOR
Definition hopscotch_hash.h:1787
U::value_type & at(const K &key)
Definition hopscotch_hash.h:1015
iterator begin() noexcept
Definition hopscotch_hash.h:743
hopscotch_hash new_hopscotch_hash(size_type bucket_count)
Definition hopscotch_hash.h:1770
const value_type * const_pointer
Definition hopscotch_hash.h:454
float m_max_load_factor
Definition hopscotch_hash.h:1861
bool compare_keys(const K1 &key1, const K2 &key2) const
Definition hopscotch_hash.h:1219
std::pair< iterator, bool > try_emplace(key_type &&k, Args &&...args)
Definition hopscotch_hash.h:906
std::pair< iterator, iterator > equal_range(const K &key)
Definition hopscotch_hash.h:1101
Allocator allocator_type
Definition hopscotch_hash.h:450
U::value_type * find_value_impl(const K &key, std::size_t my_hash, hopscotch_bucket *bucket_for_hash)
Definition hopscotch_hash.h:1607
iterator find(const K &key, std::size_t my_hash)
Definition hopscotch_hash.h:1079
size_type bucket_count() const
Definition hopscotch_hash.h:1128
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
Definition hopscotch_hash.h:856
size_type max_bucket_count() const
Definition hopscotch_hash.h:1143
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t my_hash) const
Definition hopscotch_hash.h:1119
void clear() noexcept
Definition hopscotch_hash.h:790
std::size_t bucket_for_hash(std::size_t my_hash) const
Definition hopscotch_hash.h:1224
const_iterator find(const K &key, std::size_t my_hash) const
Definition hopscotch_hash.h:1089
std::pair< iterator, bool > insert_value(std::size_t ibucket_for_hash, std::size_t my_hash, Args &&...value_type_args)
Definition hopscotch_hash.h:1430
iterator erase(const_iterator first, const_iterator last)
Definition hopscotch_hash.h:954
std::size_t find_empty_bucket(std::size_t ibucket_start) const
Definition hopscotch_hash.h:1501
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&...args)
Definition hopscotch_hash.h:901
hasher hash_function() const
Definition hopscotch_hash.h:1185
size_type size() const noexcept
Definition hopscotch_hash.h:783
iterator_overflow find_in_overflow(const K &key)
Definition hopscotch_hash.h:1738
hopscotch_hash(size_type bucket_count, const Hash &my_hash, const KeyEqual &equal, const Allocator &alloc, float max_load_factor)
Definition hopscotch_hash.h:614
hopscotch_iterator< false > iterator
Definition hopscotch_hash.h:455
std::pair< iterator, bool > insert_or_assign_impl(K &&key, M &&obj)
Definition hopscotch_hash.h:1388
U::value_type & operator[](K &&key)
Definition hopscotch_hash.h:1052
void insert(InputIt first, InputIt last)
Definition hopscotch_hash.h:836
iterator emplace_hint(const_iterator hint, Args &&...args)
Definition hopscotch_hash.h:895
iterator_overflow insert_in_overflow(std::size_t ibucket_for_hash, Args &&...value_type_args)
Definition hopscotch_hash.h:1538
iterator insert_or_assign(const_iterator hint, key_type &&k, M &&obj)
Definition hopscotch_hash.h:878
iterator insert(const_iterator hint, value_type &&value)
Definition hopscotch_hash.h:827
iterator insert(const_iterator hint, P &&value)
Definition hopscotch_hash.h:822
typename KeySelect::key_type key_type
Definition hopscotch_hash.h:444
const_iterator_overflow find_in_overflow(const K &key) const
Definition hopscotch_hash.h:1747
void erase_from_bucket(hopscotch_bucket &bucket_for_value, std::size_t ibucket_for_hash) noexcept
Definition hopscotch_hash.h:1376
std::pair< iterator, bool > insert_or_assign(key_type &&k, M &&obj)
Definition hopscotch_hash.h:861
iterator try_emplace(const_iterator hint, const key_type &k, Args &&...args)
Definition hopscotch_hash.h:912
void rehash(size_type count_)
Definition hopscotch_hash.h:1171
iterator erase(const_iterator pos)
Definition hopscotch_hash.h:937
hopscotch_hash & operator=(const hopscotch_hash &other)
Definition hopscotch_hash.h:710
bool will_neighborhood_change_on_rehash(size_t ibucket_neighborhood_check) const
Definition hopscotch_hash.h:1474
iterator try_emplace(const_iterator hint, key_type &&k, Args &&...args)
Definition hopscotch_hash.h:922
hopscotch_hash & operator=(hopscotch_hash &&other)
Definition hopscotch_hash.h:730
size_type m_max_load_threshold_rehash
Definition hopscotch_hash.h:1859
void max_load_factor(float ml)
Definition hopscotch_hash.h:1164
void rehash_impl(size_type count_)
Definition hopscotch_hash.h:1235
bool swap_empty_bucket_closer(std::size_t &ibucket_empty_in_out)
Definition hopscotch_hash.h:1568
static bool USE_STORED_HASH_ON_REHASH(size_type)
Definition hopscotch_hash.h:1802
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition hopscotch_hash.h:1113
size_type m_nb_elements
Definition hopscotch_hash.h:1845
const value_type & const_reference
Definition hopscotch_hash.h:452
std::pair< iterator, iterator > equal_range(const K &key, std::size_t my_hash)
Definition hopscotch_hash.h:1107
hopscotch_hash(size_type bucket_count, const Hash &p_hash, const KeyEqual &equal, const Allocator &alloc, float max_load_factor, const typename OC::key_compare &comp)
Definition hopscotch_hash.h:644
iterator find_impl(const K &key, std::size_t my_hash, hopscotch_bucket *bucket_for_hash)
Definition hopscotch_hash.h:1659
iterator end() noexcept
Definition hopscotch_hash.h:765
bool contains(const K &key, std::size_t my_hash) const
Definition hopscotch_hash.h:1096
iterator mutable_iterator(const_iterator pos)
Definition hopscotch_hash.h:1192
const hopscotch_bucket * find_in_buckets(const K &key, std::size_t my_hash, const hopscotch_bucket *bucket_for_hash) const
Definition hopscotch_hash.h:1707
std::size_t hash_key(const K &key) const
Definition hopscotch_hash.h:1217
const U::value_type & at(const K &key) const
Definition hopscotch_hash.h:1030
void reserve(size_type count_)
Definition hopscotch_hash.h:1177
const U::value_type & at(const K &key, std::size_t my_hash) const
Definition hopscotch_hash.h:1037
iterator find(const K &key)
Definition hopscotch_hash.h:1077
std::pair< iterator, bool > insert(value_type &&value)
Definition hopscotch_hash.h:809
size_type overflow_size() const noexcept
Definition hopscotch_hash.h:1207
ValueType value_type
Definition hopscotch_hash.h:445
std::uint_least8_t type
Definition hopscotch_hash.h:119
std::uint_least16_t type
Definition hopscotch_hash.h:127
std::uint_least32_t type
Definition hopscotch_hash.h:135
std::uint_least64_t type
Definition hopscotch_hash.h:143
Definition hopscotch_hash.h:111
Definition hopscotch_growth_policy.h:82
#define TSL_HH_THROW_OR_TERMINATE(ex, msg)
Definition hopscotch_growth_policy.h:64
#define tsl_hh_assert(expr)
Definition hopscotch_growth_policy.h:47
std::uint_least32_t truncated_hash_type
Definition hopscotch_hash.h:170
static const std::size_t SMALLEST_TYPE_MAX_BITS_SUPPORTED
Definition hopscotch_hash.h:109
static const std::size_t NB_RESERVED_BITS_IN_NEIGHBORHOOD
Definition hopscotch_hash.h:168
T numeric_cast(U value, const char *error_message="numeric_cast() failed.")
Definition hopscotch_hash.h:89
Definition bhopscotch_map.h:38
Definition hopscotch_hash.h:60
Definition hopscotch_hash.h:70
Definition hopscotch_hash.h:79
Definition hopscotch_hash.h:55
void type
Definition hopscotch_hash.h:56