24 #ifndef TSL_HOPSCOTCH_SET_H 25 #define TSL_HOPSCOTCH_SET_H 31 #include <initializer_list> 34 #include <type_traits> 72 class Hash = std::hash<Key>,
73 class KeyEqual = std::equal_to<Key>,
74 class Allocator = std::allocator<Key>,
75 unsigned int NeighborhoodSize = 62,
76 bool StoreHash =
false,
87 const key_type& operator()(
const Key& key)
const {
91 key_type& operator()(Key& key) {
97 using overflow_container_type = std::list<Key, Allocator>;
100 Allocator, NeighborhoodSize,
101 StoreHash, GrowthPolicy,
102 overflow_container_type>;
105 using key_type =
typename ht::key_type;
106 using value_type =
typename ht::value_type;
107 using size_type =
typename ht::size_type;
108 using difference_type =
typename ht::difference_type;
109 using hasher =
typename ht::hasher;
110 using key_equal =
typename ht::key_equal;
111 using allocator_type =
typename ht::allocator_type;
112 using reference =
typename ht::reference;
113 using const_reference =
typename ht::const_reference;
114 using pointer =
typename ht::pointer;
115 using const_pointer =
typename ht::const_pointer;
116 using iterator =
typename ht::iterator;
117 using const_iterator =
typename ht::const_iterator;
127 const Hash& hash = Hash(),
128 const KeyEqual& equal = KeyEqual(),
129 const Allocator& alloc = Allocator()) :
130 m_ht(bucket_count, hash, equal, alloc, ht::DEFAULT_MAX_LOAD_FACTOR)
135 const Allocator& alloc) :
hopscotch_set(bucket_count, Hash(), KeyEqual(), alloc)
141 const Allocator& alloc) :
hopscotch_set(bucket_count, hash, KeyEqual(), alloc)
148 template<
class InputIt>
150 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
151 const Hash& hash = Hash(),
152 const KeyEqual& equal = KeyEqual(),
153 const Allocator& alloc = Allocator()) :
hopscotch_set(bucket_count, hash, equal, alloc)
158 template<
class InputIt>
160 size_type bucket_count,
161 const Allocator& alloc) :
hopscotch_set(first, last, bucket_count, Hash(), KeyEqual(), alloc)
165 template<
class InputIt>
167 size_type bucket_count,
169 const Allocator& alloc) :
hopscotch_set(first, last, bucket_count, hash, KeyEqual(), alloc)
174 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
175 const Hash& hash = Hash(),
176 const KeyEqual& equal = KeyEqual(),
177 const Allocator& alloc = Allocator()) :
178 hopscotch_set(init.begin(), init.end(), bucket_count, hash, equal, alloc)
183 size_type bucket_count,
184 const Allocator& alloc) :
185 hopscotch_set(init.begin(), init.end(), bucket_count, Hash(), KeyEqual(), alloc)
190 size_type bucket_count,
192 const Allocator& alloc) :
193 hopscotch_set(init.begin(), init.end(), bucket_count, hash, KeyEqual(), alloc)
201 m_ht.reserve(ilist.size());
202 m_ht.insert(ilist.begin(), ilist.end());
213 iterator
begin()
noexcept {
return m_ht.begin(); }
214 const_iterator
begin()
const noexcept {
return m_ht.begin(); }
215 const_iterator
cbegin()
const noexcept {
return m_ht.cbegin(); }
217 iterator
end()
noexcept {
return m_ht.end(); }
218 const_iterator
end()
const noexcept {
return m_ht.end(); }
219 const_iterator
cend()
const noexcept {
return m_ht.cend(); }
225 bool empty()
const noexcept {
return m_ht.empty(); }
226 size_type
size()
const noexcept {
return m_ht.size(); }
227 size_type
max_size()
const noexcept {
return m_ht.max_size(); }
232 void clear()
noexcept { m_ht.clear(); }
237 std::pair<iterator,
bool>
insert(
const value_type& value) {
return m_ht.insert(value); }
238 std::pair<iterator,
bool>
insert(value_type&& value) {
return m_ht.insert(std::move(value)); }
240 iterator
insert(const_iterator hint,
const value_type& value) {
return m_ht.insert(hint, value); }
241 iterator
insert(const_iterator hint, value_type&& value) {
return m_ht.insert(hint, std::move(value)); }
243 template<
class InputIt>
244 void insert(InputIt first, InputIt last) { m_ht.insert(first, last); }
245 void insert(std::initializer_list<value_type> ilist) { m_ht.insert(ilist.begin(), ilist.end()); }
256 template<
class... Args>
257 std::pair<iterator,
bool>
emplace(Args&&... args) {
return m_ht.emplace(std::forward<Args>(args)...); }
268 template<
class... Args>
270 return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
276 iterator
erase(iterator pos) {
return m_ht.erase(pos); }
277 iterator
erase(const_iterator pos) {
return m_ht.erase(pos); }
278 iterator
erase(const_iterator first, const_iterator last) {
return m_ht.erase(first, last); }
279 size_type
erase(
const key_type& key) {
return m_ht.erase(key); }
285 size_type
erase(
const key_type& key, std::size_t precalculated_hash) {
286 return m_ht.erase(key, precalculated_hash);
293 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
294 size_type
erase(
const K& key) {
return m_ht.erase(key); }
302 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
303 size_type
erase(
const K& key, std::size_t precalculated_hash) {
304 return m_ht.erase(key, precalculated_hash);
316 size_type
count(
const Key& key)
const {
return m_ht.count(key); }
322 size_type
count(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
328 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
329 size_type
count(
const K& key)
const {
return m_ht.count(key); }
337 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
338 size_type
count(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
343 iterator
find(
const Key& key) {
return m_ht.find(key); }
349 iterator
find(
const Key& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
351 const_iterator
find(
const Key& key)
const {
return m_ht.find(key); }
356 const_iterator
find(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
362 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
363 iterator
find(
const K& key) {
return m_ht.find(key); }
371 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
372 iterator
find(
const K& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
377 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
378 const_iterator
find(
const K& key)
const {
return m_ht.find(key); }
386 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
387 const_iterator
find(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
392 std::pair<iterator, iterator>
equal_range(
const Key& key) {
return m_ht.equal_range(key); }
398 std::pair<iterator, iterator>
equal_range(
const Key& key, std::size_t precalculated_hash) {
399 return m_ht.equal_range(key, precalculated_hash);
402 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key)
const {
return m_ht.equal_range(key); }
407 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key, std::size_t precalculated_hash)
const {
408 return m_ht.equal_range(key, precalculated_hash);
415 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
416 std::pair<iterator, iterator>
equal_range(
const K& key) {
return m_ht.equal_range(key); }
424 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
425 std::pair<iterator, iterator>
equal_range(
const K& key, std::size_t precalculated_hash) {
426 return m_ht.equal_range(key, precalculated_hash);
432 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
433 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
return m_ht.equal_range(key); }
438 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
439 std::pair<const_iterator, const_iterator>
equal_range(
const K& key, std::size_t precalculated_hash)
const {
440 return m_ht.equal_range(key, precalculated_hash);
460 void rehash(size_type count_) { m_ht.rehash(count_); }
461 void reserve(size_type count_) { m_ht.reserve(count_); }
468 key_equal
key_eq()
const {
return m_ht.key_eq(); }
479 return m_ht.mutable_iterator(pos);
485 if(lhs.size() != rhs.size()) {
489 for(
const auto& element_lhs : lhs) {
490 const auto it_element_rhs = rhs.find(element_lhs);
491 if(it_element_rhs == rhs.cend()) {
500 return !operator==(lhs, rhs);
516 class Hash = std::hash<Key>,
517 class KeyEqual = std::equal_to<Key>,
518 class Allocator = std::allocator<Key>,
519 unsigned int NeighborhoodSize = 62,
520 bool StoreHash =
false>
hopscotch_set(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
Definition: hopscotch_set.h:182
key_equal key_eq() const
Definition: hopscotch_set.h:468
iterator insert(const_iterator hint, value_type &&value)
Definition: hopscotch_set.h:241
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: hopscotch_set.h:392
std::pair< iterator, bool > insert(value_type &&value)
Definition: hopscotch_set.h:238
iterator erase(iterator pos)
Definition: hopscotch_set.h:276
hopscotch_set(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_set.h:149
hopscotch_set(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_set.h:173
const_iterator find(const K &key, std::size_t precalculated_hash) const
Definition: hopscotch_set.h:387
hopscotch_set & operator=(std::initializer_list< value_type > ilist)
Definition: hopscotch_set.h:198
std::pair< iterator, bool > insert(const value_type &value)
Definition: hopscotch_set.h:237
Definition: hopscotch_hash.h:69
iterator begin() noexcept
Definition: hopscotch_set.h:213
Definition: bhopscotch_map.h:39
const_iterator end() const noexcept
Definition: hopscotch_set.h:218
const_iterator begin() const noexcept
Definition: hopscotch_set.h:214
hopscotch_set(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: hopscotch_set.h:126
void reserve(size_type count_)
Definition: hopscotch_set.h:461
iterator end() noexcept
Definition: hopscotch_set.h:217
size_type erase(const K &key, std::size_t precalculated_hash)
Definition: hopscotch_set.h:303
iterator insert(const_iterator hint, const value_type &value)
Definition: hopscotch_set.h:240
friend bool operator!=(const hopscotch_set &lhs, const hopscotch_set &rhs)
Definition: hopscotch_set.h:499
bool empty() const noexcept
Definition: hopscotch_set.h:225
iterator find(const K &key, std::size_t precalculated_hash)
Definition: hopscotch_set.h:372
iterator find(const K &key)
Definition: hopscotch_set.h:363
void rehash(size_type count_)
Definition: hopscotch_set.h:460
std::pair< iterator, iterator > equal_range(const K &key)
Definition: hopscotch_set.h:416
hopscotch_set(size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: hopscotch_set.h:139
hasher hash_function() const
Definition: hopscotch_set.h:467
void swap(hopscotch_set &other)
Definition: hopscotch_set.h:310
hopscotch_set(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: hopscotch_set.h:166
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
Definition: hopscotch_set.h:439
size_type size() const noexcept
Definition: hopscotch_set.h:226
std::pair< iterator, bool > emplace(Args &&... args)
Definition: hopscotch_set.h:257
friend bool operator==(const hopscotch_set &lhs, const hopscotch_set &rhs)
Definition: hopscotch_set.h:484
float load_factor() const
Definition: hopscotch_set.h:456
size_type count(const K &key) const
Definition: hopscotch_set.h:329
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition: hopscotch_set.h:433
hopscotch_set(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: hopscotch_set.h:189
size_type count(const Key &key, std::size_t precalculated_hash) const
Definition: hopscotch_set.h:322
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
Definition: hopscotch_set.h:407
size_type bucket_count() const
Definition: hopscotch_set.h:449
hopscotch_set(const Allocator &alloc)
Definition: hopscotch_set.h:145
const_iterator find(const Key &key) const
Definition: hopscotch_set.h:351
size_type erase(const key_type &key, std::size_t precalculated_hash)
Definition: hopscotch_set.h:285
friend void swap(hopscotch_set &lhs, hopscotch_set &rhs)
Definition: hopscotch_set.h:503
hopscotch_set(size_type bucket_count, const Allocator &alloc)
Definition: hopscotch_set.h:134
const_iterator find(const Key &key, std::size_t precalculated_hash) const
Definition: hopscotch_set.h:356
void insert(InputIt first, InputIt last)
Definition: hopscotch_set.h:244
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
Definition: hopscotch_set.h:425
Definition: hopscotch_growth_policy.h:49
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition: hopscotch_set.h:402
iterator mutable_iterator(const_iterator pos)
Definition: hopscotch_set.h:478
hopscotch_set()
Definition: hopscotch_set.h:123
hopscotch_set(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
Definition: hopscotch_set.h:159
Definition: hopscotch_growth_policy.h:247
size_type erase(const key_type &key)
Definition: hopscotch_set.h:279
size_type erase(const K &key)
Definition: hopscotch_set.h:294
size_type count(const K &key, std::size_t precalculated_hash) const
Definition: hopscotch_set.h:338
size_type max_bucket_count() const
Definition: hopscotch_set.h:450
void clear() noexcept
Definition: hopscotch_set.h:232
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: hopscotch_set.h:269
iterator erase(const_iterator first, const_iterator last)
Definition: hopscotch_set.h:278
const_iterator cbegin() const noexcept
Definition: hopscotch_set.h:215
Definition: hopscotch_set.h:78
float max_load_factor() const
Definition: hopscotch_set.h:457
iterator erase(const_iterator pos)
Definition: hopscotch_set.h:277
size_type max_size() const noexcept
Definition: hopscotch_set.h:227
iterator find(const Key &key, std::size_t precalculated_hash)
Definition: hopscotch_set.h:349
size_type overflow_size() const noexcept
Definition: hopscotch_set.h:482
iterator find(const Key &key)
Definition: hopscotch_set.h:343
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
Definition: hopscotch_set.h:398
const_iterator cend() const noexcept
Definition: hopscotch_set.h:219
void max_load_factor(float ml)
Definition: hopscotch_set.h:458
size_type count(const Key &key) const
Definition: hopscotch_set.h:316
void insert(std::initializer_list< value_type > ilist)
Definition: hopscotch_set.h:245
Definition: hopscotch_growth_policy.h:40
const_iterator find(const K &key) const
Definition: hopscotch_set.h:378
allocator_type get_allocator() const
Definition: hopscotch_set.h:207