24 #ifndef TSL_SPARSE_SET_H 25 #define TSL_SPARSE_SET_H 30 #include <initializer_list> 32 #include <type_traits> 75 class Hash = std::hash<Key>,
76 class KeyEqual = std::equal_to<Key>,
77 class Allocator = std::allocator<Key>,
90 const key_type& operator()(
const Key& key)
const noexcept {
94 key_type& operator()(Key& key)
noexcept {
100 ExceptionSafety, Sparsity,
104 using key_type =
typename ht::key_type;
105 using value_type =
typename ht::value_type;
106 using size_type =
typename ht::size_type;
107 using difference_type =
typename ht::difference_type;
108 using hasher =
typename ht::hasher;
109 using key_equal =
typename ht::key_equal;
110 using allocator_type =
typename ht::allocator_type;
111 using reference =
typename ht::reference;
112 using const_reference =
typename ht::const_reference;
113 using pointer =
typename ht::pointer;
114 using const_pointer =
typename ht::const_pointer;
115 using iterator =
typename ht::iterator;
116 using const_iterator =
typename ht::const_iterator;
126 const Hash& hash = Hash(),
127 const KeyEqual& equal = KeyEqual(),
128 const Allocator& alloc = Allocator()):
129 m_ht(bucket_count, hash, equal, alloc, ht::DEFAULT_MAX_LOAD_FACTOR)
134 const Allocator& alloc):
sparse_set(bucket_count, Hash(), KeyEqual(), alloc)
140 const Allocator& alloc):
sparse_set(bucket_count, hash, KeyEqual(), alloc)
147 template<
class InputIt>
149 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
150 const Hash& hash = Hash(),
151 const KeyEqual& equal = KeyEqual(),
152 const Allocator& alloc = Allocator()):
sparse_set(bucket_count, hash, equal, alloc)
157 template<
class InputIt>
159 size_type bucket_count,
160 const Allocator& alloc):
sparse_set(first, last, bucket_count, Hash(), KeyEqual(), alloc)
164 template<
class InputIt>
166 size_type bucket_count,
168 const Allocator& alloc):
sparse_set(first, last, bucket_count, hash, KeyEqual(), alloc)
173 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
174 const Hash& hash = Hash(),
175 const KeyEqual& equal = KeyEqual(),
176 const Allocator& alloc = Allocator()):
177 sparse_set(init.begin(), init.end(), bucket_count, hash, equal, alloc)
182 size_type bucket_count,
183 const Allocator& alloc):
184 sparse_set(init.begin(), init.end(), bucket_count, Hash(), KeyEqual(), alloc)
189 size_type bucket_count,
191 const Allocator& alloc):
192 sparse_set(init.begin(), init.end(), bucket_count, hash, KeyEqual(), alloc)
200 m_ht.reserve(ilist.size());
201 m_ht.insert(ilist.begin(), ilist.end());
212 iterator
begin()
noexcept {
return m_ht.begin(); }
213 const_iterator
begin()
const noexcept {
return m_ht.begin(); }
214 const_iterator
cbegin()
const noexcept {
return m_ht.cbegin(); }
216 iterator
end()
noexcept {
return m_ht.end(); }
217 const_iterator
end()
const noexcept {
return m_ht.end(); }
218 const_iterator
cend()
const noexcept {
return m_ht.cend(); }
224 bool empty()
const noexcept {
return m_ht.empty(); }
225 size_type
size()
const noexcept {
return m_ht.size(); }
226 size_type
max_size()
const noexcept {
return m_ht.max_size(); }
231 void clear()
noexcept { m_ht.clear(); }
236 std::pair<iterator,
bool>
insert(
const value_type& value) {
237 return m_ht.insert(value);
240 std::pair<iterator,
bool>
insert(value_type&& value) {
241 return m_ht.insert(std::move(value));
244 iterator
insert(const_iterator hint,
const value_type& value) {
245 return m_ht.insert(hint, value);
248 iterator
insert(const_iterator hint, value_type&& value) {
249 return m_ht.insert(hint, std::move(value));
252 template<
class InputIt>
253 void insert(InputIt first, InputIt last) {
254 m_ht.insert(first, last);
257 void insert(std::initializer_list<value_type> ilist) {
258 m_ht.insert(ilist.begin(), ilist.end());
270 template<
class... Args>
271 std::pair<iterator,
bool>
emplace(Args&&... args) {
272 return m_ht.emplace(std::forward<Args>(args)...);
283 template<
class... Args>
285 return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
290 iterator
erase(iterator pos) {
return m_ht.erase(pos); }
291 iterator
erase(const_iterator pos) {
return m_ht.erase(pos); }
292 iterator
erase(const_iterator first, const_iterator last) {
return m_ht.erase(first, last); }
293 size_type
erase(
const key_type& key) {
return m_ht.erase(key); }
300 size_type
erase(
const key_type& key, std::size_t precalculated_hash) {
301 return m_ht.erase(key, precalculated_hash);
308 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
309 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); }
339 size_type
count(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
345 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
346 size_type
count(
const K& key)
const {
return m_ht.count(key); }
355 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
356 size_type
count(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
361 iterator
find(
const Key& key) {
return m_ht.find(key); }
368 iterator
find(
const Key& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
370 const_iterator
find(
const Key& key)
const {
return m_ht.find(key); }
375 const_iterator
find(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
381 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
382 iterator
find(
const K& key) {
return m_ht.find(key); }
391 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
392 iterator
find(
const K& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
397 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
398 const_iterator
find(
const K& key)
const {
return m_ht.find(key); }
407 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
408 const_iterator
find(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
413 std::pair<iterator, iterator>
equal_range(
const Key& key) {
return m_ht.equal_range(key); }
420 std::pair<iterator, iterator>
equal_range(
const Key& key, std::size_t precalculated_hash) {
421 return m_ht.equal_range(key, precalculated_hash);
424 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key)
const {
return m_ht.equal_range(key); }
429 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key, std::size_t precalculated_hash)
const {
430 return m_ht.equal_range(key, precalculated_hash);
437 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
438 std::pair<iterator, iterator>
equal_range(
const K& key) {
return m_ht.equal_range(key); }
447 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
448 std::pair<iterator, iterator>
equal_range(
const K& key, std::size_t precalculated_hash) {
449 return m_ht.equal_range(key, precalculated_hash);
455 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
456 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
return m_ht.equal_range(key); }
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, std::size_t precalculated_hash)
const {
463 return m_ht.equal_range(key, precalculated_hash);
483 void rehash(size_type count) { m_ht.rehash(count); }
484 void reserve(size_type count) { m_ht.reserve(count); }
491 key_equal
key_eq()
const {
return m_ht.key_eq(); }
502 return m_ht.mutable_iterator(pos);
514 template<
class Serializer>
516 m_ht.serialize(serializer);
536 template<
class Deserializer>
539 set.m_ht.deserialize(deserializer, hash_compatible);
545 if(lhs.size() != rhs.size()) {
549 for(
const auto& element_lhs: lhs) {
550 const auto it_element_rhs = rhs.find(element_lhs);
551 if(it_element_rhs == rhs.cend()) {
560 return !operator==(lhs, rhs);
576 class Hash = std::hash<Key>,
577 class KeyEqual = std::equal_to<Key>,
578 class Allocator = std::allocator<Key>>
iterator insert(const_iterator hint, value_type &&value)
Definition: sparse_set.h:248
friend bool operator!=(const sparse_set &lhs, const sparse_set &rhs)
Definition: sparse_set.h:559
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
Definition: sparse_set.h:448
sparse_set(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: sparse_set.h:188
sparse_set(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: sparse_set.h:125
Definition: sparse_growth_policy.h:39
size_type count(const K &key, std::size_t precalculated_hash) const
Definition: sparse_set.h:356
sparse_set()
Definition: sparse_set.h:122
sparse_set(size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: sparse_set.h:138
const_iterator find(const K &key) const
Definition: sparse_set.h:398
sparse_set & operator=(std::initializer_list< value_type > ilist)
Definition: sparse_set.h:197
const_iterator begin() const noexcept
Definition: sparse_set.h:213
sparse_set(const Allocator &alloc)
Definition: sparse_set.h:144
hasher hash_function() const
Definition: sparse_set.h:490
iterator find(const K &key)
Definition: sparse_set.h:382
iterator erase(const_iterator pos)
Definition: sparse_set.h:291
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
Definition: sparse_set.h:429
iterator mutable_iterator(const_iterator pos)
Definition: sparse_set.h:501
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: sparse_set.h:413
iterator find(const Key &key, std::size_t precalculated_hash)
Definition: sparse_set.h:368
friend void swap(sparse_set &lhs, sparse_set &rhs)
Definition: sparse_set.h:563
size_type erase(const key_type &key, std::size_t precalculated_hash)
Definition: sparse_set.h:300
float load_factor() const
Definition: sparse_set.h:479
const_iterator cend() const noexcept
Definition: sparse_set.h:218
probing
Definition: sparse_hash.h:63
iterator find(const K &key, std::size_t precalculated_hash)
Definition: sparse_set.h:392
size_type count(const Key &key, std::size_t precalculated_hash) const
Definition: sparse_set.h:339
size_type size() const noexcept
Definition: sparse_set.h:225
static sparse_set deserialize(Deserializer &deserializer, bool hash_compatible=false)
Definition: sparse_set.h:537
const_iterator end() const noexcept
Definition: sparse_set.h:217
size_type count(const Key &key) const
Definition: sparse_set.h:332
void clear() noexcept
Definition: sparse_set.h:231
sparse_set(size_type bucket_count, const Allocator &alloc)
Definition: sparse_set.h:133
size_type erase(const key_type &key)
Definition: sparse_set.h:293
void max_load_factor(float ml)
Definition: sparse_set.h:481
sparsity
Definition: sparse_hash.h:73
iterator insert(const_iterator hint, const value_type &value)
Definition: sparse_set.h:244
exception_safety
Definition: sparse_hash.h:68
size_type erase(const K &key)
Definition: sparse_set.h:309
void insert(std::initializer_list< value_type > ilist)
Definition: sparse_set.h:257
const_iterator find(const K &key, std::size_t precalculated_hash) const
Definition: sparse_set.h:408
std::pair< iterator, bool > insert(value_type &&value)
Definition: sparse_set.h:240
Definition: sparse_set.h:81
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition: sparse_set.h:424
Definition: sparse_growth_policy.h:40
std::pair< iterator, bool > insert(const value_type &value)
Definition: sparse_set.h:236
void insert(InputIt first, InputIt last)
Definition: sparse_set.h:253
sparse_set(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
Definition: sparse_set.h:181
iterator erase(iterator pos)
Definition: sparse_set.h:290
sparse_set(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: sparse_set.h:165
float max_load_factor() const
Definition: sparse_set.h:480
bool empty() const noexcept
Definition: sparse_set.h:224
size_type erase(const K &key, std::size_t precalculated_hash)
Definition: sparse_set.h:319
iterator erase(const_iterator first, const_iterator last)
Definition: sparse_set.h:292
size_type count(const K &key) const
Definition: sparse_set.h:346
void swap(sparse_set &other)
Definition: sparse_set.h:325
Definition: sparse_growth_policy.h:247
sparse_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: sparse_set.h:148
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition: sparse_set.h:456
size_type bucket_count() const
Definition: sparse_set.h:472
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: sparse_set.h:284
friend bool operator==(const sparse_set &lhs, const sparse_set &rhs)
Definition: sparse_set.h:544
std::pair< iterator, bool > emplace(Args &&... args)
Definition: sparse_set.h:271
key_equal key_eq() const
Definition: sparse_set.h:491
sparse_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: sparse_set.h:172
Definition: sparse_hash.h:193
sparse_set(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
Definition: sparse_set.h:158
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
Definition: sparse_set.h:420
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
Definition: sparse_set.h:462
const_iterator find(const Key &key, std::size_t precalculated_hash) const
Definition: sparse_set.h:375
allocator_type get_allocator() const
Definition: sparse_set.h:206
void reserve(size_type count)
Definition: sparse_set.h:484
iterator end() noexcept
Definition: sparse_set.h:216
iterator find(const Key &key)
Definition: sparse_set.h:361
size_type max_size() const noexcept
Definition: sparse_set.h:226
iterator begin() noexcept
Definition: sparse_set.h:212
void serialize(Serializer &serializer) const
Definition: sparse_set.h:515
size_type max_bucket_count() const
Definition: sparse_set.h:473
Definition: sparse_growth_policy.h:49
const_iterator find(const Key &key) const
Definition: sparse_set.h:370
std::pair< iterator, iterator > equal_range(const K &key)
Definition: sparse_set.h:438
void rehash(size_type count)
Definition: sparse_set.h:483
Definition: sparse_hash.h:937
const_iterator cbegin() const noexcept
Definition: sparse_set.h:214