momo  3.12
unordered_map.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_map.h
10 
11  namespace momo::stdish:
12  class unordered_map_adaptor
13  class unordered_map
14  class unordered_map_open
15 
16 \**********************************************************/
17 
18 #ifndef MOMO_INCLUDE_GUARD_STDISH_UNORDERED_MAP
19 #define MOMO_INCLUDE_GUARD_STDISH_UNORDERED_MAP
20 
21 #include "set_map_utility.h"
22 #include MOMO_PARENT_HEADER(HashMap)
23 
24 namespace momo
25 {
26 
27 namespace stdish
28 {
29 
30 template<typename THashMap>
32 {
33 private:
34  typedef THashMap HashMap;
35  typedef typename HashMap::HashTraits HashTraits;
36  typedef typename HashMap::MemManager MemManager;
37 
38  typedef typename HashMap::Iterator HashMapIterator;
39 
40 public:
41  typedef typename HashMap::Key key_type;
42  typedef typename HashMap::Value mapped_type;
43  typedef typename HashTraits::Hasher hasher;
44  typedef typename HashTraits::EqualComparer key_equal;
45 
46  typedef HashMap nested_container_type;
47 
48  typedef size_t size_type;
49  typedef ptrdiff_t difference_type;
50 
51  typedef std::pair<const key_type, mapped_type> value_type;
52  typedef typename std::allocator_traits<typename MemManager::ByteAllocator>
53  ::template rebind_alloc<value_type> allocator_type;
54 
58 
59  typedef typename iterator::Reference reference;
61 
62  typedef typename iterator::Pointer pointer;
64  //typedef typename std::allocator_traits<allocator_type>::pointer pointer;
65  //typedef typename std::allocator_traits<allocator_type>::const_pointer const_pointer;
66 
69 
73 
74 private:
75  template<typename KeyArg>
76  struct IsValidKeyArg : public HashTraits::template IsValidKeyArg<KeyArg>
77  {
78  };
79 
80  struct ConstIteratorProxy : private const_iterator
81  {
82  typedef const_iterator ConstIterator;
83  MOMO_DECLARE_PROXY_FUNCTION(ConstIterator, GetBaseIterator)
84  };
85 
86  struct IteratorProxy : private iterator
87  {
88  typedef iterator Iterator;
89  MOMO_DECLARE_PROXY_FUNCTION(Iterator, GetBaseIterator)
90  };
91 
92  struct NodeTypeProxy : private node_type
93  {
94  typedef node_type NodeType;
95  MOMO_DECLARE_PROXY_FUNCTION(NodeType, GetExtractedPair)
96  };
97 
98 public:
100  {
101  }
102 
103  explicit unordered_map_adaptor(const allocator_type& alloc)
104  : mHashMap(HashTraits(), MemManager(alloc))
105  {
106  }
107 
108  explicit unordered_map_adaptor(size_type bucketCount, const allocator_type& alloc = allocator_type())
109  : mHashMap(HashTraits(bucketCount), MemManager(alloc))
110  {
111  }
112 
113  unordered_map_adaptor(size_type bucketCount, const hasher& hashFunc,
114  const allocator_type& alloc = allocator_type())
115  : mHashMap(HashTraits(bucketCount, hashFunc), MemManager(alloc))
116  {
117  }
118 
119  unordered_map_adaptor(size_type bucketCount, const hasher& hashFunc, const key_equal& equalComp,
120  const allocator_type& alloc = allocator_type())
121  : mHashMap(HashTraits(bucketCount, hashFunc, equalComp), MemManager(alloc))
122  {
123  }
124 
125  template<typename Iterator>
126  unordered_map_adaptor(Iterator first, Iterator last)
127  {
128  insert(first, last);
129  }
130 
131  template<typename Iterator>
132  unordered_map_adaptor(Iterator first, Iterator last, size_type bucketCount,
133  const allocator_type& alloc = allocator_type())
134  : unordered_map_adaptor(bucketCount, alloc)
135  {
136  insert(first, last);
137  }
138 
139  template<typename Iterator>
140  unordered_map_adaptor(Iterator first, Iterator last, size_type bucketCount, const hasher& hashFunc,
141  const allocator_type& alloc = allocator_type())
142  : unordered_map_adaptor(bucketCount, hashFunc, alloc)
143  {
144  insert(first, last);
145  }
146 
147  template<typename Iterator>
148  unordered_map_adaptor(Iterator first, Iterator last, size_type bucketCount, const hasher& hashFunc,
149  const key_equal& equalComp, const allocator_type& alloc = allocator_type())
150  : unordered_map_adaptor(bucketCount, hashFunc, equalComp, alloc)
151  {
152  insert(first, last);
153  }
154 
155  unordered_map_adaptor(std::initializer_list<value_type> values)
156  : unordered_map_adaptor(values.begin(), values.end())
157  {
158  }
159 
160  unordered_map_adaptor(std::initializer_list<value_type> values, size_type bucketCount,
161  const allocator_type& alloc = allocator_type())
162  : unordered_map_adaptor(values.begin(), values.end(), bucketCount, alloc)
163  {
164  }
165 
166  unordered_map_adaptor(std::initializer_list<value_type> values, size_type bucketCount,
167  const hasher& hashFunc, const allocator_type& alloc = allocator_type())
168  : unordered_map_adaptor(values.begin(), values.end(), bucketCount, hashFunc, alloc)
169  {
170  }
171 
172  unordered_map_adaptor(std::initializer_list<value_type> values, size_type bucketCount,
173  const hasher& hashFunc, const key_equal& equalComp, const allocator_type& alloc = allocator_type())
174  : unordered_map_adaptor(values.begin(), values.end(), bucketCount, hashFunc, equalComp, alloc)
175  {
176  }
177 
178 #ifdef MOMO_HAS_CONTAINERS_RANGES
179  template<std::ranges::input_range Range>
180  requires std::convertible_to<std::ranges::range_reference_t<Range>, value_type>
181  unordered_map_adaptor(std::from_range_t, Range&& values)
182  {
183  insert_range(std::forward<Range>(values));
184  }
185 
186  template<std::ranges::input_range Range>
187  requires std::convertible_to<std::ranges::range_reference_t<Range>, value_type>
188  unordered_map_adaptor(std::from_range_t, Range&& values, size_type bucketCount,
189  const allocator_type& alloc = allocator_type())
190  : unordered_map_adaptor(bucketCount, alloc)
191  {
192  insert_range(std::forward<Range>(values));
193  }
194 
195  template<std::ranges::input_range Range>
196  requires std::convertible_to<std::ranges::range_reference_t<Range>, value_type>
197  unordered_map_adaptor(std::from_range_t, Range&& values, size_type bucketCount,
198  const hasher& hashFunc, const allocator_type& alloc = allocator_type())
199  : unordered_map_adaptor(bucketCount, hashFunc, alloc)
200  {
201  insert_range(std::forward<Range>(values));
202  }
203 
204  template<std::ranges::input_range Range>
205  requires std::convertible_to<std::ranges::range_reference_t<Range>, value_type>
206  unordered_map_adaptor(std::from_range_t, Range&& values, size_type bucketCount,
207  const hasher& hashFunc, const key_equal& equalComp, const allocator_type& alloc = allocator_type())
208  : unordered_map_adaptor(bucketCount, hashFunc, equalComp, alloc)
209  {
210  insert_range(std::forward<Range>(values));
211  }
212 #endif // MOMO_HAS_CONTAINERS_RANGES
213 
215  : unordered_map_adaptor(std::move(right), right.get_allocator())
216  {
217  }
218 
220  : mHashMap(right.mHashMap.GetHashTraits(), MemManager(alloc))
221  {
222  if (right.get_allocator() == alloc)
223  {
224  mHashMap.Swap(right.mHashMap);
225  }
226  else
227  {
228  mHashMap.MergeFrom(right.mHashMap);
229  right.clear();
230  }
231  }
232 
234  : mHashMap(right.mHashMap)
235  {
236  }
237 
239  : mHashMap(right.mHashMap, MemManager(alloc))
240  {
241  }
242 
244 
247  {
248  return momo::internal::ContainerAssignerStd::Move(std::move(right), *this);
249  }
250 
252  {
253  return momo::internal::ContainerAssignerStd::Copy(right, *this);
254  }
255 
256  unordered_map_adaptor& operator=(std::initializer_list<value_type> values)
257  {
258  mHashMap = HashMap(values, mHashMap.GetHashTraits(), MemManager(get_allocator()));
259  return *this;
260  }
261 
262  void swap(unordered_map_adaptor& right) noexcept
263  {
265  }
266 
267  friend void swap(unordered_map_adaptor& left, unordered_map_adaptor& right) noexcept
268  {
269  left.swap(right);
270  }
271 
273  {
274  return mHashMap;
275  }
276 
278  {
279  return mHashMap;
280  }
281 
282  const_iterator begin() const noexcept
283  {
284  return momo::internal::ProxyConstructor<const_iterator>(mHashMap.GetBegin());
285  }
286 
287  iterator begin() noexcept
288  {
289  return momo::internal::ProxyConstructor<iterator>(mHashMap.GetBegin());
290  }
291 
292  const_iterator end() const noexcept
293  {
294  return momo::internal::ProxyConstructor<const_iterator>(mHashMap.GetEnd());
295  }
296 
297  iterator end() noexcept
298  {
299  return momo::internal::ProxyConstructor<iterator>(mHashMap.GetEnd());
300  }
301 
302  const_iterator cbegin() const noexcept
303  {
304  return begin();
305  }
306 
307  const_iterator cend() const noexcept
308  {
309  return end();
310  }
311 
312  float max_load_factor() const noexcept
313  {
314  return mHashMap.GetHashTraits().GetMaxLoadFactor(HashMap::bucketMaxItemCount);
315  }
316 
317  void max_load_factor(float maxLoadFactor)
318  {
319  if (maxLoadFactor == max_load_factor())
320  return;
321  if (maxLoadFactor <= 0.0 || maxLoadFactor > static_cast<float>(HashMap::bucketMaxItemCount))
322  MOMO_THROW(std::out_of_range("invalid load factor"));
323  HashTraits hashTraits(mHashMap.GetHashTraits(), maxLoadFactor);
324  HashMap hashMap(hashTraits, MemManager(get_allocator()));
325  hashMap.Reserve(size());
326  hashMap.Insert(begin(), end());
327  mHashMap = std::move(hashMap);
328  }
329 
331  {
332  return mHashMap.GetHashTraits().GetHasher();
333  }
334 
336  {
337  return mHashMap.GetHashTraits().GetEqualComparer();
338  }
339 
340  allocator_type get_allocator() const noexcept
341  {
342  return allocator_type(mHashMap.GetMemManager().GetByteAllocator());
343  }
344 
345  size_type max_size() const noexcept
346  {
347  return std::allocator_traits<allocator_type>::max_size(get_allocator());
348  }
349 
350  size_type size() const noexcept
351  {
352  return mHashMap.GetCount();
353  }
354 
355  MOMO_NODISCARD bool empty() const noexcept
356  {
357  return mHashMap.IsEmpty();
358  }
359 
360  void clear() noexcept
361  {
362  mHashMap.Clear();
363  }
364 
365  void rehash(size_type bucketCount)
366  {
367  bucketCount = momo::internal::UIntMath<>::Max(bucketCount, 2);
368  size_t logBucketCount = momo::internal::UIntMath<>::Log2(bucketCount - 1) + 1;
369  bucketCount = size_t{1} << logBucketCount;
370  reserve(mHashMap.GetHashTraits().CalcCapacity(bucketCount, HashMap::bucketMaxItemCount));
371  }
372 
374  {
375  mHashMap.Reserve(count);
376  }
377 
379  {
380  return momo::internal::ProxyConstructor<const_iterator>(mHashMap.Find(key));
381  }
382 
384  {
385  return momo::internal::ProxyConstructor<iterator>(mHashMap.Find(key));
386  }
387 
388  template<typename KeyArg>
390  const_iterator> find(const KeyArg& key) const
391  {
392  return momo::internal::ProxyConstructor<const_iterator>(mHashMap.Find(key));
393  }
394 
395  template<typename KeyArg>
397  iterator> find(const KeyArg& key)
398  {
399  return momo::internal::ProxyConstructor<iterator>(mHashMap.Find(key));
400  }
401 
403  {
404  return contains(key) ? 1 : 0;
405  }
406 
407  template<typename KeyArg>
409  size_type> count(const KeyArg& key) const
410  {
411  return contains(key) ? 1 : 0;
412  }
413 
414  MOMO_FORCEINLINE bool contains(const key_type& key) const
415  {
416  return mHashMap.ContainsKey(key);
417  }
418 
419  template<typename KeyArg>
421  bool> contains(const KeyArg& key) const
422  {
423  return mHashMap.ContainsKey(key);
424  }
425 
426  MOMO_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const key_type& key) const
427  {
428  return { find(key), end() };
429  }
430 
431  MOMO_FORCEINLINE std::pair<iterator, iterator> equal_range(const key_type& key)
432  {
433  return { find(key), end() };
434  }
435 
436  template<typename KeyArg>
438  std::pair<const_iterator, const_iterator>> equal_range(const KeyArg& key) const
439  {
440  return { find(key), end() };
441  }
442 
443  template<typename KeyArg>
445  std::pair<iterator, iterator>> equal_range(const KeyArg& key)
446  {
447  return { find(key), end() };
448  }
449 
450  template<typename ValueArg = std::pair<key_type, mapped_type>>
452  std::pair<iterator, bool>> insert(ValueArg&& valueArg)
453  {
454  return emplace(std::forward<ValueArg>(valueArg));
455  }
456 
457  template<typename ValueArg = std::pair<key_type, mapped_type>>
459  iterator> insert(const_iterator hint, ValueArg&& valueArg)
460  {
461  return emplace_hint(hint, std::forward<ValueArg>(valueArg));
462  }
463 
465  {
466  if (node.empty())
467  return { end(), false, node_type() };
468  typename HashMap::InsertResult res = mHashMap.Insert(
469  std::move(NodeTypeProxy::GetExtractedPair(node)));
471  res.inserted ? node_type() : std::move(node) };
472  }
473 
475  {
476  if MOMO_CONSTEXPR_IF (HashTraits::useHintIterators)
477  {
478  if (node.empty())
479  return end();
480  return momo::internal::ProxyConstructor<iterator>(mHashMap.Add(
481  ConstIteratorProxy::GetBaseIterator(hint),
482  std::move(NodeTypeProxy::GetExtractedPair(node))));
483  }
484  else
485  {
486  return insert(std::move(node)).position;
487  }
488  }
489 
490  template<typename Iterator>
491  void insert(Iterator first, Iterator last)
492  {
493  pvInsertRange(first, last);
494  }
495 
496  void insert(std::initializer_list<value_type> values)
497  {
498  mHashMap.Insert(values.begin(), values.end());
499  }
500 
501 #ifdef MOMO_HAS_CONTAINERS_RANGES
502  template<std::ranges::input_range Range>
503  requires std::convertible_to<std::ranges::range_reference_t<Range>, value_type>
504  void insert_range(Range&& values)
505  {
506  pvInsertRange(std::ranges::begin(values), std::ranges::end(values));
507  }
508 #endif // MOMO_HAS_CONTAINERS_RANGES
509 
510  std::pair<iterator, bool> emplace()
511  {
512  return pvEmplace(nullptr, std::tuple<>(), std::tuple<>());
513  }
514 
516  {
517  return pvEmplace(hint, std::tuple<>(), std::tuple<>()).first;
518  }
519 
520  template<typename ValueArg>
521  std::pair<iterator, bool> emplace(ValueArg&& valueArg)
522  {
523  return pvEmplace(nullptr,
524  std::forward_as_tuple(std::get<0>(std::forward<ValueArg>(valueArg))),
525  std::forward_as_tuple(std::get<1>(std::forward<ValueArg>(valueArg))));
526  }
527 
528  template<typename ValueArg>
529  iterator emplace_hint(const_iterator hint, ValueArg&& valueArg)
530  {
531  return pvEmplace(hint,
532  std::forward_as_tuple(std::get<0>(std::forward<ValueArg>(valueArg))),
533  std::forward_as_tuple(std::get<1>(std::forward<ValueArg>(valueArg)))).first;
534  }
535 
536  template<typename KeyArg, typename MappedArg>
537  std::pair<iterator, bool> emplace(KeyArg&& keyArg, MappedArg&& mappedArg)
538  {
539  return pvEmplace(nullptr, std::forward_as_tuple(std::forward<KeyArg>(keyArg)),
540  std::forward_as_tuple(std::forward<MappedArg>(mappedArg)));
541  }
542 
543  template<typename KeyArg, typename MappedArg>
544  iterator emplace_hint(const_iterator hint, KeyArg&& keyArg, MappedArg&& mappedArg)
545  {
546  return pvEmplace(hint, std::forward_as_tuple(std::forward<KeyArg>(keyArg)),
547  std::forward_as_tuple(std::forward<MappedArg>(mappedArg))).first;
548  }
549 
550  template<typename... KeyArgs, typename... MappedArgs>
551  std::pair<iterator, bool> emplace(std::piecewise_construct_t,
552  std::tuple<KeyArgs...> keyArgs, std::tuple<MappedArgs...> mappedArgs)
553  {
554  return pvEmplace(nullptr, std::move(keyArgs), std::move(mappedArgs));
555  }
556 
557  template<typename... KeyArgs, typename... MappedArgs>
558  iterator emplace_hint(const_iterator hint, std::piecewise_construct_t,
559  std::tuple<KeyArgs...> keyArgs, std::tuple<MappedArgs...> mappedArgs)
560  {
561  return pvEmplace(hint, std::move(keyArgs), std::move(mappedArgs)).first;
562  }
563 
565  {
567  mHashMap.Remove(ConstIteratorProxy::GetBaseIterator(where)));
568  }
569 
571  {
572  return erase(static_cast<const_iterator>(where));
573  }
574 
576  {
577  if (first == begin() && last == end())
578  {
579  clear();
580  return end();
581  }
582  if (first == last)
583  {
584  return momo::internal::ProxyConstructor<iterator>(mHashMap.MakeMutableIterator(
585  ConstIteratorProxy::GetBaseIterator(first)));
586  }
587  if (first != end() && std::next(first) == last)
588  return erase(first);
589  MOMO_THROW(std::invalid_argument("invalid unordered_map erase arguments"));
590  }
591 
593  {
594  return mHashMap.Remove(key) ? 1 : 0;
595  }
596 
597  template<typename ValueFilter>
598  friend size_type erase_if(unordered_map_adaptor& cont, const ValueFilter& valueFilter)
599  {
600  auto pairFilter = [&valueFilter] (const key_type& key, const mapped_type& mapped)
601  { return valueFilter(const_reference(key, mapped)); };
602  return cont.mHashMap.Remove(pairFilter);
603  }
604 
605  MOMO_FORCEINLINE typename HashMap::template ValueReference<key_type&&> operator[](
606  key_type&& key)
607  {
608  return mHashMap[std::move(key)];
609  }
610 
611  MOMO_FORCEINLINE typename HashMap::template ValueReference<const key_type&> operator[](
612  const key_type& key)
613  {
614  return mHashMap[key];
615  }
616 
617  MOMO_FORCEINLINE const mapped_type& at(const key_type& key) const
618  {
619  const_iterator iter = find(key);
620  if (iter == end())
621  MOMO_THROW(std::out_of_range("invalid unordered_map key"));
622  return iter->second;
623  }
624 
626  {
627  iterator iter = find(key);
628  if (iter == end())
629  MOMO_THROW(std::out_of_range("invalid unordered_map key"));
630  return iter->second;
631  }
632 
633  template<typename... MappedArgs>
634  std::pair<iterator, bool> try_emplace(key_type&& key, MappedArgs&&... mappedArgs)
635  {
636  return pvEmplace(nullptr, std::forward_as_tuple(std::move(key)),
637  std::forward_as_tuple(std::forward<MappedArgs>(mappedArgs)...));
638  }
639 
640  template<typename... MappedArgs>
641  iterator try_emplace(const_iterator hint, key_type&& key, MappedArgs&&... mappedArgs)
642  {
643  return pvEmplace(hint, std::forward_as_tuple(std::move(key)),
644  std::forward_as_tuple(std::forward<MappedArgs>(mappedArgs)...)).first;
645  }
646 
647  template<typename... MappedArgs>
648  std::pair<iterator, bool> try_emplace(const key_type& key, MappedArgs&&... mappedArgs)
649  {
650  return pvEmplace(nullptr, std::forward_as_tuple(key),
651  std::forward_as_tuple(std::forward<MappedArgs>(mappedArgs)...));
652  }
653 
654  template<typename... MappedArgs>
655  iterator try_emplace(const_iterator hint, const key_type& key, MappedArgs&&... mappedArgs)
656  {
657  return pvEmplace(hint, std::forward_as_tuple(key),
658  std::forward_as_tuple(std::forward<MappedArgs>(mappedArgs)...)).first;
659  }
660 
661  template<typename MappedArg>
662  std::pair<iterator, bool> insert_or_assign(key_type&& key, MappedArg&& mappedArg)
663  {
664  return pvInsertOrAssign(nullptr, std::move(key), std::forward<MappedArg>(mappedArg));
665  }
666 
667  template<typename MappedArg>
668  iterator insert_or_assign(const_iterator hint, key_type&& key, MappedArg&& mappedArg)
669  {
670  return pvInsertOrAssign(hint, std::move(key), std::forward<MappedArg>(mappedArg)).first;
671  }
672 
673  template<typename MappedArg>
674  std::pair<iterator, bool> insert_or_assign(const key_type& key, MappedArg&& mappedArg)
675  {
676  return pvInsertOrAssign(nullptr, key, std::forward<MappedArg>(mappedArg));
677  }
678 
679  template<typename MappedArg>
680  iterator insert_or_assign(const_iterator hint, const key_type& key, MappedArg&& mappedArg)
681  {
682  return pvInsertOrAssign(hint, key, std::forward<MappedArg>(mappedArg)).first;
683  }
684 
686  {
687  return node_type(*this, where); // need RVO for exception safety
688  }
689 
691  {
692  const_iterator iter = find(key);
693  return (iter != end()) ? extract(iter) : node_type();
694  }
695 
696  template<typename Map>
697  void merge(Map&& map)
698  {
699  mHashMap.MergeFrom(map.get_nested_container());
700  }
701 
702  size_type max_bucket_count() const noexcept
703  {
705  //return momo::internal::HashSetBuckets<Bucket>::maxBucketCount;
706  }
707 
708  size_type bucket_count() const noexcept
709  {
710  return mHashMap.GetBucketCount();
711  }
712 
713  size_type bucket_size(size_type bucketIndex) const
714  {
715  return mHashMap.GetBucketBounds(bucketIndex).GetCount();
716  }
717 
719  {
721  mHashMap.GetBucketBounds(bucketIndex).GetBegin());
722  }
723 
725  {
727  mHashMap.GetBucketBounds(bucketIndex).GetBegin());
728  }
729 
731  {
733  mHashMap.GetBucketBounds(bucketIndex).GetEnd());
734  }
735 
736  const_local_iterator end(size_type bucketIndex) const
737  {
739  mHashMap.GetBucketBounds(bucketIndex).GetEnd());
740  }
741 
743  {
744  return begin(bucketIndex);
745  }
746 
748  {
749  return end(bucketIndex);
750  }
751 
752  size_type bucket(const key_type& key) const
753  {
754  return mHashMap.GetBucketIndex(key);
755  }
756 
757  float load_factor() const noexcept
758  {
759  size_t count = size();
760  size_t bucketCount = bucket_count();
761  if (count == 0 && bucketCount == 0)
762  return 0.0;
763  return static_cast<float>(count) / static_cast<float>(bucketCount);
764  }
765 
766  friend bool operator==(const unordered_map_adaptor& left, const unordered_map_adaptor& right)
767  {
768  if (left.size() != right.size())
769  return false;
770  for (const_reference ref : left)
771  {
772  const_iterator iter = right.find(ref.first);
773  if (iter == right.end())
774  return false;
775  if (!(iter->second == ref.second))
776  return false;
777  }
778  return true;
779  }
780 
781  friend bool operator!=(const unordered_map_adaptor& left, const unordered_map_adaptor& right)
782  {
783  return !(left == right);
784  }
785 
786 private:
787  template<typename Hint, typename... KeyArgs, typename... MappedArgs>
788  std::pair<iterator, bool> pvEmplace(Hint hint, std::tuple<KeyArgs...>&& keyArgs,
789  std::tuple<MappedArgs...>&& mappedArgs)
790  {
791  typedef typename HashMap::KeyValueTraits
792  ::template ValueCreator<MappedArgs...> MappedCreator;
793  return pvInsert(hint, std::move(keyArgs),
794  MappedCreator(mHashMap.GetMemManager(), std::move(mappedArgs)));
795  }
796 
797  template<typename... KeyArgs, typename MappedCreator>
798  std::pair<iterator, bool> pvInsert(std::nullptr_t /*hint*/, std::tuple<KeyArgs...>&& keyArgs,
799  MappedCreator&& mappedCreator)
800  {
801  MemManager& memManager = mHashMap.GetMemManager();
804  typedef typename KeyManager::template Creator<KeyArgs...> KeyCreator;
805  KeyBuffer keyBuffer;
806  KeyCreator(memManager, std::move(keyArgs))(keyBuffer.GetPtr());
807  typename KeyManager::DestroyFinalizer keyFin(&memManager, keyBuffer.Get());
808  typename HashMap::Position pos = mHashMap.Find(keyBuffer.Get());
809  if (!!pos)
810  return { momo::internal::ProxyConstructor<iterator>(pos), false };
811  auto valueCreator = [&mappedCreator, &keyFin] (key_type* newKey, mapped_type* newMapped)
812  {
813  KeyManager::Relocate(*keyFin.GetMemManager(), *keyFin.GetPtr(), newKey);
814  keyFin.ResetPtr();
815  typename KeyManager::DestroyFinalizer newKeyFin(keyFin.GetMemManager(), *newKey);
816  std::forward<MappedCreator>(mappedCreator)(newMapped);
817  newKeyFin.ResetPtr();
818  };
819  typename HashMap::Position resPos = mHashMap.AddCrt(pos, valueCreator);
820  return { momo::internal::ProxyConstructor<iterator>(resPos), true };
821  }
822 
823  template<typename RKey, typename MappedCreator,
824  typename Key = typename std::decay<RKey>::type>
826  std::pair<iterator, bool>> pvInsert(std::nullptr_t /*hint*/, std::tuple<RKey>&& key,
827  MappedCreator&& mappedCreator)
828  {
829  typename HashMap::InsertResult res = mHashMap.InsertCrt(
830  std::forward<RKey>(std::get<0>(key)), std::forward<MappedCreator>(mappedCreator));
831  return { momo::internal::ProxyConstructor<iterator>(res.position), res.inserted };
832  }
833 
834  template<typename... KeyArgs, typename MappedCreator>
835  std::pair<iterator, bool> pvInsert(const_iterator hint, std::tuple<KeyArgs...>&& keyArgs,
836  MappedCreator&& mappedCreator)
837  {
838  if MOMO_CONSTEXPR_IF (HashTraits::useHintIterators)
839  {
840  MemManager& memManager = mHashMap.GetMemManager();
842  typedef typename KeyManager::template Creator<KeyArgs...> KeyCreator;
843  auto valueCreator = [&memManager, &keyArgs, &mappedCreator]
844  (key_type* newKey, mapped_type* newMapped)
845  {
846  KeyCreator(memManager, std::move(keyArgs))(newKey);
847  typename KeyManager::DestroyFinalizer keyFin(&memManager, *newKey);
848  std::forward<MappedCreator>(mappedCreator)(newMapped);
849  keyFin.ResetPtr();
850  };
851  typename HashMap::Position resPos = mHashMap.AddCrt(
852  ConstIteratorProxy::GetBaseIterator(hint), valueCreator);
853  return { momo::internal::ProxyConstructor<iterator>(resPos), true };
854  }
855  else
856  {
857  return pvInsert(nullptr, std::move(keyArgs), std::move(mappedCreator));
858  }
859  }
860 
861  template<typename RKey, typename MappedCreator,
862  typename Key = typename std::decay<RKey>::type>
864  std::pair<iterator, bool>> pvInsert(const_iterator hint, std::tuple<RKey>&& key,
865  MappedCreator&& mappedCreator)
866  {
867  if MOMO_CONSTEXPR_IF (HashTraits::useHintIterators)
868  {
869  typename HashMap::Position resPos = mHashMap.AddCrt(
870  ConstIteratorProxy::GetBaseIterator(hint),
871  std::forward<RKey>(std::get<0>(key)), std::forward<MappedCreator>(mappedCreator));
872  return { momo::internal::ProxyConstructor<iterator>(resPos), true };
873  }
874  else
875  {
876  return pvInsert(nullptr, std::move(key), std::move(mappedCreator));
877  }
878  }
879 
880  template<typename Iterator, typename Sentinel>
882  void> pvInsertRange(Iterator begin, Sentinel end)
883  {
884  mHashMap.Insert(std::move(begin), std::move(end));
885  }
886 
887  template<typename Iterator, typename Sentinel>
889  void> pvInsertRange(Iterator begin, Sentinel end)
890  {
891  for (Iterator iter = std::move(begin); iter != end; ++iter)
892  insert(*iter);
893  }
894 
895  template<typename Hint, typename RKey, typename MappedArg>
896  std::pair<iterator, bool> pvInsertOrAssign(Hint hint, RKey&& key, MappedArg&& mappedArg)
897  {
898  std::pair<iterator, bool> res = pvEmplace(hint,
899  std::forward_as_tuple(std::forward<RKey>(key)),
900  std::forward_as_tuple(std::forward<MappedArg>(mappedArg)));
901  if (!res.second)
902  res.first->second = std::forward<MappedArg>(mappedArg);
903  return res;
904  }
905 
906 private:
907  HashMap mHashMap;
908 };
909 
936 template<typename TKey, typename TMapped,
937  typename THasher = HashCoder<TKey>,
938  typename TEqualComparer = std::equal_to<TKey>,
939  typename TAllocator = std::allocator<std::pair<const TKey, TMapped>>>
940 class unordered_map : public unordered_map_adaptor<HashMap<TKey, TMapped,
941  HashTraitsStd<TKey, THasher, TEqualComparer, HashBucketDefault>, MemManagerStd<TAllocator>>>
942 {
943 private:
944  typedef unordered_map_adaptor<momo::HashMap<TKey, TMapped,
947 
948 public:
949  using UnorderedMapAdaptor::UnorderedMapAdaptor;
950 
951  unordered_map& operator=(std::initializer_list<typename UnorderedMapAdaptor::value_type> values)
952  {
954  return *this;
955  }
956 
957  friend void swap(unordered_map& left, unordered_map& right) noexcept
958  {
959  left.swap(right);
960  }
961 };
962 
972 template<typename TKey, typename TMapped,
973  typename THasher = HashCoder<TKey>,
974  typename TEqualComparer = std::equal_to<TKey>,
975  typename TAllocator = std::allocator<std::pair<const TKey, TMapped>>>
976 class unordered_map_open : public unordered_map_adaptor<HashMap<TKey, TMapped,
977  HashTraitsStd<TKey, THasher, TEqualComparer, HashBucketOpenDefault>, MemManagerStd<TAllocator>>>
978 {
979 private:
980  typedef unordered_map_adaptor<momo::HashMap<TKey, TMapped,
983 
984 public:
985  using UnorderedMapAdaptor::UnorderedMapAdaptor;
986 
987  unordered_map_open& operator=(std::initializer_list<typename UnorderedMapAdaptor::value_type> values)
988  {
990  return *this;
991  }
992 
993  friend void swap(unordered_map_open& left, unordered_map_open& right) noexcept
994  {
995  left.swap(right);
996  }
997 };
998 
999 #ifdef MOMO_HAS_DEDUCTION_GUIDES
1000 
1001 #define MOMO_DECLARE_DEDUCTION_GUIDES(unordered_map) \
1002 template<typename Iterator, \
1003  typename Value = typename std::iterator_traits<Iterator>::value_type, \
1004  typename Key = std::decay_t<typename Value::first_type>, \
1005  typename Mapped = std::decay_t<typename Value::second_type>> \
1006 unordered_map(Iterator, Iterator) \
1007  -> unordered_map<Key, Mapped>; \
1008 template<typename Iterator, \
1009  typename Value = typename std::iterator_traits<Iterator>::value_type, \
1010  typename Key = std::decay_t<typename Value::first_type>, \
1011  typename Mapped = std::decay_t<typename Value::second_type>, \
1012  typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
1013  typename = internal::hash_checker<Key, Allocator, HashCoder<Key>>> \
1014 unordered_map(Iterator, Iterator, size_t, Allocator = Allocator()) \
1015  -> unordered_map<Key, Mapped, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
1016 template<typename Iterator, typename Hasher, \
1017  typename Value = typename std::iterator_traits<Iterator>::value_type, \
1018  typename Key = std::decay_t<typename Value::first_type>, \
1019  typename Mapped = std::decay_t<typename Value::second_type>, \
1020  typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
1021  typename = internal::hash_checker<Key, Allocator, Hasher>> \
1022 unordered_map(Iterator, Iterator, size_t, Hasher, Allocator = Allocator()) \
1023  -> unordered_map<Key, Mapped, Hasher, std::equal_to<Key>, Allocator>; \
1024 template<typename Iterator, typename Hasher, typename EqualComparer, \
1025  typename Value = typename std::iterator_traits<Iterator>::value_type, \
1026  typename Key = std::decay_t<typename Value::first_type>, \
1027  typename Mapped = std::decay_t<typename Value::second_type>, \
1028  typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
1029  typename = internal::hash_checker<Key, Allocator, Hasher, EqualComparer>> \
1030 unordered_map(Iterator, Iterator, size_t, Hasher, EqualComparer, Allocator = Allocator()) \
1031  -> unordered_map<Key, Mapped, Hasher, EqualComparer, Allocator>; \
1032 template<typename QKey, typename Mapped, \
1033  typename Key = std::remove_const_t<QKey>> \
1034 unordered_map(std::initializer_list<std::pair<QKey, Mapped>>) \
1035  -> unordered_map<Key, Mapped>; \
1036 template<typename QKey, typename Mapped, \
1037  typename Key = std::remove_const_t<QKey>, \
1038  typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
1039  typename = internal::hash_checker<Key, Allocator, HashCoder<Key>>> \
1040 unordered_map(std::initializer_list<std::pair<QKey, Mapped>>, size_t, Allocator = Allocator()) \
1041  -> unordered_map<Key, Mapped, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
1042 template<typename QKey, typename Mapped, typename Hasher, \
1043  typename Key = std::remove_const_t<QKey>, \
1044  typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
1045  typename = internal::hash_checker<Key, Allocator, Hasher>> \
1046 unordered_map(std::initializer_list<std::pair<QKey, Mapped>>, size_t, Hasher, Allocator = Allocator()) \
1047  -> unordered_map<Key, Mapped, Hasher, std::equal_to<Key>, Allocator>; \
1048 template<typename QKey, typename Mapped, typename Hasher, typename EqualComparer, \
1049  typename Key = std::remove_const_t<QKey>, \
1050  typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
1051  typename = internal::hash_checker<Key, Allocator, Hasher, EqualComparer>> \
1052 unordered_map(std::initializer_list<std::pair<QKey, Mapped>>, size_t, \
1053  Hasher, EqualComparer, Allocator = Allocator()) \
1054  -> unordered_map<Key, Mapped, Hasher, EqualComparer, Allocator>; \
1055 template<typename Key, typename Mapped, typename Hasher, typename EqualComparer, typename Allocator> \
1056 unordered_map(unordered_map<Key, Mapped, Hasher, EqualComparer, Allocator>, \
1057  momo::internal::Identity<Allocator>) \
1058  -> unordered_map<Key, Mapped, Hasher, EqualComparer, Allocator>;
1059 
1060 MOMO_DECLARE_DEDUCTION_GUIDES(unordered_map)
1061 MOMO_DECLARE_DEDUCTION_GUIDES(unordered_map_open)
1062 
1063 #undef MOMO_DECLARE_DEDUCTION_GUIDES
1064 
1065 #ifdef MOMO_HAS_CONTAINERS_RANGES
1066 
1067 #define MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_map) \
1068 template<std::ranges::input_range Range, \
1069  typename Value = std::ranges::range_value_t<Range>, \
1070  typename Key = std::decay_t<typename Value::first_type>, \
1071  typename Mapped = std::decay_t<typename Value::second_type>> \
1072 unordered_map(std::from_range_t, Range&&) \
1073  -> unordered_map<Key, Mapped>; \
1074 template<std::ranges::input_range Range, \
1075  typename Value = std::ranges::range_value_t<Range>, \
1076  typename Key = std::decay_t<typename Value::first_type>, \
1077  typename Mapped = std::decay_t<typename Value::second_type>, \
1078  typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
1079  typename = internal::hash_checker<Key, Allocator, HashCoder<Key>>> \
1080 unordered_map(std::from_range_t, Range&&, size_t, Allocator = Allocator()) \
1081  -> unordered_map<Key, Mapped, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
1082 template<std::ranges::input_range Range, typename Hasher, \
1083  typename Value = std::ranges::range_value_t<Range>, \
1084  typename Key = std::decay_t<typename Value::first_type>, \
1085  typename Mapped = std::decay_t<typename Value::second_type>, \
1086  typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
1087  typename = internal::hash_checker<Key, Allocator, Hasher>> \
1088 unordered_map(std::from_range_t, Range&&, size_t, Hasher, Allocator = Allocator()) \
1089  -> unordered_map<Key, Mapped, Hasher, std::equal_to<Key>, Allocator>; \
1090 template<std::ranges::input_range Range, typename Hasher, typename EqualComparer, \
1091  typename Value = std::ranges::range_value_t<Range>, \
1092  typename Key = std::decay_t<typename Value::first_type>, \
1093  typename Mapped = std::decay_t<typename Value::second_type>, \
1094  typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
1095  typename = internal::hash_checker<Key, Allocator, Hasher, EqualComparer>> \
1096 unordered_map(std::from_range_t, Range&&, size_t, Hasher, EqualComparer, Allocator = Allocator()) \
1097  -> unordered_map<Key, Mapped, Hasher, EqualComparer, Allocator>;
1098 
1099 MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_map)
1100 MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_map_open)
1101 
1102 #undef MOMO_DECLARE_DEDUCTION_GUIDES_RANGES
1103 
1104 #endif // MOMO_HAS_CONTAINERS_RANGES
1105 
1106 #endif // MOMO_HAS_DEDUCTION_GUIDES
1107 
1108 } // namespace stdish
1109 
1110 } // namespace momo
1111 
1112 #endif // MOMO_INCLUDE_GUARD_STDISH_UNORDERED_MAP
momo::internal::ObjectManager
Definition: ObjectManager.h:394
momo::stdish::unordered_map_adaptor::difference_type
ptrdiff_t difference_type
Definition: unordered_map.h:49
momo::internal::HashMapPosition
Definition: HashMap.h:99
momo::stdish::unordered_map_adaptor::allocator_type
std::allocator_traits< typename MemManager::ByteAllocator >::template rebind_alloc< value_type > allocator_type
Definition: unordered_map.h:53
momo::internal::InsertResult::position
Position position
Definition: IteratorUtility.h:132
momo::internal::UIntConst::maxSize
static const size_t maxSize
Definition: Utility.h:476
momo::stdish::unordered_map_adaptor::get_nested_container
const nested_container_type & get_nested_container() const noexcept
Definition: unordered_map.h:272
momo::stdish::unordered_map_adaptor::erase
iterator erase(const_iterator where)
Definition: unordered_map.h:564
MOMO_DECLARE_PROXY_FUNCTION
#define MOMO_DECLARE_PROXY_FUNCTION(Class, Func)
Definition: Utility.h:116
momo::internal::HashDerivedIterator::Reference
TReference< typename BaseIterator::Reference > Reference
Definition: IteratorUtility.h:340
momo::stdish::unordered_map_adaptor::insert
void insert(Iterator first, Iterator last)
Definition: unordered_map.h:491
momo::stdish::unordered_map_adaptor::emplace
std::pair< iterator, bool > emplace(KeyArg &&keyArg, MappedArg &&mappedArg)
Definition: unordered_map.h:537
MOMO_THROW
#define MOMO_THROW(exception)
Definition: UserSettings.h:191
momo::stdish::map
momo::stdish::map is similar to std::map, but much more efficient in memory usage....
Definition: map.h:1012
momo::internal::UIntMath::Max
static constexpr UInt Max(UInt value1, UInt value2) noexcept
Definition: Utility.h:352
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(size_type bucketCount, const hasher &hashFunc, const key_equal &equalComp, const allocator_type &alloc=allocator_type())
Definition: unordered_map.h:119
momo::internal::HashMapBucketBounds::Iterator
HashMapIterator< typename HashSetBucketBounds::Iterator, isConst > Iterator
Definition: HashMap.h:207
momo::stdish::unordered_map_adaptor::iterator
momo::internal::HashDerivedIterator< HashMapIterator, momo::internal::MapReferenceStd > iterator
Definition: unordered_map.h:56
momo::stdish::unordered_map_adaptor::node_type
internal::map_node_handle< typename HashMap::ExtractedPair > node_type
Definition: unordered_map.h:67
momo::stdish::unordered_map_adaptor::erase_if
friend size_type erase_if(unordered_map_adaptor &cont, const ValueFilter &valueFilter)
Definition: unordered_map.h:598
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(Iterator first, Iterator last, size_type bucketCount, const hasher &hashFunc, const allocator_type &alloc=allocator_type())
Definition: unordered_map.h:140
momo::stdish::unordered_map_adaptor::erase
iterator erase(iterator where)
Definition: unordered_map.h:570
momo::stdish::unordered_map::swap
friend void swap(unordered_map &left, unordered_map &right) noexcept
Definition: unordered_map.h:957
momo::stdish::unordered_map_adaptor::get_nested_container
nested_container_type & get_nested_container() noexcept
Definition: unordered_map.h:277
momo::stdish::unordered_map_adaptor::merge
void merge(Map &&map)
Definition: unordered_map.h:697
momo::stdish::unordered_map_adaptor::~unordered_map_adaptor
~unordered_map_adaptor()=default
momo::stdish::unordered_map_adaptor::operator==
friend bool operator==(const unordered_map_adaptor &left, const unordered_map_adaptor &right)
Definition: unordered_map.h:766
momo::stdish::unordered_map_adaptor::insert
momo::internal::EnableIf< std::is_constructible< value_type, ValueArg && >::value, iterator > insert(const_iterator hint, ValueArg &&valueArg)
Definition: unordered_map.h:459
momo::stdish::unordered_map_adaptor::size
size_type size() const noexcept
Definition: unordered_map.h:350
momo::stdish::unordered_map_adaptor::operator=
unordered_map_adaptor & operator=(const unordered_map_adaptor &right)
Definition: unordered_map.h:251
momo::stdish::unordered_map_adaptor::cend
const_local_iterator cend(size_type bucketIndex) const
Definition: unordered_map.h:747
momo::stdish::unordered_map_adaptor::emplace
std::pair< iterator, bool > emplace(ValueArg &&valueArg)
Definition: unordered_map.h:521
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(const unordered_map_adaptor &right)
Definition: unordered_map.h:233
momo::HashMapCore::InsertResult
internal::InsertResult< Position > InsertResult
Definition: HashMap.h:363
momo::HashMapCore
Definition: HashMap.h:334
set_map_utility.h
momo::stdish::unordered_map_adaptor::find
MOMO_FORCEINLINE iterator find(const key_type &key)
Definition: unordered_map.h:383
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(size_type bucketCount, const allocator_type &alloc=allocator_type())
Definition: unordered_map.h:108
momo::stdish::unordered_map_adaptor::end
local_iterator end(size_type bucketIndex)
Definition: unordered_map.h:730
momo::stdish::internal::insert_return_type
Definition: set_map_utility.h:202
momo::stdish::unordered_map_open
momo::stdish::unordered_map_open is similar to std::unordered_map, but much more efficient in operati...
Definition: unordered_map.h:978
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(Iterator first, Iterator last, size_type bucketCount, const allocator_type &alloc=allocator_type())
Definition: unordered_map.h:132
momo::stdish::unordered_map_adaptor::emplace_hint
iterator emplace_hint(const_iterator hint, std::piecewise_construct_t, std::tuple< KeyArgs... > keyArgs, std::tuple< MappedArgs... > mappedArgs)
Definition: unordered_map.h:558
momo::stdish::unordered_map_adaptor::emplace
std::pair< iterator, bool > emplace()
Definition: unordered_map.h:510
momo::stdish::unordered_map_adaptor::count
MOMO_FORCEINLINE size_type count(const key_type &key) const
Definition: unordered_map.h:402
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor()
Definition: unordered_map.h:99
momo::internal::UIntMath::Log2
static UInt Log2(UInt value) noexcept
Definition: Utility.h:414
momo::internal::HashMapIterator
Definition: HashMap.h:34
momo::internal::ProxyConstructor
Definition: Utility.h:238
momo::stdish::unordered_map_adaptor::bucket_size
size_type bucket_size(size_type bucketIndex) const
Definition: unordered_map.h:713
momo::HashMapCore::bucketMaxItemCount
static const size_t bucketMaxItemCount
Definition: HashMap.h:370
momo::stdish::unordered_map_adaptor::max_bucket_count
size_type max_bucket_count() const noexcept
Definition: unordered_map.h:702
momo::stdish::unordered_map_adaptor::emplace_hint
iterator emplace_hint(const_iterator hint, KeyArg &&keyArg, MappedArg &&mappedArg)
Definition: unordered_map.h:544
momo::HashMapCore::Key
KeyValueTraits::Key Key
Definition: HashMap.h:339
momo::stdish::unordered_map_adaptor::at
MOMO_FORCEINLINE const mapped_type & at(const key_type &key) const
Definition: unordered_map.h:617
momo::MemManagerStd
MemManagerStd uses allocator<unsigned char>::allocate and deallocate
Definition: MemManager.h:179
momo::stdish::unordered_map_adaptor::reserve
void reserve(size_type count)
Definition: unordered_map.h:373
momo::stdish::unordered_map_adaptor::key_eq
key_equal key_eq() const
Definition: unordered_map.h:335
momo::stdish::unordered_map_adaptor::equal_range
MOMO_FORCEINLINE std::pair< const_iterator, const_iterator > equal_range(const key_type &key) const
Definition: unordered_map.h:426
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(std::initializer_list< value_type > values, size_type bucketCount, const hasher &hashFunc, const key_equal &equalComp, const allocator_type &alloc=allocator_type())
Definition: unordered_map.h:172
momo::stdish::unordered_map_adaptor::insert
iterator insert(const_iterator hint, node_type &&node)
Definition: unordered_map.h:474
momo::stdish::unordered_map_adaptor::begin
const_iterator begin() const noexcept
Definition: unordered_map.h:282
momo::stdish::unordered_map_adaptor::load_factor
float load_factor() const noexcept
Definition: unordered_map.h:757
momo::HashMapCore::MemManager
KeyValueTraits::MemManager MemManager
Definition: HashMap.h:341
momo::stdish::unordered_map_adaptor::at
MOMO_FORCEINLINE mapped_type & at(const key_type &key)
Definition: unordered_map.h:625
momo::internal::ContainerAssignerStd::Move
static Container & Move(Container &&srcCont, Container &dstCont) noexcept(IsNothrowMoveAssignable< Container >::value)
Definition: Utility.h:515
momo::internal::InsertResult
Definition: IteratorUtility.h:100
momo::stdish::unordered_map_adaptor::bucket_count
size_type bucket_count() const noexcept
Definition: unordered_map.h:708
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(size_type bucketCount, const hasher &hashFunc, const allocator_type &alloc=allocator_type())
Definition: unordered_map.h:113
momo::stdish::unordered_map_adaptor::extract
node_type extract(const_iterator where)
Definition: unordered_map.h:685
momo::stdish::unordered_map_adaptor::insert_return_type
internal::insert_return_type< iterator, node_type > insert_return_type
Definition: unordered_map.h:68
momo::stdish::unordered_map_adaptor::equal_range
MOMO_FORCEINLINE momo::internal::EnableIf< IsValidKeyArg< KeyArg >::value, std::pair< const_iterator, const_iterator > > equal_range(const KeyArg &key) const
Definition: unordered_map.h:438
momo::stdish::unordered_map_adaptor::size_type
size_t size_type
Definition: unordered_map.h:48
momo::stdish::internal::map_node_handle
Definition: set_map_utility.h:112
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(std::initializer_list< value_type > values)
Definition: unordered_map.h:155
momo::stdish::unordered_map_adaptor::insert_or_assign
iterator insert_or_assign(const_iterator hint, key_type &&key, MappedArg &&mappedArg)
Definition: unordered_map.h:668
momo::stdish::unordered_map_adaptor::operator=
unordered_map_adaptor & operator=(unordered_map_adaptor &&right) noexcept(momo::internal::ContainerAssignerStd::IsNothrowMoveAssignable< unordered_map_adaptor >::value)
Definition: unordered_map.h:245
momo::internal::EnableIf
typename std::enable_if< value, Type >::type EnableIf
Definition: Utility.h:199
momo::stdish::unordered_map_adaptor::key_equal
HashTraits::EqualComparer key_equal
Definition: unordered_map.h:44
momo
Definition: Array.h:27
momo::HashMapCore::HashTraits
THashTraits HashTraits
Definition: HashMap.h:337
momo::stdish::unordered_map_adaptor::reference
iterator::Reference reference
Definition: unordered_map.h:59
momo::stdish::unordered_map
momo::stdish::unordered_map is similar to std::unordered_map, but much more efficient in memory usage...
Definition: unordered_map.h:942
momo::stdish::unordered_map_adaptor::rehash
void rehash(size_type bucketCount)
Definition: unordered_map.h:365
momo::stdish::unordered_map_adaptor::const_iterator
iterator::ConstIterator const_iterator
Definition: unordered_map.h:57
momo::stdish::unordered_map_adaptor::cend
const_iterator cend() const noexcept
Definition: unordered_map.h:307
momo::internal::ContainerAssignerStd::IsNothrowMoveAssignable
BoolConstant< std::is_empty< Allocator >::value||std::allocator_traits< Allocator >::propagate_on_container_move_assignment::value > IsNothrowMoveAssignable
Definition: Utility.h:511
momo::stdish::unordered_map_adaptor::count
MOMO_FORCEINLINE momo::internal::EnableIf< IsValidKeyArg< KeyArg >::value, size_type > count(const KeyArg &key) const
Definition: unordered_map.h:409
momo::HashCoder< TKey >
momo::stdish::unordered_map_adaptor::find
MOMO_FORCEINLINE momo::internal::EnableIf< IsValidKeyArg< KeyArg >::value, iterator > find(const KeyArg &key)
Definition: unordered_map.h:397
momo::stdish::unordered_map_adaptor::insert_or_assign
std::pair< iterator, bool > insert_or_assign(const key_type &key, MappedArg &&mappedArg)
Definition: unordered_map.h:674
momo::stdish::unordered_map_adaptor::cbegin
const_local_iterator cbegin(size_type bucketIndex) const
Definition: unordered_map.h:742
momo::internal::IteratorPointer
Definition: IteratorUtility.h:228
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(const unordered_map_adaptor &right, const allocator_type &alloc)
Definition: unordered_map.h:238
momo::stdish::unordered_map_adaptor::const_reference
const_iterator::Reference const_reference
Definition: unordered_map.h:60
momo::stdish::unordered_map_adaptor::insert_or_assign
iterator insert_or_assign(const_iterator hint, const key_type &key, MappedArg &&mappedArg)
Definition: unordered_map.h:680
momo::internal::InsertResult::inserted
bool inserted
Definition: IteratorUtility.h:135
momo::stdish::unordered_map_adaptor::operator[]
MOMO_FORCEINLINE HashMap::template ValueReference< const key_type & > operator[](const key_type &key)
Definition: unordered_map.h:611
momo::stdish::unordered_map_adaptor
Definition: unordered_map.h:32
momo::stdish::unordered_map_adaptor::bucket
size_type bucket(const key_type &key) const
Definition: unordered_map.h:752
momo::stdish::unordered_map_adaptor::nested_container_type
HashMap nested_container_type
Definition: unordered_map.h:46
momo::stdish::unordered_map_adaptor::find
MOMO_FORCEINLINE momo::internal::EnableIf< IsValidKeyArg< KeyArg >::value, const_iterator > find(const KeyArg &key) const
Definition: unordered_map.h:390
momo::stdish::unordered_map_adaptor::insert
momo::internal::EnableIf< std::is_constructible< value_type, ValueArg && >::value, std::pair< iterator, bool > > insert(ValueArg &&valueArg)
Definition: unordered_map.h:452
momo::stdish::unordered_map_adaptor::equal_range
MOMO_FORCEINLINE momo::internal::EnableIf< IsValidKeyArg< KeyArg >::value, std::pair< iterator, iterator > > equal_range(const KeyArg &key)
Definition: unordered_map.h:445
momo::stdish::unordered_map_open::swap
friend void swap(unordered_map_open &left, unordered_map_open &right) noexcept
Definition: unordered_map.h:993
momo::stdish::unordered_map_adaptor::const_pointer
const_iterator::Pointer const_pointer
Definition: unordered_map.h:63
momo::stdish::unordered_map_adaptor::get_allocator
allocator_type get_allocator() const noexcept
Definition: unordered_map.h:340
momo::HashTraitsStd
Definition: HashTraits.h:196
momo::internal::HashDerivedIterator
Definition: IteratorUtility.h:335
momo::stdish::unordered_map_open::operator=
unordered_map_open & operator=(std::initializer_list< typename UnorderedMapAdaptor::value_type > values)
Definition: unordered_map.h:987
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(std::initializer_list< value_type > values, size_type bucketCount, const allocator_type &alloc=allocator_type())
Definition: unordered_map.h:160
momo::stdish::unordered_map_adaptor::equal_range
MOMO_FORCEINLINE std::pair< iterator, iterator > equal_range(const key_type &key)
Definition: unordered_map.h:431
momo::stdish::unordered_map_adaptor::operator!=
friend bool operator!=(const unordered_map_adaptor &left, const unordered_map_adaptor &right)
Definition: unordered_map.h:781
momo::stdish::unordered_map_adaptor::try_emplace
std::pair< iterator, bool > try_emplace(const key_type &key, MappedArgs &&... mappedArgs)
Definition: unordered_map.h:648
momo::stdish::unordered_map_adaptor::operator[]
MOMO_FORCEINLINE HashMap::template ValueReference< key_type && > operator[](key_type &&key)
Definition: unordered_map.h:605
momo::stdish::unordered_map_adaptor::insert
insert_return_type insert(node_type &&node)
Definition: unordered_map.h:464
momo::stdish::unordered_map_adaptor::try_emplace
std::pair< iterator, bool > try_emplace(key_type &&key, MappedArgs &&... mappedArgs)
Definition: unordered_map.h:634
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(std::initializer_list< value_type > values, size_type bucketCount, const hasher &hashFunc, const allocator_type &alloc=allocator_type())
Definition: unordered_map.h:166
momo::stdish::unordered_map_adaptor::end
const_iterator end() const noexcept
Definition: unordered_map.h:292
momo::stdish::unordered_map_adaptor::local_iterator
momo::internal::HashDerivedIterator< typename HashMap::BucketBounds::Iterator, momo::internal::MapReferenceStd > local_iterator
Definition: unordered_map.h:71
momo::stdish::unordered_map_adaptor::end
iterator end() noexcept
Definition: unordered_map.h:297
momo::internal::ObjectBuffer
Definition: ObjectManager.h:190
MOMO_CONSTEXPR_IF
#define MOMO_CONSTEXPR_IF
Definition: UserSettings.h:228
momo::stdish::unordered_map_adaptor::value_type
std::pair< const key_type, mapped_type > value_type
Definition: unordered_map.h:51
std
Definition: Array.h:1178
momo::stdish::unordered_map_adaptor::extract
node_type extract(const key_type &key)
Definition: unordered_map.h:690
momo::stdish::unordered_map_adaptor::operator=
unordered_map_adaptor & operator=(std::initializer_list< value_type > values)
Definition: unordered_map.h:256
MOMO_FORCEINLINE
#define MOMO_FORCEINLINE
Definition: UserSettings.h:125
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(unordered_map_adaptor &&right)
Definition: unordered_map.h:214
momo::stdish::unordered_map_adaptor::try_emplace
iterator try_emplace(const_iterator hint, key_type &&key, MappedArgs &&... mappedArgs)
Definition: unordered_map.h:641
momo::stdish::unordered_map_adaptor::erase
size_type erase(const key_type &key)
Definition: unordered_map.h:592
momo::HashMapCore::Value
KeyValueTraits::Value Value
Definition: HashMap.h:340
momo::stdish::unordered_map_adaptor::insert
void insert(std::initializer_list< value_type > values)
Definition: unordered_map.h:496
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(unordered_map_adaptor &&right, const allocator_type &alloc)
Definition: unordered_map.h:219
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(Iterator first, Iterator last, size_type bucketCount, const hasher &hashFunc, const key_equal &equalComp, const allocator_type &alloc=allocator_type())
Definition: unordered_map.h:148
momo::stdish::unordered_map_adaptor::empty
MOMO_NODISCARD bool empty() const noexcept
Definition: unordered_map.h:355
momo::stdish::unordered_map_adaptor::hasher
HashTraits::Hasher hasher
Definition: unordered_map.h:43
momo::stdish::unordered_map_adaptor::max_load_factor
void max_load_factor(float maxLoadFactor)
Definition: unordered_map.h:317
momo::stdish::unordered_map_adaptor::max_size
size_type max_size() const noexcept
Definition: unordered_map.h:345
momo::stdish::unordered_map_adaptor::erase
iterator erase(const_iterator first, const_iterator last)
Definition: unordered_map.h:575
momo::stdish::unordered_map_adaptor::pointer
iterator::Pointer pointer
Definition: unordered_map.h:62
momo::stdish::unordered_map_adaptor::emplace
std::pair< iterator, bool > emplace(std::piecewise_construct_t, std::tuple< KeyArgs... > keyArgs, std::tuple< MappedArgs... > mappedArgs)
Definition: unordered_map.h:551
momo::stdish::unordered_map_adaptor::key_type
HashMap::Key key_type
Definition: unordered_map.h:41
momo::stdish::unordered_map_adaptor::swap
friend void swap(unordered_map_adaptor &left, unordered_map_adaptor &right) noexcept
Definition: unordered_map.h:267
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(Iterator first, Iterator last)
Definition: unordered_map.h:126
momo::stdish::unordered_map_adaptor::try_emplace
iterator try_emplace(const_iterator hint, const key_type &key, MappedArgs &&... mappedArgs)
Definition: unordered_map.h:655
momo::stdish::unordered_map_adaptor::begin
local_iterator begin(size_type bucketIndex)
Definition: unordered_map.h:718
momo::stdish::unordered_map_adaptor::mapped_type
HashMap::Value mapped_type
Definition: unordered_map.h:42
momo::stdish::unordered_map_adaptor::contains
MOMO_FORCEINLINE momo::internal::EnableIf< IsValidKeyArg< KeyArg >::value, bool > contains(const KeyArg &key) const
Definition: unordered_map.h:421
momo::stdish::unordered_map_adaptor::end
const_local_iterator end(size_type bucketIndex) const
Definition: unordered_map.h:736
momo::stdish::unordered_map_adaptor::begin
const_local_iterator begin(size_type bucketIndex) const
Definition: unordered_map.h:724
momo::stdish::unordered_map_adaptor::clear
void clear() noexcept
Definition: unordered_map.h:360
momo::internal::ContainerAssignerStd::Copy
static Container & Copy(const Container &srcCont, Container &dstCont)
Definition: Utility.h:531
momo::stdish::unordered_map_adaptor::find
MOMO_FORCEINLINE const_iterator find(const key_type &key) const
Definition: unordered_map.h:378
momo::stdish::unordered_map_adaptor::emplace_hint
iterator emplace_hint(const_iterator hint)
Definition: unordered_map.h:515
momo::stdish::unordered_map_adaptor::unordered_map_adaptor
unordered_map_adaptor(const allocator_type &alloc)
Definition: unordered_map.h:103
momo::stdish::unordered_map_adaptor::max_load_factor
float max_load_factor() const noexcept
Definition: unordered_map.h:312
momo::stdish::unordered_map_adaptor::begin
iterator begin() noexcept
Definition: unordered_map.h:287
momo::stdish::unordered_map_adaptor::insert_or_assign
std::pair< iterator, bool > insert_or_assign(key_type &&key, MappedArg &&mappedArg)
Definition: unordered_map.h:662
momo::stdish::unordered_map_adaptor::const_local_iterator
local_iterator::ConstIterator const_local_iterator
Definition: unordered_map.h:72
momo::stdish::unordered_map_adaptor::hash_function
hasher hash_function() const
Definition: unordered_map.h:330
momo::stdish::unordered_map_adaptor::contains
MOMO_FORCEINLINE bool contains(const key_type &key) const
Definition: unordered_map.h:414
momo::internal::ContainerAssignerStd::Swap
static void Swap(Container &cont1, Container &cont2) noexcept
Definition: Utility.h:546
momo::stdish::unordered_map::operator=
unordered_map & operator=(std::initializer_list< typename UnorderedMapAdaptor::value_type > values)
Definition: unordered_map.h:951
momo::HashMapCore::Position
internal::HashMapPosition< HashSetConstPosition > Position
Definition: HashMap.h:360
MOMO_NODISCARD
#define MOMO_NODISCARD
Definition: UserSettings.h:262
momo::stdish::unordered_map_adaptor::cbegin
const_iterator cbegin() const noexcept
Definition: unordered_map.h:302
momo::stdish::unordered_map_adaptor::swap
void swap(unordered_map_adaptor &right) noexcept
Definition: unordered_map.h:262
momo::stdish::unordered_map_adaptor::emplace_hint
iterator emplace_hint(const_iterator hint, ValueArg &&valueArg)
Definition: unordered_map.h:529
momo::internal::MapReferenceStd
Definition: MapUtility.h:68
momo::HashMap
HashMapCore< HashMapKeyValueTraits< TKey, TValue, TMemManager >, THashTraits > HashMap
Definition: HashMap.h:856