30 #ifndef _GLIBCXX_DEBUG_UNORDERED_SET
31 #define _GLIBCXX_DEBUG_UNORDERED_SET 1
33 #ifndef __GXX_EXPERIMENTAL_CXX0X__
42 namespace std _GLIBCXX_VISIBILITY(default)
47 template<
typename _Value,
52 :
public _GLIBCXX_STD_C::unordered_set<_Value, _Hash, _Pred, _Alloc>,
56 typedef _GLIBCXX_STD_C::unordered_set<_Value, _Hash,
59 typedef typename _Base::const_iterator _Base_const_iterator;
60 typedef typename _Base::iterator _Base_iterator;
61 typedef typename _Base::const_local_iterator _Base_const_local_iterator;
62 typedef typename _Base::local_iterator _Base_local_iterator;
65 typedef typename _Base::size_type size_type;
66 typedef typename _Base::hasher hasher;
67 typedef typename _Base::key_equal key_equal;
68 typedef typename _Base::allocator_type allocator_type;
70 typedef typename _Base::key_type key_type;
71 typedef typename _Base::value_type value_type;
84 const hasher& __hf = hasher(),
85 const key_equal& __eql = key_equal(),
86 const allocator_type& __a = allocator_type())
87 :
_Base(__n, __hf, __eql, __a) { }
89 template<
typename _InputIterator>
92 const hasher& __hf = hasher(),
93 const key_equal& __eql = key_equal(),
94 const allocator_type& __a = allocator_type())
107 :
_Base(std::move(__x)) { }
111 const hasher& __hf = hasher(),
112 const key_equal& __eql = key_equal(),
113 const allocator_type& __a = allocator_type())
114 :
_Base(__l, __n, __hf, __eql, __a) { }
121 *
static_cast<_Base*
>(
this) = __x;
122 this->_M_invalidate_all();
155 this->_M_invalidate_all();
160 {
return iterator(_Base::begin(),
this); }
163 begin()
const noexcept
168 {
return iterator(_Base::end(),
this); }
175 cbegin()
const noexcept
179 cend()
const noexcept
192 begin(size_type __b)
const
196 end(size_type __b)
const
200 cbegin(size_type __b)
const
204 cend(size_type __b)
const
207 template<
typename... _Args>
209 emplace(_Args&&... __args)
211 size_type __bucket_count = this->bucket_count();
213 = _Base::emplace(std::forward<_Args>(__args)...);
214 _M_check_rehashed(__bucket_count);
218 template<
typename... _Args>
223 size_type __bucket_count = this->bucket_count();
224 _Base_iterator __it = _Base::emplace_hint(__hint.
base(),
225 std::forward<_Args>(__args)...);
226 _M_check_rehashed(__bucket_count);
231 insert(
const value_type& __obj)
233 size_type __bucket_count = this->bucket_count();
235 __pair_type __res = _Base::insert(__obj);
236 _M_check_rehashed(__bucket_count);
244 size_type __bucket_count = this->bucket_count();
245 _Base_iterator __it = _Base::insert(__hint.
base(), __obj);
246 _M_check_rehashed(__bucket_count);
251 insert(value_type&& __obj)
253 size_type __bucket_count = this->bucket_count();
255 __pair_type __res = _Base::insert(std::move(__obj));
256 _M_check_rehashed(__bucket_count);
264 size_type __bucket_count = this->bucket_count();
265 _Base_iterator __it = _Base::insert(__hint.
base(), std::move(__obj));
266 _M_check_rehashed(__bucket_count);
273 size_type __bucket_count = this->bucket_count();
275 _M_check_rehashed(__bucket_count);
278 template<
typename _InputIterator>
280 insert(_InputIterator __first, _InputIterator __last)
282 __glibcxx_check_valid_range(__first, __last);
283 size_type __bucket_count = this->bucket_count();
286 _M_check_rehashed(__bucket_count);
290 find(
const key_type& __key)
291 {
return iterator(_Base::find(__key),
this); }
294 find(
const key_type& __key)
const
298 equal_range(
const key_type& __key)
301 __pair_type __res = _Base::equal_range(__key);
307 equal_range(
const key_type& __key)
const
310 __res = _Base::equal_range(__key);
316 erase(
const key_type& __key)
319 _Base_iterator __victim(_Base::find(__key));
320 if (__victim != _Base::end())
323 [__victim](_Base_const_iterator __it)
324 {
return __it == __victim; });
325 _Base_local_iterator __local_victim = _S_to_local(__victim);
327 [__local_victim](_Base_const_local_iterator __it)
328 {
return __it == __local_victim; });
329 size_type __bucket_count = this->bucket_count();
330 _Base::erase(__victim);
331 _M_check_rehashed(__bucket_count);
341 _Base_const_iterator __victim = __it.
base();
343 [__victim](_Base_const_iterator __it)
344 {
return __it == __victim; });
345 _Base_const_local_iterator __local_victim = _S_to_local(__victim);
347 [__local_victim](_Base_const_local_iterator __it)
348 {
return __it == __local_victim; });
349 size_type __bucket_count = this->bucket_count();
350 _Base_iterator __next = _Base::erase(__it.base());
351 _M_check_rehashed(__bucket_count);
363 for (_Base_const_iterator __tmp = __first.
base();
364 __tmp != __last.
base(); ++__tmp)
366 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
367 _M_message(__gnu_debug::__msg_valid_range)
368 ._M_iterator(__first,
"first")
369 ._M_iterator(__last,
"last"));
371 [__tmp](_Base_const_iterator __it)
372 {
return __it == __tmp; });
373 _Base_const_local_iterator __local_tmp = _S_to_local(__tmp);
375 [__local_tmp](_Base_const_local_iterator __it)
376 {
return __it == __local_tmp; });
378 size_type __bucket_count = this->bucket_count();
379 _Base_iterator __next = _Base::erase(__first.
base(),
381 _M_check_rehashed(__bucket_count);
386 _M_base() noexcept {
return *
this; }
389 _M_base()
const noexcept {
return *
this; }
393 _M_invalidate_locals()
395 _Base_local_iterator __local_end = _Base::end(0);
397 [__local_end](_Base_const_local_iterator __it)
398 {
return __it != __local_end; });
404 _Base_iterator __end = _Base::end();
406 [__end](_Base_const_iterator __it)
407 {
return __it != __end; });
408 _M_invalidate_locals();
412 _M_check_rehashed(size_type __prev_count)
414 if (__prev_count != this->bucket_count())
415 _M_invalidate_locals();
418 static _Base_local_iterator
419 _S_to_local(_Base_iterator __it)
423 return _Base_local_iterator(__it._M_cur, 0, 0);
426 static _Base_const_local_iterator
427 _S_to_local(_Base_const_iterator __it)
431 return _Base_const_local_iterator(__it._M_cur, 0, 0);
435 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
441 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
445 {
return __x._M_equal(__y); }
447 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
449 operator!=(
const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
450 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
451 {
return !(__x == __y); }
455 template<
typename _Value,
460 :
public _GLIBCXX_STD_C::unordered_multiset<_Value, _Hash, _Pred, _Alloc>,
462 unordered_multiset<_Value, _Hash, _Pred, _Alloc> >
464 typedef _GLIBCXX_STD_C::unordered_multiset<_Value, _Hash,
465 _Pred, _Alloc>
_Base;
468 typedef typename _Base::const_iterator _Base_const_iterator;
469 typedef typename _Base::iterator _Base_iterator;
470 typedef typename _Base::const_local_iterator _Base_const_local_iterator;
471 typedef typename _Base::local_iterator _Base_local_iterator;
474 typedef typename _Base::size_type size_type;
475 typedef typename _Base::hasher hasher;
476 typedef typename _Base::key_equal key_equal;
477 typedef typename _Base::allocator_type allocator_type;
479 typedef typename _Base::key_type key_type;
480 typedef typename _Base::value_type value_type;
493 const hasher& __hf = hasher(),
494 const key_equal& __eql = key_equal(),
495 const allocator_type& __a = allocator_type())
496 :
_Base(__n, __hf, __eql, __a) { }
498 template<
typename _InputIterator>
501 const hasher& __hf = hasher(),
502 const key_equal& __eql = key_equal(),
503 const allocator_type& __a = allocator_type())
507 __hf, __eql, __a) { }
516 :
_Base(std::move(__x)) { }
520 const hasher& __hf = hasher(),
521 const key_equal& __eql = key_equal(),
522 const allocator_type& __a = allocator_type())
523 :
_Base(__l, __n, __hf, __eql, __a) { }
530 *
static_cast<_Base*
>(
this) = __x;
531 this->_M_invalidate_all();
564 this->_M_invalidate_all();
569 {
return iterator(_Base::begin(),
this); }
572 begin()
const noexcept
577 {
return iterator(_Base::end(),
this); }
584 cbegin()
const noexcept
588 cend()
const noexcept
601 begin(size_type __b)
const
605 end(size_type __b)
const
609 cbegin(size_type __b)
const
613 cend(size_type __b)
const
616 template<
typename... _Args>
618 emplace(_Args&&... __args)
620 size_type __bucket_count = this->bucket_count();
622 = _Base::emplace(std::forward<_Args>(__args)...);
623 _M_check_rehashed(__bucket_count);
627 template<
typename... _Args>
632 size_type __bucket_count = this->bucket_count();
633 _Base_iterator __it = _Base::emplace_hint(__hint.
base(),
634 std::forward<_Args>(__args)...);
635 _M_check_rehashed(__bucket_count);
640 insert(
const value_type& __obj)
642 size_type __bucket_count = this->bucket_count();
643 _Base_iterator __it = _Base::insert(__obj);
644 _M_check_rehashed(__bucket_count);
652 size_type __bucket_count = this->bucket_count();
653 _Base_iterator __it = _Base::insert(__hint.
base(), __obj);
654 _M_check_rehashed(__bucket_count);
659 insert(value_type&& __obj)
661 size_type __bucket_count = this->bucket_count();
662 _Base_iterator __it = _Base::insert(std::move(__obj));
663 _M_check_rehashed(__bucket_count);
671 size_type __bucket_count = this->bucket_count();
672 _Base_iterator __it = _Base::insert(__hint.
base(), std::move(__obj));
673 _M_check_rehashed(__bucket_count);
680 size_type __bucket_count = this->bucket_count();
682 _M_check_rehashed(__bucket_count);
685 template<
typename _InputIterator>
687 insert(_InputIterator __first, _InputIterator __last)
689 __glibcxx_check_valid_range(__first, __last);
690 size_type __bucket_count = this->bucket_count();
693 _M_check_rehashed(__bucket_count);
697 find(
const key_type& __key)
698 {
return iterator(_Base::find(__key),
this); }
701 find(
const key_type& __key)
const
705 equal_range(
const key_type& __key)
708 __pair_type __res = _Base::equal_range(__key);
714 equal_range(
const key_type& __key)
const
717 __res = _Base::equal_range(__key);
723 erase(
const key_type& __key)
727 _Base::equal_range(__key);
728 for (_Base_iterator __victim = __pair.
first; __victim != __pair.
second;)
731 {
return __it == __victim; });
732 _Base_local_iterator __local_victim = _S_to_local(__victim);
734 [__local_victim](_Base_const_local_iterator __it)
735 {
return __it == __local_victim; });
736 _Base::erase(__victim++);
746 _Base_const_iterator __victim = __it.
base();
748 {
return __it == __victim; });
749 _Base_const_local_iterator __local_victim = _S_to_local(__victim);
751 [__local_victim](_Base_const_local_iterator __it)
752 {
return __it == __local_victim; });
753 return iterator(_Base::erase(__it.base()),
this);
764 for (_Base_const_iterator __tmp = __first.
base();
765 __tmp != __last.
base(); ++__tmp)
767 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
768 _M_message(__gnu_debug::__msg_valid_range)
769 ._M_iterator(__first,
"first")
770 ._M_iterator(__last,
"last"));
772 {
return __it == __tmp; });
773 _Base_const_local_iterator __local_tmp = _S_to_local(__tmp);
775 [__local_tmp](_Base_const_local_iterator __it)
776 {
return __it == __local_tmp; });
779 __last.
base()),
this);
783 _M_base() noexcept {
return *
this; }
786 _M_base()
const noexcept {
return *
this; }
790 _M_invalidate_locals()
792 _Base_local_iterator __local_end = _Base::end(0);
794 [__local_end](_Base_const_local_iterator __it)
795 {
return __it != __local_end; });
801 _Base_iterator __end = _Base::end();
803 {
return __it != __end; });
804 _M_invalidate_locals();
808 _M_check_rehashed(size_type __prev_count)
810 if (__prev_count != this->bucket_count())
811 _M_invalidate_locals();
814 static _Base_local_iterator
815 _S_to_local(_Base_iterator __it)
819 return _Base_local_iterator(__it._M_cur, 0, 0);
822 static _Base_const_local_iterator
823 _S_to_local(_Base_const_iterator __it)
827 return _Base_const_local_iterator(__it._M_cur, 0, 0);
831 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
837 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
841 {
return __x._M_equal(__y); }
843 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
845 operator!=(
const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
846 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
847 {
return !(__x == __y); }
852 #endif // __GXX_EXPERIMENTAL_CXX0X__