66 namespace std _GLIBCXX_VISIBILITY(default)
68 _GLIBCXX_BEGIN_NAMESPACE_VERSION
86 enum _Rb_tree_color { _S_red =
false, _S_black =
true };
88 struct _Rb_tree_node_base
90 typedef _Rb_tree_node_base* _Base_ptr;
91 typedef const _Rb_tree_node_base* _Const_Base_ptr;
93 _Rb_tree_color _M_color;
99 _S_minimum(_Base_ptr __x)
101 while (__x->_M_left != 0) __x = __x->_M_left;
105 static _Const_Base_ptr
106 _S_minimum(_Const_Base_ptr __x)
108 while (__x->_M_left != 0) __x = __x->_M_left;
113 _S_maximum(_Base_ptr __x)
115 while (__x->_M_right != 0) __x = __x->_M_right;
119 static _Const_Base_ptr
120 _S_maximum(_Const_Base_ptr __x)
122 while (__x->_M_right != 0) __x = __x->_M_right;
127 template<
typename _Val>
128 struct _Rb_tree_node :
public _Rb_tree_node_base
130 typedef _Rb_tree_node<_Val>* _Link_type;
133 #if __cplusplus >= 201103L
134 template<
typename... _Args>
135 _Rb_tree_node(_Args&&... __args)
136 : _Rb_tree_node_base(),
137 _M_value_field(std::
forward<_Args>(__args)...) { }
141 _GLIBCXX_PURE _Rb_tree_node_base*
142 _Rb_tree_increment(_Rb_tree_node_base* __x)
throw ();
144 _GLIBCXX_PURE
const _Rb_tree_node_base*
145 _Rb_tree_increment(
const _Rb_tree_node_base* __x)
throw ();
147 _GLIBCXX_PURE _Rb_tree_node_base*
148 _Rb_tree_decrement(_Rb_tree_node_base* __x)
throw ();
150 _GLIBCXX_PURE
const _Rb_tree_node_base*
151 _Rb_tree_decrement(
const _Rb_tree_node_base* __x)
throw ();
153 template<
typename _Tp>
154 struct _Rb_tree_iterator
156 typedef _Tp value_type;
157 typedef _Tp& reference;
158 typedef _Tp* pointer;
160 typedef bidirectional_iterator_tag iterator_category;
161 typedef ptrdiff_t difference_type;
163 typedef _Rb_tree_iterator<_Tp> _Self;
164 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
165 typedef _Rb_tree_node<_Tp>* _Link_type;
171 _Rb_tree_iterator(_Link_type __x)
176 {
return static_cast<_Link_type
>(_M_node)->_M_value_field; }
181 (_M_node)->_M_value_field); }
186 _M_node = _Rb_tree_increment(_M_node);
194 _M_node = _Rb_tree_increment(_M_node);
201 _M_node = _Rb_tree_decrement(_M_node);
209 _M_node = _Rb_tree_decrement(_M_node);
214 operator==(
const _Self& __x)
const
215 {
return _M_node == __x._M_node; }
218 operator!=(
const _Self& __x)
const
219 {
return _M_node != __x._M_node; }
224 template<
typename _Tp>
225 struct _Rb_tree_const_iterator
227 typedef _Tp value_type;
228 typedef const _Tp& reference;
229 typedef const _Tp* pointer;
231 typedef _Rb_tree_iterator<_Tp> iterator;
233 typedef bidirectional_iterator_tag iterator_category;
234 typedef ptrdiff_t difference_type;
236 typedef _Rb_tree_const_iterator<_Tp> _Self;
237 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
238 typedef const _Rb_tree_node<_Tp>* _Link_type;
240 _Rb_tree_const_iterator()
244 _Rb_tree_const_iterator(_Link_type __x)
247 _Rb_tree_const_iterator(
const iterator& __it)
248 : _M_node(__it._M_node) { }
251 _M_const_cast()
const
252 {
return iterator(static_cast<typename iterator::_Link_type>
253 (const_cast<typename iterator::_Base_ptr>(_M_node))); }
257 {
return static_cast<_Link_type
>(_M_node)->_M_value_field; }
262 (_M_node)->_M_value_field); }
267 _M_node = _Rb_tree_increment(_M_node);
275 _M_node = _Rb_tree_increment(_M_node);
282 _M_node = _Rb_tree_decrement(_M_node);
290 _M_node = _Rb_tree_decrement(_M_node);
295 operator==(
const _Self& __x)
const
296 {
return _M_node == __x._M_node; }
299 operator!=(
const _Self& __x)
const
300 {
return _M_node != __x._M_node; }
305 template<
typename _Val>
307 operator==(
const _Rb_tree_iterator<_Val>& __x,
308 const _Rb_tree_const_iterator<_Val>& __y)
309 {
return __x._M_node == __y._M_node; }
311 template<
typename _Val>
313 operator!=(
const _Rb_tree_iterator<_Val>& __x,
314 const _Rb_tree_const_iterator<_Val>& __y)
315 {
return __x._M_node != __y._M_node; }
318 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
319 _Rb_tree_node_base* __x,
320 _Rb_tree_node_base* __p,
321 _Rb_tree_node_base& __header)
throw ();
324 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
325 _Rb_tree_node_base& __header)
throw ();
328 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
329 typename _Compare,
typename _Alloc = allocator<_Val> >
332 typedef typename _Alloc::template rebind<_Rb_tree_node<_Val> >::other
336 typedef _Rb_tree_node_base* _Base_ptr;
337 typedef const _Rb_tree_node_base* _Const_Base_ptr;
340 typedef _Key key_type;
341 typedef _Val value_type;
342 typedef value_type* pointer;
343 typedef const value_type* const_pointer;
344 typedef value_type& reference;
345 typedef const value_type& const_reference;
346 typedef _Rb_tree_node<_Val>* _Link_type;
347 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
348 typedef size_t size_type;
349 typedef ptrdiff_t difference_type;
350 typedef _Alloc allocator_type;
353 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
354 {
return *
static_cast<_Node_allocator*
>(&this->_M_impl); }
356 const _Node_allocator&
357 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
358 {
return *
static_cast<const _Node_allocator*
>(&this->_M_impl); }
361 get_allocator() const _GLIBCXX_NOEXCEPT
362 {
return allocator_type(_M_get_Node_allocator()); }
367 {
return _M_impl._Node_allocator::allocate(1); }
370 _M_put_node(_Link_type __p)
371 { _M_impl._Node_allocator::deallocate(__p, 1); }
373 #if __cplusplus < 201103L
375 _M_create_node(
const value_type& __x)
377 _Link_type __tmp = _M_get_node();
379 { get_allocator().construct
384 __throw_exception_again;
390 _M_destroy_node(_Link_type __p)
396 template<
typename... _Args>
398 _M_create_node(_Args&&... __args)
400 _Link_type __tmp = _M_get_node();
403 _M_get_Node_allocator().construct(__tmp,
404 std::forward<_Args>(__args)...);
409 __throw_exception_again;
415 _M_destroy_node(_Link_type __p)
417 _M_get_Node_allocator().destroy(__p);
423 _M_clone_node(_Const_Link_type __x)
425 _Link_type __tmp = _M_create_node(__x->_M_value_field);
426 __tmp->_M_color = __x->_M_color;
433 template<
typename _Key_compare,
434 bool _Is_pod_comparator = __is_pod(_Key_compare)>
435 struct _Rb_tree_impl :
public _Node_allocator
437 _Key_compare _M_key_compare;
438 _Rb_tree_node_base _M_header;
439 size_type _M_node_count;
442 : _Node_allocator(), _M_key_compare(), _M_header(),
446 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
447 : _Node_allocator(__a), _M_key_compare(__comp), _M_header(),
451 #if __cplusplus >= 201103L
452 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
453 : _Node_allocator(std::move(__a)), _M_key_compare(__comp),
454 _M_header(), _M_node_count(0)
462 this->_M_header._M_color = _S_red;
463 this->_M_header._M_parent = 0;
464 this->_M_header._M_left = &this->_M_header;
465 this->_M_header._M_right = &this->_M_header;
469 _Rb_tree_impl<_Compare> _M_impl;
474 {
return this->_M_impl._M_header._M_parent; }
478 {
return this->_M_impl._M_header._M_parent; }
482 {
return this->_M_impl._M_header._M_left; }
486 {
return this->_M_impl._M_header._M_left; }
490 {
return this->_M_impl._M_header._M_right; }
494 {
return this->_M_impl._M_header._M_right; }
498 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
503 return static_cast<_Const_Link_type
>
504 (this->_M_impl._M_header._M_parent);
509 {
return static_cast<_Link_type
>(&this->_M_impl._M_header); }
513 {
return static_cast<_Const_Link_type
>(&this->_M_impl._M_header); }
515 static const_reference
516 _S_value(_Const_Link_type __x)
517 {
return __x->_M_value_field; }
520 _S_key(_Const_Link_type __x)
521 {
return _KeyOfValue()(_S_value(__x)); }
524 _S_left(_Base_ptr __x)
525 {
return static_cast<_Link_type
>(__x->_M_left); }
527 static _Const_Link_type
528 _S_left(_Const_Base_ptr __x)
529 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
532 _S_right(_Base_ptr __x)
533 {
return static_cast<_Link_type
>(__x->_M_right); }
535 static _Const_Link_type
536 _S_right(_Const_Base_ptr __x)
537 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
539 static const_reference
540 _S_value(_Const_Base_ptr __x)
541 {
return static_cast<_Const_Link_type
>(__x)->_M_value_field; }
544 _S_key(_Const_Base_ptr __x)
545 {
return _KeyOfValue()(_S_value(__x)); }
548 _S_minimum(_Base_ptr __x)
549 {
return _Rb_tree_node_base::_S_minimum(__x); }
551 static _Const_Base_ptr
552 _S_minimum(_Const_Base_ptr __x)
553 {
return _Rb_tree_node_base::_S_minimum(__x); }
556 _S_maximum(_Base_ptr __x)
557 {
return _Rb_tree_node_base::_S_maximum(__x); }
559 static _Const_Base_ptr
560 _S_maximum(_Const_Base_ptr __x)
561 {
return _Rb_tree_node_base::_S_maximum(__x); }
564 typedef _Rb_tree_iterator<value_type> iterator;
565 typedef _Rb_tree_const_iterator<value_type> const_iterator;
571 pair<_Base_ptr, _Base_ptr>
572 _M_get_insert_unique_pos(
const key_type& __k);
574 pair<_Base_ptr, _Base_ptr>
575 _M_get_insert_equal_pos(
const key_type& __k);
577 pair<_Base_ptr, _Base_ptr>
578 _M_get_insert_hint_unique_pos(const_iterator __pos,
579 const key_type& __k);
581 pair<_Base_ptr, _Base_ptr>
582 _M_get_insert_hint_equal_pos(const_iterator __pos,
583 const key_type& __k);
585 #if __cplusplus >= 201103L
586 template<
typename _Arg>
588 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v);
591 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
593 template<
typename _Arg>
595 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
597 template<
typename _Arg>
599 _M_insert_equal_lower(_Arg&& __x);
602 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
605 _M_insert_equal_lower_node(_Link_type __z);
608 _M_insert_(_Base_ptr __x, _Base_ptr __y,
609 const value_type& __v);
614 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
617 _M_insert_equal_lower(
const value_type& __x);
621 _M_copy(_Const_Link_type __x, _Link_type __p);
624 _M_erase(_Link_type __x);
627 _M_lower_bound(_Link_type __x, _Link_type __y,
631 _M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
632 const _Key& __k)
const;
635 _M_upper_bound(_Link_type __x, _Link_type __y,
639 _M_upper_bound(_Const_Link_type __x, _Const_Link_type __y,
640 const _Key& __k)
const;
646 _Rb_tree(
const _Compare& __comp,
647 const allocator_type& __a = allocator_type())
648 : _M_impl(__comp, _Node_allocator(__a)) { }
650 _Rb_tree(
const _Rb_tree& __x)
651 : _M_impl(__x._M_impl._M_key_compare, __x._M_get_Node_allocator())
653 if (__x._M_root() != 0)
655 _M_root() = _M_copy(__x._M_begin(), _M_end());
656 _M_leftmost() = _S_minimum(_M_root());
657 _M_rightmost() = _S_maximum(_M_root());
658 _M_impl._M_node_count = __x._M_impl._M_node_count;
662 #if __cplusplus >= 201103L
663 _Rb_tree(_Rb_tree&& __x);
666 ~_Rb_tree() _GLIBCXX_NOEXCEPT
667 { _M_erase(_M_begin()); }
670 operator=(
const _Rb_tree& __x);
675 {
return _M_impl._M_key_compare; }
678 begin() _GLIBCXX_NOEXCEPT
680 return iterator(static_cast<_Link_type>
681 (this->_M_impl._M_header._M_left));
685 begin() const _GLIBCXX_NOEXCEPT
687 return const_iterator(static_cast<_Const_Link_type>
688 (this->_M_impl._M_header._M_left));
692 end() _GLIBCXX_NOEXCEPT
693 {
return iterator(static_cast<_Link_type>(&this->_M_impl._M_header)); }
696 end() const _GLIBCXX_NOEXCEPT
698 return const_iterator(static_cast<_Const_Link_type>
699 (&this->_M_impl._M_header));
703 rbegin() _GLIBCXX_NOEXCEPT
704 {
return reverse_iterator(
end()); }
706 const_reverse_iterator
707 rbegin() const _GLIBCXX_NOEXCEPT
708 {
return const_reverse_iterator(
end()); }
711 rend() _GLIBCXX_NOEXCEPT
712 {
return reverse_iterator(
begin()); }
714 const_reverse_iterator
715 rend() const _GLIBCXX_NOEXCEPT
716 {
return const_reverse_iterator(
begin()); }
719 empty() const _GLIBCXX_NOEXCEPT
720 {
return _M_impl._M_node_count == 0; }
723 size() const _GLIBCXX_NOEXCEPT
724 {
return _M_impl._M_node_count; }
727 max_size() const _GLIBCXX_NOEXCEPT
728 {
return _M_get_Node_allocator().max_size(); }
734 #if __cplusplus >= 201103L
735 template<
typename _Arg>
737 _M_insert_unique(_Arg&& __x);
739 template<
typename _Arg>
741 _M_insert_equal(_Arg&& __x);
743 template<
typename _Arg>
745 _M_insert_unique_(const_iterator __position, _Arg&& __x);
747 template<
typename _Arg>
749 _M_insert_equal_(const_iterator __position, _Arg&& __x);
751 template<
typename... _Args>
753 _M_emplace_unique(_Args&&... __args);
755 template<
typename... _Args>
757 _M_emplace_equal(_Args&&... __args);
759 template<
typename... _Args>
761 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
763 template<
typename... _Args>
765 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
768 _M_insert_unique(
const value_type& __x);
771 _M_insert_equal(
const value_type& __x);
774 _M_insert_unique_(const_iterator __position,
const value_type& __x);
777 _M_insert_equal_(const_iterator __position,
const value_type& __x);
780 template<
typename _InputIterator>
782 _M_insert_unique(_InputIterator __first, _InputIterator __last);
784 template<
typename _InputIterator>
786 _M_insert_equal(_InputIterator __first, _InputIterator __last);
790 _M_erase_aux(const_iterator __position);
793 _M_erase_aux(const_iterator __first, const_iterator __last);
796 #if __cplusplus >= 201103L
800 erase(const_iterator __position)
802 const_iterator __result = __position;
804 _M_erase_aux(__position);
805 return __result._M_const_cast();
810 erase(iterator __position)
812 iterator __result = __position;
814 _M_erase_aux(__position);
819 erase(iterator __position)
820 { _M_erase_aux(__position); }
823 erase(const_iterator __position)
824 { _M_erase_aux(__position); }
827 erase(
const key_type& __x);
829 #if __cplusplus >= 201103L
833 erase(const_iterator __first, const_iterator __last)
835 _M_erase_aux(__first, __last);
836 return __last._M_const_cast();
840 erase(iterator __first, iterator __last)
841 { _M_erase_aux(__first, __last); }
844 erase(const_iterator __first, const_iterator __last)
845 { _M_erase_aux(__first, __last); }
848 erase(
const key_type* __first,
const key_type* __last);
851 clear() _GLIBCXX_NOEXCEPT
853 _M_erase(_M_begin());
854 _M_leftmost() = _M_end();
856 _M_rightmost() = _M_end();
857 _M_impl._M_node_count = 0;
862 find(
const key_type& __k);
865 find(
const key_type& __k)
const;
868 count(
const key_type& __k)
const;
871 lower_bound(
const key_type& __k)
872 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
875 lower_bound(
const key_type& __k)
const
876 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
879 upper_bound(
const key_type& __k)
880 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
883 upper_bound(
const key_type& __k)
const
884 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
886 pair<iterator, iterator>
887 equal_range(
const key_type& __k);
889 pair<const_iterator, const_iterator>
890 equal_range(
const key_type& __k)
const;
897 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
898 typename _Compare,
typename _Alloc>
900 operator==(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
901 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
903 return __x.size() == __y.size()
904 &&
std::equal(__x.begin(), __x.end(), __y.begin());
907 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
908 typename _Compare,
typename _Alloc>
910 operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
911 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
914 __y.begin(), __y.end());
917 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
918 typename _Compare,
typename _Alloc>
920 operator!=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
921 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
922 {
return !(__x == __y); }
924 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
925 typename _Compare,
typename _Alloc>
927 operator>(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
928 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
929 {
return __y < __x; }
931 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
932 typename _Compare,
typename _Alloc>
934 operator<=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
935 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
936 {
return !(__y < __x); }
938 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
939 typename _Compare,
typename _Alloc>
941 operator>=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
942 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
943 {
return !(__x < __y); }
945 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
946 typename _Compare,
typename _Alloc>
948 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
949 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
952 #if __cplusplus >= 201103L
953 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
954 typename _Compare,
typename _Alloc>
955 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
956 _Rb_tree(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&& __x)
957 : _M_impl(__x._M_impl._M_key_compare,
958 std::move(__x._M_get_Node_allocator()))
960 if (__x._M_root() != 0)
962 _M_root() = __x._M_root();
963 _M_leftmost() = __x._M_leftmost();
964 _M_rightmost() = __x._M_rightmost();
965 _M_root()->_M_parent = _M_end();
968 __x._M_leftmost() = __x._M_end();
969 __x._M_rightmost() = __x._M_end();
971 this->_M_impl._M_node_count = __x._M_impl._M_node_count;
972 __x._M_impl._M_node_count = 0;
977 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
978 typename _Compare,
typename _Alloc>
979 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
980 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
981 operator=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x)
987 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
988 if (__x._M_root() != 0)
990 _M_root() = _M_copy(__x._M_begin(), _M_end());
991 _M_leftmost() = _S_minimum(_M_root());
992 _M_rightmost() = _S_maximum(_M_root());
993 _M_impl._M_node_count = __x._M_impl._M_node_count;
999 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1000 typename _Compare,
typename _Alloc>
1001 #if __cplusplus >= 201103L
1002 template<
typename _Arg>
1004 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1005 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1006 #if __cplusplus >= 201103L
1007 _M_insert_(_Base_ptr __x, _Base_ptr __p, _Arg&& __v)
1009 _M_insert_(_Base_ptr __x, _Base_ptr __p,
const _Val& __v)
1012 bool __insert_left = (__x != 0 || __p == _M_end()
1013 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1016 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1018 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1019 this->_M_impl._M_header);
1020 ++_M_impl._M_node_count;
1021 return iterator(__z);
1024 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1025 typename _Compare,
typename _Alloc>
1026 #if __cplusplus >= 201103L
1027 template<
typename _Arg>
1029 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1030 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1031 #if __cplusplus >= 201103L
1032 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1034 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1037 bool __insert_left = (__p == _M_end()
1038 || !_M_impl._M_key_compare(_S_key(__p),
1039 _KeyOfValue()(__v)));
1041 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1043 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1044 this->_M_impl._M_header);
1045 ++_M_impl._M_node_count;
1046 return iterator(__z);
1049 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1050 typename _Compare,
typename _Alloc>
1051 #if __cplusplus >= 201103L
1052 template<
typename _Arg>
1054 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1055 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1056 #if __cplusplus >= 201103L
1057 _M_insert_equal_lower(_Arg&& __v)
1059 _M_insert_equal_lower(
const _Val& __v)
1062 _Link_type __x = _M_begin();
1063 _Link_type __y = _M_end();
1067 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1068 _S_left(__x) : _S_right(__x);
1070 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1073 template<
typename _Key,
typename _Val,
typename _KoV,
1074 typename _Compare,
typename _Alloc>
1075 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1076 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1077 _M_copy(_Const_Link_type __x, _Link_type __p)
1080 _Link_type __top = _M_clone_node(__x);
1081 __top->_M_parent = __p;
1086 __top->_M_right = _M_copy(_S_right(__x), __top);
1092 _Link_type __y = _M_clone_node(__x);
1094 __y->_M_parent = __p;
1096 __y->_M_right = _M_copy(_S_right(__x), __y);
1104 __throw_exception_again;
1109 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1110 typename _Compare,
typename _Alloc>
1112 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1113 _M_erase(_Link_type __x)
1118 _M_erase(_S_right(__x));
1119 _Link_type __y = _S_left(__x);
1120 _M_destroy_node(__x);
1125 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1126 typename _Compare,
typename _Alloc>
1127 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1128 _Compare, _Alloc>::iterator
1129 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1130 _M_lower_bound(_Link_type __x, _Link_type __y,
1134 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1135 __y = __x, __x = _S_left(__x);
1137 __x = _S_right(__x);
1138 return iterator(__y);
1141 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1142 typename _Compare,
typename _Alloc>
1143 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1144 _Compare, _Alloc>::const_iterator
1145 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1146 _M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
1147 const _Key& __k)
const
1150 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1151 __y = __x, __x = _S_left(__x);
1153 __x = _S_right(__x);
1154 return const_iterator(__y);
1157 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1158 typename _Compare,
typename _Alloc>
1159 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1160 _Compare, _Alloc>::iterator
1161 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1162 _M_upper_bound(_Link_type __x, _Link_type __y,
1166 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1167 __y = __x, __x = _S_left(__x);
1169 __x = _S_right(__x);
1170 return iterator(__y);
1173 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1174 typename _Compare,
typename _Alloc>
1175 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1176 _Compare, _Alloc>::const_iterator
1177 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1178 _M_upper_bound(_Const_Link_type __x, _Const_Link_type __y,
1179 const _Key& __k)
const
1182 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1183 __y = __x, __x = _S_left(__x);
1185 __x = _S_right(__x);
1186 return const_iterator(__y);
1189 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1190 typename _Compare,
typename _Alloc>
1191 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1192 _Compare, _Alloc>::iterator,
1193 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1194 _Compare, _Alloc>::iterator>
1195 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1196 equal_range(
const _Key& __k)
1198 _Link_type __x = _M_begin();
1199 _Link_type __y = _M_end();
1202 if (_M_impl._M_key_compare(_S_key(__x), __k))
1203 __x = _S_right(__x);
1204 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1205 __y = __x, __x = _S_left(__x);
1208 _Link_type __xu(__x), __yu(__y);
1209 __y = __x, __x = _S_left(__x);
1210 __xu = _S_right(__xu);
1211 return pair<iterator,
1212 iterator>(_M_lower_bound(__x, __y, __k),
1213 _M_upper_bound(__xu, __yu, __k));
1216 return pair<iterator, iterator>(iterator(__y),
1220 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1221 typename _Compare,
typename _Alloc>
1222 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1223 _Compare, _Alloc>::const_iterator,
1224 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1225 _Compare, _Alloc>::const_iterator>
1226 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1227 equal_range(
const _Key& __k)
const
1229 _Const_Link_type __x = _M_begin();
1230 _Const_Link_type __y = _M_end();
1233 if (_M_impl._M_key_compare(_S_key(__x), __k))
1234 __x = _S_right(__x);
1235 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1236 __y = __x, __x = _S_left(__x);
1239 _Const_Link_type __xu(__x), __yu(__y);
1240 __y = __x, __x = _S_left(__x);
1241 __xu = _S_right(__xu);
1242 return pair<const_iterator,
1243 const_iterator>(_M_lower_bound(__x, __y, __k),
1244 _M_upper_bound(__xu, __yu, __k));
1247 return pair<const_iterator, const_iterator>(const_iterator(__y),
1248 const_iterator(__y));
1251 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1252 typename _Compare,
typename _Alloc>
1254 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1255 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __t)
1259 if (__t._M_root() != 0)
1261 _M_root() = __t._M_root();
1262 _M_leftmost() = __t._M_leftmost();
1263 _M_rightmost() = __t._M_rightmost();
1264 _M_root()->_M_parent = _M_end();
1267 __t._M_leftmost() = __t._M_end();
1268 __t._M_rightmost() = __t._M_end();
1271 else if (__t._M_root() == 0)
1273 __t._M_root() = _M_root();
1274 __t._M_leftmost() = _M_leftmost();
1275 __t._M_rightmost() = _M_rightmost();
1276 __t._M_root()->_M_parent = __t._M_end();
1279 _M_leftmost() = _M_end();
1280 _M_rightmost() = _M_end();
1284 std::swap(_M_root(),__t._M_root());
1285 std::swap(_M_leftmost(),__t._M_leftmost());
1286 std::swap(_M_rightmost(),__t._M_rightmost());
1288 _M_root()->_M_parent = _M_end();
1289 __t._M_root()->_M_parent = __t._M_end();
1292 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
1293 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
1297 std::__alloc_swap<_Node_allocator>::
1298 _S_do_it(_M_get_Node_allocator(), __t._M_get_Node_allocator());
1301 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1302 typename _Compare,
typename _Alloc>
1303 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1304 _Compare, _Alloc>::_Base_ptr,
1305 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1306 _Compare, _Alloc>::_Base_ptr>
1307 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1308 _M_get_insert_unique_pos(
const key_type& __k)
1310 typedef pair<_Base_ptr, _Base_ptr> _Res;
1311 _Link_type __x = _M_begin();
1312 _Link_type __y = _M_end();
1317 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
1318 __x = __comp ? _S_left(__x) : _S_right(__x);
1320 iterator __j = iterator(__y);
1324 return _Res(__x, __y);
1328 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
1329 return _Res(__x, __y);
1330 return _Res(__j._M_node, 0);
1333 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1334 typename _Compare,
typename _Alloc>
1335 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1336 _Compare, _Alloc>::_Base_ptr,
1337 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1338 _Compare, _Alloc>::_Base_ptr>
1339 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1340 _M_get_insert_equal_pos(
const key_type& __k)
1342 typedef pair<_Base_ptr, _Base_ptr> _Res;
1343 _Link_type __x = _M_begin();
1344 _Link_type __y = _M_end();
1348 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
1349 _S_left(__x) : _S_right(__x);
1351 return _Res(__x, __y);
1354 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1355 typename _Compare,
typename _Alloc>
1356 #if __cplusplus >= 201103L
1357 template<
typename _Arg>
1359 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1360 _Compare, _Alloc>::iterator,
bool>
1361 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1362 #if __cplusplus >= 201103L
1363 _M_insert_unique(_Arg&& __v)
1365 _M_insert_unique(
const _Val& __v)
1368 typedef pair<iterator, bool> _Res;
1369 pair<_Base_ptr, _Base_ptr> __res
1370 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
1373 return _Res(_M_insert_(__res.first, __res.second,
1374 _GLIBCXX_FORWARD(_Arg, __v)),
1377 return _Res(iterator(static_cast<_Link_type>(__res.first)),
false);
1380 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1381 typename _Compare,
typename _Alloc>
1382 #if __cplusplus >= 201103L
1383 template<
typename _Arg>
1385 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1386 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1387 #if __cplusplus >= 201103L
1388 _M_insert_equal(_Arg&& __v)
1390 _M_insert_equal(
const _Val& __v)
1393 pair<_Base_ptr, _Base_ptr> __res
1394 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
1395 return _M_insert_(__res.first, __res.second, _GLIBCXX_FORWARD(_Arg, __v));
1398 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1399 typename _Compare,
typename _Alloc>
1400 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1401 _Compare, _Alloc>::_Base_ptr,
1402 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1403 _Compare, _Alloc>::_Base_ptr>
1404 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1405 _M_get_insert_hint_unique_pos(const_iterator __position,
1406 const key_type& __k)
1408 iterator __pos = __position._M_const_cast();
1409 typedef pair<_Base_ptr, _Base_ptr> _Res;
1412 if (__pos._M_node == _M_end())
1415 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
1416 return _Res(0, _M_rightmost());
1418 return _M_get_insert_unique_pos(__k);
1420 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
1423 iterator __before = __pos;
1424 if (__pos._M_node == _M_leftmost())
1425 return _Res(_M_leftmost(), _M_leftmost());
1426 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
1428 if (_S_right(__before._M_node) == 0)
1429 return _Res(0, __before._M_node);
1431 return _Res(__pos._M_node, __pos._M_node);
1434 return _M_get_insert_unique_pos(__k);
1436 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
1439 iterator __after = __pos;
1440 if (__pos._M_node == _M_rightmost())
1441 return _Res(0, _M_rightmost());
1442 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
1444 if (_S_right(__pos._M_node) == 0)
1445 return _Res(0, __pos._M_node);
1447 return _Res(__after._M_node, __after._M_node);
1450 return _M_get_insert_unique_pos(__k);
1454 return _Res(__pos._M_node, 0);
1457 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1458 typename _Compare,
typename _Alloc>
1459 #if __cplusplus >= 201103L
1460 template<
typename _Arg>
1462 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1463 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1464 #if __cplusplus >= 201103L
1465 _M_insert_unique_(const_iterator __position, _Arg&& __v)
1467 _M_insert_unique_(const_iterator __position,
const _Val& __v)
1470 pair<_Base_ptr, _Base_ptr> __res
1471 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
1474 return _M_insert_(__res.first, __res.second,
1475 _GLIBCXX_FORWARD(_Arg, __v));
1476 return iterator(static_cast<_Link_type>(__res.first));
1479 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1480 typename _Compare,
typename _Alloc>
1481 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1482 _Compare, _Alloc>::_Base_ptr,
1483 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1484 _Compare, _Alloc>::_Base_ptr>
1485 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1486 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
1488 iterator __pos = __position._M_const_cast();
1489 typedef pair<_Base_ptr, _Base_ptr> _Res;
1492 if (__pos._M_node == _M_end())
1495 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
1496 return _Res(0, _M_rightmost());
1498 return _M_get_insert_equal_pos(__k);
1500 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
1503 iterator __before = __pos;
1504 if (__pos._M_node == _M_leftmost())
1505 return _Res(_M_leftmost(), _M_leftmost());
1506 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
1508 if (_S_right(__before._M_node) == 0)
1509 return _Res(0, __before._M_node);
1511 return _Res(__pos._M_node, __pos._M_node);
1514 return _M_get_insert_equal_pos(__k);
1519 iterator __after = __pos;
1520 if (__pos._M_node == _M_rightmost())
1521 return _Res(0, _M_rightmost());
1522 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
1524 if (_S_right(__pos._M_node) == 0)
1525 return _Res(0, __pos._M_node);
1527 return _Res(__after._M_node, __after._M_node);
1534 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1535 typename _Compare,
typename _Alloc>
1536 #if __cplusplus >= 201103L
1537 template<
typename _Arg>
1539 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1540 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1541 #if __cplusplus >= 201103L
1542 _M_insert_equal_(const_iterator __position, _Arg&& __v)
1544 _M_insert_equal_(const_iterator __position,
const _Val& __v)
1547 pair<_Base_ptr, _Base_ptr> __res
1548 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
1551 return _M_insert_(__res.first, __res.second,
1552 _GLIBCXX_FORWARD(_Arg, __v));
1554 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
1557 #if __cplusplus >= 201103L
1558 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1559 typename _Compare,
typename _Alloc>
1560 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1561 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1562 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
1564 bool __insert_left = (__x != 0 || __p == _M_end()
1565 || _M_impl._M_key_compare(_S_key(__z),
1568 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1569 this->_M_impl._M_header);
1570 ++_M_impl._M_node_count;
1571 return iterator(__z);
1574 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1575 typename _Compare,
typename _Alloc>
1576 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1577 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1578 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
1580 bool __insert_left = (__p == _M_end()
1581 || !_M_impl._M_key_compare(_S_key(__p),
1584 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1585 this->_M_impl._M_header);
1586 ++_M_impl._M_node_count;
1587 return iterator(__z);
1590 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1591 typename _Compare,
typename _Alloc>
1592 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1593 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1594 _M_insert_equal_lower_node(_Link_type __z)
1596 _Link_type __x = _M_begin();
1597 _Link_type __y = _M_end();
1601 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
1602 _S_left(__x) : _S_right(__x);
1604 return _M_insert_lower_node(__y, __z);
1607 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1608 typename _Compare,
typename _Alloc>
1609 template<
typename... _Args>
1610 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1611 _Compare, _Alloc>::iterator,
bool>
1612 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1613 _M_emplace_unique(_Args&&... __args)
1615 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1619 typedef pair<iterator, bool> _Res;
1620 auto __res = _M_get_insert_unique_pos(_S_key(__z));
1622 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
1624 _M_destroy_node(__z);
1625 return _Res(iterator(static_cast<_Link_type>(__res.first)),
false);
1629 _M_destroy_node(__z);
1630 __throw_exception_again;
1634 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1635 typename _Compare,
typename _Alloc>
1636 template<
typename... _Args>
1637 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1638 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1639 _M_emplace_equal(_Args&&... __args)
1641 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1645 auto __res = _M_get_insert_equal_pos(_S_key(__z));
1646 return _M_insert_node(__res.first, __res.second, __z);
1650 _M_destroy_node(__z);
1651 __throw_exception_again;
1655 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1656 typename _Compare,
typename _Alloc>
1657 template<
typename... _Args>
1658 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1659 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1660 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
1662 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1666 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
1669 return _M_insert_node(__res.first, __res.second, __z);
1671 _M_destroy_node(__z);
1672 return iterator(static_cast<_Link_type>(__res.first));
1676 _M_destroy_node(__z);
1677 __throw_exception_again;
1681 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1682 typename _Compare,
typename _Alloc>
1683 template<
typename... _Args>
1684 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1685 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1686 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
1688 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1692 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
1695 return _M_insert_node(__res.first, __res.second, __z);
1697 return _M_insert_equal_lower_node(__z);
1701 _M_destroy_node(__z);
1702 __throw_exception_again;
1707 template<
typename _Key,
typename _Val,
typename _KoV,
1708 typename _Cmp,
typename _Alloc>
1711 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
1712 _M_insert_unique(_II __first, _II __last)
1714 for (; __first != __last; ++__first)
1715 _M_insert_unique_(
end(), *__first);
1718 template<
typename _Key,
typename _Val,
typename _KoV,
1719 typename _Cmp,
typename _Alloc>
1722 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
1723 _M_insert_equal(_II __first, _II __last)
1725 for (; __first != __last; ++__first)
1726 _M_insert_equal_(
end(), *__first);
1729 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1730 typename _Compare,
typename _Alloc>
1732 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1733 _M_erase_aux(const_iterator __position)
1736 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
1737 (const_cast<_Base_ptr>(__position._M_node),
1738 this->_M_impl._M_header));
1739 _M_destroy_node(__y);
1740 --_M_impl._M_node_count;
1743 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1744 typename _Compare,
typename _Alloc>
1746 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1747 _M_erase_aux(const_iterator __first, const_iterator __last)
1749 if (__first ==
begin() && __last ==
end())
1752 while (__first != __last)
1756 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1757 typename _Compare,
typename _Alloc>
1758 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
1759 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1760 erase(
const _Key& __x)
1762 pair<iterator, iterator> __p = equal_range(__x);
1763 const size_type __old_size =
size();
1764 erase(__p.first, __p.second);
1765 return __old_size -
size();
1768 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1769 typename _Compare,
typename _Alloc>
1771 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1772 erase(
const _Key* __first,
const _Key* __last)
1774 while (__first != __last)
1778 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1779 typename _Compare,
typename _Alloc>
1780 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1781 _Compare, _Alloc>::iterator
1782 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1783 find(
const _Key& __k)
1785 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
1786 return (__j ==
end()
1787 || _M_impl._M_key_compare(__k,
1788 _S_key(__j._M_node))) ?
end() : __j;
1791 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1792 typename _Compare,
typename _Alloc>
1793 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1794 _Compare, _Alloc>::const_iterator
1795 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1796 find(
const _Key& __k)
const
1798 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
1799 return (__j ==
end()
1800 || _M_impl._M_key_compare(__k,
1801 _S_key(__j._M_node))) ?
end() : __j;
1804 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1805 typename _Compare,
typename _Alloc>
1806 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
1808 count(
const _Key& __k)
const
1810 pair<const_iterator, const_iterator> __p = equal_range(__k);
1815 _GLIBCXX_PURE
unsigned int
1816 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
1817 const _Rb_tree_node_base* __root)
throw ();
1819 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1820 typename _Compare,
typename _Alloc>
1822 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const
1824 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
1825 return _M_impl._M_node_count == 0 &&
begin() ==
end()
1826 && this->_M_impl._M_header._M_left == _M_end()
1827 && this->_M_impl._M_header._M_right == _M_end();
1829 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
1830 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
1832 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
1833 _Const_Link_type __L = _S_left(__x);
1834 _Const_Link_type __R = _S_right(__x);
1836 if (__x->_M_color == _S_red)
1837 if ((__L && __L->_M_color == _S_red)
1838 || (__R && __R->_M_color == _S_red))
1841 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
1843 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
1846 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
1850 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
1852 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
1857 _GLIBCXX_END_NAMESPACE_VERSION