sparse-map
sparse_set.h
Go to the documentation of this file.
1 /**
2  * MIT License
3  *
4  * Copyright (c) 2017 Tessil
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef TSL_SPARSE_SET_H
25 #define TSL_SPARSE_SET_H
26 
27 
28 #include <cstddef>
29 #include <functional>
30 #include <initializer_list>
31 #include <memory>
32 #include <type_traits>
33 #include <utility>
34 #include "sparse_hash.h"
35 
36 
37 namespace tsl {
38 
39 
40 /**
41  * Implementation of a sparse hash set using open-addressing with quadratic probing.
42  * The goal on the hash set is to be the most memory efficient possible, even at low load factor,
43  * while keeping reasonable performances.
44  *
45  * `GrowthPolicy` defines how the set grows and consequently how a hash value is mapped to a bucket.
46  * By default the set uses `tsl::sh::power_of_two_growth_policy`. This policy keeps the number of buckets
47  * to a power of two and uses a mask to map the hash to a bucket instead of the slow modulo.
48  * Other growth policies are available and you may define your own growth policy,
49  * check `tsl::sh::power_of_two_growth_policy` for the interface.
50  *
51  * `ExceptionSafety` defines the exception guarantee provided by the class. By default only the basic
52  * exception safety is guaranteed which mean that all resources used by the hash set will be freed (no memory leaks)
53  * but the hash set may end-up in an undefined state if an exception is thrown (undefined here means that some elements
54  * may be missing). This can ONLY happen on rehash (either on insert or if `rehash` is called explicitly) and will
55  * occur if the Allocator can't allocate memory (`std::bad_alloc`) or if the copy constructor (when a nothrow
56  * move constructor is not available) throws an exception. This can be avoided by calling `reserve` beforehand.
57  * This basic guarantee is similar to the one of `google::sparse_hash_map` and `spp::sparse_hash_map`.
58  * It is possible to ask for the strong exception guarantee with `tsl::sh::exception_safety::strong`, the drawback
59  * is that the set will be slower on rehashes and will also need more memory on rehashes.
60  *
61  * `Sparsity` defines how much the hash set will compromise between insertion speed and memory usage. A high
62  * sparsity means less memory usage but longer insertion times, and vice-versa for low sparsity. The default
63  * `tsl::sh::sparsity::medium` sparsity offers a good compromise. It doesn't change the lookup speed.
64  *
65  * `Key` must be nothrow move constructible and/or copy constructible.
66  *
67  * If the destructor of `Key` throws an exception, the behaviour of the class is undefined.
68  *
69  * Iterators invalidation:
70  * - clear, operator=, reserve, rehash: always invalidate the iterators.
71  * - insert, emplace, emplace_hint: if there is an effective insert, invalidate the iterators.
72  * - erase: always invalidate the iterators.
73  */
74 template<class Key,
75  class Hash = std::hash<Key>,
76  class KeyEqual = std::equal_to<Key>,
77  class Allocator = std::allocator<Key>,
78  class GrowthPolicy = tsl::sh::power_of_two_growth_policy<2>,
81 class sparse_set {
82 private:
83  template<typename U>
84  using has_is_transparent = tsl::detail_sparse_hash::has_is_transparent<U>;
85 
86  class KeySelect {
87  public:
88  using key_type = Key;
89 
90  const key_type& operator()(const Key& key) const noexcept {
91  return key;
92  }
93 
94  key_type& operator()(Key& key) noexcept {
95  return key;
96  }
97  };
98 
99  using ht = detail_sparse_hash::sparse_hash<Key, KeySelect, void, Hash, KeyEqual, Allocator, GrowthPolicy,
100  ExceptionSafety, Sparsity,
102 
103 public:
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;
117 
118 
119  /*
120  * Constructors
121  */
122  sparse_set(): sparse_set(ht::DEFAULT_INIT_BUCKETS_SIZE) {
123  }
124 
125  explicit sparse_set(size_type bucket_count,
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)
130  {
131  }
132 
133  sparse_set(size_type bucket_count,
134  const Allocator& alloc): sparse_set(bucket_count, Hash(), KeyEqual(), alloc)
135  {
136  }
137 
138  sparse_set(size_type bucket_count,
139  const Hash& hash,
140  const Allocator& alloc): sparse_set(bucket_count, hash, KeyEqual(), alloc)
141  {
142  }
143 
144  explicit sparse_set(const Allocator& alloc): sparse_set(ht::DEFAULT_INIT_BUCKETS_SIZE, alloc) {
145  }
146 
147  template<class InputIt>
148  sparse_set(InputIt first, InputIt last,
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)
153  {
154  insert(first, last);
155  }
156 
157  template<class InputIt>
158  sparse_set(InputIt first, InputIt last,
159  size_type bucket_count,
160  const Allocator& alloc): sparse_set(first, last, bucket_count, Hash(), KeyEqual(), alloc)
161  {
162  }
163 
164  template<class InputIt>
165  sparse_set(InputIt first, InputIt last,
166  size_type bucket_count,
167  const Hash& hash,
168  const Allocator& alloc): sparse_set(first, last, bucket_count, hash, KeyEqual(), alloc)
169  {
170  }
171 
172  sparse_set(std::initializer_list<value_type> init,
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)
178  {
179  }
180 
181  sparse_set(std::initializer_list<value_type> init,
182  size_type bucket_count,
183  const Allocator& alloc):
184  sparse_set(init.begin(), init.end(), bucket_count, Hash(), KeyEqual(), alloc)
185  {
186  }
187 
188  sparse_set(std::initializer_list<value_type> init,
189  size_type bucket_count,
190  const Hash& hash,
191  const Allocator& alloc):
192  sparse_set(init.begin(), init.end(), bucket_count, hash, KeyEqual(), alloc)
193  {
194  }
195 
196 
197  sparse_set& operator=(std::initializer_list<value_type> ilist) {
198  m_ht.clear();
199 
200  m_ht.reserve(ilist.size());
201  m_ht.insert(ilist.begin(), ilist.end());
202 
203  return *this;
204  }
205 
206  allocator_type get_allocator() const { return m_ht.get_allocator(); }
207 
208 
209  /*
210  * Iterators
211  */
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(); }
215 
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(); }
219 
220 
221  /*
222  * Capacity
223  */
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(); }
227 
228  /*
229  * Modifiers
230  */
231  void clear() noexcept { m_ht.clear(); }
232 
233 
234 
235 
236  std::pair<iterator, bool> insert(const value_type& value) {
237  return m_ht.insert(value);
238  }
239 
240  std::pair<iterator, bool> insert(value_type&& value) {
241  return m_ht.insert(std::move(value));
242  }
243 
244  iterator insert(const_iterator hint, const value_type& value) {
245  return m_ht.insert(hint, value);
246  }
247 
248  iterator insert(const_iterator hint, value_type&& value) {
249  return m_ht.insert(hint, std::move(value));
250  }
251 
252  template<class InputIt>
253  void insert(InputIt first, InputIt last) {
254  m_ht.insert(first, last);
255  }
256 
257  void insert(std::initializer_list<value_type> ilist) {
258  m_ht.insert(ilist.begin(), ilist.end());
259  }
260 
261 
262 
263 
264  /**
265  * Due to the way elements are stored, emplace will need to move or copy the key-value once.
266  * The method is equivalent to `insert(value_type(std::forward<Args>(args)...));`.
267  *
268  * Mainly here for compatibility with the `std::unordered_map` interface.
269  */
270  template<class... Args>
271  std::pair<iterator, bool> emplace(Args&&... args) {
272  return m_ht.emplace(std::forward<Args>(args)...);
273  }
274 
275 
276 
277  /**
278  * Due to the way elements are stored, emplace_hint will need to move or copy the key-value once.
279  * The method is equivalent to `insert(hint, value_type(std::forward<Args>(args)...));`.
280  *
281  * Mainly here for compatibility with the `std::unordered_map` interface.
282  */
283  template<class... Args>
284  iterator emplace_hint(const_iterator hint, Args&&... args) {
285  return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
286  }
287 
288 
289 
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); }
294 
295  /**
296  * Use the hash value `precalculated_hash` instead of hashing the key. The hash value should be the same
297  * as `hash_function()(key)`, otherwise the behaviour is undefined. Useful to speed-up the lookup
298  * if you already have the hash.
299  */
300  size_type erase(const key_type& key, std::size_t precalculated_hash) {
301  return m_ht.erase(key, precalculated_hash);
302  }
303 
304  /**
305  * This overload only participates in the overload resolution if the typedef `KeyEqual::is_transparent` exists.
306  * If so, `K` must be hashable and comparable to `Key`.
307  */
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); }
310 
311  /**
312  * @copydoc erase(const K& key)
313  *
314  * Use the hash value `precalculated_hash` instead of hashing the key. The hash value should be the same
315  * as `hash_function()(key)`, otherwise the behaviour is undefined. Useful to speed-up the lookup
316  * if you already have the hash.
317  */
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);
321  }
322 
323 
324 
325  void swap(sparse_set& other) { other.m_ht.swap(m_ht); }
326 
327 
328 
329  /*
330  * Lookup
331  */
332  size_type count(const Key& key) const { return m_ht.count(key); }
333 
334  /**
335  * Use the hash value `precalculated_hash` instead of hashing the key. The hash value should be the same
336  * as `hash_function()(key)`, otherwise the behaviour is undefined. Useful to speed-up the lookup
337  * if you already have the hash.
338  */
339  size_type count(const Key& key, std::size_t precalculated_hash) const { return m_ht.count(key, precalculated_hash); }
340 
341  /**
342  * This overload only participates in the overload resolution if the typedef `KeyEqual::is_transparent` exists.
343  * If so, `K` must be hashable and comparable to `Key`.
344  */
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); }
347 
348  /**
349  * @copydoc count(const K& key) const
350  *
351  * Use the hash value `precalculated_hash` instead of hashing the key. The hash value should be the same
352  * as `hash_function()(key)`, otherwise the behaviour is undefined. Useful to speed-up the lookup
353  * if you already have the hash.
354  */
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); }
357 
358 
359 
360 
361  iterator find(const Key& key) { return m_ht.find(key); }
362 
363  /**
364  * Use the hash value `precalculated_hash` instead of hashing the key. The hash value should be the same
365  * as `hash_function()(key)`, otherwise the behaviour is undefined. Useful to speed-up the lookup
366  * if you already have the hash.
367  */
368  iterator find(const Key& key, std::size_t precalculated_hash) { return m_ht.find(key, precalculated_hash); }
369 
370  const_iterator find(const Key& key) const { return m_ht.find(key); }
371 
372  /**
373  * @copydoc find(const Key& key, std::size_t precalculated_hash)
374  */
375  const_iterator find(const Key& key, std::size_t precalculated_hash) const { return m_ht.find(key, precalculated_hash); }
376 
377  /**
378  * This overload only participates in the overload resolution if the typedef `KeyEqual::is_transparent` exists.
379  * If so, `K` must be hashable and comparable to `Key`.
380  */
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); }
383 
384  /**
385  * @copydoc find(const K& key)
386  *
387  * Use the hash value `precalculated_hash` instead of hashing the key. The hash value should be the same
388  * as `hash_function()(key)`, otherwise the behaviour is undefined. Useful to speed-up the lookup
389  * if you already have the hash.
390  */
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); }
393 
394  /**
395  * @copydoc find(const K& key)
396  */
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); }
399 
400  /**
401  * @copydoc find(const K& key)
402  *
403  * Use the hash value `precalculated_hash` instead of hashing the key. The hash value should be the same
404  * as `hash_function()(key)`, otherwise the behaviour is undefined. Useful to speed-up the lookup
405  * if you already have the hash.
406  */
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); }
409 
410 
411 
412 
413  std::pair<iterator, iterator> equal_range(const Key& key) { return m_ht.equal_range(key); }
414 
415  /**
416  * Use the hash value `precalculated_hash` instead of hashing the key. The hash value should be the same
417  * as `hash_function()(key)`, otherwise the behaviour is undefined. Useful to speed-up the lookup
418  * if you already have the hash.
419  */
420  std::pair<iterator, iterator> equal_range(const Key& key, std::size_t precalculated_hash) {
421  return m_ht.equal_range(key, precalculated_hash);
422  }
423 
424  std::pair<const_iterator, const_iterator> equal_range(const Key& key) const { return m_ht.equal_range(key); }
425 
426  /**
427  * @copydoc equal_range(const Key& key, std::size_t precalculated_hash)
428  */
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);
431  }
432 
433  /**
434  * This overload only participates in the overload resolution if the typedef `KeyEqual::is_transparent` exists.
435  * If so, `K` must be hashable and comparable to `Key`.
436  */
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); }
439 
440  /**
441  * @copydoc equal_range(const K& key)
442  *
443  * Use the hash value `precalculated_hash` instead of hashing the key. The hash value should be the same
444  * as `hash_function()(key)`, otherwise the behaviour is undefined. Useful to speed-up the lookup
445  * if you already have the hash.
446  */
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);
450  }
451 
452  /**
453  * @copydoc equal_range(const K& key)
454  */
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); }
457 
458  /**
459  * @copydoc equal_range(const K& key, std::size_t precalculated_hash)
460  */
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);
464  }
465 
466 
467 
468 
469  /*
470  * Bucket interface
471  */
472  size_type bucket_count() const { return m_ht.bucket_count(); }
473  size_type max_bucket_count() const { return m_ht.max_bucket_count(); }
474 
475 
476  /*
477  * Hash policy
478  */
479  float load_factor() const { return m_ht.load_factor(); }
480  float max_load_factor() const { return m_ht.max_load_factor(); }
481  void max_load_factor(float ml) { m_ht.max_load_factor(ml); }
482 
483  void rehash(size_type count) { m_ht.rehash(count); }
484  void reserve(size_type count) { m_ht.reserve(count); }
485 
486 
487  /*
488  * Observers
489  */
490  hasher hash_function() const { return m_ht.hash_function(); }
491  key_equal key_eq() const { return m_ht.key_eq(); }
492 
493 
494  /*
495  * Other
496  */
497 
498  /**
499  * Convert a `const_iterator` to an `iterator`.
500  */
501  iterator mutable_iterator(const_iterator pos) {
502  return m_ht.mutable_iterator(pos);
503  }
504 
505  /**
506  * Serialize the set through the `serializer` parameter.
507  *
508  * The `serializer` parameter must be a function object that supports the following call:
509  * - `void operator()(const U& value);` where the types `std::uint64_t`, `float` and `Key` must be supported for U.
510  *
511  * The implementation leaves binary compatibilty (endianness, IEEE 754 for floats, ...) of the types it serializes
512  * in the hands of the `Serializer` function object if compatibilty is required.
513  */
514  template<class Serializer>
515  void serialize(Serializer& serializer) const {
516  m_ht.serialize(serializer);
517  }
518 
519  /**
520  * Deserialize a previouly serialized set through the `deserializer` parameter.
521  *
522  * The `deserializer` parameter must be a function object that supports the following calls:
523  * - `template<typename U> U operator()();` where the types `std::uint64_t`, `float` and `Key` must be supported for U.
524  *
525  * If the deserialized hash set type is hash compatible with the serialized set, the deserialization process can be
526  * sped up by setting `hash_compatible` to true. To be hash compatible, the Hash, KeyEqual and GrowthPolicy must behave the
527  * same way than the ones used on the serialized set. The `std::size_t` must also be of the same size as the one on the platform used
528  * to serialize the set. If these criteria are not met, the behaviour is undefined with `hash_compatible` sets to true, .
529  *
530  * The behaviour is undefined if the type `Key` of the `sparse_set` is not the same as the
531  * type used during serialization.
532  *
533  * The implementation leaves binary compatibilty (endianness, IEEE 754 for floats, size of int, ...) of the types it
534  * deserializes in the hands of the `Deserializer` function object if compatibilty is required.
535  */
536  template<class Deserializer>
537  static sparse_set deserialize(Deserializer& deserializer, bool hash_compatible = false) {
538  sparse_set set(0);
539  set.m_ht.deserialize(deserializer, hash_compatible);
540 
541  return set;
542  }
543 
544  friend bool operator==(const sparse_set& lhs, const sparse_set& rhs) {
545  if(lhs.size() != rhs.size()) {
546  return false;
547  }
548 
549  for(const auto& element_lhs: lhs) {
550  const auto it_element_rhs = rhs.find(element_lhs);
551  if(it_element_rhs == rhs.cend()) {
552  return false;
553  }
554  }
555 
556  return true;
557  }
558 
559  friend bool operator!=(const sparse_set& lhs, const sparse_set& rhs) {
560  return !operator==(lhs, rhs);
561  }
562 
563  friend void swap(sparse_set& lhs, sparse_set& rhs) {
564  lhs.swap(rhs);
565  }
566 
567 private:
568  ht m_ht;
569 };
570 
571 
572 /**
573  * Same as `tsl::sparse_set<Key, Hash, KeyEqual, Allocator, tsl::sh::prime_growth_policy>`.
574  */
575 template<class Key,
576  class Hash = std::hash<Key>,
577  class KeyEqual = std::equal_to<Key>,
578  class Allocator = std::allocator<Key>>
579 using sparse_pg_set = sparse_set<Key, Hash, KeyEqual, Allocator, tsl::sh::prime_growth_policy>;
580 
581 } // end namespace tsl
582 
583 #endif
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