momo  3.11
unordered_set.h
Go to the documentation of this file.
1 /**********************************************************\
2 
3  This file is part of the
4  https://github.com/morzhovets/momo
5  project, distributed under the MIT License. See
6  https://github.com/morzhovets/momo/blob/branch_cpp11/LICENSE
7  for details.
8 
9  momo/stdish/unordered_set.h
10 
11  namespace momo::stdish:
12  class unordered_set
13  class unordered_set_open
14 
15 \**********************************************************/
16 
17 #ifndef MOMO_INCLUDE_GUARD_STDISH_UNORDERED_SET
18 #define MOMO_INCLUDE_GUARD_STDISH_UNORDERED_SET
19 
20 #ifdef __has_include
21 # if __has_include(<momo/Utility.h>)
22 # include <momo/Utility.h>
23 # endif
24 #endif
25 #ifndef MOMO_PARENT_HEADER
26 # include "../Utility.h"
27 #endif
28 
29 #include MOMO_PARENT_HEADER(HashSet)
30 #include "set_map_utility.h"
31 
32 namespace momo
33 {
34 
35 namespace stdish
36 {
37 
60 template<typename TKey,
61  typename THasher = HashCoder<TKey>,
62  typename TEqualComparer = std::equal_to<TKey>,
63  typename TAllocator = std::allocator<TKey>,
64  typename THashSet = HashSet<TKey, HashTraitsStd<TKey, THasher, TEqualComparer>,
65  MemManagerStd<TAllocator>>>
67 {
68 private:
69  typedef THashSet HashSet;
70  typedef typename HashSet::HashTraits HashTraits;
71  typedef typename HashSet::MemManager MemManager;
72 
73 public:
74  typedef TKey key_type;
75  typedef THasher hasher;
76  typedef TEqualComparer key_equal;
77  typedef TAllocator allocator_type;
78 
80 
81  typedef size_t size_type;
82  typedef ptrdiff_t difference_type;
83 
85 
87  typedef typename HashSet::Iterator iterator;
88 
89  //typedef typename iterator::Reference reference;
92 
93  //typedef typename iterator::Pointer pointer;
94  typedef value_type* pointer;
96  //typedef typename std::allocator_traits<allocator_type>::pointer pointer;
97  //typedef typename std::allocator_traits<allocator_type>::const_pointer const_pointer;
98 
101 
104 
105 private:
106  template<typename KeyArg>
107  struct IsValidKeyArg : public HashTraits::template IsValidKeyArg<KeyArg>
108  {
109  };
110 
111  struct NodeTypeProxy : private node_type
112  {
113  typedef node_type NodeType;
114  MOMO_DECLARE_PROXY_FUNCTION(NodeType, GetExtractedItem)
115  };
116 
117 public:
119  {
120  }
121 
122  explicit unordered_set(const allocator_type& alloc)
123  : mHashSet(HashTraits(), MemManager(alloc))
124  {
125  }
126 
127  explicit unordered_set(size_type bucketCount, const allocator_type& alloc = allocator_type())
128  : mHashSet(HashTraits(bucketCount), MemManager(alloc))
129  {
130  }
131 
132  unordered_set(size_type bucketCount, const hasher& hashFunc,
133  const allocator_type& alloc = allocator_type())
134  : mHashSet(HashTraits(bucketCount, hashFunc), MemManager(alloc))
135  {
136  }
137 
138  unordered_set(size_type bucketCount, const hasher& hashFunc, const key_equal& equalComp,
139  const allocator_type& alloc = allocator_type())
140  : mHashSet(HashTraits(bucketCount, hashFunc, equalComp), MemManager(alloc))
141  {
142  }
143 
144  template<typename Iterator>
145  unordered_set(Iterator first, Iterator last)
146  {
147  insert(first, last);
148  }
149 
150  template<typename Iterator>
151  unordered_set(Iterator first, Iterator last, size_type bucketCount,
152  const allocator_type& alloc = allocator_type())
153  : unordered_set(bucketCount, alloc)
154  {
155  insert(first, last);
156  }
157 
158  template<typename Iterator>
159  unordered_set(Iterator first, Iterator last, size_type bucketCount, const hasher& hashFunc,
160  const allocator_type& alloc = allocator_type())
161  : unordered_set(bucketCount, hashFunc, alloc)
162  {
163  insert(first, last);
164  }
165 
166  template<typename Iterator>
167  unordered_set(Iterator first, Iterator last, size_type bucketCount, const hasher& hashFunc,
168  const key_equal& equalComp, const allocator_type& alloc = allocator_type())
169  : unordered_set(bucketCount, hashFunc, equalComp, alloc)
170  {
171  insert(first, last);
172  }
173 
175  : mHashSet(values)
176  {
177  }
178 
180  size_type bucketCount, const allocator_type& alloc = allocator_type())
181  : mHashSet(values, HashTraits(bucketCount), MemManager(alloc))
182  {
183  }
184 
186  size_type bucketCount, const hasher& hashFunc, const allocator_type& alloc = allocator_type())
187  : mHashSet(values, HashTraits(bucketCount, hashFunc), MemManager(alloc))
188  {
189  }
190 
192  size_type bucketCount, const hasher& hashFunc, const key_equal& equalComp,
193  const allocator_type& alloc = allocator_type())
194  : mHashSet(values, HashTraits(bucketCount, hashFunc, equalComp), MemManager(alloc))
195  {
196  }
197 
198 #ifdef MOMO_HAS_CONTAINERS_RANGES
199  template<std::ranges::input_range Range>
200  requires std::convertible_to<std::ranges::range_reference_t<Range>, value_type>
201  unordered_set(std::from_range_t, Range&& values)
202  {
203  insert_range(std::forward<Range>(values));
204  }
205 
206  template<std::ranges::input_range Range>
207  requires std::convertible_to<std::ranges::range_reference_t<Range>, value_type>
208  unordered_set(std::from_range_t, Range&& values, size_type bucketCount,
209  const allocator_type& alloc = allocator_type())
210  : unordered_set(bucketCount, alloc)
211  {
212  insert_range(std::forward<Range>(values));
213  }
214 
215  template<std::ranges::input_range Range>
216  requires std::convertible_to<std::ranges::range_reference_t<Range>, value_type>
217  unordered_set(std::from_range_t, Range&& values, size_type bucketCount, const hasher& hashFunc,
218  const allocator_type& alloc = allocator_type())
219  : unordered_set(bucketCount, hashFunc, alloc)
220  {
221  insert_range(std::forward<Range>(values));
222  }
223 
224  template<std::ranges::input_range Range>
225  requires std::convertible_to<std::ranges::range_reference_t<Range>, value_type>
226  unordered_set(std::from_range_t, Range&& values, size_type bucketCount, const hasher& hashFunc,
227  const key_equal& equalComp, const allocator_type& alloc = allocator_type())
228  : unordered_set(bucketCount, hashFunc, equalComp, alloc)
229  {
230  insert_range(std::forward<Range>(values));
231  }
232 #endif // MOMO_HAS_CONTAINERS_RANGES
233 
235  : unordered_set(std::move(right), right.get_allocator())
236  {
237  }
238 
240  : mHashSet(right.mHashSet.GetHashTraits(), MemManager(alloc))
241  {
242  if (right.get_allocator() == alloc)
243  {
244  mHashSet.Swap(right.mHashSet);
245  }
246  else
247  {
248  mHashSet.MergeFrom(right.mHashSet);
249  right.clear();
250  }
251  }
252 
254  : mHashSet(right.mHashSet)
255  {
256  }
257 
259  : mHashSet(right.mHashSet, MemManager(alloc))
260  {
261  }
262 
263  ~unordered_set() = default;
264 
267  {
268  return momo::internal::ContainerAssignerStd::Move(std::move(right), *this);
269  }
270 
272  {
273  return momo::internal::ContainerAssignerStd::Copy(right, *this);
274  }
275 
276  unordered_set& operator=(std::initializer_list<value_type> values)
277  {
278  mHashSet = HashSet(values, mHashSet.GetHashTraits(), MemManager(get_allocator()));
279  return *this;
280  }
281 
282  void swap(unordered_set& right) noexcept
283  {
285  }
286 
287  friend void swap(unordered_set& left, unordered_set& right) noexcept
288  {
289  left.swap(right);
290  }
291 
293  {
294  return mHashSet;
295  }
296 
298  {
299  return mHashSet;
300  }
301 
302  const_iterator begin() const noexcept
303  {
304  return mHashSet.GetBegin();
305  }
306 
307  //iterator begin() noexcept
308 
309  const_iterator end() const noexcept
310  {
311  return mHashSet.GetEnd();
312  }
313 
314  //iterator end() noexcept
315 
316  const_iterator cbegin() const noexcept
317  {
318  return begin();
319  }
320 
321  const_iterator cend() const noexcept
322  {
323  return end();
324  }
325 
326  float max_load_factor() const noexcept
327  {
328  return mHashSet.GetHashTraits().GetMaxLoadFactor(HashSet::bucketMaxItemCount);
329  }
330 
331  void max_load_factor(float maxLoadFactor)
332  {
333  if (maxLoadFactor == max_load_factor())
334  return;
335  if (maxLoadFactor <= 0.0 || maxLoadFactor > static_cast<float>(HashSet::bucketMaxItemCount))
336  throw std::out_of_range("invalid load factor");
337  HashTraits hashTraits(mHashSet.GetHashTraits(), maxLoadFactor);
338  HashSet hashSet(hashTraits, MemManager(get_allocator()));
339  hashSet.Reserve(size());
340  hashSet.Insert(begin(), end());
341  mHashSet = std::move(hashSet);
342  }
343 
345  {
346  return mHashSet.GetHashTraits().GetHasher();
347  }
348 
350  {
351  return mHashSet.GetHashTraits().GetEqualComparer();
352  }
353 
354  allocator_type get_allocator() const noexcept
355  {
356  return allocator_type(mHashSet.GetMemManager().GetByteAllocator());
357  }
358 
359  size_type max_size() const noexcept
360  {
361  return std::allocator_traits<allocator_type>::max_size(get_allocator());
362  }
363 
364  size_type size() const noexcept
365  {
366  return mHashSet.GetCount();
367  }
368 
369  MOMO_NODISCARD bool empty() const noexcept
370  {
371  return mHashSet.IsEmpty();
372  }
373 
374  void clear() noexcept
375  {
376  mHashSet.Clear();
377  }
378 
379  void rehash(size_type bucketCount)
380  {
381  bucketCount = std::minmax(bucketCount, size_t{2}).second;
382  size_t logBucketCount = momo::internal::UIntMath<>::Log2(bucketCount - 1) + 1;
383  bucketCount = size_t{1} << logBucketCount;
384  reserve(mHashSet.GetHashTraits().CalcCapacity(bucketCount, HashSet::bucketMaxItemCount));
385  }
386 
388  {
389  mHashSet.Reserve(count);
390  }
391 
393  {
394  return mHashSet.Find(key);
395  }
396 
397  //iterator find(const key_type& key)
398 
399  template<typename KeyArg>
401  const_iterator> find(const KeyArg& key) const
402  {
403  return mHashSet.Find(key);
404  }
405 
406  //template<typename KeyArg>
407  //momo::internal::EnableIf<IsValidKeyArg<KeyArg>::value,
408  //iterator> find(const KeyArg& key)
409 
411  {
412  return contains(key) ? 1 : 0;
413  }
414 
415  template<typename KeyArg>
417  size_type> count(const KeyArg& key) const
418  {
419  return contains(key) ? 1 : 0;
420  }
421 
422  MOMO_FORCEINLINE bool contains(const key_type& key) const
423  {
424  return mHashSet.ContainsKey(key);
425  }
426 
427  template<typename KeyArg>
429  bool> contains(const KeyArg& key) const
430  {
431  return mHashSet.ContainsKey(key);
432  }
433 
434  MOMO_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(
435  const key_type& key) const
436  {
437  return { find(key), end() };
438  }
439 
440  //std::pair<iterator, iterator> equal_range(const key_type& key)
441 
442  template<typename KeyArg>
444  std::pair<const_iterator, const_iterator>> equal_range(const KeyArg& key) const
445  {
446  return { find(key), end() };
447  }
448 
449  //template<typename KeyArg>
450  //momo::internal::EnableIf<IsValidKeyArg<KeyArg>::value,
451  //std::pair<iterator, iterator>> equal_range(const KeyArg& key)
452 
453  std::pair<iterator, bool> insert(value_type&& value)
454  {
455  typename HashSet::InsertResult res = mHashSet.Insert(std::move(value));
456  return { res.position, res.inserted };
457  }
458 
460  {
461 #ifdef MOMO_USE_UNORDERED_HINT_ITERATORS
462  return mHashSet.Add(hint, std::move(value));
463 #else
464  (void)hint;
465  return insert(std::move(value)).first;
466 #endif
467  }
468 
469  std::pair<iterator, bool> insert(const value_type& value)
470  {
471  typename HashSet::InsertResult res = mHashSet.Insert(value);
472  return { res.position, res.inserted };
473  }
474 
476  {
477 #ifdef MOMO_USE_UNORDERED_HINT_ITERATORS
478  return mHashSet.Add(hint, value);
479 #else
480  (void)hint;
481  return insert(value).first;
482 #endif
483  }
484 
486  {
487  if (node.empty())
488  return { end(), false, node_type() };
489  typename HashSet::InsertResult res = mHashSet.Insert(
490  std::move(NodeTypeProxy::GetExtractedItem(node)));
491  return { res.position, res.inserted, res.inserted ? node_type() : std::move(node) };
492  }
493 
495  {
496 #ifdef MOMO_USE_UNORDERED_HINT_ITERATORS
497  if (node.empty())
498  return end();
499  return mHashSet.Add(hint, std::move(NodeTypeProxy::GetExtractedItem(node)));
500 #else
501  (void)hint;
502  return insert(std::move(node)).position;
503 #endif
504  }
505 
506  template<typename Iterator>
507  void insert(Iterator first, Iterator last)
508  {
509  pvInsertRange(first, last);
510  }
511 
512  void insert(std::initializer_list<value_type> values)
513  {
514  mHashSet.Insert(values);
515  }
516 
517 #ifdef MOMO_HAS_CONTAINERS_RANGES
518  template<std::ranges::input_range Range>
519  requires std::convertible_to<std::ranges::range_reference_t<Range>, value_type>
520  void insert_range(Range&& values)
521  {
522  pvInsertRange(std::ranges::begin(values), std::ranges::end(values));
523  }
524 #endif // MOMO_HAS_CONTAINERS_RANGES
525 
526  template<typename... ValueArgs>
527  std::pair<iterator, bool> emplace(ValueArgs&&... valueArgs)
528  {
529  MemManager& memManager = mHashSet.GetMemManager();
530  typename HashSet::ExtractedItem extItem;
531  typedef typename HashSet::ItemTraits::template Creator<ValueArgs...> ValueCreator;
532  extItem.Create(ValueCreator(memManager, std::forward<ValueArgs>(valueArgs)...));
533  typename HashSet::InsertResult res = mHashSet.Insert(std::move(extItem));
534  return { res.position, res.inserted };
535  }
536 
537  template<typename ValueArg>
539  std::pair<iterator, bool>> emplace(ValueArg&& valueArg)
540  {
541  typename HashSet::InsertResult res = mHashSet.InsertVar(
542  static_cast<const key_type&>(valueArg), std::forward<ValueArg>(valueArg));
543  return { res.position, res.inserted };
544  }
545 
546  template<typename... ValueArgs>
547  iterator emplace_hint(const_iterator hint, ValueArgs&&... valueArgs)
548  {
549 #ifdef MOMO_USE_UNORDERED_HINT_ITERATORS
550  return mHashSet.AddVar(hint, std::forward<ValueArgs>(valueArgs)...);
551 #else
552  (void)hint;
553  return emplace(std::forward<ValueArgs>(valueArgs)...).first;
554 #endif
555  }
556 
558  {
559  return mHashSet.Remove(where);
560  }
561 
562  //iterator erase(iterator where)
563 
565  {
566  if (first == begin() && last == end())
567  {
568  clear();
569  return end();
570  }
571  if (first == last)
572  return first;
573  if (first != end() && std::next(first) == last)
574  return erase(first);
575  throw std::invalid_argument("invalid unordered_set erase arguments");
576  }
577 
579  {
580  return mHashSet.Remove(key) ? 1 : 0;
581  }
582 
583  template<typename ValueFilter>
584  friend size_type erase_if(unordered_set& cont, const ValueFilter& valueFilter)
585  {
586  return cont.mHashSet.Remove(valueFilter);
587  }
588 
590  {
591  return node_type(*this, where); // need RVO for exception safety
592  }
593 
595  {
596  const_iterator iter = find(key);
597  return (iter != end()) ? extract(iter) : node_type();
598  }
599 
600  template<typename Set>
601  void merge(Set&& set)
602  {
603  mHashSet.MergeFrom(set.get_nested_container());
604  }
605 
606  size_type max_bucket_count() const noexcept
607  {
609  //return momo::internal::HashSetBuckets<Bucket>::maxBucketCount;
610  }
611 
612  size_type bucket_count() const noexcept
613  {
614  return mHashSet.GetBucketCount();
615  }
616 
617  size_type bucket_size(size_type bucketIndex) const
618  {
619  return mHashSet.GetBucketBounds(bucketIndex).GetCount();
620  }
621 
623  {
624  return mHashSet.GetBucketBounds(bucketIndex).GetBegin();
625  }
626 
628  {
629  return mHashSet.GetBucketBounds(bucketIndex).GetBegin();
630  }
631 
633  {
634  return mHashSet.GetBucketBounds(bucketIndex).GetEnd();
635  }
636 
637  const_local_iterator end(size_type bucketIndex) const
638  {
639  return mHashSet.GetBucketBounds(bucketIndex).GetEnd();
640  }
641 
643  {
644  return begin(bucketIndex);
645  }
646 
648  {
649  return end(bucketIndex);
650  }
651 
652  size_type bucket(const key_type& key) const
653  {
654  return mHashSet.GetBucketIndex(key);
655  }
656 
657  float load_factor() const noexcept
658  {
659  size_t count = size();
660  size_t bucketCount = bucket_count();
661  if (count == 0 && bucketCount == 0)
662  return 0.0;
663  return static_cast<float>(count) / static_cast<float>(bucketCount);
664  }
665 
666  friend bool operator==(const unordered_set& left, const unordered_set& right)
667  {
668  if (left.size() != right.size())
669  return false;
670  for (const_reference ref : left)
671  {
672  if (right.find(ref) == right.end())
673  return false;
674  }
675  return true;
676  }
677 
678  friend bool operator!=(const unordered_set& left, const unordered_set& right)
679  {
680  return !(left == right);
681  }
682 
683 private:
684  template<typename Iterator, typename Sentinel>
686  void> pvInsertRange(Iterator begin, Sentinel end)
687  {
688  mHashSet.Insert(std::move(begin), std::move(end));
689  }
690 
691  template<typename Iterator, typename Sentinel>
693  void> pvInsertRange(Iterator begin, Sentinel end)
694  {
695  for (Iterator iter = std::move(begin); iter != end; ++iter)
696  emplace(*iter);
697  }
698 
699 private:
700  HashSet mHashSet;
701 };
702 
712 template<typename TKey,
713  typename THasher = HashCoder<TKey>,
714  typename TEqualComparer = std::equal_to<TKey>,
715  typename TAllocator = std::allocator<TKey>>
716 class unordered_set_open : public unordered_set<TKey, THasher, TEqualComparer, TAllocator,
717  HashSet<TKey, HashTraitsStd<TKey, THasher, TEqualComparer, HashBucketOpenDefault>,
718  MemManagerStd<TAllocator>>>
719 {
720 private:
721  typedef unordered_set<TKey, THasher, TEqualComparer, TAllocator,
724 
725 public:
726  using typename UnorderedSet::size_type;
727  using typename UnorderedSet::value_type;
728 
729 public:
730  using UnorderedSet::UnorderedSet;
731 
732  unordered_set_open& operator=(std::initializer_list<value_type> values)
733  {
734  UnorderedSet::operator=(values);
735  return *this;
736  }
737 
738  friend void swap(unordered_set_open& left, unordered_set_open& right) noexcept
739  {
740  left.swap(right);
741  }
742 
743  template<typename ValueFilter>
744  friend size_type erase_if(unordered_set_open& cont, const ValueFilter& valueFilter)
745  {
746  return cont.get_nested_container().Remove(valueFilter);
747  }
748 };
749 
750 #ifdef MOMO_HAS_DEDUCTION_GUIDES
751 
752 #define MOMO_DECLARE_DEDUCTION_GUIDES(unordered_set) \
753 template<typename Iterator, \
754  typename Key = typename std::iterator_traits<Iterator>::value_type> \
755 unordered_set(Iterator, Iterator) \
756  -> unordered_set<Key>; \
757 template<typename Iterator, \
758  typename Key = typename std::iterator_traits<Iterator>::value_type, \
759  typename Allocator = std::allocator<Key>, \
760  typename = internal::unordered_checker<Key, Allocator, HashCoder<Key>>> \
761 unordered_set(Iterator, Iterator, size_t, Allocator = Allocator()) \
762  -> unordered_set<Key, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
763 template<typename Iterator, typename Hasher, \
764  typename Key = typename std::iterator_traits<Iterator>::value_type, \
765  typename Allocator = std::allocator<Key>, \
766  typename = internal::unordered_checker<Key, Allocator, Hasher>> \
767 unordered_set(Iterator, Iterator, size_t, Hasher, Allocator = Allocator()) \
768  -> unordered_set<Key, Hasher, std::equal_to<Key>, Allocator>; \
769 template<typename Iterator, typename Hasher, typename EqualComparer, \
770  typename Key = typename std::iterator_traits<Iterator>::value_type, \
771  typename Allocator = std::allocator<Key>, \
772  typename = internal::unordered_checker<Key, Allocator, Hasher, EqualComparer>> \
773 unordered_set(Iterator, Iterator, size_t, Hasher, EqualComparer, Allocator = Allocator()) \
774  -> unordered_set<Key, Hasher, EqualComparer, Allocator>; \
775 template<typename Key> \
776 unordered_set(std::initializer_list<Key>) \
777  -> unordered_set<Key>; \
778 template<typename Key, \
779  typename Allocator = std::allocator<Key>, \
780  typename = internal::unordered_checker<Key, Allocator, HashCoder<Key>>> \
781 unordered_set(std::initializer_list<Key>, size_t, Allocator = Allocator()) \
782  -> unordered_set<Key, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
783 template<typename Key, typename Hasher, \
784  typename Allocator = std::allocator<Key>, \
785  typename = internal::unordered_checker<Key, Allocator, Hasher>> \
786 unordered_set(std::initializer_list<Key>, size_t, Hasher, Allocator = Allocator()) \
787  -> unordered_set<Key, Hasher, std::equal_to<Key>, Allocator>; \
788 template<typename Key, typename Hasher, typename EqualComparer, \
789  typename Allocator = std::allocator<Key>, \
790  typename = internal::unordered_checker<Key, Allocator, Hasher, EqualComparer>> \
791 unordered_set(std::initializer_list<Key>, size_t, Hasher, EqualComparer, Allocator = Allocator()) \
792  -> unordered_set<Key, Hasher, EqualComparer, Allocator>;
793 
794 MOMO_DECLARE_DEDUCTION_GUIDES(unordered_set)
795 MOMO_DECLARE_DEDUCTION_GUIDES(unordered_set_open)
796 
797 #undef MOMO_DECLARE_DEDUCTION_GUIDES
798 
799 #ifdef MOMO_HAS_CONTAINERS_RANGES
800 
801 #define MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_set) \
802 template<std::ranges::input_range Range, \
803  typename Key = std::ranges::range_value_t<Range>> \
804 unordered_set(std::from_range_t, Range&&) \
805  -> unordered_set<Key>; \
806 template<std::ranges::input_range Range, \
807  typename Key = std::ranges::range_value_t<Range>, \
808  typename Allocator = std::allocator<Key>, \
809  typename = internal::unordered_checker<Key, Allocator, HashCoder<Key>>> \
810 unordered_set(std::from_range_t, Range&&, size_t, Allocator = Allocator()) \
811  -> unordered_set<Key, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
812 template<std::ranges::input_range Range, typename Hasher, \
813  typename Key = std::ranges::range_value_t<Range>, \
814  typename Allocator = std::allocator<Key>, \
815  typename = internal::unordered_checker<Key, Allocator, Hasher>> \
816 unordered_set(std::from_range_t, Range&&, size_t, Hasher, Allocator = Allocator()) \
817  -> unordered_set<Key, Hasher, std::equal_to<Key>, Allocator>; \
818 template<std::ranges::input_range Range, typename Hasher, typename EqualComparer, \
819  typename Key = std::ranges::range_value_t<Range>, \
820  typename Allocator = std::allocator<Key>, \
821  typename = internal::unordered_checker<Key, Allocator, Hasher, EqualComparer>> \
822 unordered_set(std::from_range_t, Range&&, size_t, Hasher, EqualComparer, Allocator = Allocator()) \
823  -> unordered_set<Key, Hasher, EqualComparer, Allocator>;
824 
825 MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_set)
826 MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_set_open)
827 
828 #undef MOMO_DECLARE_DEDUCTION_GUIDES_RANGES
829 
830 #endif // MOMO_HAS_CONTAINERS_RANGES
831 
832 #endif // MOMO_HAS_DEDUCTION_GUIDES
833 
834 } // namespace stdish
835 
836 } // namespace momo
837 
838 #endif // MOMO_INCLUDE_GUARD_STDISH_UNORDERED_SET
momo::stdish::unordered_set::erase
iterator erase(const_iterator first, const_iterator last)
Definition: unordered_set.h:564
momo::stdish::unordered_set::hash_function
hasher hash_function() const
Definition: unordered_set.h:344
momo::stdish::unordered_set::insert
insert_return_type insert(node_type &&node)
Definition: unordered_set.h:485
momo::internal::InsertResult::position
Position position
Definition: IteratorUtility.h:168
momo::internal::UIntConst::maxSize
static const size_t maxSize
Definition: Utility.h:457
momo::stdish::unordered_set::reference
value_type & reference
Definition: unordered_set.h:90
momo::stdish::unordered_set::operator=
unordered_set & operator=(std::initializer_list< value_type > values)
Definition: unordered_set.h:276
momo::stdish::unordered_set::unordered_set
unordered_set(Iterator first, Iterator last)
Definition: unordered_set.h:145
momo::HashSet::MemManager
TMemManager MemManager
Definition: HashSet.h:470
momo::stdish::unordered_set::cbegin
const_iterator cbegin() const noexcept
Definition: unordered_set.h:316
momo::stdish::unordered_set::insert
std::pair< iterator, bool > insert(value_type &&value)
Definition: unordered_set.h:453
momo::stdish::unordered_set::reserve
void reserve(size_type count)
Definition: unordered_set.h:387
momo::stdish::unordered_set::nested_container_type
HashSet nested_container_type
Definition: unordered_set.h:79
momo::stdish::unordered_set::contains
MOMO_FORCEINLINE momo::internal::EnableIf< IsValidKeyArg< KeyArg >::value, bool > contains(const KeyArg &key) const
Definition: unordered_set.h:429
momo::stdish::unordered_set::find
MOMO_FORCEINLINE const_iterator find(const key_type &key) const
Definition: unordered_set.h:392
momo::stdish::unordered_set::insert
iterator insert(const_iterator hint, const value_type &value)
Definition: unordered_set.h:475
momo::stdish::set::get_nested_container
const nested_container_type & get_nested_container() const noexcept
Definition: set.h:236
momo::stdish::unordered_set::emplace_hint
iterator emplace_hint(const_iterator hint, ValueArgs &&... valueArgs)
Definition: unordered_set.h:547
momo::stdish::unordered_set::unordered_set
unordered_set(unordered_set &&right, const momo::internal::Identity< allocator_type > &alloc)
Definition: unordered_set.h:239
momo::stdish::unordered_set::unordered_set
unordered_set(const allocator_type &alloc)
Definition: unordered_set.h:122
momo::stdish::unordered_set::insert
iterator insert(const_iterator hint, node_type &&node)
Definition: unordered_set.h:494
momo::stdish::unordered_set::operator==
friend bool operator==(const unordered_set &left, const unordered_set &right)
Definition: unordered_set.h:666
set_map_utility.h
momo::stdish::unordered_set::bucket_count
size_type bucket_count() const noexcept
Definition: unordered_set.h:612
momo::stdish::unordered_set::unordered_set
unordered_set(std::initializer_list< momo::internal::Identity< value_type >> values, size_type bucketCount, const hasher &hashFunc, const allocator_type &alloc=allocator_type())
Definition: unordered_set.h:185
momo::stdish::internal::insert_return_type
Definition: set_map_utility.h:202
momo::internal::HashSetConstIterator::Pointer
const Item * Pointer
Definition: HashSet.h:206
momo::stdish::unordered_set::max_bucket_count
size_type max_bucket_count() const noexcept
Definition: unordered_set.h:606
momo::stdish::unordered_set::unordered_set
unordered_set(unordered_set &&right)
Definition: unordered_set.h:234
momo::internal::UIntMath::Log2
static UInt Log2(UInt value) noexcept
Definition: Utility.h:395
momo::stdish::unordered_set::size_type
size_t size_type
Definition: unordered_set.h:81
momo::stdish::unordered_set::erase
iterator erase(const_iterator where)
Definition: unordered_set.h:557
momo::stdish::unordered_set::const_pointer
const_iterator::Pointer const_pointer
Definition: unordered_set.h:95
momo::internal::HashSetConstIterator::Reference
const Item & Reference
Definition: HashSet.h:205
momo::HashSet::Reserve
void Reserve(size_t capacity)
Definition: HashSet.h:714
momo::stdish::unordered_set::equal_range
MOMO_FORCEINLINE momo::internal::EnableIf< IsValidKeyArg< KeyArg >::value, std::pair< const_iterator, const_iterator > > equal_range(const KeyArg &key) const
Definition: unordered_set.h:444
momo::stdish::unordered_set_open::operator=
unordered_set_open & operator=(std::initializer_list< value_type > values)
Definition: unordered_set.h:732
momo::stdish::unordered_set::contains
MOMO_FORCEINLINE bool contains(const key_type &key) const
Definition: unordered_set.h:422
momo::stdish::set
momo::stdish::set is similar to std::set, but much more efficient in memory usage....
Definition: set.h:67
momo::stdish::unordered_set::rehash
void rehash(size_type bucketCount)
Definition: unordered_set.h:379
momo::MemManagerStd
MemManagerStd uses allocator<unsigned char>::allocate and deallocate
Definition: MemManager.h:177
momo::stdish::unordered_set::unordered_set
unordered_set(std::initializer_list< momo::internal::Identity< value_type >> values, size_type bucketCount, const allocator_type &alloc=allocator_type())
Definition: unordered_set.h:179
momo::stdish::unordered_set::hasher
THasher hasher
Definition: unordered_set.h:75
momo::stdish::unordered_set::merge
void merge(Set &&set)
Definition: unordered_set.h:601
momo::stdish::unordered_set::erase_if
friend size_type erase_if(unordered_set &cont, const ValueFilter &valueFilter)
Definition: unordered_set.h:584
momo::HashSet::Remove
ConstIterator Remove(ConstIterator iter)
Definition: HashSet.h:854
momo::stdish::unordered_set::erase
size_type erase(const key_type &key)
Definition: unordered_set.h:578
momo::internal::ContainerAssignerStd::Move
static Container & Move(Container &&srcCont, Container &dstCont) noexcept(IsNothrowMoveAssignable< Container >::value)
Definition: Utility.h:496
momo::internal::InsertResult
Definition: IteratorUtility.h:136
momo::internal::HashSetConstIterator
Definition: HashSet.h:279
momo::stdish::unordered_set::cend
const_iterator cend() const noexcept
Definition: unordered_set.h:321
momo::stdish::unordered_set::load_factor
float load_factor() const noexcept
Definition: unordered_set.h:657
momo::stdish::unordered_set::cbegin
const_local_iterator cbegin(size_type bucketIndex) const
Definition: unordered_set.h:642
momo::stdish::unordered_set::difference_type
ptrdiff_t difference_type
Definition: unordered_set.h:82
momo::stdish::unordered_set::count
MOMO_FORCEINLINE momo::internal::EnableIf< IsValidKeyArg< KeyArg >::value, size_type > count(const KeyArg &key) const
Definition: unordered_set.h:417
momo::HashSet::Insert
InsertResult Insert(Item &&item)
Definition: HashSet.h:776
momo::stdish::unordered_set::iterator
HashSet::Iterator iterator
Definition: unordered_set.h:87
momo::HashSet::HashTraits
THashTraits HashTraits
Definition: HashSet.h:469
momo::internal::EnableIf
typename std::enable_if< value, Type >::type EnableIf
Definition: Utility.h:209
momo::stdish::unordered_set::bucket
size_type bucket(const key_type &key) const
Definition: unordered_set.h:652
momo::stdish::unordered_set::const_reference
const_iterator::Reference const_reference
Definition: unordered_set.h:91
momo
Definition: Array.h:26
momo::stdish::unordered_set::end
const_local_iterator end(size_type bucketIndex) const
Definition: unordered_set.h:637
momo::internal::ContainerAssignerStd::IsNothrowMoveAssignable
BoolConstant< std::is_empty< Allocator >::value||std::allocator_traits< Allocator >::propagate_on_container_move_assignment::value > IsNothrowMoveAssignable
Definition: Utility.h:492
momo::stdish::unordered_set::unordered_set
unordered_set()
Definition: unordered_set.h:118
momo::HashCoder< TKey >
momo::HashSet::bucketMaxItemCount
static const size_t bucketMaxItemCount
Definition: HashSet.h:504
momo::stdish::unordered_set::begin
const_iterator begin() const noexcept
Definition: unordered_set.h:302
momo::internal::InsertResult::inserted
bool inserted
Definition: IteratorUtility.h:171
momo::internal::Identity
EnableIf< true, Type > Identity
Definition: Utility.h:212
momo::stdish::unordered_set::begin
const_local_iterator begin(size_type bucketIndex) const
Definition: unordered_set.h:627
momo::stdish::unordered_set::emplace
momo::internal::EnableIf< std::is_same< key_type, typename std::decay< ValueArg >::type >::value, std::pair< iterator, bool > > emplace(ValueArg &&valueArg)
Definition: unordered_set.h:539
momo::stdish::unordered_set::get_allocator
allocator_type get_allocator() const noexcept
Definition: unordered_set.h:354
momo::stdish::unordered_set::key_eq
key_equal key_eq() const
Definition: unordered_set.h:349
momo::stdish::unordered_set::extract
node_type extract(const key_type &key)
Definition: unordered_set.h:594
momo::stdish::unordered_set::const_iterator
HashSet::ConstIterator const_iterator
Definition: unordered_set.h:86
momo::stdish::unordered_set::unordered_set
unordered_set(size_type bucketCount, const allocator_type &alloc=allocator_type())
Definition: unordered_set.h:127
momo::stdish::unordered_set::value_type
key_type value_type
Definition: unordered_set.h:84
momo::stdish::unordered_set::key_equal
TEqualComparer key_equal
Definition: unordered_set.h:76
momo::stdish::unordered_set::unordered_set
unordered_set(Iterator first, Iterator last, size_type bucketCount, const allocator_type &alloc=allocator_type())
Definition: unordered_set.h:151
momo::stdish::unordered_set::insert_return_type
internal::insert_return_type< iterator, node_type > insert_return_type
Definition: unordered_set.h:100
momo::stdish::unordered_set::unordered_set
unordered_set(std::initializer_list< momo::internal::Identity< value_type >> values)
Definition: unordered_set.h:174
momo::stdish::unordered_set_open
momo::stdish::unordered_set_open is similar to std::unordered_set, but much more efficient in operati...
Definition: unordered_set.h:719
momo::stdish::unordered_set::~unordered_set
~unordered_set()=default
momo::stdish::unordered_set::equal_range
MOMO_FORCEINLINE std::pair< const_iterator, const_iterator > equal_range(const key_type &key) const
Definition: unordered_set.h:434
momo::stdish::unordered_set::insert
void insert(Iterator first, Iterator last)
Definition: unordered_set.h:507
momo::HashTraitsStd
Definition: HashTraits.h:196
momo::stdish::unordered_set::bucket_size
size_type bucket_size(size_type bucketIndex) const
Definition: unordered_set.h:617
momo::stdish::unordered_set::unordered_set
unordered_set(Iterator first, Iterator last, size_type bucketCount, const hasher &hashFunc, const key_equal &equalComp, const allocator_type &alloc=allocator_type())
Definition: unordered_set.h:167
momo::HashSet< TKey, HashTraitsStd< TKey, HashCoder< TKey >, std::equal_to< TKey >, HashBucketOpenDefault >, MemManagerStd< std::allocator< TKey > > >
momo::stdish::unordered_set::cend
const_local_iterator cend(size_type bucketIndex) const
Definition: unordered_set.h:647
momo::stdish::unordered_set::operator=
unordered_set & operator=(unordered_set &&right) noexcept(momo::internal::ContainerAssignerStd::IsNothrowMoveAssignable< unordered_set >::value)
Definition: unordered_set.h:265
momo::stdish::unordered_set::begin
local_iterator begin(size_type bucketIndex)
Definition: unordered_set.h:622
momo::stdish::unordered_set_open::erase_if
friend size_type erase_if(unordered_set_open &cont, const ValueFilter &valueFilter)
Definition: unordered_set.h:744
MOMO_DECLARE_PROXY_FUNCTION
#define MOMO_DECLARE_PROXY_FUNCTION(Object, Func)
Definition: Utility.h:126
momo::stdish::unordered_set::insert
std::pair< iterator, bool > insert(const value_type &value)
Definition: unordered_set.h:469
momo::stdish::unordered_set::clear
void clear() noexcept
Definition: unordered_set.h:374
std
Definition: Array.h:1173
momo::stdish::unordered_set::extract
node_type extract(const_iterator where)
Definition: unordered_set.h:589
momo::stdish::unordered_set::find
MOMO_FORCEINLINE momo::internal::EnableIf< IsValidKeyArg< KeyArg >::value, const_iterator > find(const KeyArg &key) const
Definition: unordered_set.h:401
momo::stdish::unordered_set::unordered_set
unordered_set(const unordered_set &right, const momo::internal::Identity< allocator_type > &alloc)
Definition: unordered_set.h:258
momo::stdish::unordered_set::end
local_iterator end(size_type bucketIndex)
Definition: unordered_set.h:632
momo::stdish::unordered_set::unordered_set
unordered_set(std::initializer_list< momo::internal::Identity< value_type >> values, size_type bucketCount, const hasher &hashFunc, const key_equal &equalComp, const allocator_type &alloc=allocator_type())
Definition: unordered_set.h:191
momo::stdish::unordered_set::get_nested_container
nested_container_type & get_nested_container() noexcept
Definition: unordered_set.h:297
MOMO_FORCEINLINE
#define MOMO_FORCEINLINE
Definition: UserSettings.h:119
momo::stdish::unordered_set::pointer
value_type * pointer
Definition: unordered_set.h:94
momo::stdish::unordered_set::const_local_iterator
HashSet::ConstBucketBounds::Iterator const_local_iterator
Definition: unordered_set.h:102
momo::internal::SetExtractedItem::Create
void Create(ItemCreator &&itemCreator)
Definition: SetUtility.h:321
momo::stdish::unordered_set::max_size
size_type max_size() const noexcept
Definition: unordered_set.h:359
momo::stdish::unordered_set_open::size_type
size_t size_type
Definition: unordered_set.h:81
momo::stdish::unordered_set::max_load_factor
float max_load_factor() const noexcept
Definition: unordered_set.h:326
momo::stdish::unordered_set::insert
iterator insert(const_iterator hint, value_type &&value)
Definition: unordered_set.h:459
momo::stdish::unordered_set::swap
void swap(unordered_set &right) noexcept
Definition: unordered_set.h:282
momo::stdish::unordered_set::insert
void insert(std::initializer_list< value_type > values)
Definition: unordered_set.h:512
momo::stdish::unordered_set::key_type
TKey key_type
Definition: unordered_set.h:74
momo::stdish::internal::set_node_handle
Definition: set_map_utility.h:42
momo::stdish::unordered_set::unordered_set
unordered_set(size_type bucketCount, const hasher &hashFunc, const key_equal &equalComp, const allocator_type &alloc=allocator_type())
Definition: unordered_set.h:138
momo::internal::ContainerAssignerStd::Copy
static Container & Copy(const Container &srcCont, Container &dstCont)
Definition: Utility.h:512
momo::stdish::unordered_set::allocator_type
TAllocator allocator_type
Definition: unordered_set.h:77
momo::stdish::unordered_set::operator!=
friend bool operator!=(const unordered_set &left, const unordered_set &right)
Definition: unordered_set.h:678
momo::stdish::unordered_set::max_load_factor
void max_load_factor(float maxLoadFactor)
Definition: unordered_set.h:331
momo::stdish::unordered_set
momo::stdish::unordered_set is similar to std::unordered_set, but much more efficient in memory usage...
Definition: unordered_set.h:67
momo::stdish::unordered_set::unordered_set
unordered_set(Iterator first, Iterator last, size_type bucketCount, const hasher &hashFunc, const allocator_type &alloc=allocator_type())
Definition: unordered_set.h:159
Utility.h
momo::stdish::unordered_set::size
size_type size() const noexcept
Definition: unordered_set.h:364
momo::stdish::unordered_set::swap
friend void swap(unordered_set &left, unordered_set &right) noexcept
Definition: unordered_set.h:287
momo::stdish::unordered_set::operator=
unordered_set & operator=(const unordered_set &right)
Definition: unordered_set.h:271
momo::internal::SetExtractedItem
Definition: SetUtility.h:256
momo::internal::ContainerAssignerStd::Swap
static void Swap(Container &cont1, Container &cont2) noexcept
Definition: Utility.h:527
momo::stdish::unordered_set::local_iterator
const_local_iterator local_iterator
Definition: unordered_set.h:103
momo::stdish::unordered_set::get_nested_container
const nested_container_type & get_nested_container() const noexcept
Definition: unordered_set.h:292
momo::stdish::unordered_set::node_type
internal::set_node_handle< typename HashSet::ExtractedItem > node_type
Definition: unordered_set.h:99
momo::stdish::unordered_set::emplace
std::pair< iterator, bool > emplace(ValueArgs &&... valueArgs)
Definition: unordered_set.h:527
momo::stdish::unordered_set::count
MOMO_FORCEINLINE size_type count(const key_type &key) const
Definition: unordered_set.h:410
MOMO_NODISCARD
#define MOMO_NODISCARD
Definition: UserSettings.h:217
momo::stdish::unordered_set::unordered_set
unordered_set(size_type bucketCount, const hasher &hashFunc, const allocator_type &alloc=allocator_type())
Definition: unordered_set.h:132
momo::stdish::unordered_set_open::swap
friend void swap(unordered_set_open &left, unordered_set_open &right) noexcept
Definition: unordered_set.h:738
momo::stdish::unordered_set::unordered_set
unordered_set(const unordered_set &right)
Definition: unordered_set.h:253
momo::stdish::unordered_set::end
const_iterator end() const noexcept
Definition: unordered_set.h:309
momo::stdish::unordered_set::empty
MOMO_NODISCARD bool empty() const noexcept
Definition: unordered_set.h:369