24 #ifndef TSL_HOPSCOTCH_MAP_H 25 #define TSL_HOPSCOTCH_MAP_H 31 #include <initializer_list> 34 #include <type_traits> 70 template <
class Key,
class T,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
71 class Allocator = std::allocator<std::pair<Key, T>>,
unsigned int NeighborhoodSize = 62,
72 bool StoreHash = false,
class GrowthPolicy = tsl::hh::power_of_two_growth_policy<2>>
86 return key_value.first;
99 return key_value.second;
108 KeyEqual, Allocator, NeighborhoodSize, StoreHash,
133 const KeyEqual &equal = KeyEqual(),
const Allocator &alloc = Allocator())
153 template <
class InputIt>
156 const KeyEqual &equal = KeyEqual(),
const Allocator &alloc = Allocator())
162 template <
class InputIt>
168 template <
class InputIt>
170 const Allocator &alloc)
177 const KeyEqual &equal = KeyEqual(),
const Allocator &alloc = Allocator())
183 const Allocator &alloc)
189 const Allocator &alloc)
231 template <class P, typename std::enable_if<std::is_constructible<value_type, P &&>::value>::type
233 std::pair<iterator, bool>
insert(P &&value)
245 template <class P, typename std::enable_if<std::is_constructible<value_type, P &&>::value>::type
249 return m_ht.
insert(hint, std::forward<P>(value));
257 template <
class InputIt>
void insert(InputIt first, InputIt last) {
m_ht.
insert(first, last); }
259 void insert(std::initializer_list<value_type> ilist)
290 template <
class... Args> std::pair<iterator, bool>
emplace(Args &&... args)
306 template <
class... Args>
317 template <
class... Args>
323 template <
class... Args>
326 return m_ht.
try_emplace(hint, std::move(k), std::forward<Args>(args)...);
341 return m_ht.
erase(key, precalculated_hash);
348 template <
class K,
class KE = KeyEqual,
349 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
362 template <
class K,
class KE = KeyEqual,
363 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
366 return m_ht.
erase(key, precalculated_hash);
381 T &
at(
const Key &key, std::size_t precalculated_hash)
383 return m_ht.
at(key, precalculated_hash);
386 const T &
at(
const Key &key)
const {
return m_ht.
at(key); }
391 const T &
at(
const Key &key, std::size_t precalculated_hash)
const 393 return m_ht.
at(key, precalculated_hash);
400 template <
class K,
class KE = KeyEqual,
401 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
414 template <
class K,
class KE = KeyEqual,
415 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
416 T &
at(
const K &key, std::size_t precalculated_hash)
418 return m_ht.
at(key, precalculated_hash);
424 template <
class K,
class KE = KeyEqual,
425 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
426 const T &
at(
const K &key)
const 434 template <
class K,
class KE = KeyEqual,
435 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
436 const T &
at(
const K &key, std::size_t precalculated_hash)
const 438 return m_ht.
at(key, precalculated_hash);
453 return m_ht.
count(key, precalculated_hash);
460 template <
class K,
class KE = KeyEqual,
461 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
474 template <
class K,
class KE = KeyEqual,
475 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
478 return m_ht.
count(key, precalculated_hash);
490 return m_ht.
find(key, precalculated_hash);
500 return m_ht.
find(key, precalculated_hash);
507 template <
class K,
class KE = KeyEqual,
508 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
521 template <
class K,
class KE = KeyEqual,
522 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
525 return m_ht.
find(key, precalculated_hash);
531 template <
class K,
class KE = KeyEqual,
532 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
545 template <
class K,
class KE = KeyEqual,
546 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
549 return m_ht.
find(key, precalculated_hash);
559 std::pair<iterator, iterator>
equal_range(
const Key &key, std::size_t precalculated_hash)
564 std::pair<const_iterator, const_iterator>
equal_range(
const Key &key)
const 572 std::pair<const_iterator, const_iterator>
equal_range(
const Key & key,
573 std::size_t precalculated_hash)
const 582 template <
class K,
class KE = KeyEqual,
583 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
596 template <
class K,
class KE = KeyEqual,
597 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
598 std::pair<iterator, iterator>
equal_range(
const K &key, std::size_t precalculated_hash)
606 template <
class K,
class KE = KeyEqual,
607 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
608 std::pair<const_iterator, const_iterator>
equal_range(
const K &key)
const 616 template <
class K,
class KE = KeyEqual,
617 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
618 std::pair<const_iterator, const_iterator>
equal_range(
const K & key,
619 std::size_t precalculated_hash)
const 663 for (
const auto &element_lhs : lhs) {
664 const auto it_element_rhs = rhs.
find(element_lhs.first);
665 if (it_element_rhs == rhs.
cend() || element_lhs.second != it_element_rhs->second) {
688 template <
class Key,
class T,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
689 class Allocator = std::allocator<std::pair<Key, T>>,
unsigned int NeighborhoodSize = 62,
690 bool StoreHash = false>
Definition: hopscotch_hash.h:69
void insert(InputIt first, InputIt last)
Definition: hopscotch_map.h:257
hopscotch_map(size_type bucket_count, const Allocator &alloc)
Definition: hopscotch_map.h:138
iterator mutable_iterator(const_iterator pos)
Definition: hopscotch_map.h:653
void reserve(size_type count_)
Definition: hopscotch_hash.h:1162
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::size_type std::size_t size_type
Definition: hopscotch_hash.h:445
iterator find(const K &key)
Definition: hopscotch_hash.h:1071
size_type bucket_count() const
Definition: hopscotch_hash.h:1114
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::const_reference const value_type & const_reference
Definition: hopscotch_hash.h:451
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::allocator_type Allocator allocator_type
Definition: hopscotch_hash.h:449
hopscotch_map()
Definition: hopscotch_map.h:130
const_iterator cend() const noexcept
Definition: hopscotch_map.h:215
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::difference_type std::ptrdiff_t difference_type
Definition: hopscotch_hash.h:446
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >
size_type max_size() const noexcept
Definition: hopscotch_map.h:222
const_iterator cbegin() const noexcept
Definition: hopscotch_hash.h:749
friend bool operator!=(const hopscotch_map &lhs, const hopscotch_map &rhs)
Definition: hopscotch_map.h:673
size_type overflow_size() const noexcept
Definition: hopscotch_map.h:655
const_iterator cbegin() const noexcept
Definition: hopscotch_map.h:211
T & operator[](Key &&key)
Definition: hopscotch_map.h:442
std::list< std::pair< Key, T >, Allocator > overflow_container_type
Definition: hopscotch_map.h:105
std::pair< iterator, bool > insert(const value_type &value)
Definition: hopscotch_hash.h:793
T value_type
Definition: hopscotch_map.h:95
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::DEFAULT_INIT_BUCKETS_SIZE static const size_type DEFAULT_INIT_BUCKETS_SIZE
Definition: hopscotch_hash.h:1755
iterator end() noexcept
Definition: hopscotch_hash.h:759
hopscotch_map(const Allocator &alloc)
Definition: hopscotch_map.h:148
std::pair< iterator, bool > insert(const value_type &value)
Definition: hopscotch_map.h:229
const T & at(const Key &key) const
Definition: hopscotch_map.h:386
Definition: hopscotch_growth_policy.h:37
hopscotch_map(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: hopscotch_map.h:132
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::value_type std::pair< Key, T > value_type
Definition: hopscotch_hash.h:444
typename ht::value_type value_type
Definition: hopscotch_map.h:114
key_equal key_eq() const
Definition: hopscotch_map.h:644
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
Definition: hopscotch_hash.h:849
float load_factor() const
Definition: hopscotch_map.h:633
hopscotch_map(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: hopscotch_map.h:169
iterator begin() noexcept
Definition: hopscotch_hash.h:737
typename ht::reference reference
Definition: hopscotch_map.h:120
hasher hash_function() const
Definition: hopscotch_hash.h:1170
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition: hopscotch_map.h:564
iterator insert(const_iterator hint, value_type &&value)
Definition: hopscotch_map.h:252
float max_load_factor() const
Definition: hopscotch_hash.h:1147
T mapped_type
Definition: hopscotch_map.h:113
typename ht::pointer pointer
Definition: hopscotch_map.h:122
void clear() noexcept
Definition: hopscotch_map.h:227
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&... args)
Definition: hopscotch_hash.h:894
typename ht::const_reference const_reference
Definition: hopscotch_map.h:121
iterator insert(const_iterator hint, P &&value)
Definition: hopscotch_map.h:247
const_iterator find(const K &key) const
Definition: hopscotch_map.h:533
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
Definition: hopscotch_map.h:559
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::hasher Hash hasher
Definition: hopscotch_hash.h:447
iterator mutable_iterator(const_iterator pos)
Definition: hopscotch_hash.h:1177
Key key_type
Definition: hopscotch_map.h:82
bool empty() const noexcept
Definition: hopscotch_hash.h:774
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: hopscotch_hash.h:888
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::const_iterator hopscotch_iterator< true > const_iterator
Definition: hopscotch_hash.h:455
iterator insert(const_iterator hint, const value_type &value)
Definition: hopscotch_map.h:240
size_type erase(const key_type &key)
Definition: hopscotch_map.h:332
ht m_ht
Definition: hopscotch_map.h:681
iterator insert_or_assign(const_iterator hint, key_type &&k, M &&obj)
Definition: hopscotch_map.h:279
size_type size() const noexcept
Definition: hopscotch_hash.h:776
void max_load_factor(float ml)
Definition: hopscotch_map.h:635
allocator_type get_allocator() const
Definition: hopscotch_map.h:204
size_type bucket_count() const
Definition: hopscotch_map.h:627
std::pair< iterator, iterator > equal_range(const K &key)
Definition: hopscotch_hash.h:1088
typename ht::size_type size_type
Definition: hopscotch_map.h:115
iterator insert_or_assign(const_iterator hint, const key_type &k, M &&obj)
Definition: hopscotch_map.h:274
size_type size() const noexcept
Definition: hopscotch_map.h:221
const key_type & operator()(const std::pair< Key, T > &key_value) const
Definition: hopscotch_map.h:84
hopscotch_map(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
Definition: hopscotch_map.h:182
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< 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:443
iterator erase(const_iterator first, const_iterator last)
Definition: hopscotch_map.h:331
size_type count(const K &key, std::size_t precalculated_hash) const
Definition: hopscotch_map.h:476
size_type max_bucket_count() const
Definition: hopscotch_map.h:628
hasher hash_function() const
Definition: hopscotch_map.h:643
friend bool operator==(const hopscotch_map &lhs, const hopscotch_map &rhs)
Definition: hopscotch_map.h:657
typename ht::difference_type difference_type
Definition: hopscotch_map.h:116
hopscotch_map(InputIt first, InputIt last, size_type bucket_count=ht::DEFAULT_INIT_BUCKETS_SIZE, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: hopscotch_map.h:154
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
Definition: hopscotch_map.h:618
U::value_type & at(const K &key)
Definition: hopscotch_hash.h:1008
Definition: hopscotch_map.h:79
std::pair< iterator, bool > emplace(Args &&... args)
Definition: hopscotch_hash.h:883
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: hopscotch_map.h:552
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::key_equal KeyEqual key_equal
Definition: hopscotch_hash.h:448
T & at(const Key &key)
Definition: hopscotch_map.h:374
void swap(hopscotch_hash &other)
Definition: hopscotch_hash.h:987
typename ht::key_equal key_equal
Definition: hopscotch_map.h:118
size_type count(const Key &key) const
Definition: hopscotch_map.h:444
iterator find(const Key &key)
Definition: hopscotch_map.h:481
const_iterator find(const Key &key) const
Definition: hopscotch_map.h:493
std::pair< iterator, iterator > equal_range(const K &key)
Definition: hopscotch_map.h:584
iterator end() noexcept
Definition: hopscotch_map.h:213
const_iterator find(const K &key, std::size_t precalculated_hash) const
Definition: hopscotch_map.h:547
std::pair< iterator, bool > insert(P &&value)
Definition: hopscotch_map.h:233
size_type erase(const K &key)
Definition: hopscotch_map.h:350
Definition: hopscotch_map.h:92
T & at(const K &key, std::size_t precalculated_hash)
Definition: hopscotch_map.h:416
iterator find(const Key &key, std::size_t precalculated_hash)
Definition: hopscotch_map.h:488
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::iterator hopscotch_iterator< false > iterator
Definition: hopscotch_hash.h:454
T & operator[](const Key &key)
Definition: hopscotch_map.h:441
const value_type & operator()(const std::pair< Key, T > &key_value) const
Definition: hopscotch_map.h:97
size_type erase(const K &key, std::size_t precalculated_hash)
Definition: hopscotch_map.h:364
key_equal key_eq() const
Definition: hopscotch_hash.h:1172
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: hopscotch_map.h:301
iterator find(const K &key)
Definition: hopscotch_map.h:509
typename ht::allocator_type allocator_type
Definition: hopscotch_map.h:119
std::pair< iterator, bool > emplace(Args &&... args)
Definition: hopscotch_map.h:290
size_type count(const K &key) const
Definition: hopscotch_map.h:462
size_type max_bucket_count() const
Definition: hopscotch_hash.h:1128
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition: hopscotch_map.h:608
Definition: hopscotch_growth_policy.h:250
void swap(hopscotch_map &other)
Definition: hopscotch_map.h:369
const_iterator find(const Key &key, std::size_t precalculated_hash) const
Definition: hopscotch_map.h:498
hopscotch_map(size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: hopscotch_map.h:143
Definition: hopscotch_map.h:73
size_type count(const K &key) const
Definition: hopscotch_hash.h:1064
std::pair< iterator, bool > try_emplace(key_type &&k, Args &&... args)
Definition: hopscotch_map.h:312
size_type erase(const key_type &key, std::size_t precalculated_hash)
Definition: hopscotch_map.h:339
const T & at(const K &key, std::size_t precalculated_hash) const
Definition: hopscotch_map.h:436
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::reference value_type & reference
Definition: hopscotch_hash.h:450
const T & at(const Key &key, std::size_t precalculated_hash) const
Definition: hopscotch_map.h:391
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
Definition: hopscotch_map.h:598
const_iterator begin() const noexcept
Definition: hopscotch_map.h:210
iterator try_emplace(const_iterator hint, const key_type &k, Args &&... args)
Definition: hopscotch_map.h:318
struct anonymous_namespace{Ioss_SmartAssert.C}::assert_initializer init
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::const_pointer const value_type * const_pointer
Definition: hopscotch_hash.h:453
iterator find(const K &key, std::size_t precalculated_hash)
Definition: hopscotch_map.h:523
typename ht::const_pointer const_pointer
Definition: hopscotch_map.h:123
float max_load_factor() const
Definition: hopscotch_map.h:634
hopscotch_map(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: hopscotch_map.h:188
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
Definition: hopscotch_map.h:264
hopscotch_map(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
Definition: hopscotch_map.h:163
typename ht::hasher hasher
Definition: hopscotch_map.h:117
float load_factor() const
Definition: hopscotch_hash.h:1138
size_type overflow_size() const noexcept
Definition: hopscotch_hash.h:1191
const T & at(const K &key) const
Definition: hopscotch_map.h:426
hopscotch_map(std::initializer_list< value_type > init, size_type bucket_count=ht::DEFAULT_INIT_BUCKETS_SIZE, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: hopscotch_map.h:175
size_type count(const Key &key, std::size_t precalculated_hash) const
Definition: hopscotch_map.h:451
value_type & operator()(std::pair< Key, T > &key_value)
Definition: hopscotch_map.h:102
void rehash(size_type count_)
Definition: hopscotch_hash.h:1156
typename ht::iterator iterator
Definition: hopscotch_map.h:124
void insert(std::initializer_list< value_type > ilist)
Definition: hopscotch_map.h:259
std::pair< iterator, bool > insert(value_type &&value)
Definition: hopscotch_map.h:238
size_type max_size() const noexcept
Definition: hopscotch_hash.h:778
iterator begin() noexcept
Definition: hopscotch_map.h:209
void clear() noexcept
Definition: hopscotch_hash.h:783
const_iterator cend() const noexcept
Definition: hopscotch_hash.h:766
typename ht::key_type key_type
Definition: hopscotch_map.h:112
void rehash(size_type count_)
Definition: hopscotch_map.h:637
iterator try_emplace(const_iterator hint, key_type &&k, Args &&... args)
Definition: hopscotch_map.h:324
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
Definition: hopscotch_map.h:572
const_iterator end() const noexcept
Definition: hopscotch_map.h:214
std::pair< iterator, bool > insert_or_assign(key_type &&k, M &&obj)
Definition: hopscotch_map.h:269
key_type & operator()(std::pair< Key, T > &key_value)
Definition: hopscotch_map.h:89
allocator_type get_allocator() const
Definition: hopscotch_hash.h:732
void reserve(size_type count_)
Definition: hopscotch_map.h:638
bool empty() const noexcept
Definition: hopscotch_map.h:220
T & at(const K &key)
Definition: hopscotch_map.h:402
friend void swap(hopscotch_map &lhs, hopscotch_map &rhs)
Definition: hopscotch_map.h:678
iterator erase(iterator pos)
Definition: hopscotch_hash.h:928
T & at(const Key &key, std::size_t precalculated_hash)
Definition: hopscotch_map.h:381
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&... args)
Definition: hopscotch_map.h:307
iterator erase(const_iterator pos)
Definition: hopscotch_map.h:330
iterator erase(iterator pos)
Definition: hopscotch_map.h:329
typename ht::const_iterator const_iterator
Definition: hopscotch_map.h:125
tsl::detail_hopscotch_hash::hopscotch_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy, overflow_container_type >::pointer value_type * pointer
Definition: hopscotch_hash.h:452
hopscotch_map & operator=(std::initializer_list< value_type > ilist)
Definition: hopscotch_map.h:194