24 #ifndef TSL_BHOPSCOTCH_SET_H 25 #define TSL_BHOPSCOTCH_SET_H 31 #include <initializer_list> 34 #include <type_traits> 57 class Hash = std::hash<Key>,
58 class KeyEqual = std::equal_to<Key>,
59 class Compare = std::less<Key>,
60 class Allocator = std::allocator<Key>,
61 unsigned int NeighborhoodSize = 62,
62 bool StoreHash =
false,
73 const key_type& operator()(
const Key& key)
const {
77 key_type& operator()(Key& key) {
83 using overflow_container_type = std::set<Key, Compare, Allocator>;
86 Allocator, NeighborhoodSize,
87 StoreHash, GrowthPolicy,
88 overflow_container_type>;
91 using key_type =
typename ht::key_type;
92 using value_type =
typename ht::value_type;
93 using size_type =
typename ht::size_type;
94 using difference_type =
typename ht::difference_type;
95 using hasher =
typename ht::hasher;
96 using key_equal =
typename ht::key_equal;
97 using key_compare = Compare;
98 using allocator_type =
typename ht::allocator_type;
99 using reference =
typename ht::reference;
100 using const_reference =
typename ht::const_reference;
101 using pointer =
typename ht::pointer;
102 using const_pointer =
typename ht::const_pointer;
103 using iterator =
typename ht::iterator;
104 using const_iterator =
typename ht::const_iterator;
114 const Hash& hash = Hash(),
115 const KeyEqual& equal = KeyEqual(),
116 const Allocator& alloc = Allocator(),
117 const Compare& comp = Compare()) :
118 m_ht(bucket_count, hash, equal, alloc, ht::DEFAULT_MAX_LOAD_FACTOR, comp)
123 const Allocator& alloc) :
bhopscotch_set(bucket_count, Hash(), KeyEqual(), alloc)
129 const Allocator& alloc) :
bhopscotch_set(bucket_count, hash, KeyEqual(), alloc)
136 template<
class InputIt>
138 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
139 const Hash& hash = Hash(),
140 const KeyEqual& equal = KeyEqual(),
141 const Allocator& alloc = Allocator()) :
bhopscotch_set(bucket_count, hash, equal, alloc)
146 template<
class InputIt>
148 size_type bucket_count,
149 const Allocator& alloc) :
bhopscotch_set(first, last, bucket_count, Hash(), KeyEqual(), alloc)
153 template<
class InputIt>
155 size_type bucket_count,
157 const Allocator& alloc) :
bhopscotch_set(first, last, bucket_count, hash, KeyEqual(), alloc)
162 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
163 const Hash& hash = Hash(),
164 const KeyEqual& equal = KeyEqual(),
165 const Allocator& alloc = Allocator()) :
166 bhopscotch_set(init.begin(), init.end(), bucket_count, hash, equal, alloc)
171 size_type bucket_count,
172 const Allocator& alloc) :
173 bhopscotch_set(init.begin(), init.end(), bucket_count, Hash(), KeyEqual(), alloc)
178 size_type bucket_count,
180 const Allocator& alloc) :
181 bhopscotch_set(init.begin(), init.end(), bucket_count, hash, KeyEqual(), alloc)
189 m_ht.reserve(ilist.size());
190 m_ht.insert(ilist.begin(), ilist.end());
201 iterator
begin()
noexcept {
return m_ht.begin(); }
202 const_iterator
begin()
const noexcept {
return m_ht.begin(); }
203 const_iterator
cbegin()
const noexcept {
return m_ht.cbegin(); }
205 iterator
end()
noexcept {
return m_ht.end(); }
206 const_iterator
end()
const noexcept {
return m_ht.end(); }
207 const_iterator
cend()
const noexcept {
return m_ht.cend(); }
213 bool empty()
const noexcept {
return m_ht.empty(); }
214 size_type
size()
const noexcept {
return m_ht.size(); }
215 size_type
max_size()
const noexcept {
return m_ht.max_size(); }
220 void clear()
noexcept { m_ht.clear(); }
225 std::pair<iterator,
bool>
insert(
const value_type& value) {
return m_ht.insert(value); }
226 std::pair<iterator,
bool>
insert(value_type&& value) {
return m_ht.insert(std::move(value)); }
228 iterator
insert(const_iterator hint,
const value_type& value) {
return m_ht.insert(hint, value); }
229 iterator
insert(const_iterator hint, value_type&& value) {
return m_ht.insert(hint, std::move(value)); }
231 template<
class InputIt>
232 void insert(InputIt first, InputIt last) { m_ht.insert(first, last); }
233 void insert(std::initializer_list<value_type> ilist) { m_ht.insert(ilist.begin(), ilist.end()); }
244 template<
class... Args>
245 std::pair<iterator,
bool>
emplace(Args&&... args) {
return m_ht.emplace(std::forward<Args>(args)...); }
256 template<
class... Args>
258 return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
264 iterator
erase(iterator pos) {
return m_ht.erase(pos); }
265 iterator
erase(const_iterator pos) {
return m_ht.erase(pos); }
266 iterator
erase(const_iterator first, const_iterator last) {
return m_ht.erase(first, last); }
267 size_type
erase(
const key_type& key) {
return m_ht.erase(key); }
273 size_type
erase(
const key_type& key, std::size_t precalculated_hash) {
274 return m_ht.erase(key, precalculated_hash);
282 template<
class K,
class KE = KeyEqual,
class CP = Compare,
283 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
284 size_type
erase(
const K& key) {
return m_ht.erase(key); }
292 template<
class K,
class KE = KeyEqual,
class CP = Compare,
293 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
294 size_type
erase(
const K& key, std::size_t precalculated_hash) {
return m_ht.erase(key, precalculated_hash); }
305 size_type
count(
const Key& key)
const {
return m_ht.count(key); }
311 size_type
count(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
318 template<
class K,
class KE = KeyEqual,
class CP = Compare,
319 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
320 size_type
count(
const K& key)
const {
return m_ht.count(key); }
328 template<
class K,
class KE = KeyEqual,
class CP = Compare,
329 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
330 size_type
count(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
335 iterator
find(
const Key& key) {
return m_ht.find(key); }
341 iterator
find(
const Key& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
343 const_iterator
find(
const Key& key)
const {
return m_ht.find(key); }
348 const_iterator
find(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
355 template<
class K,
class KE = KeyEqual,
class CP = Compare,
356 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
357 iterator
find(
const K& key) {
return m_ht.find(key); }
365 template<
class K,
class KE = KeyEqual,
class CP = Compare,
366 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
367 iterator
find(
const K& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
372 template<
class K,
class KE = KeyEqual,
class CP = Compare,
373 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
374 const_iterator
find(
const K& key)
const {
return m_ht.find(key); }
382 template<
class K,
class KE = KeyEqual,
class CP = Compare,
383 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
384 const_iterator
find(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
389 std::pair<iterator, iterator>
equal_range(
const Key& key) {
return m_ht.equal_range(key); }
395 std::pair<iterator, iterator>
equal_range(
const Key& key, std::size_t precalculated_hash) {
396 return m_ht.equal_range(key, precalculated_hash);
399 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key)
const {
return m_ht.equal_range(key); }
404 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key, std::size_t precalculated_hash)
const {
405 return m_ht.equal_range(key, precalculated_hash);
413 template<
class K,
class KE = KeyEqual,
class CP = Compare,
414 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
415 std::pair<iterator, iterator>
equal_range(
const K& key) {
return m_ht.equal_range(key); }
423 template<
class K,
class KE = KeyEqual,
class CP = Compare,
424 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::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,
class CP = Compare,
433 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
434 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
return m_ht.equal_range(key); }
439 template<
class K,
class KE = KeyEqual,
class CP = Compare,
440 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
441 std::pair<const_iterator, const_iterator>
equal_range(
const K& key, std::size_t precalculated_hash)
const {
442 return m_ht.equal_range(key, precalculated_hash);
462 void rehash(size_type count_) { m_ht.rehash(count_); }
463 void reserve(size_type count_) { m_ht.reserve(count_); }
470 key_equal
key_eq()
const {
return m_ht.key_eq(); }
471 key_compare
key_comp()
const {
return m_ht.key_comp(); }
482 return m_ht.mutable_iterator(pos);
488 if(lhs.size() != rhs.size()) {
492 for(
const auto& element_lhs : lhs) {
493 const auto it_element_rhs = rhs.find(element_lhs);
494 if(it_element_rhs == rhs.cend()) {
503 return !operator==(lhs, rhs);
519 class Hash = std::hash<Key>,
520 class KeyEqual = std::equal_to<Key>,
521 class Compare = std::less<Key>,
522 class Allocator = std::allocator<Key>,
523 unsigned int NeighborhoodSize = 62,
524 bool StoreHash =
false>
void swap(bhopscotch_set &other)
Definition: bhopscotch_set.h:299
bhopscotch_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: bhopscotch_set.h:137
void max_load_factor(float ml)
Definition: bhopscotch_set.h:460
bhopscotch_set()
Definition: bhopscotch_set.h:110
bhopscotch_set(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator(), const Compare &comp=Compare())
Definition: bhopscotch_set.h:113
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: bhopscotch_set.h:257
size_type overflow_size() const noexcept
Definition: bhopscotch_set.h:485
std::pair< iterator, bool > insert(const value_type &value)
Definition: bhopscotch_set.h:225
Definition: hopscotch_hash.h:69
bhopscotch_set(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
Definition: bhopscotch_set.h:147
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
Definition: bhopscotch_set.h:395
void rehash(size_type count_)
Definition: bhopscotch_set.h:462
Definition: bhopscotch_map.h:39
float load_factor() const
Definition: bhopscotch_set.h:458
iterator find(const Key &key)
Definition: bhopscotch_set.h:335
bool empty() const noexcept
Definition: bhopscotch_set.h:213
bhopscotch_set(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: bhopscotch_set.h:154
size_type erase(const key_type &key)
Definition: bhopscotch_set.h:267
iterator begin() noexcept
Definition: bhopscotch_set.h:201
void clear() noexcept
Definition: bhopscotch_set.h:220
bhopscotch_set(size_type bucket_count, const Allocator &alloc)
Definition: bhopscotch_set.h:122
const_iterator cend() const noexcept
Definition: bhopscotch_set.h:207
std::pair< iterator, bool > insert(value_type &&value)
Definition: bhopscotch_set.h:226
size_type erase(const K &key)
Definition: bhopscotch_set.h:284
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: bhopscotch_set.h:389
void insert(std::initializer_list< value_type > ilist)
Definition: bhopscotch_set.h:233
iterator erase(const_iterator pos)
Definition: bhopscotch_set.h:265
iterator find(const K &key)
Definition: bhopscotch_set.h:357
Definition: bhopscotch_set.h:64
size_type max_size() const noexcept
Definition: bhopscotch_set.h:215
size_type size() const noexcept
Definition: bhopscotch_set.h:214
bhopscotch_set(size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: bhopscotch_set.h:127
key_compare key_comp() const
Definition: bhopscotch_set.h:471
allocator_type get_allocator() const
Definition: bhopscotch_set.h:195
iterator find(const K &key, std::size_t precalculated_hash)
Definition: bhopscotch_set.h:367
friend void swap(bhopscotch_set &lhs, bhopscotch_set &rhs)
Definition: bhopscotch_set.h:506
const_iterator find(const Key &key, std::size_t precalculated_hash) const
Definition: bhopscotch_set.h:348
bhopscotch_set(const Allocator &alloc)
Definition: bhopscotch_set.h:133
iterator end() noexcept
Definition: bhopscotch_set.h:205
key_equal key_eq() const
Definition: bhopscotch_set.h:470
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
Definition: bhopscotch_set.h:404
size_type erase(const key_type &key, std::size_t precalculated_hash)
Definition: bhopscotch_set.h:273
size_type count(const Key &key, std::size_t precalculated_hash) const
Definition: bhopscotch_set.h:311
hasher hash_function() const
Definition: bhopscotch_set.h:469
const_iterator end() const noexcept
Definition: bhopscotch_set.h:206
Definition: hopscotch_growth_policy.h:49
const_iterator find(const K &key, std::size_t precalculated_hash) const
Definition: bhopscotch_set.h:384
size_type count(const Key &key) const
Definition: bhopscotch_set.h:305
bhopscotch_set(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
Definition: bhopscotch_set.h:170
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition: bhopscotch_set.h:399
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition: bhopscotch_set.h:434
Definition: hopscotch_growth_policy.h:247
iterator find(const Key &key, std::size_t precalculated_hash)
Definition: bhopscotch_set.h:341
std::pair< iterator, iterator > equal_range(const K &key)
Definition: bhopscotch_set.h:415
friend bool operator==(const bhopscotch_set &lhs, const bhopscotch_set &rhs)
Definition: bhopscotch_set.h:487
size_type max_bucket_count() const
Definition: bhopscotch_set.h:452
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
Definition: bhopscotch_set.h:441
size_type bucket_count() const
Definition: bhopscotch_set.h:451
void insert(InputIt first, InputIt last)
Definition: bhopscotch_set.h:232
const_iterator find(const Key &key) const
Definition: bhopscotch_set.h:343
iterator insert(const_iterator hint, const value_type &value)
Definition: bhopscotch_set.h:228
friend bool operator!=(const bhopscotch_set &lhs, const bhopscotch_set &rhs)
Definition: bhopscotch_set.h:502
const_iterator begin() const noexcept
Definition: bhopscotch_set.h:202
iterator erase(iterator pos)
Definition: bhopscotch_set.h:264
bhopscotch_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: bhopscotch_set.h:161
size_type count(const K &key, std::size_t precalculated_hash) const
Definition: bhopscotch_set.h:330
void reserve(size_type count_)
Definition: bhopscotch_set.h:463
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
Definition: bhopscotch_set.h:425
const_iterator find(const K &key) const
Definition: bhopscotch_set.h:374
iterator insert(const_iterator hint, value_type &&value)
Definition: bhopscotch_set.h:229
iterator mutable_iterator(const_iterator pos)
Definition: bhopscotch_set.h:481
size_type erase(const K &key, std::size_t precalculated_hash)
Definition: bhopscotch_set.h:294
bhopscotch_set(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: bhopscotch_set.h:177
std::pair< iterator, bool > emplace(Args &&... args)
Definition: bhopscotch_set.h:245
Definition: hopscotch_growth_policy.h:40
iterator erase(const_iterator first, const_iterator last)
Definition: bhopscotch_set.h:266
float max_load_factor() const
Definition: bhopscotch_set.h:459
size_type count(const K &key) const
Definition: bhopscotch_set.h:320
const_iterator cbegin() const noexcept
Definition: bhopscotch_set.h:203
bhopscotch_set & operator=(std::initializer_list< value_type > ilist)
Definition: bhopscotch_set.h:186