29 #ifndef _GLIBCXX_DEBUG_UNORDERED_MAP
30 #define _GLIBCXX_DEBUG_UNORDERED_MAP 1
32 #if __cplusplus < 201103L
41 namespace std _GLIBCXX_VISIBILITY(default)
46 template<
typename _Key,
typename _Tp,
51 :
public _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>,
53 _Hash, _Pred, _Alloc> >
55 typedef _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash,
58 typedef typename _Base::const_iterator _Base_const_iterator;
59 typedef typename _Base::iterator _Base_iterator;
60 typedef typename _Base::const_local_iterator _Base_const_local_iterator;
61 typedef typename _Base::local_iterator _Base_local_iterator;
64 typedef typename _Base::size_type size_type;
65 typedef typename _Base::hasher hasher;
66 typedef typename _Base::key_equal key_equal;
67 typedef typename _Base::allocator_type allocator_type;
69 typedef typename _Base::key_type key_type;
70 typedef typename _Base::value_type value_type;
83 const hasher& __hf = hasher(),
84 const key_equal& __eql = key_equal(),
85 const allocator_type& __a = allocator_type())
86 :
_Base(__n, __hf, __eql, __a) { }
88 template<
typename _InputIterator>
91 const hasher& __hf = hasher(),
92 const key_equal& __eql = key_equal(),
93 const allocator_type& __a = allocator_type())
108 const hasher& __hf = hasher(),
109 const key_equal& __eql = key_equal(),
110 const allocator_type& __a = allocator_type())
111 :
_Base(__l, __n, __hf, __eql, __a) { }
118 *
static_cast<_Base*
>(
this) = __x;
119 this->_M_invalidate_all();
128 __glibcxx_check_self_move_assign(__x);
153 this->_M_invalidate_all();
158 {
return iterator(_Base::begin(),
this); }
161 begin()
const noexcept
166 {
return iterator(_Base::end(),
this); }
173 cbegin()
const noexcept
177 cend()
const noexcept
184 __glibcxx_check_bucket_index(__b);
191 __glibcxx_check_bucket_index(__b);
196 begin(size_type __b)
const
198 __glibcxx_check_bucket_index(__b);
203 end(size_type __b)
const
205 __glibcxx_check_bucket_index(__b);
210 cbegin(size_type __b)
const
212 __glibcxx_check_bucket_index(__b);
217 cend(size_type __b)
const
219 __glibcxx_check_bucket_index(__b);
224 bucket_size(size_type __b)
const
226 __glibcxx_check_bucket_index(__b);
227 return _Base::bucket_size(__b);
231 max_load_factor()
const noexcept
232 {
return _Base::max_load_factor(); }
235 max_load_factor(
float __f)
237 __glibcxx_check_max_load_factor(__f);
238 _Base::max_load_factor(__f);
241 template<
typename... _Args>
243 emplace(_Args&&... __args)
245 size_type __bucket_count = this->bucket_count();
247 = _Base::emplace(std::forward<_Args>(__args)...);
248 _M_check_rehashed(__bucket_count);
252 template<
typename... _Args>
257 size_type __bucket_count = this->bucket_count();
258 _Base_iterator __it = _Base::emplace_hint(__hint.
base(),
259 std::forward<_Args>(__args)...);
260 _M_check_rehashed(__bucket_count);
265 insert(
const value_type& __obj)
267 size_type __bucket_count = this->bucket_count();
269 _M_check_rehashed(__bucket_count);
277 size_type __bucket_count = this->bucket_count();
278 _Base_iterator __it = _Base::insert(__hint.
base(), __obj);
279 _M_check_rehashed(__bucket_count);
283 template<
typename _Pair,
typename =
typename
285 _Pair&&>::value>::type>
287 insert(_Pair&& __obj)
289 size_type __bucket_count = this->bucket_count();
291 _Base::insert(std::forward<_Pair>(__obj));
292 _M_check_rehashed(__bucket_count);
296 template<
typename _Pair,
typename =
typename
298 _Pair&&>::value>::type>
303 size_type __bucket_count = this->bucket_count();
304 _Base_iterator __it =
305 _Base::insert(__hint.
base(), std::forward<_Pair>(__obj));
306 _M_check_rehashed(__bucket_count);
313 size_type __bucket_count = this->bucket_count();
315 _M_check_rehashed(__bucket_count);
318 template<
typename _InputIterator>
320 insert(_InputIterator __first, _InputIterator __last)
322 __glibcxx_check_valid_range(__first, __last);
323 size_type __bucket_count = this->bucket_count();
326 _M_check_rehashed(__bucket_count);
330 find(
const key_type& __key)
331 {
return iterator(_Base::find(__key),
this); }
334 find(
const key_type& __key)
const
338 equal_range(
const key_type& __key)
341 _Base::equal_range(__key);
347 equal_range(
const key_type& __key)
const
350 _Base::equal_range(__key);
356 erase(
const key_type& __key)
359 _Base_iterator __victim(_Base::find(__key));
360 if (__victim != _Base::end())
363 {
return __it == __victim; });
365 [__victim](_Base_const_local_iterator __it)
366 {
return __it._M_cur == __victim._M_cur; });
367 size_type __bucket_count = this->bucket_count();
368 _Base::erase(__victim);
369 _M_check_rehashed(__bucket_count);
379 _Base_const_iterator __victim = __it.
base();
381 {
return __it == __victim; });
383 [__victim](_Base_const_local_iterator __it)
384 {
return __it._M_cur == __victim._M_cur; });
385 size_type __bucket_count = this->bucket_count();
386 _Base_iterator __next = _Base::erase(__it.base());
387 _M_check_rehashed(__bucket_count);
399 for (_Base_const_iterator __tmp = __first.
base();
400 __tmp != __last.
base(); ++__tmp)
402 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
403 _M_message(__gnu_debug::__msg_valid_range)
404 ._M_iterator(__first,
"first")
405 ._M_iterator(__last,
"last"));
407 {
return __it == __tmp; });
409 [__tmp](_Base_const_local_iterator __it)
410 {
return __it._M_cur == __tmp._M_cur; });
412 size_type __bucket_count = this->bucket_count();
413 _Base_iterator __next = _Base::erase(__first.
base(), __last.
base());
414 _M_check_rehashed(__bucket_count);
419 _M_base() noexcept {
return *
this; }
422 _M_base()
const noexcept {
return *
this; }
426 _M_invalidate_locals()
428 _Base_local_iterator __local_end = _Base::end(0);
430 [__local_end](_Base_const_local_iterator __it)
431 {
return __it != __local_end; });
437 _Base_iterator __end = _Base::end();
439 {
return __it != __end; });
440 _M_invalidate_locals();
444 _M_check_rehashed(size_type __prev_count)
446 if (__prev_count != this->bucket_count())
447 _M_invalidate_locals();
451 template<
typename _Key,
typename _Tp,
typename _Hash,
452 typename _Pred,
typename _Alloc>
458 template<
typename _Key,
typename _Tp,
typename _Hash,
459 typename _Pred,
typename _Alloc>
463 {
return __x._M_base() == __y._M_base(); }
465 template<
typename _Key,
typename _Tp,
typename _Hash,
466 typename _Pred,
typename _Alloc>
468 operator!=(
const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
469 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
470 {
return !(__x == __y); }
474 template<
typename _Key,
typename _Tp,
479 :
public _GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, _Hash,
482 _Tp, _Hash, _Pred, _Alloc> >
484 typedef _GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, _Hash,
485 _Pred, _Alloc>
_Base;
488 typedef typename _Base::const_iterator _Base_const_iterator;
489 typedef typename _Base::iterator _Base_iterator;
490 typedef typename _Base::const_local_iterator _Base_const_local_iterator;
491 typedef typename _Base::local_iterator _Base_local_iterator;
494 typedef typename _Base::size_type size_type;
495 typedef typename _Base::hasher hasher;
496 typedef typename _Base::key_equal key_equal;
497 typedef typename _Base::allocator_type allocator_type;
499 typedef typename _Base::key_type key_type;
500 typedef typename _Base::value_type value_type;
513 const hasher& __hf = hasher(),
514 const key_equal& __eql = key_equal(),
515 const allocator_type& __a = allocator_type())
516 :
_Base(__n, __hf, __eql, __a) { }
518 template<
typename _InputIterator>
521 const hasher& __hf = hasher(),
522 const key_equal& __eql = key_equal(),
523 const allocator_type& __a = allocator_type())
527 __hf, __eql, __a) { }
538 const hasher& __hf = hasher(),
539 const key_equal& __eql = key_equal(),
540 const allocator_type& __a = allocator_type())
541 :
_Base(__l, __n, __hf, __eql, __a) { }
548 *
static_cast<_Base*
>(
this) = __x;
549 this->_M_invalidate_all();
558 __glibcxx_check_self_move_assign(__x);
583 this->_M_invalidate_all();
588 {
return iterator(_Base::begin(),
this); }
591 begin()
const noexcept
596 {
return iterator(_Base::end(),
this); }
603 cbegin()
const noexcept
607 cend()
const noexcept
614 __glibcxx_check_bucket_index(__b);
621 __glibcxx_check_bucket_index(__b);
626 begin(size_type __b)
const
628 __glibcxx_check_bucket_index(__b);
633 end(size_type __b)
const
635 __glibcxx_check_bucket_index(__b);
640 cbegin(size_type __b)
const
642 __glibcxx_check_bucket_index(__b);
647 cend(size_type __b)
const
649 __glibcxx_check_bucket_index(__b);
654 bucket_size(size_type __b)
const
656 __glibcxx_check_bucket_index(__b);
657 return _Base::bucket_size(__b);
661 max_load_factor()
const noexcept
662 {
return _Base::max_load_factor(); }
665 max_load_factor(
float __f)
667 __glibcxx_check_max_load_factor(__f);
668 _Base::max_load_factor(__f);
671 template<
typename... _Args>
673 emplace(_Args&&... __args)
675 size_type __bucket_count = this->bucket_count();
677 = _Base::emplace(std::forward<_Args>(__args)...);
678 _M_check_rehashed(__bucket_count);
682 template<
typename... _Args>
687 size_type __bucket_count = this->bucket_count();
688 _Base_iterator __it = _Base::emplace_hint(__hint.
base(),
689 std::forward<_Args>(__args)...);
690 _M_check_rehashed(__bucket_count);
695 insert(
const value_type& __obj)
697 size_type __bucket_count = this->bucket_count();
698 _Base_iterator __it = _Base::insert(__obj);
699 _M_check_rehashed(__bucket_count);
707 size_type __bucket_count = this->bucket_count();
708 _Base_iterator __it = _Base::insert(__hint.
base(), __obj);
709 _M_check_rehashed(__bucket_count);
713 template<
typename _Pair,
typename =
typename
715 _Pair&&>::value>::type>
717 insert(_Pair&& __obj)
719 size_type __bucket_count = this->bucket_count();
720 _Base_iterator __it = _Base::insert(std::forward<_Pair>(__obj));
721 _M_check_rehashed(__bucket_count);
725 template<
typename _Pair,
typename =
typename
727 _Pair&&>::value>::type>
732 size_type __bucket_count = this->bucket_count();
733 _Base_iterator __it =
734 _Base::insert(__hint.
base(), std::forward<_Pair>(__obj));
735 _M_check_rehashed(__bucket_count);
741 { _Base::insert(__l); }
743 template<
typename _InputIterator>
745 insert(_InputIterator __first, _InputIterator __last)
747 __glibcxx_check_valid_range(__first, __last);
748 size_type __bucket_count = this->bucket_count();
751 _M_check_rehashed(__bucket_count);
755 find(
const key_type& __key)
756 {
return iterator(_Base::find(__key),
this); }
759 find(
const key_type& __key)
const
763 equal_range(
const key_type& __key)
766 _Base::equal_range(__key);
772 equal_range(
const key_type& __key)
const
775 _Base::equal_range(__key);
781 erase(
const key_type& __key)
784 size_type __bucket_count = this->bucket_count();
786 _Base::equal_range(__key);
787 for (_Base_iterator __victim = __pair.
first; __victim != __pair.
second;)
790 {
return __it == __victim; });
792 [__victim](_Base_const_local_iterator __it)
793 {
return __it._M_cur == __victim._M_cur; });
794 _Base::erase(__victim++);
797 _M_check_rehashed(__bucket_count);
805 _Base_const_iterator __victim = __it.
base();
807 {
return __it == __victim; });
809 [__victim](_Base_const_local_iterator __it)
810 {
return __it._M_cur == __victim._M_cur; });
811 size_type __bucket_count = this->bucket_count();
812 _Base_iterator __next = _Base::erase(__it.base());
813 _M_check_rehashed(__bucket_count);
825 for (_Base_const_iterator __tmp = __first.
base();
826 __tmp != __last.
base(); ++__tmp)
828 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
829 _M_message(__gnu_debug::__msg_valid_range)
830 ._M_iterator(__first,
"first")
831 ._M_iterator(__last,
"last"));
833 {
return __it == __tmp; });
835 [__tmp](_Base_const_local_iterator __it)
836 {
return __it._M_cur == __tmp._M_cur; });
838 size_type __bucket_count = this->bucket_count();
839 _Base_iterator __next = _Base::erase(__first.
base(), __last.
base());
840 _M_check_rehashed(__bucket_count);
845 _M_base() noexcept {
return *
this; }
848 _M_base()
const noexcept {
return *
this; }
852 _M_invalidate_locals()
854 _Base_local_iterator __local_end = _Base::end(0);
856 [__local_end](_Base_const_local_iterator __it)
857 {
return __it != __local_end; });
863 _Base_iterator __end = _Base::end();
865 {
return __it != __end; });
866 _M_invalidate_locals();
870 _M_check_rehashed(size_type __prev_count)
872 if (__prev_count != this->bucket_count())
873 _M_invalidate_locals();
877 template<
typename _Key,
typename _Tp,
typename _Hash,
878 typename _Pred,
typename _Alloc>
884 template<
typename _Key,
typename _Tp,
typename _Hash,
885 typename _Pred,
typename _Alloc>
889 {
return __x._M_base() == __y._M_base(); }
891 template<
typename _Key,
typename _Tp,
typename _Hash,
892 typename _Pred,
typename _Alloc>
894 operator!=(
const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
895 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
896 {
return !(__x == __y); }