24 #ifndef TSL_ROBIN_SET_H 25 #define TSL_ROBIN_SET_H 30 #include <initializer_list> 32 #include <type_traits> 79 class Hash = std::hash<Key>,
80 class KeyEqual = std::equal_to<Key>,
81 class Allocator = std::allocator<Key>,
82 bool StoreHash =
false,
93 const key_type& operator()(
const Key& key)
const noexcept {
97 key_type& operator()(Key& key)
noexcept {
103 Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy>;
106 using key_type =
typename ht::key_type;
107 using value_type =
typename ht::value_type;
108 using size_type =
typename ht::size_type;
109 using difference_type =
typename ht::difference_type;
110 using hasher =
typename ht::hasher;
111 using key_equal =
typename ht::key_equal;
112 using allocator_type =
typename ht::allocator_type;
113 using reference =
typename ht::reference;
114 using const_reference =
typename ht::const_reference;
115 using pointer =
typename ht::pointer;
116 using const_pointer =
typename ht::const_pointer;
117 using iterator =
typename ht::iterator;
118 using const_iterator =
typename ht::const_iterator;
128 const Hash& hash = Hash(),
129 const KeyEqual& equal = KeyEqual(),
130 const Allocator& alloc = Allocator()):
131 m_ht(bucket_count, hash, equal, alloc)
136 const Allocator& alloc):
robin_set(bucket_count, Hash(), KeyEqual(), alloc)
142 const Allocator& alloc):
robin_set(bucket_count, hash, KeyEqual(), alloc)
149 template<
class InputIt>
151 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
152 const Hash& hash = Hash(),
153 const KeyEqual& equal = KeyEqual(),
154 const Allocator& alloc = Allocator()):
robin_set(bucket_count, hash, equal, alloc)
159 template<
class InputIt>
161 size_type bucket_count,
162 const Allocator& alloc):
robin_set(first, last, bucket_count, Hash(), KeyEqual(), alloc)
166 template<
class InputIt>
168 size_type bucket_count,
170 const Allocator& alloc):
robin_set(first, last, bucket_count, hash, KeyEqual(), alloc)
175 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
176 const Hash& hash = Hash(),
177 const KeyEqual& equal = KeyEqual(),
178 const Allocator& alloc = Allocator()):
179 robin_set(init.begin(), init.end(), bucket_count, hash, equal, alloc)
184 size_type bucket_count,
185 const Allocator& alloc):
186 robin_set(init.begin(), init.end(), bucket_count, Hash(), KeyEqual(), alloc)
191 size_type bucket_count,
193 const Allocator& alloc):
194 robin_set(init.begin(), init.end(), bucket_count, hash, KeyEqual(), alloc)
202 m_ht.reserve(ilist.size());
203 m_ht.insert(ilist.begin(), ilist.end());
214 iterator
begin()
noexcept {
return m_ht.begin(); }
215 const_iterator
begin()
const noexcept {
return m_ht.begin(); }
216 const_iterator
cbegin()
const noexcept {
return m_ht.cbegin(); }
218 iterator
end()
noexcept {
return m_ht.end(); }
219 const_iterator
end()
const noexcept {
return m_ht.end(); }
220 const_iterator
cend()
const noexcept {
return m_ht.cend(); }
226 bool empty()
const noexcept {
return m_ht.empty(); }
227 size_type
size()
const noexcept {
return m_ht.size(); }
228 size_type
max_size()
const noexcept {
return m_ht.max_size(); }
233 void clear()
noexcept { m_ht.clear(); }
238 std::pair<iterator,
bool>
insert(
const value_type& value) {
239 return m_ht.insert(value);
242 std::pair<iterator,
bool>
insert(value_type&& value) {
243 return m_ht.insert(std::move(value));
246 iterator
insert(const_iterator hint,
const value_type& value) {
247 return m_ht.insert_hint(hint, value);
250 iterator
insert(const_iterator hint, value_type&& value) {
251 return m_ht.insert_hint(hint, std::move(value));
254 template<
class InputIt>
255 void insert(InputIt first, InputIt last) {
256 m_ht.insert(first, last);
259 void insert(std::initializer_list<value_type> ilist) {
260 m_ht.insert(ilist.begin(), ilist.end());
272 template<
class... Args>
273 std::pair<iterator,
bool>
emplace(Args&&... args) {
274 return m_ht.emplace(std::forward<Args>(args)...);
285 template<
class... Args>
287 return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
292 iterator
erase(iterator pos) {
return m_ht.erase(pos); }
293 iterator
erase(const_iterator pos) {
return m_ht.erase(pos); }
294 iterator
erase(const_iterator first, const_iterator last) {
return m_ht.erase(first, last); }
295 size_type
erase(
const key_type& key) {
return m_ht.erase(key); }
301 size_type
erase(
const key_type& key, std::size_t precalculated_hash) {
302 return m_ht.erase(key, precalculated_hash);
309 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
310 size_type
erase(
const K& key) {
return m_ht.erase(key); }
318 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
319 size_type
erase(
const K& key, std::size_t precalculated_hash) {
320 return m_ht.erase(key, precalculated_hash);
332 size_type
count(
const Key& key)
const {
return m_ht.count(key); }
338 size_type
count(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
344 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
345 size_type
count(
const K& key)
const {
return m_ht.count(key); }
353 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
354 size_type
count(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
359 iterator
find(
const Key& key) {
return m_ht.find(key); }
365 iterator
find(
const Key& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
367 const_iterator
find(
const Key& key)
const {
return m_ht.find(key); }
372 const_iterator
find(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
378 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
379 iterator
find(
const K& key) {
return m_ht.find(key); }
387 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
388 iterator
find(
const K& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
393 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
394 const_iterator
find(
const K& key)
const {
return m_ht.find(key); }
402 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
403 const_iterator
find(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
408 std::pair<iterator, iterator>
equal_range(
const Key& key) {
return m_ht.equal_range(key); }
414 std::pair<iterator, iterator>
equal_range(
const Key& key, std::size_t precalculated_hash) {
415 return m_ht.equal_range(key, precalculated_hash);
418 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key)
const {
return m_ht.equal_range(key); }
423 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key, std::size_t precalculated_hash)
const {
424 return m_ht.equal_range(key, precalculated_hash);
431 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
432 std::pair<iterator, iterator>
equal_range(
const K& key) {
return m_ht.equal_range(key); }
440 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
441 std::pair<iterator, iterator>
equal_range(
const K& key, std::size_t precalculated_hash) {
442 return m_ht.equal_range(key, precalculated_hash);
448 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
449 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
return m_ht.equal_range(key); }
454 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
455 std::pair<const_iterator, const_iterator>
equal_range(
const K& key, std::size_t precalculated_hash)
const {
456 return m_ht.equal_range(key, precalculated_hash);
488 void rehash(size_type count) { m_ht.rehash(count); }
489 void reserve(size_type count) { m_ht.reserve(count); }
496 key_equal
key_eq()
const {
return m_ht.key_eq(); }
507 return m_ht.mutable_iterator(pos);
511 if(lhs.size() != rhs.size()) {
515 for(
const auto& element_lhs: lhs) {
516 const auto it_element_rhs = rhs.find(element_lhs);
517 if(it_element_rhs == rhs.cend()) {
526 return !operator==(lhs, rhs);
542 class Hash = std::hash<Key>,
543 class KeyEqual = std::equal_to<Key>,
544 class Allocator = std::allocator<Key>,
545 bool StoreHash =
false>
const_iterator find(const Key &key) const
Definition: robin_set.h:367
size_type erase(const key_type &key, std::size_t precalculated_hash)
Definition: robin_set.h:301
size_type count(const K &key, std::size_t precalculated_hash) const
Definition: robin_set.h:354
std::pair< iterator, bool > insert(value_type &&value)
Definition: robin_set.h:242
iterator mutable_iterator(const_iterator pos)
Definition: robin_set.h:506
const_iterator begin() const noexcept
Definition: robin_set.h:215
const_iterator find(const K &key, std::size_t precalculated_hash) const
Definition: robin_set.h:403
Definition: robin_growth_policy.h:69
iterator find(const K &key, std::size_t precalculated_hash)
Definition: robin_set.h:388
iterator insert(const_iterator hint, value_type &&value)
Definition: robin_set.h:250
iterator end() noexcept
Definition: robin_set.h:218
robin_set(size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: robin_set.h:140
robin_set(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: robin_set.h:127
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
Definition: robin_set.h:414
size_type erase(const key_type &key)
Definition: robin_set.h:295
iterator insert(const_iterator hint, const value_type &value)
Definition: robin_set.h:246
Definition: robin_growth_policy.h:68
size_type size() const noexcept
Definition: robin_set.h:227
std::pair< iterator, bool > emplace(Args &&... args)
Definition: robin_set.h:273
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: robin_set.h:286
std::pair< iterator, bool > insert(const value_type &value)
Definition: robin_set.h:238
robin_set(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: robin_set.h:167
hasher hash_function() const
Definition: robin_set.h:495
size_type bucket_count() const
Definition: robin_set.h:465
iterator erase(const_iterator first, const_iterator last)
Definition: robin_set.h:294
const_iterator cend() const noexcept
Definition: robin_set.h:220
void max_load_factor(float ml)
Definition: robin_set.h:486
friend void swap(robin_set &lhs, robin_set &rhs)
Definition: robin_set.h:529
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
Definition: robin_set.h:423
float min_load_factor() const
Definition: robin_set.h:474
size_type erase(const K &key)
Definition: robin_set.h:310
iterator find(const K &key)
Definition: robin_set.h:379
iterator erase(const_iterator pos)
Definition: robin_set.h:293
bool empty() const noexcept
Definition: robin_set.h:226
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
Definition: robin_set.h:455
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
Definition: robin_set.h:441
key_equal key_eq() const
Definition: robin_set.h:496
robin_set()
Definition: robin_set.h:124
const_iterator find(const Key &key, std::size_t precalculated_hash) const
Definition: robin_set.h:372
iterator erase(iterator pos)
Definition: robin_set.h:292
const_iterator find(const K &key) const
Definition: robin_set.h:394
robin_set(const Allocator &alloc)
Definition: robin_set.h:146
size_type count(const Key &key) const
Definition: robin_set.h:332
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition: robin_set.h:418
robin_set(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
Definition: robin_set.h:160
size_type count(const K &key) const
Definition: robin_set.h:345
allocator_type get_allocator() const
Definition: robin_set.h:208
const_iterator cbegin() const noexcept
Definition: robin_set.h:216
Definition: robin_set.h:84
void min_load_factor(float ml)
Definition: robin_set.h:485
void rehash(size_type count)
Definition: robin_set.h:488
robin_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: robin_set.h:150
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition: robin_set.h:449
robin_set & operator=(std::initializer_list< value_type > ilist)
Definition: robin_set.h:199
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: robin_set.h:408
Definition: robin_growth_policy.h:276
size_type count(const Key &key, std::size_t precalculated_hash) const
Definition: robin_set.h:338
friend bool operator==(const robin_set &lhs, const robin_set &rhs)
Definition: robin_set.h:510
void reserve(size_type count)
Definition: robin_set.h:489
size_type max_bucket_count() const
Definition: robin_set.h:466
robin_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: robin_set.h:174
size_type erase(const K &key, std::size_t precalculated_hash)
Definition: robin_set.h:319
Definition: robin_hash.h:317
float load_factor() const
Definition: robin_set.h:472
iterator find(const Key &key)
Definition: robin_set.h:359
friend bool operator!=(const robin_set &lhs, const robin_set &rhs)
Definition: robin_set.h:525
void clear() noexcept
Definition: robin_set.h:233
const_iterator end() const noexcept
Definition: robin_set.h:219
void insert(std::initializer_list< value_type > ilist)
Definition: robin_set.h:259
std::pair< iterator, iterator > equal_range(const K &key)
Definition: robin_set.h:432
iterator find(const Key &key, std::size_t precalculated_hash)
Definition: robin_set.h:365
void insert(InputIt first, InputIt last)
Definition: robin_set.h:255
Definition: robin_growth_policy.h:78
size_type max_size() const noexcept
Definition: robin_set.h:228
void swap(robin_set &other)
Definition: robin_set.h:325
robin_set(size_type bucket_count, const Allocator &alloc)
Definition: robin_set.h:135
robin_set(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
Definition: robin_set.h:183
robin_set(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: robin_set.h:190
iterator begin() noexcept
Definition: robin_set.h:214
Definition: robin_hash.h:47
float max_load_factor() const
Definition: robin_set.h:475