24 #ifndef TSL_HOPSCOTCH_HASH_H 25 #define TSL_HOPSCOTCH_HASH_H 35 #include <initializer_list> 41 #include <type_traits> 45 #if (defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 9)) 46 #define TSL_HH_NO_RANGE_ERASE_WITH_CONST_ITERATOR 55 #define tsl_hh_assert(expr) assert(expr) 57 #define tsl_hh_assert(expr) (static_cast<void>(0)) 62 namespace detail_hopscotch_hash {
92 template <std::
size_t GrowthFactor>
106 template <
unsigned int MinBits>
108 typename std::enable_if<(MinBits > 0) && (MinBits <= 8)>
::type>
111 using type = std::uint_least8_t;
114 template <
unsigned int MinBits>
116 MinBits, typename std::enable_if<(MinBits > 8) && (MinBits <= 16)>
::type>
119 using type = std::uint_least16_t;
122 template <
unsigned int MinBits>
124 MinBits, typename std::enable_if<(MinBits > 16) && (MinBits <= 32)>
::type>
127 using type = std::uint_least32_t;
130 template <
unsigned int MinBits>
132 MinBits, typename std::enable_if<(MinBits > 32) && (MinBits <= 64)>
::type>
135 using type = std::uint_least64_t;
197 template <
typename ValueType,
unsigned int NeighborhoodSize,
bool StoreHash>
205 static_assert(NeighborhoodSize >= 4,
"NeighborhoodSize should be >= 4.");
209 static_assert(NeighborhoodSize <= 62,
"NeighborhoodSize should be <= 62.");
213 static_assert(!StoreHash || NeighborhoodSize <= 30,
214 "NeighborhoodSize should be <= 30 if StoreHash is true.");
232 std::is_nothrow_copy_constructible<value_type>::value)
235 if (!bucket.empty()) {
243 std::is_nothrow_move_constructible<value_type>::value)
246 if (!bucket.empty()) {
247 ::new (static_cast<void *>(std::addressof(
m_value)))
255 std::is_nothrow_copy_constructible<value_type>::value)
257 if (
this != &bucket) {
260 bucket_hash::operator=(bucket);
261 if (!bucket.empty()) {
319 return *reinterpret_cast<value_type *>(std::addressof(
m_value));
325 return *reinterpret_cast<const value_type *>(std::addressof(
m_value));
328 template <
typename... Args>
333 ::new (static_cast<void *>(std::addressof(
m_value)))
334 value_type(std::forward<Args>(value_type_args)...);
343 ::new (static_cast<void *>(std::addressof(empty_bucket.
m_value)))
374 return std::numeric_limits<typename bucket_hash::hash_type>::max();
377 return std::numeric_limits<std::size_t>::max();
400 value().~value_type();
426 template <
class ValueType,
class KeySelect,
class ValueSelect,
class Hash,
class KeyEqual,
427 class Allocator,
unsigned int NeighborhoodSize,
bool StoreHash,
class GrowthPolicy,
428 class OverflowContainer>
432 template <
typename U>
433 using has_mapped_type =
typename std::integral_constant<bool, !std::is_same<U, void>::value>;
435 static_assert(noexcept(std::declval<GrowthPolicy>().
bucket_for_hash(std::size_t(0))),
436 "GrowthPolicy::bucket_for_hash must be noexcept.");
437 static_assert(noexcept(std::declval<GrowthPolicy>().
clear()),
438 "GrowthPolicy::clear must be noexcept.");
463 typename std::allocator_traits<allocator_type>::template rebind_alloc<hopscotch_bucket>;
468 static_assert(std::is_same<typename overflow_container_type::value_type, ValueType>::value,
469 "OverflowContainer should have ValueType as type.");
472 std::is_same<typename overflow_container_type::allocator_type, Allocator>::value,
473 "Invalid allocator, not the same type as the value_type.");
489 template <
bool IsConst>
class hopscotch_iterator
530 return KeySelect()(*m_overflow_iterator);
533 template <
class U = ValueSelect,
534 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
535 typename std::conditional<IsConst,
const typename U::value_type &,
536 typename U::value_type &>::type
543 return U()(*m_overflow_iterator);
588 return lhs.m_buckets_iterator == rhs.m_buckets_iterator &&
589 lhs.m_overflow_iterator == rhs.m_overflow_iterator;
594 return !(lhs == rhs);
604 template <
class OC = OverflowContainer,
605 typename std::enable_if<!has_key_compare<OC>::value>::type * =
nullptr>
613 throw std::length_error(
"The map exceeds its maxmimum size.");
617 static_assert(NeighborhoodSize - 1 > 0,
"");
630 std::is_nothrow_move_constructible<value_type>::value ||
631 std::is_copy_constructible<value_type>::value,
632 "value_type must be either copy constructible or nothrow move constructible.");
635 template <
class OC = OverflowContainer,
636 typename std::enable_if<has_key_compare<OC>::value>::type * =
nullptr>
639 const typename OC::key_compare &comp)
646 throw std::length_error(
"The map exceeds its maxmimum size.");
650 static_assert(NeighborhoodSize - 1 > 0,
"");
663 std::is_nothrow_move_constructible<value_type>::value ||
664 std::is_copy_constructible<value_type>::value,
665 "value_type must be either copy constructible or nothrow move constructible.");
680 std::is_nothrow_move_constructible<Hash>::value &&std::is_nothrow_move_constructible<
681 KeyEqual>::value &&std::is_nothrow_move_constructible<GrowthPolicy>::value
682 && std::is_nothrow_move_constructible<buckets_container_type>::value
683 && std::is_nothrow_move_constructible<overflow_container_type>::value)
684 : Hash(std::move(static_cast<Hash &>(other))),
685 KeyEqual(std::move(static_cast<KeyEqual &>(other))),
686 GrowthPolicy(std::move(static_cast<GrowthPolicy &>(other))),
695 other.GrowthPolicy::clear();
696 other.m_buckets.clear();
697 other.m_overflow_elements.clear();
699 other.m_nb_elements = 0;
700 other.m_max_load_threshold_rehash = 0;
701 other.m_min_load_threshold_rehash = 0;
706 if (&other !=
this) {
707 Hash:: operator=(other);
708 KeyEqual:: operator=(other);
709 GrowthPolicy::operator=(other);
795 template <
class P,
typename std::enable_if<
796 std::is_constructible<value_type, P &&>::value>::type * =
nullptr>
797 std::pair<iterator, bool>
insert(P &&value)
806 if (hint !=
cend() &&
compare_keys(KeySelect()(*hint), KeySelect()(value))) {
810 return insert(value).first;
813 template <
class P,
typename std::enable_if<
814 std::is_constructible<value_type, P &&>::value>::type * =
nullptr>
822 if (hint !=
cend() &&
compare_keys(KeySelect()(*hint), KeySelect()(value))) {
826 return insert(std::move(value)).first;
829 template <
class InputIt>
void insert(InputIt first, InputIt last)
831 if (std::is_base_of<std::forward_iterator_tag,
832 typename std::iterator_traits<InputIt>::iterator_category>::value) {
833 const auto nb_elements_insert = std::distance(first, last);
839 if (nb_elements_insert > 0 && nb_free_buckets < std::size_t(nb_elements_insert)) {
840 reserve(nb_elements_in_buckets + std::size_t(nb_elements_insert));
844 for (; first != last; ++first) {
863 it.value() = std::forward<M>(obj);
875 it.value() = std::forward<M>(obj);
883 template <
class... Args> std::pair<iterator, bool>
emplace(Args &&... args)
893 template <
class... Args>
904 template <
class... Args>
911 return try_emplace(k, std::forward<Args>(args)...).first;
914 template <
class... Args>
921 return try_emplace(std::move(k), std::forward<Args>(args)...).first;
934 if (pos.m_buckets_iterator != pos.m_buckets_end_iterator) {
953 auto to_delete =
erase(first);
954 while (to_delete != last) {
955 to_delete =
erase(to_delete);
969 if (bucket_found !=
nullptr) {
991 swap(static_cast<Hash &>(*
this), static_cast<Hash &>(other));
992 swap(static_cast<KeyEqual &>(*
this), static_cast<KeyEqual &>(other));
993 swap(static_cast<GrowthPolicy &>(*
this), static_cast<GrowthPolicy &>(other));
1006 template <
class K,
class U = ValueSelect,
1007 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1008 typename U::value_type &
at(
const K &key)
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, std::size_t hash)
1017 return const_cast<typename U::value_type &>(
1018 static_cast<const hopscotch_hash *>(
this)->
at(key, hash));
1021 template <
class K,
class U = ValueSelect,
1022 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1023 const typename U::value_type &
at(
const K &key)
const 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, std::size_t hash)
const 1032 using T =
typename U::value_type;
1036 if (value ==
nullptr) {
1037 throw std::out_of_range(
"Couldn't find key.");
1044 template <
class K,
class U = ValueSelect,
1045 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1048 using T =
typename U::value_type;
1050 const std::size_t hash =
hash_key(key);
1054 if (value !=
nullptr) {
1058 return insert_impl(ibucket_for_hash, hash, std::piecewise_construct,
1059 std::forward_as_tuple(std::forward<K>(key)), std::forward_as_tuple())
1088 template <
class K> std::pair<iterator, iterator>
equal_range(
const K &key)
1093 template <
class K> std::pair<iterator, iterator>
equal_range(
const K &key, std::size_t hash)
1096 return std::make_pair(it, (it ==
end()) ? it : std::next(it));
1099 template <
class K> std::pair<const_iterator, const_iterator>
equal_range(
const K &key)
const 1105 std::pair<const_iterator, const_iterator>
equal_range(
const K &key, std::size_t hash)
const 1108 return std::make_pair(it, (it ==
cend()) ? it : std::next(it));
1125 return m_buckets.size() - NeighborhoodSize + 1;
1131 std::min(GrowthPolicy::max_bucket_count(),
m_buckets.max_size());
1179 if (pos.m_buckets_iterator != pos.m_buckets_end_iterator) {
1181 auto it =
m_buckets.begin() + std::distance(
m_buckets.cbegin(), pos.m_buckets_iterator);
1193 template <
class U = OverflowContainer,
1194 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1201 template <
class K> std::size_t
hash_key(
const K &key)
const {
return Hash::operator()(key); }
1203 template <
class K1,
class K2>
bool compare_keys(
const K1 &key1,
const K2 &key2)
const 1205 return KeyEqual::operator()(key1, key2);
1210 const std::size_t bucket = GrowthPolicy::bucket_for_hash(hash);
1218 typename std::enable_if<std::is_nothrow_move_constructible<U>::value>::type * =
nullptr>
1228 const std::size_t ibucket_for_hash =
1230 new_map.
m_buckets[ibucket_for_hash].set_overflow(
true);
1236 for (
auto it_bucket =
m_buckets.begin(); it_bucket !=
m_buckets.end(); ++it_bucket) {
1237 if (it_bucket->empty()) {
1241 const std::size_t hash = use_stored_hash
1242 ? it_bucket->truncated_bucket_hash()
1243 : new_map.
hash_key(KeySelect()(it_bucket->value()));
1246 new_map.
insert_impl(ibucket_for_hash, hash, std::move(it_bucket->value()));
1259 for (
auto it_bucket = new_map.
m_buckets.begin(); it_bucket != new_map.
m_buckets.end();
1261 if (it_bucket->empty()) {
1265 const std::size_t hash = use_stored_hash ? it_bucket->truncated_bucket_hash()
1266 :
hash_key(KeySelect()(it_bucket->value()));
1271 insert_impl(ibucket_for_hash, hash, std::move(it_bucket->value()));
1277 new_map.
swap(*
this);
1282 typename std::enable_if<std::is_copy_constructible<U>::value &&
1283 !std::is_nothrow_move_constructible<U>::value>::type * =
nullptr>
1290 if (bucket.empty()) {
1294 const std::size_t hash = use_stored_hash ? bucket.truncated_bucket_hash()
1295 : new_map.
hash_key(KeySelect()(bucket.value()));
1298 new_map.
insert_impl(ibucket_for_hash, hash, bucket.value());
1302 const std::size_t hash = new_map.
hash_key(KeySelect()(value));
1305 new_map.
insert_impl(ibucket_for_hash, hash, value);
1308 new_map.
swap(*
this);
1311 #ifdef TSL_HH_NO_RANGE_ERASE_WITH_CONST_ITERATOR 1326 std::size_t ibucket_for_hash)
1328 #ifdef TSL_HH_NO_RANGE_ERASE_WITH_CONST_ITERATOR 1339 if (bucket_for_value == ibucket_for_hash) {
1344 m_buckets[ibucket_for_hash].set_overflow(
false);
1353 std::size_t ibucket_for_hash) noexcept
1355 const std::size_t ibucket_for_value = std::distance(
m_buckets.data(), &bucket_for_value);
1358 bucket_for_value.remove_value();
1359 m_buckets[ibucket_for_hash].toggle_neighbor_presence(ibucket_for_value - ibucket_for_hash);
1367 it.first.value() = std::forward<M>(obj);
1373 template <
typename P,
class... Args>
1376 const std::size_t hash =
hash_key(key);
1381 if (it_find !=
end()) {
1382 return std::make_pair(it_find,
false);
1385 return insert_impl(ibucket_for_hash, hash, std::piecewise_construct,
1386 std::forward_as_tuple(std::forward<P>(key)),
1387 std::forward_as_tuple(std::forward<Args>(args_value)...));
1390 template <
typename P> std::pair<iterator, bool>
insert_impl(P &&value)
1392 const std::size_t hash =
hash_key(KeySelect()(value));
1398 if (it_find !=
end()) {
1399 return std::make_pair(it_find,
false);
1402 return insert_impl(ibucket_for_hash, hash, std::forward<P>(value));
1405 template <
typename... Args>
1406 std::pair<iterator, bool>
insert_impl(std::size_t ibucket_for_hash, std::size_t hash,
1407 Args &&... value_type_args)
1410 rehash(GrowthPolicy::next_bucket_count());
1420 if (ibucket_empty - ibucket_for_hash < NeighborhoodSize) {
1422 std::forward<Args>(value_type_args)...);
1435 auto it =
insert_in_overflow(ibucket_for_hash, std::forward<Args>(value_type_args)...);
1439 rehash(GrowthPolicy::next_bucket_count());
1442 return insert_impl(ibucket_for_hash, hash, std::forward<Args>(value_type_args)...);
1452 std::size_t expand_bucket_count = GrowthPolicy::next_bucket_count();
1453 GrowthPolicy expand_growth_policy(expand_bucket_count);
1456 for (
size_t ibucket = ibucket_neighborhood_check;
1458 (ibucket - ibucket_neighborhood_check) < NeighborhoodSize;
1462 const size_t hash = use_stored_hash ?
m_buckets[ibucket].truncated_bucket_hash()
1464 if (
bucket_for_hash(hash) != expand_growth_policy.bucket_for_hash(hash)) {
1478 const std::size_t limit =
1480 for (; ibucket_start < limit; ibucket_start++) {
1482 return ibucket_start;
1494 template <
typename... Args>
1496 std::size_t hash, Args &&... value_type_args)
1501 std::forward<Args>(value_type_args)...);
1504 m_buckets[ibucket_for_hash].toggle_neighbor_presence(ibucket_empty - ibucket_for_hash);
1507 return m_buckets.begin() + ibucket_empty;
1510 template <
class... Args,
class U = OverflowContainer,
1511 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1515 std::forward<Args>(value_type_args)...);
1517 m_buckets[ibucket_for_hash].set_overflow(
true);
1523 template <
class... Args,
class U = OverflowContainer,
1524 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1529 m_buckets[ibucket_for_hash].set_overflow(
true);
1545 const std::size_t neighborhood_start = ibucket_empty_in_out - NeighborhoodSize + 1;
1547 for (std::size_t to_check = neighborhood_start; to_check < ibucket_empty_in_out;
1550 std::size_t to_swap = to_check;
1552 while (neighborhood_infos != 0 && to_swap < ibucket_empty_in_out) {
1553 if ((neighborhood_infos & 1) == 1) {
1560 !
m_buckets[to_check].check_neighbor_presence(ibucket_empty_in_out - to_check));
1563 m_buckets[to_check].toggle_neighbor_presence(ibucket_empty_in_out - to_check);
1564 m_buckets[to_check].toggle_neighbor_presence(to_swap - to_check);
1566 ibucket_empty_in_out = to_swap;
1579 template <
class K,
class U = ValueSelect,
1580 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1584 return const_cast<typename U::value_type *>(
1594 template <
class K,
class U = ValueSelect,
1595 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1600 if (bucket_found !=
nullptr) {
1601 return std::addressof(ValueSelect()(bucket_found->
value()));
1607 return std::addressof(ValueSelect()(*it_overflow));
1634 if (bucket_found !=
nullptr) {
1651 if (bucket_found !=
nullptr) {
1668 static_cast<const hopscotch_hash *>(
this)->find_in_buckets(key, hash,
bucket_for_hash);
1669 return const_cast<hopscotch_bucket *>(bucket_found);
1686 while (neighborhood_infos != 0) {
1687 if ((neighborhood_infos & 1) == 1) {
1705 template <
class K,
class U = OverflowContainer,
1706 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1709 return std::find_if(
1714 template <
class K,
class U = OverflowContainer,
1715 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1718 return std::find_if(
1723 template <
class K,
class U = OverflowContainer,
1724 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1730 template <
class K,
class U = OverflowContainer,
1731 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1737 template <
class U = OverflowContainer,
1738 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1745 template <
class U = OverflowContainer,
1746 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1767 return (
bucket_count - 1) <= std::numeric_limits<truncated_hash_type>::max();
1780 return &empty_bucket;
iterator erase(const_iterator pos)
Definition: hopscotch_hash.h:930
Definition: hopscotch_hash.h:69
size_type count_impl(const K &key, std::size_t hash, const hopscotch_bucket *bucket_for_hash) const
Definition: hopscotch_hash.h:1615
static bool USE_STORED_HASH_ON_REHASH(size_type bucket_count)
Definition: hopscotch_hash.h:1762
static constexpr float MIN_LOAD_FACTOR_FOR_REHASH
Definition: hopscotch_hash.h:1760
hopscotch_hash(const hopscotch_hash &other)
Definition: hopscotch_hash.h:668
void reserve(size_type count_)
Definition: hopscotch_hash.h:1162
std::size_t size_type
Definition: hopscotch_hash.h:445
std::size_t hash_key(const K &key) const
Definition: hopscotch_hash.h:1201
iterator find(const K &key)
Definition: hopscotch_hash.h:1071
friend bool operator==(const hopscotch_iterator &lhs, const hopscotch_iterator &rhs)
Definition: hopscotch_hash.h:586
size_type bucket_count() const
Definition: hopscotch_hash.h:1114
const value_type & const_reference
Definition: hopscotch_hash.h:451
void rehash_impl(size_type count_)
Definition: hopscotch_hash.h:1219
std::pair< iterator, bool > insert_or_assign(key_type &&k, M &&obj)
Definition: hopscotch_hash.h:854
Definition: hopscotch_hash.h:198
const_iterator end() const noexcept
Definition: hopscotch_hash.h:764
hopscotch_bucket * find_in_buckets(const K &key, std::size_t hash, hopscotch_bucket *bucket_for_hash)
Definition: hopscotch_hash.h:1664
Allocator allocator_type
Definition: hopscotch_hash.h:449
iterator_overflow erase_from_overflow(const_iterator_overflow pos, std::size_t ibucket_for_hash)
Definition: hopscotch_hash.h:1325
void type
Definition: hopscotch_hash.h:66
hopscotch_bucket * static_empty_bucket_ptr()
Definition: hopscotch_hash.h:1777
void set_value_of_empty_bucket(truncated_hash_type hash, Args &&... value_type_args)
Definition: hopscotch_hash.h:329
static const std::size_t MAX_NEIGHBORHOOD_SIZE
Definition: hopscotch_hash.h:202
std::uint_least16_t type
Definition: hopscotch_hash.h:119
std::ptrdiff_t difference_type
Definition: hopscotch_hash.h:446
Definition: hopscotch_hash.h:429
const_iterator cbegin() const noexcept
Definition: hopscotch_hash.h:749
pointer operator->() const
Definition: hopscotch_hash.h:555
const_iterator find_impl(const K &key, std::size_t hash, const hopscotch_bucket *bucket_for_hash) const
Definition: hopscotch_hash.h:1647
std::pair< iterator, bool > insert(const value_type &value)
Definition: hopscotch_hash.h:793
hopscotch_bucket(const hopscotch_bucket &bucket) noexcept(std::is_nothrow_copy_constructible< value_type >::value)
Definition: hopscotch_hash.h:231
ValueType value_type
Definition: hopscotch_hash.h:221
static const size_type DEFAULT_INIT_BUCKETS_SIZE
Definition: hopscotch_hash.h:1755
iterator insert(const_iterator hint, const value_type &value)
Definition: hopscotch_hash.h:804
iterator end() noexcept
Definition: hopscotch_hash.h:759
iterator_overflow m_overflow_iterator
Definition: hopscotch_hash.h:600
Definition: hopscotch_growth_policy.h:37
iterator insert(const_iterator hint, value_type &&value)
Definition: hopscotch_hash.h:820
Definition: hopscotch_hash.h:64
Key value_type
Definition: hopscotch_hash.h:444
iterator insert_or_assign(const_iterator hint, key_type &&k, M &&obj)
Definition: hopscotch_hash.h:871
typename std::integral_constant< bool, !std::is_same< U, void >::value > has_mapped_type
Definition: hopscotch_hash.h:433
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
Definition: hopscotch_hash.h:849
value_type & value() noexcept
Definition: hopscotch_hash.h:316
typename overflow_container_type::iterator iterator_overflow
Definition: hopscotch_hash.h:478
iterator_bucket m_buckets_iterator
Definition: hopscotch_hash.h:598
iterator begin() noexcept
Definition: hopscotch_hash.h:737
bool bucket_hash_equal(std::size_t hash) const noexcept
Definition: hopscotch_hash.h:181
hasher hash_function() const
Definition: hopscotch_hash.h:1170
iterator try_emplace(const_iterator hint, key_type &&k, Args &&... args)
Definition: hopscotch_hash.h:915
float max_load_factor() const
Definition: hopscotch_hash.h:1147
std::uint_least32_t truncated_hash_type
Definition: hopscotch_hash.h:160
hopscotch_bucket * m_first_or_empty_bucket
Definition: hopscotch_hash.h:1792
std::pair< iterator, bool > insert_impl(std::size_t ibucket_for_hash, std::size_t hash, Args &&... value_type_args)
Definition: hopscotch_hash.h:1406
~hopscotch_bucket() noexcept
Definition: hopscotch_hash.h:273
static truncated_hash_type truncate_hash(std::size_t hash) noexcept
Definition: hopscotch_hash.h:381
U::value_type & at(const K &key, std::size_t hash)
Definition: hopscotch_hash.h:1015
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&... args)
Definition: hopscotch_hash.h:894
void set_empty(bool is_empty) noexcept
Definition: hopscotch_hash.h:387
#define tsl_hh_assert(expr)
Definition: hopscotch_hash.h:57
const_iterator find(const K &key) const
Definition: hopscotch_hash.h:1078
Hash hasher
Definition: hopscotch_hash.h:447
const U::value_type * find_value_impl(const K &key, std::size_t hash, const hopscotch_bucket *bucket_for_hash) const
Definition: hopscotch_hash.h:1596
const value_type & value() const noexcept
Definition: hopscotch_hash.h:322
iterator mutable_iterator(const_iterator pos)
Definition: hopscotch_hash.h:1177
bool empty() const noexcept
Definition: hopscotch_hash.h:774
buckets_container_type m_buckets
Definition: hopscotch_hash.h:1784
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: hopscotch_hash.h:888
bool compare_keys(const K1 &key1, const K2 &key2) const
Definition: hopscotch_hash.h:1203
std::pair< iterator, bool > insert(P &&value)
Definition: hopscotch_hash.h:797
hopscotch_iterator< true > const_iterator
Definition: hopscotch_hash.h:455
overflow_container_type m_overflow_elements
Definition: hopscotch_hash.h:1785
std::pair< iterator, bool > insert(value_type &&value)
Definition: hopscotch_hash.h:802
size_type size() const noexcept
Definition: hopscotch_hash.h:776
static const std::size_t MAX_PROBES_FOR_EMPTY_BUCKET
Definition: hopscotch_hash.h:1759
std::pair< iterator, iterator > equal_range(const K &key)
Definition: hopscotch_hash.h:1088
iterator erase(const_iterator first, const_iterator last)
Definition: hopscotch_hash.h:947
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:679
hopscotch_iterator() noexcept
Definition: hopscotch_hash.h:515
iterator_overflow find_in_overflow(const K &key)
Definition: hopscotch_hash.h:1707
iterator_buckets insert_in_bucket(std::size_t ibucket_empty, std::size_t ibucket_for_hash, std::size_t hash, Args &&... value_type_args)
Definition: hopscotch_hash.h:1495
std::pair< iterator, bool > try_emplace(key_type &&k, Args &&... args)
Definition: hopscotch_hash.h:899
void toggle_neighbor_presence(std::size_t ineighbor) noexcept
Definition: hopscotch_hash.h:299
typename KeySelect::key_type key_type
Definition: hopscotch_hash.h:443
hopscotch_bucket(hopscotch_bucket &&bucket) noexcept(std::is_nothrow_move_constructible< value_type >::value)
Definition: hopscotch_hash.h:242
void max_load_factor(float ml)
Definition: hopscotch_hash.h:1149
const U::value_type & at(const K &key, std::size_t hash) const
Definition: hopscotch_hash.h:1030
value_type * pointer
Definition: hopscotch_hash.h:513
typename buckets_container_type::iterator iterator_buckets
Definition: hopscotch_hash.h:475
float m_max_load_factor
Definition: hopscotch_hash.h:1796
const typename hopscotch_hash::value_type value_type
Definition: hopscotch_hash.h:510
bool bucket_hash_equal(std::size_t) const noexcept
Definition: hopscotch_hash.h:168
bool has_overflow() const noexcept
Definition: hopscotch_hash.h:295
std::uint_least32_t type
Definition: hopscotch_hash.h:127
void destroy_value() noexcept
Definition: hopscotch_hash.h:397
Definition: hopscotch_hash.h:79
typename std::conditional< IsConst, typename hopscotch_hash::const_iterator_buckets, typename hopscotch_hash::iterator_buckets >::type iterator_bucket
Definition: hopscotch_hash.h:496
U::value_type & at(const K &key)
Definition: hopscotch_hash.h:1008
std::ptrdiff_t difference_type
Definition: hopscotch_hash.h:511
size_type erase(const K &key, std::size_t hash)
Definition: hopscotch_hash.h:963
typename std::conditional< IsConst, typename hopscotch_hash::const_iterator_overflow, typename hopscotch_hash::iterator_overflow >::type iterator_overflow
Definition: hopscotch_hash.h:499
static constexpr float DEFAULT_MAX_LOAD_FACTOR
Definition: hopscotch_hash.h:1756
std::pair< iterator, bool > emplace(Args &&... args)
Definition: hopscotch_hash.h:883
KeyEqual key_equal
Definition: hopscotch_hash.h:448
void set_overflow(bool has_overflow) noexcept
Definition: hopscotch_hash.h:285
void swap(hopscotch_hash &other)
Definition: hopscotch_hash.h:987
iterator try_emplace(const_iterator hint, const key_type &k, Args &&... args)
Definition: hopscotch_hash.h:905
static const std::size_t MIN_NEIGHBORHOOD_SIZE
Definition: hopscotch_hash.h:201
std::pair< iterator, bool > insert_or_assign_impl(K &&key, M &&obj)
Definition: hopscotch_hash.h:1363
hopscotch_iterator(iterator_bucket buckets_iterator, iterator_bucket buckets_end_iterator, iterator_overflow overflow_iterator) noexcept
Definition: hopscotch_hash.h:501
void set_hash(truncated_hash_type) noexcept
Definition: hopscotch_hash.h:175
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t hash) const
Definition: hopscotch_hash.h:1105
typename smallest_type_for_min_bits< NeighborhoodSize+NB_RESERVED_BITS_IN_NEIGHBORHOOD >::type neighborhood_bitmap
Definition: hopscotch_hash.h:224
typename std::allocator_traits< allocator_type >::template rebind_alloc< hopscotch_bucket > buckets_allocator
Definition: hopscotch_hash.h:463
static std::size_t max_size() noexcept
Definition: hopscotch_hash.h:371
typename std::aligned_storage< sizeof(value_type), alignof(value_type)>::type storage
Definition: hopscotch_hash.h:404
void insert(InputIt first, InputIt last)
Definition: hopscotch_hash.h:829
std::pair< iterator, bool > try_emplace_impl(P &&key, Args &&... args_value)
Definition: hopscotch_hash.h:1374
std::uint_least64_t type
Definition: hopscotch_hash.h:135
bool swap_empty_bucket_closer(std::size_t &ibucket_empty_in_out)
Definition: hopscotch_hash.h:1542
typename overflow_container_type::const_iterator const_iterator_overflow
Definition: hopscotch_hash.h:479
static const std::size_t SMALLEST_TYPE_MAX_BITS_SUPPORTED
Definition: hopscotch_hash.h:101
void swap_value_into_empty_bucket(hopscotch_bucket &empty_bucket)
Definition: hopscotch_hash.h:339
size_type m_min_load_threshold_rehash
Definition: hopscotch_hash.h:1808
hopscotch_iterator< false > iterator
Definition: hopscotch_hash.h:454
U::key_compare key_comp() const
Definition: hopscotch_hash.h:1195
reference operator *() const
Definition: hopscotch_hash.h:546
std::size_t find_empty_bucket(std::size_t ibucket_start) const
Definition: hopscotch_hash.h:1476
key_equal key_eq() const
Definition: hopscotch_hash.h:1172
Definition: hopscotch_growth_policy.h:47
void erase_from_bucket(hopscotch_bucket &bucket_for_value, std::size_t ibucket_for_hash) noexcept
Definition: hopscotch_hash.h:1352
const_iterator_overflow find_in_overflow(const K &key) const
Definition: hopscotch_hash.h:1716
std::forward_iterator_tag iterator_category
Definition: hopscotch_hash.h:509
size_type m_nb_elements
Definition: hopscotch_hash.h:1794
iterator_bucket m_buckets_end_iterator
Definition: hopscotch_hash.h:599
std::conditional< IsConst, const typename U::value_type &, typename U::value_type & >::type value() const
Definition: hopscotch_hash.h:537
size_type m_max_load_threshold_rehash
Definition: hopscotch_hash.h:1801
std::pair< iterator, bool > insert_impl(P &&value)
Definition: hopscotch_hash.h:1390
iterator_overflow mutable_overflow_iterator(const_iterator_overflow it)
Definition: hopscotch_hash.h:1318
hopscotch_hash(size_type bucket_count, const Hash &hash, const KeyEqual &equal, const Allocator &alloc, float max_load_factor, const typename OC::key_compare &comp)
Definition: hopscotch_hash.h:637
size_type max_bucket_count() const
Definition: hopscotch_hash.h:1128
void copy_hash(const hopscotch_bucket_hash &bucket) noexcept
Definition: hopscotch_hash.h:189
U::value_type * find_value_impl(const K &key, std::size_t hash, hopscotch_bucket *bucket_for_hash)
Definition: hopscotch_hash.h:1581
hopscotch_bucket & operator=(const hopscotch_bucket &bucket) noexcept(std::is_nothrow_copy_constructible< value_type >::value)
Definition: hopscotch_hash.h:254
void clear() noexcept
Definition: hopscotch_hash.h:361
bool empty() const noexcept
Definition: hopscotch_hash.h:297
hopscotch_bucket() noexcept
Definition: hopscotch_hash.h:226
size_type count(const K &key, std::size_t hash) const
Definition: hopscotch_hash.h:1066
void remove_value() noexcept
Definition: hopscotch_hash.h:353
size_type count(const K &key) const
Definition: hopscotch_hash.h:1064
iterator find(const K &key, std::size_t hash)
Definition: hopscotch_hash.h:1073
friend bool operator!=(const hopscotch_iterator &lhs, const hopscotch_iterator &rhs)
Definition: hopscotch_hash.h:592
Definition: hopscotch_hash.h:165
std::vector< char > data
Definition: cth_pressure_map.C:73
value_type & reference
Definition: hopscotch_hash.h:450
hopscotch_iterator operator++(int)
Definition: hopscotch_hash.h:578
std::pair< iterator, iterator > equal_range(const K &key, std::size_t hash)
Definition: hopscotch_hash.h:1093
Definition: hopscotch_hash.h:102
hopscotch_iterator & operator++()
Definition: hopscotch_hash.h:564
typename hopscotch_bucket::neighborhood_bitmap neighborhood_bitmap
Definition: hopscotch_hash.h:460
void set_hash(truncated_hash_type hash) noexcept
Definition: hopscotch_hash.h:191
std::uint_least8_t type
Definition: hopscotch_hash.h:111
const value_type * const_pointer
Definition: hopscotch_hash.h:453
truncated_hash_type m_hash
Definition: hopscotch_hash.h:194
std::vector< hopscotch_bucket, buckets_allocator > buckets_container_type
Definition: hopscotch_hash.h:464
neighborhood_bitmap neighborhood_infos() const noexcept
Definition: hopscotch_hash.h:280
float load_factor() const
Definition: hopscotch_hash.h:1138
size_type overflow_size() const noexcept
Definition: hopscotch_hash.h:1191
const U::value_type & at(const K &key) const
Definition: hopscotch_hash.h:1023
const hopscotch_hash::key_type & key() const
Definition: hopscotch_hash.h:524
iterator insert_or_assign(const_iterator hint, const key_type &k, M &&obj)
Definition: hopscotch_hash.h:859
iterator_overflow insert_in_overflow(std::size_t ibucket_for_hash, Args &&... value_type_args)
Definition: hopscotch_hash.h:1512
bool check_neighbor_presence(std::size_t ineighbor) const noexcept
Definition: hopscotch_hash.h:306
void rehash(size_type count_)
Definition: hopscotch_hash.h:1156
overflow_container_type overflow_container_type
Definition: hopscotch_hash.h:466
Definition: hopscotch_hash.h:441
neighborhood_bitmap m_neighborhood_infos
Definition: hopscotch_hash.h:406
truncated_hash_type truncated_bucket_hash() const noexcept
Definition: hopscotch_hash.h:186
truncated_hash_type truncated_bucket_hash() const noexcept
Definition: hopscotch_hash.h:170
static const std::size_t NB_RESERVED_BITS_IN_NEIGHBORHOOD
Definition: hopscotch_hash.h:158
Definition: hopscotch_hash.h:88
hopscotch_hash & operator=(hopscotch_hash &&other)
Definition: hopscotch_hash.h:724
void copy_hash(const hopscotch_bucket_hash &) noexcept
Definition: hopscotch_hash.h:173
size_type max_size() const noexcept
Definition: hopscotch_hash.h:778
U::value_type & operator[](K &&key)
Definition: hopscotch_hash.h:1046
void clear() noexcept
Definition: hopscotch_hash.h:783
const_iterator cend() const noexcept
Definition: hopscotch_hash.h:766
storage m_value
Definition: hopscotch_hash.h:407
const_iterator find(const K &key, std::size_t hash) const
Definition: hopscotch_hash.h:1083
size_type erase(const K &key)
Definition: hopscotch_hash.h:961
hopscotch_hash(size_type bucket_count, const Hash &hash, const KeyEqual &equal, const Allocator &alloc, float max_load_factor)
Definition: hopscotch_hash.h:606
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition: hopscotch_hash.h:1099
value_type & reference
Definition: hopscotch_hash.h:512
iterator find_impl(const K &key, std::size_t hash, hopscotch_bucket *bucket_for_hash)
Definition: hopscotch_hash.h:1631
allocator_type get_allocator() const
Definition: hopscotch_hash.h:732
hopscotch_hash new_hopscotch_hash(size_type bucket_count)
Definition: hopscotch_hash.h:1739
typename buckets_container_type::const_iterator const_iterator_buckets
Definition: hopscotch_hash.h:476
const hopscotch_bucket * find_in_buckets(const K &key, std::size_t hash, const hopscotch_bucket *bucket_for_hash) const
Definition: hopscotch_hash.h:1676
std::size_t bucket_for_hash(std::size_t hash) const
Definition: hopscotch_hash.h:1208
iterator erase(iterator pos)
Definition: hopscotch_hash.h:928
bool will_neighborhood_change_on_rehash(size_t ibucket_neighborhood_check) const
Definition: hopscotch_hash.h:1450
hopscotch_iterator(const hopscotch_iterator< false > &other) noexcept
Definition: hopscotch_hash.h:517
hopscotch_hash & operator=(const hopscotch_hash &other)
Definition: hopscotch_hash.h:704
iterator insert(const_iterator hint, P &&value)
Definition: hopscotch_hash.h:815
value_type * pointer
Definition: hopscotch_hash.h:452
const_iterator begin() const noexcept
Definition: hopscotch_hash.h:747