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