24 #ifndef TSL_ORDERED_SET_H 25 #define TSL_ORDERED_SET_H 32 #include <initializer_list> 34 #include <type_traits> 70 class Hash = std::hash<Key>,
71 class KeyEqual = std::equal_to<Key>,
72 class Allocator = std::allocator<Key>,
73 class ValueTypeContainer = std::deque<Key, Allocator>,
74 class IndexType = std::uint_least32_t>
84 const key_type& operator()(
const Key& key)
const noexcept {
88 key_type& operator()(Key& key)
noexcept {
94 Hash, KeyEqual, Allocator, ValueTypeContainer, IndexType>;
97 using key_type =
typename ht::key_type;
98 using value_type =
typename ht::value_type;
99 using size_type =
typename ht::size_type;
100 using difference_type =
typename ht::difference_type;
101 using hasher =
typename ht::hasher;
102 using key_equal =
typename ht::key_equal;
103 using allocator_type =
typename ht::allocator_type;
104 using reference =
typename ht::reference;
105 using const_reference =
typename ht::const_reference;
106 using pointer =
typename ht::pointer;
107 using const_pointer =
typename ht::const_pointer;
108 using iterator =
typename ht::iterator;
109 using const_iterator =
typename ht::const_iterator;
110 using reverse_iterator =
typename ht::reverse_iterator;
111 using const_reverse_iterator =
typename ht::const_reverse_iterator;
113 using values_container_type =
typename ht::values_container_type;
123 const Hash& hash = Hash(),
124 const KeyEqual& equal = KeyEqual(),
125 const Allocator& alloc = Allocator()):
126 m_ht(bucket_count, hash, equal, alloc, ht::DEFAULT_MAX_LOAD_FACTOR)
131 const Allocator& alloc):
ordered_set(bucket_count, Hash(), KeyEqual(), alloc)
137 const Allocator& alloc):
ordered_set(bucket_count, hash, KeyEqual(), alloc)
144 template<
class InputIt>
146 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
147 const Hash& hash = Hash(),
148 const KeyEqual& equal = KeyEqual(),
149 const Allocator& alloc = Allocator()):
ordered_set(bucket_count, hash, equal, alloc)
154 template<
class InputIt>
156 size_type bucket_count,
157 const Allocator& alloc):
ordered_set(first, last, bucket_count, Hash(), KeyEqual(), alloc)
161 template<
class InputIt>
163 size_type bucket_count,
165 const Allocator& alloc):
ordered_set(first, last, bucket_count, hash, KeyEqual(), alloc)
170 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
171 const Hash& hash = Hash(),
172 const KeyEqual& equal = KeyEqual(),
173 const Allocator& alloc = Allocator()):
174 ordered_set(init.begin(), init.end(), bucket_count, hash, equal, alloc)
179 size_type bucket_count,
180 const Allocator& alloc):
181 ordered_set(init.begin(), init.end(), bucket_count, Hash(), KeyEqual(), alloc)
186 size_type bucket_count,
188 const Allocator& alloc):
189 ordered_set(init.begin(), init.end(), bucket_count, hash, KeyEqual(), alloc)
197 m_ht.reserve(ilist.size());
198 m_ht.insert(ilist.begin(), ilist.end());
209 iterator
begin()
noexcept {
return m_ht.begin(); }
210 const_iterator
begin()
const noexcept {
return m_ht.begin(); }
211 const_iterator
cbegin()
const noexcept {
return m_ht.cbegin(); }
213 iterator
end()
noexcept {
return m_ht.end(); }
214 const_iterator
end()
const noexcept {
return m_ht.end(); }
215 const_iterator
cend()
const noexcept {
return m_ht.cend(); }
217 reverse_iterator
rbegin()
noexcept {
return m_ht.rbegin(); }
218 const_reverse_iterator
rbegin()
const noexcept {
return m_ht.rbegin(); }
219 const_reverse_iterator
rcbegin()
const noexcept {
return m_ht.rcbegin(); }
221 reverse_iterator
rend()
noexcept {
return m_ht.rend(); }
222 const_reverse_iterator
rend()
const noexcept {
return m_ht.rend(); }
223 const_reverse_iterator
rcend()
const noexcept {
return m_ht.rcend(); }
229 bool empty()
const noexcept {
return m_ht.empty(); }
230 size_type
size()
const noexcept {
return m_ht.size(); }
231 size_type
max_size()
const noexcept {
return m_ht.max_size(); }
236 void clear()
noexcept { m_ht.clear(); }
240 std::pair<iterator,
bool>
insert(
const value_type& value) {
return m_ht.insert(value); }
241 std::pair<iterator,
bool>
insert(value_type&& value) {
return m_ht.insert(std::move(value)); }
243 iterator
insert(const_iterator hint,
const value_type& value) {
244 return m_ht.insert_hint(hint, value);
247 iterator
insert(const_iterator hint, value_type&& value) {
248 return m_ht.insert_hint(hint, std::move(value));
251 template<
class InputIt>
252 void insert(InputIt first, InputIt last) { m_ht.insert(first, last); }
253 void insert(std::initializer_list<value_type> ilist) { m_ht.insert(ilist.begin(), ilist.end()); }
263 template<
class... Args>
264 std::pair<iterator,
bool>
emplace(Args&&... args) {
return m_ht.emplace(std::forward<Args>(args)...); }
272 template<
class... Args>
274 return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
284 iterator
erase(iterator pos) {
return m_ht.erase(pos); }
289 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); }
299 size_type
erase(
const key_type& key) {
return m_ht.erase(key); }
307 size_type
erase(
const key_type& key, std::size_t precalculated_hash) {
308 return m_ht.erase(key, precalculated_hash);
317 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
318 size_type
erase(
const K& key) {
return m_ht.erase(key); }
326 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
327 size_type
erase(
const K& key, std::size_t precalculated_hash) {
328 return m_ht.erase(key, precalculated_hash);
338 size_type
count(
const Key& key)
const {
return m_ht.count(key); }
344 size_type
count(
const Key& key, std::size_t precalculated_hash)
const {
345 return m_ht.count(key, precalculated_hash);
352 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
353 size_type
count(
const K& key)
const {
return m_ht.count(key); }
361 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
362 size_type
count(
const K& key, std::size_t precalculated_hash)
const {
363 return m_ht.count(key, precalculated_hash);
369 iterator
find(
const Key& key) {
return m_ht.find(key); }
375 iterator
find(
const Key& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
377 const_iterator
find(
const Key& key)
const {
return m_ht.find(key); }
382 const_iterator
find(
const Key& key, std::size_t precalculated_hash)
const {
383 return m_ht.find(key, precalculated_hash);
390 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
391 iterator
find(
const K& key) {
return m_ht.find(key); }
399 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
400 iterator
find(
const K& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
405 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
406 const_iterator
find(
const K& key)
const {
return m_ht.find(key); }
414 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
415 const_iterator
find(
const K& key, std::size_t precalculated_hash)
const {
416 return m_ht.find(key, precalculated_hash);
421 std::pair<iterator, iterator>
equal_range(
const Key& key) {
return m_ht.equal_range(key); }
427 std::pair<iterator, iterator>
equal_range(
const Key& key, std::size_t precalculated_hash) {
428 return m_ht.equal_range(key, precalculated_hash);
431 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key)
const {
return m_ht.equal_range(key); }
436 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key, std::size_t precalculated_hash)
const {
437 return m_ht.equal_range(key, precalculated_hash);
444 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
445 std::pair<iterator, iterator>
equal_range(
const K& key) {
return m_ht.equal_range(key); }
453 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
454 std::pair<iterator, iterator>
equal_range(
const K& key, std::size_t precalculated_hash) {
455 return m_ht.equal_range(key, precalculated_hash);
461 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
462 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
return m_ht.equal_range(key); }
467 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
468 std::pair<const_iterator, const_iterator>
equal_range(
const K& key, std::size_t precalculated_hash)
const {
469 return m_ht.equal_range(key, precalculated_hash);
487 void rehash(size_type count) { m_ht.rehash(count); }
488 void reserve(size_type count) { m_ht.reserve(count); }
495 key_equal
key_eq()
const {
return m_ht.key_eq(); }
506 return m_ht.mutable_iterator(pos);
514 iterator
nth(size_type index) {
return m_ht.nth(index); }
519 const_iterator
nth(size_type index)
const {
return m_ht.nth(index); }
525 const_reference
front()
const {
return m_ht.front(); }
530 const_reference
back()
const {
return m_ht.back(); }
536 template<
class U = values_container_type,
typename std::enable_if<
tsl::
detail_ordered_hash::is_vector<U>::value>::type* =
nullptr>
537 const typename values_container_type::
value_type*
data()
const noexcept {
return m_ht.data(); }
543 const values_container_type&
values_container()
const noexcept {
return m_ht.values_container(); }
545 template<
class U = values_container_type,
typename std::enable_if<
tsl::
detail_ordered_hash::is_vector<U>::value>::type* =
nullptr>
546 size_type
capacity()
const noexcept {
return m_ht.capacity(); }
559 return m_ht.insert_at_position(pos, value);
566 return m_ht.insert_at_position(pos, std::move(value));
575 template<
class... Args>
577 return m_ht.emplace_at_position(pos, std::forward<Args>(args)...);
608 return m_ht.unordered_erase(key, precalculated_hash);
617 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
626 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
628 return m_ht.unordered_erase(key, precalculated_hash);
640 template<
class Serializer>
642 m_ht.serialize(serializer);
663 template<
class Deserializer>
666 set.m_ht.deserialize(deserializer, hash_compatible);
void swap(ordered_set &other)
Definition: ordered_set.h:333
iterator mutable_iterator(const_iterator pos)
Definition: ordered_set.h:505
const values_container_type::value_type * data() const noexcept
Definition: ordered_set.h:537
friend void swap(ordered_set &lhs, ordered_set &rhs)
Definition: ordered_set.h:680
iterator insert(const_iterator hint, const value_type &value)
Definition: ordered_set.h:243
ordered_set(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: ordered_set.h:162
void rehash(size_type count)
Definition: ordered_set.h:487
size_type count(const Key &key) const
Definition: ordered_set.h:338
Definition: ordered_hash.h:279
size_type erase(const K &key)
Definition: ordered_set.h:318
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
Definition: ordered_set.h:436
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition: ordered_set.h:462
size_type unordered_erase(const key_type &key)
Definition: ordered_set.h:599
iterator nth(size_type index)
Definition: ordered_set.h:514
float max_load_factor() const
Definition: ordered_set.h:484
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: ordered_set.h:273
std::pair< iterator, bool > insert(const value_type &value)
Definition: ordered_set.h:240
const_reference front() const
Definition: ordered_set.h:525
Definition: ordered_hash.h:82
Definition: ordered_hash.h:80
Definition: ordered_set.h:75
size_type max_bucket_count() const
Definition: ordered_set.h:477
size_type unordered_erase(const K &key)
Definition: ordered_set.h:618
static ordered_set deserialize(Deserializer &deserializer, bool hash_compatible=false)
Definition: ordered_set.h:664
const_iterator begin() const noexcept
Definition: ordered_set.h:210
void insert(InputIt first, InputIt last)
Definition: ordered_set.h:252
size_type count(const K &key, std::size_t precalculated_hash) const
Definition: ordered_set.h:362
std::pair< iterator, bool > insert_at_position(const_iterator pos, const value_type &value)
Definition: ordered_set.h:558
ordered_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: ordered_set.h:145
void reserve(size_type count)
Definition: ordered_set.h:488
key_equal key_eq() const
Definition: ordered_set.h:495
std::pair< iterator, bool > insert_at_position(const_iterator pos, value_type &&value)
Definition: ordered_set.h:565
const_reverse_iterator rend() const noexcept
Definition: ordered_set.h:222
ordered_set & operator=(std::initializer_list< value_type > ilist)
Definition: ordered_set.h:194
iterator unordered_erase(const_iterator pos)
Definition: ordered_set.h:594
iterator begin() noexcept
Definition: ordered_set.h:209
ordered_set(size_type bucket_count, const Allocator &alloc)
Definition: ordered_set.h:130
void pop_back()
Definition: ordered_set.h:582
size_type erase(const key_type &key)
Definition: ordered_set.h:299
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
Definition: ordered_set.h:427
void insert(std::initializer_list< value_type > ilist)
Definition: ordered_set.h:253
const_iterator find(const K &key, std::size_t precalculated_hash) const
Definition: ordered_set.h:415
ordered_set(const Allocator &alloc)
Definition: ordered_set.h:141
size_type capacity() const noexcept
Definition: ordered_set.h:546
friend bool operator>=(const ordered_set &lhs, const ordered_set &rhs)
Definition: ordered_set.h:678
std::pair< iterator, bool > insert(value_type &&value)
Definition: ordered_set.h:241
ordered_set()
Definition: ordered_set.h:119
iterator find(const K &key)
Definition: ordered_set.h:391
size_type unordered_erase(const key_type &key, std::size_t precalculated_hash)
Definition: ordered_set.h:607
const_iterator cend() const noexcept
Definition: ordered_set.h:215
ordered_set(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: ordered_set.h:122
hasher hash_function() const
Definition: ordered_set.h:494
allocator_type get_allocator() const
Definition: ordered_set.h:203
void clear() noexcept
Definition: ordered_set.h:236
const_iterator find(const K &key) const
Definition: ordered_set.h:406
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
Definition: ordered_set.h:454
friend bool operator<=(const ordered_set &lhs, const ordered_set &rhs)
Definition: ordered_set.h:676
reverse_iterator rbegin() noexcept
Definition: ordered_set.h:217
iterator unordered_erase(iterator pos)
Definition: ordered_set.h:589
ordered_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: ordered_set.h:169
const_iterator nth(size_type index) const
Definition: ordered_set.h:519
ordered_set(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: ordered_set.h:185
const_iterator end() const noexcept
Definition: ordered_set.h:214
void shrink_to_fit()
Definition: ordered_set.h:548
friend bool operator>(const ordered_set &lhs, const ordered_set &rhs)
Definition: ordered_set.h:677
iterator insert(const_iterator hint, value_type &&value)
Definition: ordered_set.h:247
size_type max_size() const noexcept
Definition: ordered_set.h:231
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
Definition: ordered_set.h:468
iterator find(const Key &key, std::size_t precalculated_hash)
Definition: ordered_set.h:375
const_reverse_iterator rcend() const noexcept
Definition: ordered_set.h:223
size_type unordered_erase(const K &key, std::size_t precalculated_hash)
Definition: ordered_set.h:627
iterator erase(iterator pos)
Definition: ordered_set.h:284
iterator find(const Key &key)
Definition: ordered_set.h:369
bool empty() const noexcept
Definition: ordered_set.h:229
std::pair< iterator, bool > emplace(Args &&... args)
Definition: ordered_set.h:264
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: ordered_set.h:421
size_type count(const K &key) const
Definition: ordered_set.h:353
const_reverse_iterator rcbegin() const noexcept
Definition: ordered_set.h:219
void max_load_factor(float ml)
Definition: ordered_set.h:485
friend bool operator<(const ordered_set &lhs, const ordered_set &rhs)
Definition: ordered_set.h:675
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition: ordered_set.h:431
const values_container_type & values_container() const noexcept
Definition: ordered_set.h:543
reverse_iterator rend() noexcept
Definition: ordered_set.h:221
iterator find(const K &key, std::size_t precalculated_hash)
Definition: ordered_set.h:400
friend bool operator!=(const ordered_set &lhs, const ordered_set &rhs)
Definition: ordered_set.h:674
const_reverse_iterator rbegin() const noexcept
Definition: ordered_set.h:218
iterator end() noexcept
Definition: ordered_set.h:213
size_type bucket_count() const
Definition: ordered_set.h:476
const_iterator cbegin() const noexcept
Definition: ordered_set.h:211
iterator erase(const_iterator pos)
Definition: ordered_set.h:289
float load_factor() const
Definition: ordered_set.h:483
size_type size() const noexcept
Definition: ordered_set.h:230
friend bool operator==(const ordered_set &lhs, const ordered_set &rhs)
Definition: ordered_set.h:673
void serialize(Serializer &serializer) const
Definition: ordered_set.h:641
std::pair< iterator, bool > emplace_at_position(const_iterator pos, Args &&... args)
Definition: ordered_set.h:576
size_type erase(const K &key, std::size_t precalculated_hash)
Definition: ordered_set.h:327
ordered_set(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
Definition: ordered_set.h:155
const_reference back() const
Definition: ordered_set.h:530
iterator erase(const_iterator first, const_iterator last)
Definition: ordered_set.h:294
ordered_set(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
Definition: ordered_set.h:178
ordered_set(size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: ordered_set.h:135
std::pair< iterator, iterator > equal_range(const K &key)
Definition: ordered_set.h:445
const_iterator find(const Key &key, std::size_t precalculated_hash) const
Definition: ordered_set.h:382
const_iterator find(const Key &key) const
Definition: ordered_set.h:377
size_type count(const Key &key, std::size_t precalculated_hash) const
Definition: ordered_set.h:344
size_type erase(const key_type &key, std::size_t precalculated_hash)
Definition: ordered_set.h:307