Go to the documentation of this file.
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)))
390 value().~value_type();
416 template <
class ValueType,
class KeySelect,
class ValueSelect,
class Hash,
class KeyEqual,
417 class Allocator,
unsigned int NeighborhoodSize,
bool StoreHash,
class GrowthPolicy,
418 class OverflowContainer>
422 template <
typename U>
423 using has_mapped_type =
typename std::integral_constant<bool, !std::is_same<U, void>::value>;
425 static_assert(noexcept(std::declval<GrowthPolicy>().
bucket_for_hash(std::size_t(0))),
426 "GrowthPolicy::bucket_for_hash must be noexcept.");
427 static_assert(noexcept(std::declval<GrowthPolicy>().
clear()),
428 "GrowthPolicy::clear must be noexcept.");
453 typename std::allocator_traits<allocator_type>::template rebind_alloc<hopscotch_bucket>;
458 static_assert(std::is_same<typename overflow_container_type::value_type, ValueType>::value,
459 "OverflowContainer should have ValueType as type.");
462 std::is_same<typename overflow_container_type::allocator_type, Allocator>::value,
463 "Invalid allocator, not the same type as the value_type.");
479 template <
bool IsConst>
class hopscotch_iterator
508 template <bool TIsConst = IsConst, typename std::enable_if<TIsConst>::type * =
nullptr>
527 return KeySelect()(*m_overflow_iterator);
530 template <
class U = ValueSelect,
531 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
532 typename std::conditional<IsConst,
const typename U::value_type &,
533 typename U::value_type &>::type
540 return U()(*m_overflow_iterator);
585 return lhs.m_buckets_iterator == rhs.m_buckets_iterator &&
586 lhs.m_overflow_iterator == rhs.m_overflow_iterator;
591 return !(lhs == rhs);
601 template <
class OC = OverflowContainer,
602 typename std::enable_if<!has_key_compare<OC>::value>::type * =
nullptr>
609 throw std::length_error(
"The map exceeds its maxmimum size.");
613 static_assert(NeighborhoodSize - 1 > 0,
"");
626 std::is_nothrow_move_constructible<value_type>::value ||
627 std::is_copy_constructible<value_type>::value,
628 "value_type must be either copy constructible or nothrow move constructible.");
631 template <
class OC = OverflowContainer,
632 typename std::enable_if<has_key_compare<OC>::value>::type * =
nullptr>
635 const typename OC::key_compare &comp)
641 throw std::length_error(
"The map exceeds its maxmimum size.");
645 static_assert(NeighborhoodSize - 1 > 0,
"");
658 std::is_nothrow_move_constructible<value_type>::value ||
659 std::is_copy_constructible<value_type>::value,
660 "value_type must be either copy constructible or nothrow move constructible.");
674 std::is_nothrow_move_constructible<Hash>::value &&std::is_nothrow_move_constructible<
675 KeyEqual>::value &&std::is_nothrow_move_constructible<GrowthPolicy>::value
676 && std::is_nothrow_move_constructible<buckets_container_type>::value
677 && std::is_nothrow_move_constructible<overflow_container_type>::value)
678 : Hash(std::move(static_cast<Hash &>(other))),
679 KeyEqual(std::move(static_cast<KeyEqual &>(other))),
680 GrowthPolicy(std::move(static_cast<GrowthPolicy &>(other))),
688 other.GrowthPolicy::clear();
689 other.m_buckets_data.clear();
690 other.m_overflow_elements.clear();
692 other.m_nb_elements = 0;
693 other.m_max_load_threshold_rehash = 0;
694 other.m_min_load_threshold_rehash = 0;
699 if (&other !=
this) {
700 Hash:: operator=(other);
701 KeyEqual:: operator=(other);
702 GrowthPolicy::operator=(other);
788 template <
class P,
typename std::enable_if<
789 std::is_constructible<value_type, P &&>::value>::type * =
nullptr>
790 std::pair<iterator, bool>
insert(P &&value)
799 if (hint !=
cend() &&
compare_keys(KeySelect()(*hint), KeySelect()(value))) {
803 return insert(value).first;
806 template <
class P,
typename std::enable_if<
807 std::is_constructible<value_type, P &&>::value>::type * =
nullptr>
815 if (hint !=
cend() &&
compare_keys(KeySelect()(*hint), KeySelect()(value))) {
819 return insert(std::move(value)).first;
822 template <
class InputIt>
void insert(InputIt first, InputIt last)
824 if (std::is_base_of<std::forward_iterator_tag,
825 typename std::iterator_traits<InputIt>::iterator_category>::value) {
826 const auto nb_elements_insert = std::distance(first, last);
832 if (nb_elements_insert > 0 && nb_free_buckets < std::size_t(nb_elements_insert)) {
833 reserve(nb_elements_in_buckets + std::size_t(nb_elements_insert));
837 for (; first != last; ++first) {
856 it.value() = std::forward<M>(obj);
868 it.value() = std::forward<M>(obj);
876 template <
class... Args> std::pair<iterator, bool>
emplace(Args &&... args)
886 template <
class... Args>
897 template <
class... Args>
904 return try_emplace(k, std::forward<Args>(args)...).first;
907 template <
class... Args>
914 return try_emplace(std::move(k), std::forward<Args>(args)...).first;
927 if (pos.m_buckets_iterator != pos.m_buckets_end_iterator) {
946 auto to_delete =
erase(first);
947 while (to_delete != last) {
948 to_delete =
erase(to_delete);
962 if (bucket_found !=
nullptr) {
968 if (
m_buckets[ibucket_for_hash].has_overflow()) {
984 swap(static_cast<Hash &>(*
this), static_cast<Hash &>(other));
985 swap(static_cast<KeyEqual &>(*
this), static_cast<KeyEqual &>(other));
986 swap(static_cast<GrowthPolicy &>(*
this), static_cast<GrowthPolicy &>(other));
999 template <
class K,
class U = ValueSelect,
1000 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1001 typename U::value_type &
at(
const K &key)
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, std::size_t my_hash)
1010 return const_cast<typename U::value_type &>(
1011 static_cast<const hopscotch_hash *>(
this)->
at(key, my_hash));
1014 template <
class K,
class U = ValueSelect,
1015 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1016 const typename U::value_type &
at(
const K &key)
const
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, std::size_t my_hash)
const
1025 using T =
typename U::value_type;
1028 if (value ==
nullptr) {
1029 throw std::out_of_range(
"Couldn't find key.");
1036 template <
class K,
class U = ValueSelect,
1037 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1040 using T =
typename U::value_type;
1042 const std::size_t my_hash =
hash_key(key);
1046 if (value !=
nullptr) {
1050 return insert_value(ibucket_for_hash, my_hash, std::piecewise_construct,
1051 std::forward_as_tuple(std::forward<K>(key)), std::forward_as_tuple())
1082 template <
class K>
bool contains(
const K &key, std::size_t my_hash)
const
1084 return count(key, my_hash) != 0;
1087 template <
class K> std::pair<iterator, iterator>
equal_range(
const K &key)
1093 std::pair<iterator, iterator>
equal_range(
const K &key, std::size_t my_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 my_hash)
const
1108 return std::make_pair(it, (it ==
cend()) ? it : std::next(it));
1131 std::min(GrowthPolicy::max_bucket_count(),
m_buckets_data.max_size());
1179 if (pos.m_buckets_iterator != pos.m_buckets_end_iterator) {
1194 template <
class U = OverflowContainer,
1195 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1202 template <
class K> std::size_t
hash_key(
const K &key)
const {
return Hash::operator()(key); }
1204 template <
class K1,
class K2>
bool compare_keys(
const K1 &key1,
const K2 &key2)
const
1206 return KeyEqual::operator()(key1, key2);
1211 const std::size_t bucket = GrowthPolicy::bucket_for_hash(my_hash);
1219 typename std::enable_if<std::is_nothrow_move_constructible<U>::value>::type * =
nullptr>
1229 const std::size_t ibucket_for_hash =
1239 if (it_bucket->empty()) {
1243 const std::size_t my_hash = use_stored_hash
1244 ? it_bucket->truncated_bucket_hash()
1245 : new_map.
hash_key(KeySelect()(it_bucket->value()));
1246 const std::size_t ibucket_for_hash = new_map.
bucket_for_hash(my_hash);
1248 new_map.
insert_value(ibucket_for_hash, my_hash, std::move(it_bucket->value()));
1263 if (it_bucket->empty()) {
1267 const std::size_t my_hash = use_stored_hash ? it_bucket->truncated_bucket_hash()
1268 :
hash_key(KeySelect()(it_bucket->value()));
1273 insert_value(ibucket_for_hash, my_hash, std::move(it_bucket->value()));
1279 new_map.
swap(*
this);
1284 typename std::enable_if<std::is_copy_constructible<U>::value &&
1285 !std::is_nothrow_move_constructible<U>::value>::type * =
nullptr>
1292 if (bucket.empty()) {
1296 const std::size_t my_hash = use_stored_hash
1297 ? bucket.truncated_bucket_hash()
1298 : new_map.
hash_key(KeySelect()(bucket.value()));
1299 const std::size_t ibucket_for_hash = new_map.
bucket_for_hash(my_hash);
1301 new_map.
insert_value(ibucket_for_hash, my_hash, bucket.value());
1305 const std::size_t my_hash = new_map.
hash_key(KeySelect()(value));
1306 const std::size_t ibucket_for_hash = new_map.
bucket_for_hash(my_hash);
1308 new_map.
insert_value(ibucket_for_hash, my_hash, value);
1311 new_map.
swap(*
this);
1314 #ifdef TSL_HH_NO_RANGE_ERASE_WITH_CONST_ITERATOR
1329 std::size_t ibucket_for_hash)
1331 #ifdef TSL_HH_NO_RANGE_ERASE_WITH_CONST_ITERATOR
1342 if (bucket_for_value == ibucket_for_hash) {
1356 std::size_t ibucket_for_hash) noexcept
1358 const std::size_t ibucket_for_value =
1362 bucket_for_value.remove_value();
1371 it.first.value() = std::forward<M>(obj);
1377 template <
typename P,
class... Args>
1380 const std::size_t my_hash =
hash_key(key);
1385 if (it_find !=
end()) {
1386 return std::make_pair(it_find,
false);
1389 return insert_value(ibucket_for_hash, my_hash, std::piecewise_construct,
1390 std::forward_as_tuple(std::forward<P>(key)),
1391 std::forward_as_tuple(std::forward<Args>(args_value)...));
1394 template <
typename P> std::pair<iterator, bool>
insert_impl(P &&value)
1396 const std::size_t my_hash =
hash_key(KeySelect()(value));
1401 if (it_find !=
end()) {
1402 return std::make_pair(it_find,
false);
1405 return insert_value(ibucket_for_hash, my_hash, std::forward<P>(value));
1408 template <
typename... Args>
1409 std::pair<iterator, bool>
insert_value(std::size_t ibucket_for_hash, std::size_t my_hash,
1410 Args &&... value_type_args)
1413 rehash(GrowthPolicy::next_bucket_count());
1423 if (ibucket_empty - ibucket_for_hash < NeighborhoodSize) {
1425 std::forward<Args>(value_type_args)...);
1438 auto it =
insert_in_overflow(ibucket_for_hash, std::forward<Args>(value_type_args)...);
1442 rehash(GrowthPolicy::next_bucket_count());
1445 return insert_value(ibucket_for_hash, my_hash, std::forward<Args>(value_type_args)...);
1455 std::size_t expand_bucket_count = GrowthPolicy::next_bucket_count();
1456 GrowthPolicy expand_growth_policy(expand_bucket_count);
1459 for (
size_t ibucket = ibucket_neighborhood_check;
1461 (ibucket - ibucket_neighborhood_check) < NeighborhoodSize;
1465 const size_t my_hash = use_stored_hash
1468 if (
bucket_for_hash(my_hash) != expand_growth_policy.bucket_for_hash(my_hash)) {
1482 const std::size_t limit =
1484 for (; ibucket_start < limit; ibucket_start++) {
1486 return ibucket_start;
1498 template <
typename... Args>
1500 std::size_t my_hash, Args &&... value_type_args)
1505 std::forward<Args>(value_type_args)...);
1514 template <
class... Args,
class U = OverflowContainer,
1515 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1519 std::forward<Args>(value_type_args)...);
1527 template <
class... Args,
class U = OverflowContainer,
1528 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1549 const std::size_t neighborhood_start = ibucket_empty_in_out - NeighborhoodSize + 1;
1551 for (std::size_t to_check = neighborhood_start; to_check < ibucket_empty_in_out;
1554 std::size_t to_swap = to_check;
1556 while (neighborhood_infos != 0 && to_swap < ibucket_empty_in_out) {
1557 if ((neighborhood_infos & 1) == 1) {
1564 !
m_buckets[to_check].check_neighbor_presence(ibucket_empty_in_out - to_check));
1570 ibucket_empty_in_out = to_swap;
1583 template <
class K,
class U = ValueSelect,
1584 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1588 return const_cast<typename U::value_type *>(
1589 static_cast<const hopscotch_hash *>(
this)->
find_value_impl(key, my_hash,
1599 template <
class K,
class U = ValueSelect,
1600 typename std::enable_if<has_mapped_type<U>::value>::type * =
nullptr>
1605 if (bucket_found !=
nullptr) {
1606 return std::addressof(ValueSelect()(bucket_found->
value()));
1612 return std::addressof(ValueSelect()(*it_overflow));
1639 if (bucket_found !=
nullptr) {
1657 if (bucket_found !=
nullptr) {
1675 static_cast<const hopscotch_hash *>(
this)->find_in_buckets(key, my_hash,
1677 return const_cast<hopscotch_bucket *>(bucket_found);
1694 while (neighborhood_infos != 0) {
1695 if ((neighborhood_infos & 1) == 1) {
1713 template <
class K,
class U = OverflowContainer,
1714 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1717 return std::find_if(
1722 template <
class K,
class U = OverflowContainer,
1723 typename std::enable_if<!has_key_compare<U>::value>::type * =
nullptr>
1726 return std::find_if(
1731 template <
class K,
class U = OverflowContainer,
1732 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1738 template <
class K,
class U = OverflowContainer,
1739 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>
1753 template <
class U = OverflowContainer,
1754 typename std::enable_if<has_key_compare<U>::value>::type * =
nullptr>
1778 typename std::enable_if<std::is_same<T, truncated_hash_type>::value>::type * =
nullptr>
1786 typename std::enable_if<!std::is_same<T, truncated_hash_type>::value>::type * =
nullptr>
1792 return (
bucket_count - 1) <= std::numeric_limits<truncated_hash_type>::max();
1805 return &empty_bucket;
std::pair< iterator, iterator > equal_range(const K &key)
Definition: hopscotch_hash.h:1087
float max_load_factor() const
Definition: hopscotch_hash.h:1147
iterator insert_or_assign(const_iterator hint, key_type &&k, M &&obj)
Definition: hopscotch_hash.h:864
hopscotch_bucket * static_empty_bucket_ptr()
Definition: hopscotch_hash.h:1802
hopscotch_hash(const hopscotch_hash &other)
Definition: hopscotch_hash.h:663
~hopscotch_bucket() noexcept
Definition: hopscotch_hash.h:273
hopscotch_hash(size_type bucket_count, const Hash &my_hash, const KeyEqual &equal, const Allocator &alloc, float max_load_factor)
Definition: hopscotch_hash.h:603
Definition: bhopscotch_map.h:37
void clear() noexcept
Definition: hopscotch_hash.h:361
hopscotch_hash & operator=(const hopscotch_hash &other)
Definition: hopscotch_hash.h:697
hopscotch_iterator(iterator_bucket buckets_iterator, iterator_bucket buckets_end_iterator, iterator_overflow overflow_iterator) noexcept
Definition: hopscotch_hash.h:491
iterator_overflow mutable_overflow_iterator(const_iterator_overflow it)
Definition: hopscotch_hash.h:1321
hopscotch_iterator operator++(int)
Definition: hopscotch_hash.h:575
hopscotch_hash new_hopscotch_hash(size_type bucket_count)
Definition: hopscotch_hash.h:1747
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&... args)
Definition: hopscotch_hash.h:887
std::pair< iterator, bool > insert_or_assign_impl(K &&key, M &&obj)
Definition: hopscotch_hash.h:1367
std::size_t find_empty_bucket(std::size_t ibucket_start) const
Definition: hopscotch_hash.h:1480
std::uint_least64_t type
Definition: hopscotch_hash.h:135
iterator_bucket m_buckets_end_iterator
Definition: hopscotch_hash.h:596
iterator find(const K &key, std::size_t my_hash)
Definition: hopscotch_hash.h:1065
hopscotch_iterator() noexcept
Definition: hopscotch_hash.h:505
static truncated_hash_type truncate_hash(std::size_t my_hash) noexcept
Definition: hopscotch_hash.h:371
typename std::conditional< IsConst, typename hopscotch_hash::const_iterator_buckets, typename hopscotch_hash::iterator_buckets >::type iterator_bucket
Definition: hopscotch_hash.h:486
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::const_iterator_overflow typename overflow_container_type::const_iterator const_iterator_overflow
Definition: hopscotch_hash.h:469
std::pair< iterator, bool > try_emplace(key_type &&k, Args &&... args)
Definition: hopscotch_hash.h:892
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::reference value_type & reference
Definition: hopscotch_hash.h:440
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::overflow_container_type overflow_container_type overflow_container_type
Definition: hopscotch_hash.h:456
std::ptrdiff_t difference_type
Definition: hopscotch_hash.h:501
Definition: hopscotch_hash.h:64
buckets_container_type m_buckets_data
Definition: hopscotch_hash.h:1809
truncated_hash_type truncated_bucket_hash() const noexcept
Definition: hopscotch_hash.h:186
hopscotch_bucket(const hopscotch_bucket &bucket) noexcept(std::is_nothrow_copy_constructible< value_type >::value)
Definition: hopscotch_hash.h:231
bool contains(const K &key, std::size_t my_hash) const
Definition: hopscotch_hash.h:1082
std::pair< iterator, bool > insert(const value_type &value)
Definition: hopscotch_hash.h:786
void clear() noexcept
Definition: hopscotch_hash.h:776
void rehash(size_type count_)
Definition: hopscotch_hash.h:1156
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::allocator_type Allocator allocator_type
Definition: hopscotch_hash.h:439
const U::value_type & at(const K &key) const
Definition: hopscotch_hash.h:1016
bool bucket_hash_equal(std::size_t) const noexcept
Definition: hopscotch_hash.h:168
const_iterator begin() const noexcept
Definition: hopscotch_hash.h:739
std::size_t hash_key(const K &key) const
Definition: hopscotch_hash.h:1202
void copy_hash(const hopscotch_bucket_hash &) noexcept
Definition: hopscotch_hash.h:173
allocator_type get_allocator() const
Definition: hopscotch_hash.h:724
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::const_reference const value_type & const_reference
Definition: hopscotch_hash.h:441
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::hasher Hash hasher
Definition: hopscotch_hash.h:437
std::pair< iterator, bool > try_emplace_impl(P &&key, Args &&... args_value)
Definition: hopscotch_hash.h:1378
std::size_t bucket_for_hash(std::size_t my_hash) const
Definition: hopscotch_hash.h:1209
size_type overflow_size() const noexcept
Definition: hopscotch_hash.h:1192
bool contains(const K &key) const
Definition: hopscotch_hash.h:1080
hopscotch_hash(size_type bucket_count, const Hash &my_hash, const KeyEqual &equal, const Allocator &alloc, float max_load_factor, const typename OC::key_compare &comp)
Definition: hopscotch_hash.h:633
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::key_type typename KeySelect::key_type key_type
Definition: hopscotch_hash.h:433
static const std::size_t MAX_PROBES_FOR_EMPTY_BUCKET
Definition: hopscotch_hash.h:1767
Definition: hopscotch_hash.h:198
bool empty() const noexcept
Definition: hopscotch_hash.h:297
hasher hash_function() const
Definition: hopscotch_hash.h:1170
iterator try_emplace(const_iterator hint, key_type &&k, Args &&... args)
Definition: hopscotch_hash.h:908
float load_factor() const
Definition: hopscotch_hash.h:1138
static bool USE_STORED_HASH_ON_REHASH(size_type bucket_count)
Definition: hopscotch_hash.h:1787
std::pair< iterator, bool > emplace(Args &&... args)
Definition: hopscotch_hash.h:876
iterator_bucket m_buckets_iterator
Definition: hopscotch_hash.h:595
Definition: hopscotch_hash.h:88
static const std::size_t MAX_NEIGHBORHOOD_SIZE
Definition: hopscotch_hash.h:202
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::difference_type std::ptrdiff_t difference_type
Definition: hopscotch_hash.h:436
static const size_type DEFAULT_INIT_BUCKETS_SIZE
Definition: hopscotch_hash.h:1763
const value_type & value() const noexcept
Definition: hopscotch_hash.h:322
value_type * pointer
Definition: hopscotch_hash.h:503
U::key_compare key_comp() const
Definition: hopscotch_hash.h:1196
iterator insert(const_iterator hint, value_type &&value)
Definition: hopscotch_hash.h:813
iterator erase(const_iterator first, const_iterator last)
Definition: hopscotch_hash.h:940
size_type max_size() const noexcept
Definition: hopscotch_hash.h:771
size_type erase(const K &key)
Definition: hopscotch_hash.h:954
std::pair< iterator, bool > insert(value_type &&value)
Definition: hopscotch_hash.h:795
void set_overflow(bool has_overflow) noexcept
Definition: hopscotch_hash.h:285
hopscotch_iterator & operator=(const hopscotch_iterator &other)=default
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::value_type std::pair< const Key, T > value_type
Definition: hopscotch_hash.h:434
const hopscotch_hash::key_type & key() const
Definition: hopscotch_hash.h:521
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::iterator_buckets typename buckets_container_type::iterator iterator_buckets
Definition: hopscotch_hash.h:465
iterator_overflow insert_in_overflow(std::size_t ibucket_for_hash, Args &&... value_type_args)
Definition: hopscotch_hash.h:1516
void copy_hash(const hopscotch_bucket_hash &bucket) noexcept
Definition: hopscotch_hash.h:189
overflow_container_type m_overflow_elements
Definition: hopscotch_hash.h:1810
iterator end() noexcept
Definition: hopscotch_hash.h:751
size_type size() const noexcept
Definition: hopscotch_hash.h:769
bool has_overflow() const noexcept
Definition: hopscotch_hash.h:295
typename smallest_type_for_min_bits< NeighborhoodSize+NB_RESERVED_BITS_IN_NEIGHBORHOOD >::type neighborhood_bitmap
Definition: hopscotch_hash.h:224
size_type m_nb_elements
Definition: hopscotch_hash.h:1822
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::key_equal KeyEqual key_equal
Definition: hopscotch_hash.h:438
iterator_overflow find_in_overflow(const K &key)
Definition: hopscotch_hash.h:1715
void reserve(size_type count_)
Definition: hopscotch_hash.h:1162
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::size_type std::size_t size_type
Definition: hopscotch_hash.h:435
iterator insert_or_assign(const_iterator hint, const key_type &k, M &&obj)
Definition: hopscotch_hash.h:852
U::value_type & at(const K &key, std::size_t my_hash)
Definition: hopscotch_hash.h:1008
bool bucket_hash_equal(std::size_t my_hash) const noexcept
Definition: hopscotch_hash.h:181
hopscotch_iterator(const hopscotch_iterator<!TIsConst > &other) noexcept
Definition: hopscotch_hash.h:509
pointer operator->() const
Definition: hopscotch_hash.h:552
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t my_hash) const
Definition: hopscotch_hash.h:1105
hopscotch_bucket(hopscotch_bucket &&bucket) noexcept(std::is_nothrow_move_constructible< value_type >::value)
Definition: hopscotch_hash.h:242
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::const_iterator hopscotch_iterator< true > const_iterator
Definition: hopscotch_hash.h:445
iterator begin() noexcept
Definition: hopscotch_hash.h:729
std::conditional< IsConst, const typename U::value_type &, typename U::value_type & >::type value() const
Definition: hopscotch_hash.h:534
size_type m_max_load_threshold_rehash
Definition: hopscotch_hash.h:1829
bool will_neighborhood_change_on_rehash(size_t ibucket_neighborhood_check) const
Definition: hopscotch_hash.h:1453
void set_empty(bool is_empty) noexcept
Definition: hopscotch_hash.h:377
size_type count_impl(const K &key, std::size_t my_hash, const hopscotch_bucket *bucket_for_hash) const
Definition: hopscotch_hash.h:1620
friend bool operator==(const hopscotch_iterator &lhs, const hopscotch_iterator &rhs)
Definition: hopscotch_hash.h:583
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
Definition: hopscotch_hash.h:842
iterator erase(iterator pos)
Definition: hopscotch_hash.h:921
void erase_from_bucket(hopscotch_bucket &bucket_for_value, std::size_t ibucket_for_hash) noexcept
Definition: hopscotch_hash.h:1355
iterator find(const K &key)
Definition: hopscotch_hash.h:1063
storage m_value
Definition: hopscotch_hash.h:397
void set_hash(truncated_hash_type) noexcept
Definition: hopscotch_hash.h:175
typename std::conditional< IsConst, typename hopscotch_hash::const_iterator_overflow, typename hopscotch_hash::iterator_overflow >::type iterator_overflow
Definition: hopscotch_hash.h:489
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::const_pointer const value_type * const_pointer
Definition: hopscotch_hash.h:443
Definition: hopscotch_hash.h:102
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::pointer value_type * pointer
Definition: hopscotch_hash.h:442
Definition: hopscotch_hash.h:165
#define tsl_hh_assert(expr)
Definition: hopscotch_hash.h:57
iterator insert(const_iterator hint, const value_type &value)
Definition: hopscotch_hash.h:797
neighborhood_bitmap neighborhood_infos() const noexcept
Definition: hopscotch_hash.h:280
bool compare_keys(const K1 &key1, const K2 &key2) const
Definition: hopscotch_hash.h:1204
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: hopscotch_hash.h:881
static const std::size_t NB_RESERVED_BITS_IN_NEIGHBORHOOD
Definition: hopscotch_hash.h:158
Definition: hopscotch_hash.h:79
const_iterator_overflow find_in_overflow(const K &key) const
Definition: hopscotch_hash.h:1724
iterator find_impl(const K &key, std::size_t my_hash, hopscotch_bucket *bucket_for_hash)
Definition: hopscotch_hash.h:1636
const_iterator cbegin() const noexcept
Definition: hopscotch_hash.h:741
key_equal key_eq() const
Definition: hopscotch_hash.h:1172
bool check_neighbor_presence(std::size_t ineighbor) const noexcept
Definition: hopscotch_hash.h:306
const_iterator find(const K &key, std::size_t my_hash) const
Definition: hopscotch_hash.h:1075
U::value_type & operator[](K &&key)
Definition: hopscotch_hash.h:1038
hopscotch_bucket * find_in_buckets(const K &key, std::size_t my_hash, hopscotch_bucket *bucket_for_hash)
Definition: hopscotch_hash.h:1671
std::uint_least32_t type
Definition: hopscotch_hash.h:127
Definition: hopscotch_hash.h:69
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::buckets_allocator typename std::allocator_traits< allocator_type >::template rebind_alloc< hopscotch_bucket > buckets_allocator
Definition: hopscotch_hash.h:453
hopscotch_bucket() noexcept
Definition: hopscotch_hash.h:226
const U::value_type & at(const K &key, std::size_t my_hash) const
Definition: hopscotch_hash.h:1023
static bool USE_STORED_HASH_ON_REHASH(size_type)
Definition: hopscotch_hash.h:1779
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::iterator hopscotch_iterator< false > iterator
Definition: hopscotch_hash.h:444
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::has_mapped_type typename std::integral_constant< bool, !std::is_same< U, void >::value > has_mapped_type
Definition: hopscotch_hash.h:423
size_type erase(const K &key, std::size_t my_hash)
Definition: hopscotch_hash.h:956
truncated_hash_type m_hash
Definition: hopscotch_hash.h:194
std::forward_iterator_tag iterator_category
Definition: hopscotch_hash.h:499
Definition: hopscotch_growth_policy.h:47
void swap(hopscotch_hash &other)
Definition: hopscotch_hash.h:980
float m_max_load_factor
Definition: hopscotch_hash.h:1824
hopscotch_hash & operator=(hopscotch_hash &&other)
Definition: hopscotch_hash.h:716
std::uint_least8_t type
Definition: hopscotch_hash.h:111
static constexpr float MIN_LOAD_FACTOR_FOR_REHASH
Definition: hopscotch_hash.h:1768
std::uint_least32_t truncated_hash_type
Definition: hopscotch_hash.h:160
ValueType value_type
Definition: hopscotch_hash.h:221
bool empty() const noexcept
Definition: hopscotch_hash.h:767
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::iterator_overflow typename overflow_container_type::iterator iterator_overflow
Definition: hopscotch_hash.h:468
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::neighborhood_bitmap typename hopscotch_bucket::neighborhood_bitmap neighborhood_bitmap
Definition: hopscotch_hash.h:450
size_type count(const K &key) const
Definition: hopscotch_hash.h:1056
iterator erase(const_iterator pos)
Definition: hopscotch_hash.h:923
size_type count(const K &key, std::size_t my_hash) const
Definition: hopscotch_hash.h:1058
void insert(InputIt first, InputIt last)
Definition: hopscotch_hash.h:822
const typename hopscotch_hash::value_type value_type
Definition: hopscotch_hash.h:500
bool swap_empty_bucket_closer(std::size_t &ibucket_empty_in_out)
Definition: hopscotch_hash.h:1546
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition: hopscotch_hash.h:1099
static const std::size_t SMALLEST_TYPE_MAX_BITS_SUPPORTED
Definition: hopscotch_hash.h:101
Definition: hopscotch_hash.h:419
Definition: hopscotch_hash.h:431
iterator try_emplace(const_iterator hint, const key_type &k, Args &&... args)
Definition: hopscotch_hash.h:898
typename std::aligned_storage< sizeof(value_type), alignof(value_type)>::type storage
Definition: hopscotch_hash.h:394
hopscotch_bucket & operator=(const hopscotch_bucket &bucket) noexcept(std::is_nothrow_copy_constructible< value_type >::value)
Definition: hopscotch_hash.h:254
std::vector< char > data
Definition: cth_pressure_map.C:74
void type
Definition: hopscotch_hash.h:66
std::pair< iterator, bool > insert_impl(P &&value)
Definition: hopscotch_hash.h:1394
std::pair< iterator, bool > insert(P &&value)
Definition: hopscotch_hash.h:790
const_iterator cend() const noexcept
Definition: hopscotch_hash.h:758
iterator_overflow erase_from_overflow(const_iterator_overflow pos, std::size_t ibucket_for_hash)
Definition: hopscotch_hash.h:1328
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::buckets_container_type std::vector< hopscotch_bucket, buckets_allocator > buckets_container_type
Definition: hopscotch_hash.h:454
size_type max_bucket_count() const
Definition: hopscotch_hash.h:1128
void remove_value() noexcept
Definition: hopscotch_hash.h:353
void swap_value_into_empty_bucket(hopscotch_bucket &empty_bucket)
Definition: hopscotch_hash.h:339
U::value_type & at(const K &key)
Definition: hopscotch_hash.h:1001
void toggle_neighbor_presence(std::size_t ineighbor) noexcept
Definition: hopscotch_hash.h:299
std::pair< iterator, iterator > equal_range(const K &key, std::size_t my_hash)
Definition: hopscotch_hash.h:1093
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:1684
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:1409
neighborhood_bitmap m_neighborhood_infos
Definition: hopscotch_hash.h:396
const_iterator find(const K &key) const
Definition: hopscotch_hash.h:1070
friend bool operator!=(const hopscotch_iterator &lhs, const hopscotch_iterator &rhs)
Definition: hopscotch_hash.h:589
hopscotch_iterator & operator++()
Definition: hopscotch_hash.h:561
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:1499
void destroy_value() noexcept
Definition: hopscotch_hash.h:387
hopscotch_bucket * m_buckets
Definition: hopscotch_hash.h:1820
value_type & value() noexcept
Definition: hopscotch_hash.h:316
iterator_overflow m_overflow_iterator
Definition: hopscotch_hash.h:597
void set_value_of_empty_bucket(truncated_hash_type my_hash, Args &&... value_type_args)
Definition: hopscotch_hash.h:329
reference operator*() const
Definition: hopscotch_hash.h:543
void rehash_impl(size_type count_)
Definition: hopscotch_hash.h:1220
std::pair< iterator, bool > insert_or_assign(key_type &&k, M &&obj)
Definition: hopscotch_hash.h:847
size_type m_min_load_threshold_rehash
Definition: hopscotch_hash.h:1836
size_type bucket_count() const
Definition: hopscotch_hash.h:1114
const_iterator end() const noexcept
Definition: hopscotch_hash.h:756
iterator mutable_iterator(const_iterator pos)
Definition: hopscotch_hash.h:1177
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< const Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::const_iterator_buckets typename buckets_container_type::const_iterator const_iterator_buckets
Definition: hopscotch_hash.h:466
void max_load_factor(float ml)
Definition: hopscotch_hash.h:1149
std::uint_least16_t type
Definition: hopscotch_hash.h:119
const_iterator find_impl(const K &key, std::size_t my_hash, const hopscotch_bucket *bucket_for_hash) const
Definition: hopscotch_hash.h:1653
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:673
static const std::size_t MIN_NEIGHBORHOOD_SIZE
Definition: hopscotch_hash.h:201
U::value_type * find_value_impl(const K &key, std::size_t my_hash, hopscotch_bucket *bucket_for_hash)
Definition: hopscotch_hash.h:1585
void set_hash(truncated_hash_type my_hash) noexcept
Definition: hopscotch_hash.h:191
static constexpr float DEFAULT_MAX_LOAD_FACTOR
Definition: hopscotch_hash.h:1764
truncated_hash_type truncated_bucket_hash() const noexcept
Definition: hopscotch_hash.h:170
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:1601
iterator insert(const_iterator hint, P &&value)
Definition: hopscotch_hash.h:808
value_type & reference
Definition: hopscotch_hash.h:502