65 #if __cplusplus >= 201103L
69 namespace std _GLIBCXX_VISIBILITY(default)
71 _GLIBCXX_BEGIN_NAMESPACE_VERSION
89 enum _Rb_tree_color { _S_red =
false, _S_black =
true };
91 struct _Rb_tree_node_base
93 typedef _Rb_tree_node_base* _Base_ptr;
94 typedef const _Rb_tree_node_base* _Const_Base_ptr;
96 _Rb_tree_color _M_color;
102 _S_minimum(_Base_ptr __x)
104 while (__x->_M_left != 0) __x = __x->_M_left;
108 static _Const_Base_ptr
109 _S_minimum(_Const_Base_ptr __x)
111 while (__x->_M_left != 0) __x = __x->_M_left;
116 _S_maximum(_Base_ptr __x)
118 while (__x->_M_right != 0) __x = __x->_M_right;
122 static _Const_Base_ptr
123 _S_maximum(_Const_Base_ptr __x)
125 while (__x->_M_right != 0) __x = __x->_M_right;
130 template<
typename _Val>
131 struct _Rb_tree_node :
public _Rb_tree_node_base
133 typedef _Rb_tree_node<_Val>* _Link_type;
136 #if __cplusplus >= 201103L
137 template<
typename... _Args>
138 _Rb_tree_node(_Args&&... __args)
139 : _Rb_tree_node_base(),
140 _M_value_field(std::
forward<_Args>(__args)...) { }
144 _GLIBCXX_PURE _Rb_tree_node_base*
145 _Rb_tree_increment(_Rb_tree_node_base* __x)
throw ();
147 _GLIBCXX_PURE
const _Rb_tree_node_base*
148 _Rb_tree_increment(
const _Rb_tree_node_base* __x)
throw ();
150 _GLIBCXX_PURE _Rb_tree_node_base*
151 _Rb_tree_decrement(_Rb_tree_node_base* __x)
throw ();
153 _GLIBCXX_PURE
const _Rb_tree_node_base*
154 _Rb_tree_decrement(
const _Rb_tree_node_base* __x)
throw ();
156 template<
typename _Tp>
157 struct _Rb_tree_iterator
159 typedef _Tp value_type;
160 typedef _Tp& reference;
161 typedef _Tp* pointer;
163 typedef bidirectional_iterator_tag iterator_category;
164 typedef ptrdiff_t difference_type;
166 typedef _Rb_tree_iterator<_Tp> _Self;
167 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
168 typedef _Rb_tree_node<_Tp>* _Link_type;
174 _Rb_tree_iterator(_Link_type __x)
179 {
return static_cast<_Link_type
>(_M_node)->_M_value_field; }
184 (_M_node)->_M_value_field); }
189 _M_node = _Rb_tree_increment(_M_node);
197 _M_node = _Rb_tree_increment(_M_node);
204 _M_node = _Rb_tree_decrement(_M_node);
212 _M_node = _Rb_tree_decrement(_M_node);
217 operator==(
const _Self& __x)
const
218 {
return _M_node == __x._M_node; }
221 operator!=(
const _Self& __x)
const
222 {
return _M_node != __x._M_node; }
227 template<
typename _Tp>
228 struct _Rb_tree_const_iterator
230 typedef _Tp value_type;
231 typedef const _Tp& reference;
232 typedef const _Tp* pointer;
234 typedef _Rb_tree_iterator<_Tp> iterator;
236 typedef bidirectional_iterator_tag iterator_category;
237 typedef ptrdiff_t difference_type;
239 typedef _Rb_tree_const_iterator<_Tp> _Self;
240 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
241 typedef const _Rb_tree_node<_Tp>* _Link_type;
243 _Rb_tree_const_iterator()
247 _Rb_tree_const_iterator(_Link_type __x)
250 _Rb_tree_const_iterator(
const iterator& __it)
251 : _M_node(__it._M_node) { }
254 _M_const_cast()
const
255 {
return iterator(static_cast<typename iterator::_Link_type>
256 (const_cast<typename iterator::_Base_ptr>(_M_node))); }
260 {
return static_cast<_Link_type
>(_M_node)->_M_value_field; }
265 (_M_node)->_M_value_field); }
270 _M_node = _Rb_tree_increment(_M_node);
278 _M_node = _Rb_tree_increment(_M_node);
285 _M_node = _Rb_tree_decrement(_M_node);
293 _M_node = _Rb_tree_decrement(_M_node);
298 operator==(
const _Self& __x)
const
299 {
return _M_node == __x._M_node; }
302 operator!=(
const _Self& __x)
const
303 {
return _M_node != __x._M_node; }
308 template<
typename _Val>
310 operator==(
const _Rb_tree_iterator<_Val>& __x,
311 const _Rb_tree_const_iterator<_Val>& __y)
312 {
return __x._M_node == __y._M_node; }
314 template<
typename _Val>
316 operator!=(
const _Rb_tree_iterator<_Val>& __x,
317 const _Rb_tree_const_iterator<_Val>& __y)
318 {
return __x._M_node != __y._M_node; }
321 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
322 _Rb_tree_node_base* __x,
323 _Rb_tree_node_base* __p,
324 _Rb_tree_node_base& __header)
throw ();
327 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
328 _Rb_tree_node_base& __header)
throw ();
331 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
332 typename _Compare,
typename _Alloc = allocator<_Val> >
335 typedef typename _Alloc::template rebind<_Rb_tree_node<_Val> >::other
339 typedef _Rb_tree_node_base* _Base_ptr;
340 typedef const _Rb_tree_node_base* _Const_Base_ptr;
343 typedef _Key key_type;
344 typedef _Val value_type;
345 typedef value_type* pointer;
346 typedef const value_type* const_pointer;
347 typedef value_type& reference;
348 typedef const value_type& const_reference;
349 typedef _Rb_tree_node<_Val>* _Link_type;
350 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
351 typedef size_t size_type;
352 typedef ptrdiff_t difference_type;
353 typedef _Alloc allocator_type;
356 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
357 {
return *
static_cast<_Node_allocator*
>(&this->_M_impl); }
359 const _Node_allocator&
360 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
361 {
return *
static_cast<const _Node_allocator*
>(&this->_M_impl); }
364 get_allocator() const _GLIBCXX_NOEXCEPT
365 {
return allocator_type(_M_get_Node_allocator()); }
370 {
return _M_impl._Node_allocator::allocate(1); }
373 _M_put_node(_Link_type __p)
374 { _M_impl._Node_allocator::deallocate(__p, 1); }
376 #if __cplusplus < 201103L
378 _M_create_node(
const value_type& __x)
380 _Link_type __tmp = _M_get_node();
382 { get_allocator().construct
387 __throw_exception_again;
393 _M_destroy_node(_Link_type __p)
399 template<
typename... _Args>
401 _M_create_node(_Args&&... __args)
403 _Link_type __tmp = _M_get_node();
407 construct(_M_get_Node_allocator(), __tmp,
408 std::forward<_Args>(__args)...);
413 __throw_exception_again;
419 _M_destroy_node(_Link_type __p)
421 _M_get_Node_allocator().destroy(__p);
427 _M_clone_node(_Const_Link_type __x)
429 _Link_type __tmp = _M_create_node(__x->_M_value_field);
430 __tmp->_M_color = __x->_M_color;
437 template<
typename _Key_compare,
438 bool _Is_pod_comparator = __is_pod(_Key_compare)>
439 struct _Rb_tree_impl :
public _Node_allocator
441 _Key_compare _M_key_compare;
442 _Rb_tree_node_base _M_header;
443 size_type _M_node_count;
446 : _Node_allocator(), _M_key_compare(), _M_header(),
450 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
451 : _Node_allocator(__a), _M_key_compare(__comp), _M_header(),
455 #if __cplusplus >= 201103L
456 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
457 : _Node_allocator(std::move(__a)), _M_key_compare(__comp),
458 _M_header(), _M_node_count(0)
466 this->_M_header._M_color = _S_red;
467 this->_M_header._M_parent = 0;
468 this->_M_header._M_left = &this->_M_header;
469 this->_M_header._M_right = &this->_M_header;
473 _Rb_tree_impl<_Compare> _M_impl;
478 {
return this->_M_impl._M_header._M_parent; }
482 {
return this->_M_impl._M_header._M_parent; }
486 {
return this->_M_impl._M_header._M_left; }
490 {
return this->_M_impl._M_header._M_left; }
494 {
return this->_M_impl._M_header._M_right; }
498 {
return this->_M_impl._M_header._M_right; }
502 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
507 return static_cast<_Const_Link_type
>
508 (this->_M_impl._M_header._M_parent);
513 {
return static_cast<_Link_type
>(&this->_M_impl._M_header); }
517 {
return static_cast<_Const_Link_type
>(&this->_M_impl._M_header); }
519 static const_reference
520 _S_value(_Const_Link_type __x)
521 {
return __x->_M_value_field; }
524 _S_key(_Const_Link_type __x)
525 {
return _KeyOfValue()(_S_value(__x)); }
528 _S_left(_Base_ptr __x)
529 {
return static_cast<_Link_type
>(__x->_M_left); }
531 static _Const_Link_type
532 _S_left(_Const_Base_ptr __x)
533 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
536 _S_right(_Base_ptr __x)
537 {
return static_cast<_Link_type
>(__x->_M_right); }
539 static _Const_Link_type
540 _S_right(_Const_Base_ptr __x)
541 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
543 static const_reference
544 _S_value(_Const_Base_ptr __x)
545 {
return static_cast<_Const_Link_type
>(__x)->_M_value_field; }
548 _S_key(_Const_Base_ptr __x)
549 {
return _KeyOfValue()(_S_value(__x)); }
552 _S_minimum(_Base_ptr __x)
553 {
return _Rb_tree_node_base::_S_minimum(__x); }
555 static _Const_Base_ptr
556 _S_minimum(_Const_Base_ptr __x)
557 {
return _Rb_tree_node_base::_S_minimum(__x); }
560 _S_maximum(_Base_ptr __x)
561 {
return _Rb_tree_node_base::_S_maximum(__x); }
563 static _Const_Base_ptr
564 _S_maximum(_Const_Base_ptr __x)
565 {
return _Rb_tree_node_base::_S_maximum(__x); }
568 typedef _Rb_tree_iterator<value_type> iterator;
569 typedef _Rb_tree_const_iterator<value_type> const_iterator;
575 pair<_Base_ptr, _Base_ptr>
576 _M_get_insert_unique_pos(
const key_type& __k);
578 pair<_Base_ptr, _Base_ptr>
579 _M_get_insert_equal_pos(
const key_type& __k);
581 pair<_Base_ptr, _Base_ptr>
582 _M_get_insert_hint_unique_pos(const_iterator __pos,
583 const key_type& __k);
585 pair<_Base_ptr, _Base_ptr>
586 _M_get_insert_hint_equal_pos(const_iterator __pos,
587 const key_type& __k);
589 #if __cplusplus >= 201103L
590 template<
typename _Arg>
592 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v);
595 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
597 template<
typename _Arg>
599 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
601 template<
typename _Arg>
603 _M_insert_equal_lower(_Arg&& __x);
606 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
609 _M_insert_equal_lower_node(_Link_type __z);
612 _M_insert_(_Base_ptr __x, _Base_ptr __y,
613 const value_type& __v);
618 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
621 _M_insert_equal_lower(
const value_type& __x);
625 _M_copy(_Const_Link_type __x, _Link_type __p);
628 _M_erase(_Link_type __x);
631 _M_lower_bound(_Link_type __x, _Link_type __y,
635 _M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
636 const _Key& __k)
const;
639 _M_upper_bound(_Link_type __x, _Link_type __y,
643 _M_upper_bound(_Const_Link_type __x, _Const_Link_type __y,
644 const _Key& __k)
const;
650 _Rb_tree(
const _Compare& __comp,
651 const allocator_type& __a = allocator_type())
652 : _M_impl(__comp, _Node_allocator(__a)) { }
654 _Rb_tree(
const _Rb_tree& __x)
655 : _M_impl(__x._M_impl._M_key_compare, __x._M_get_Node_allocator())
657 if (__x._M_root() != 0)
659 _M_root() = _M_copy(__x._M_begin(), _M_end());
660 _M_leftmost() = _S_minimum(_M_root());
661 _M_rightmost() = _S_maximum(_M_root());
662 _M_impl._M_node_count = __x._M_impl._M_node_count;
666 #if __cplusplus >= 201103L
667 _Rb_tree(_Rb_tree&& __x);
670 ~_Rb_tree() _GLIBCXX_NOEXCEPT
671 { _M_erase(_M_begin()); }
674 operator=(
const _Rb_tree& __x);
679 {
return _M_impl._M_key_compare; }
682 begin() _GLIBCXX_NOEXCEPT
684 return iterator(static_cast<_Link_type>
685 (this->_M_impl._M_header._M_left));
689 begin() const _GLIBCXX_NOEXCEPT
691 return const_iterator(static_cast<_Const_Link_type>
692 (this->_M_impl._M_header._M_left));
696 end() _GLIBCXX_NOEXCEPT
697 {
return iterator(static_cast<_Link_type>(&this->_M_impl._M_header)); }
700 end() const _GLIBCXX_NOEXCEPT
702 return const_iterator(static_cast<_Const_Link_type>
703 (&this->_M_impl._M_header));
707 rbegin() _GLIBCXX_NOEXCEPT
708 {
return reverse_iterator(
end()); }
710 const_reverse_iterator
711 rbegin() const _GLIBCXX_NOEXCEPT
712 {
return const_reverse_iterator(
end()); }
715 rend() _GLIBCXX_NOEXCEPT
716 {
return reverse_iterator(
begin()); }
718 const_reverse_iterator
719 rend() const _GLIBCXX_NOEXCEPT
720 {
return const_reverse_iterator(
begin()); }
723 empty() const _GLIBCXX_NOEXCEPT
724 {
return _M_impl._M_node_count == 0; }
727 size() const _GLIBCXX_NOEXCEPT
728 {
return _M_impl._M_node_count; }
731 max_size() const _GLIBCXX_NOEXCEPT
732 {
return _M_get_Node_allocator().max_size(); }
738 #if __cplusplus >= 201103L
739 template<
typename _Arg>
741 _M_insert_unique(_Arg&& __x);
743 template<
typename _Arg>
745 _M_insert_equal(_Arg&& __x);
747 template<
typename _Arg>
749 _M_insert_unique_(const_iterator __position, _Arg&& __x);
751 template<
typename _Arg>
753 _M_insert_equal_(const_iterator __position, _Arg&& __x);
755 template<
typename... _Args>
757 _M_emplace_unique(_Args&&... __args);
759 template<
typename... _Args>
761 _M_emplace_equal(_Args&&... __args);
763 template<
typename... _Args>
765 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
767 template<
typename... _Args>
769 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
772 _M_insert_unique(
const value_type& __x);
775 _M_insert_equal(
const value_type& __x);
778 _M_insert_unique_(const_iterator __position,
const value_type& __x);
781 _M_insert_equal_(const_iterator __position,
const value_type& __x);
784 template<
typename _InputIterator>
786 _M_insert_unique(_InputIterator __first, _InputIterator __last);
788 template<
typename _InputIterator>
790 _M_insert_equal(_InputIterator __first, _InputIterator __last);
794 _M_erase_aux(const_iterator __position);
797 _M_erase_aux(const_iterator __first, const_iterator __last);
800 #if __cplusplus >= 201103L
804 erase(const_iterator __position)
806 const_iterator __result = __position;
808 _M_erase_aux(__position);
809 return __result._M_const_cast();
814 erase(iterator __position)
816 iterator __result = __position;
818 _M_erase_aux(__position);
823 erase(iterator __position)
824 { _M_erase_aux(__position); }
827 erase(const_iterator __position)
828 { _M_erase_aux(__position); }
831 erase(
const key_type& __x);
833 #if __cplusplus >= 201103L
837 erase(const_iterator __first, const_iterator __last)
839 _M_erase_aux(__first, __last);
840 return __last._M_const_cast();
844 erase(iterator __first, iterator __last)
845 { _M_erase_aux(__first, __last); }
848 erase(const_iterator __first, const_iterator __last)
849 { _M_erase_aux(__first, __last); }
852 erase(
const key_type* __first,
const key_type* __last);
855 clear() _GLIBCXX_NOEXCEPT
857 _M_erase(_M_begin());
858 _M_leftmost() = _M_end();
860 _M_rightmost() = _M_end();
861 _M_impl._M_node_count = 0;
866 find(
const key_type& __k);
869 find(
const key_type& __k)
const;
872 count(
const key_type& __k)
const;
875 lower_bound(
const key_type& __k)
876 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
879 lower_bound(
const key_type& __k)
const
880 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
883 upper_bound(
const key_type& __k)
884 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
887 upper_bound(
const key_type& __k)
const
888 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
890 pair<iterator, iterator>
891 equal_range(
const key_type& __k);
893 pair<const_iterator, const_iterator>
894 equal_range(
const key_type& __k)
const;
901 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
902 typename _Compare,
typename _Alloc>
904 operator==(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
905 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
907 return __x.size() == __y.size()
908 &&
std::equal(__x.begin(), __x.end(), __y.begin());
911 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
912 typename _Compare,
typename _Alloc>
914 operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
915 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
918 __y.begin(), __y.end());
921 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
922 typename _Compare,
typename _Alloc>
924 operator!=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
925 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
926 {
return !(__x == __y); }
928 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
929 typename _Compare,
typename _Alloc>
931 operator>(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
932 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
933 {
return __y < __x; }
935 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
936 typename _Compare,
typename _Alloc>
938 operator<=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
939 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
940 {
return !(__y < __x); }
942 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
943 typename _Compare,
typename _Alloc>
945 operator>=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
946 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
947 {
return !(__x < __y); }
949 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
950 typename _Compare,
typename _Alloc>
952 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
953 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
956 #if __cplusplus >= 201103L
957 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
958 typename _Compare,
typename _Alloc>
959 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
960 _Rb_tree(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&& __x)
961 : _M_impl(__x._M_impl._M_key_compare,
962 std::move(__x._M_get_Node_allocator()))
964 if (__x._M_root() != 0)
966 _M_root() = __x._M_root();
967 _M_leftmost() = __x._M_leftmost();
968 _M_rightmost() = __x._M_rightmost();
969 _M_root()->_M_parent = _M_end();
972 __x._M_leftmost() = __x._M_end();
973 __x._M_rightmost() = __x._M_end();
975 this->_M_impl._M_node_count = __x._M_impl._M_node_count;
976 __x._M_impl._M_node_count = 0;
981 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
982 typename _Compare,
typename _Alloc>
983 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
984 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
985 operator=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x)
991 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
992 if (__x._M_root() != 0)
994 _M_root() = _M_copy(__x._M_begin(), _M_end());
995 _M_leftmost() = _S_minimum(_M_root());
996 _M_rightmost() = _S_maximum(_M_root());
997 _M_impl._M_node_count = __x._M_impl._M_node_count;
1003 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1004 typename _Compare,
typename _Alloc>
1005 #if __cplusplus >= 201103L
1006 template<
typename _Arg>
1008 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1009 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1010 #if __cplusplus >= 201103L
1011 _M_insert_(_Base_ptr __x, _Base_ptr __p, _Arg&& __v)
1013 _M_insert_(_Base_ptr __x, _Base_ptr __p,
const _Val& __v)
1016 bool __insert_left = (__x != 0 || __p == _M_end()
1017 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1020 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1022 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1023 this->_M_impl._M_header);
1024 ++_M_impl._M_node_count;
1025 return iterator(__z);
1028 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1029 typename _Compare,
typename _Alloc>
1030 #if __cplusplus >= 201103L
1031 template<
typename _Arg>
1033 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1034 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1035 #if __cplusplus >= 201103L
1036 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1038 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1041 bool __insert_left = (__p == _M_end()
1042 || !_M_impl._M_key_compare(_S_key(__p),
1043 _KeyOfValue()(__v)));
1045 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1047 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1048 this->_M_impl._M_header);
1049 ++_M_impl._M_node_count;
1050 return iterator(__z);
1053 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1054 typename _Compare,
typename _Alloc>
1055 #if __cplusplus >= 201103L
1056 template<
typename _Arg>
1058 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1059 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1060 #if __cplusplus >= 201103L
1061 _M_insert_equal_lower(_Arg&& __v)
1063 _M_insert_equal_lower(
const _Val& __v)
1066 _Link_type __x = _M_begin();
1067 _Link_type __y = _M_end();
1071 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1072 _S_left(__x) : _S_right(__x);
1074 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1077 template<
typename _Key,
typename _Val,
typename _KoV,
1078 typename _Compare,
typename _Alloc>
1079 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1080 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1081 _M_copy(_Const_Link_type __x, _Link_type __p)
1084 _Link_type __top = _M_clone_node(__x);
1085 __top->_M_parent = __p;
1090 __top->_M_right = _M_copy(_S_right(__x), __top);
1096 _Link_type __y = _M_clone_node(__x);
1098 __y->_M_parent = __p;
1100 __y->_M_right = _M_copy(_S_right(__x), __y);
1108 __throw_exception_again;
1113 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1114 typename _Compare,
typename _Alloc>
1116 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1117 _M_erase(_Link_type __x)
1122 _M_erase(_S_right(__x));
1123 _Link_type __y = _S_left(__x);
1124 _M_destroy_node(__x);
1129 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1130 typename _Compare,
typename _Alloc>
1131 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1132 _Compare, _Alloc>::iterator
1133 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1134 _M_lower_bound(_Link_type __x, _Link_type __y,
1138 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1139 __y = __x, __x = _S_left(__x);
1141 __x = _S_right(__x);
1142 return iterator(__y);
1145 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1146 typename _Compare,
typename _Alloc>
1147 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1148 _Compare, _Alloc>::const_iterator
1149 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1150 _M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
1151 const _Key& __k)
const
1154 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1155 __y = __x, __x = _S_left(__x);
1157 __x = _S_right(__x);
1158 return const_iterator(__y);
1161 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1162 typename _Compare,
typename _Alloc>
1163 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1164 _Compare, _Alloc>::iterator
1165 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1166 _M_upper_bound(_Link_type __x, _Link_type __y,
1170 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1171 __y = __x, __x = _S_left(__x);
1173 __x = _S_right(__x);
1174 return iterator(__y);
1177 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1178 typename _Compare,
typename _Alloc>
1179 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1180 _Compare, _Alloc>::const_iterator
1181 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1182 _M_upper_bound(_Const_Link_type __x, _Const_Link_type __y,
1183 const _Key& __k)
const
1186 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1187 __y = __x, __x = _S_left(__x);
1189 __x = _S_right(__x);
1190 return const_iterator(__y);
1193 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1194 typename _Compare,
typename _Alloc>
1195 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1196 _Compare, _Alloc>::iterator,
1197 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1198 _Compare, _Alloc>::iterator>
1199 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1200 equal_range(
const _Key& __k)
1202 _Link_type __x = _M_begin();
1203 _Link_type __y = _M_end();
1206 if (_M_impl._M_key_compare(_S_key(__x), __k))
1207 __x = _S_right(__x);
1208 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1209 __y = __x, __x = _S_left(__x);
1212 _Link_type __xu(__x), __yu(__y);
1213 __y = __x, __x = _S_left(__x);
1214 __xu = _S_right(__xu);
1215 return pair<iterator,
1216 iterator>(_M_lower_bound(__x, __y, __k),
1217 _M_upper_bound(__xu, __yu, __k));
1220 return pair<iterator, iterator>(iterator(__y),
1224 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1225 typename _Compare,
typename _Alloc>
1226 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1227 _Compare, _Alloc>::const_iterator,
1228 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1229 _Compare, _Alloc>::const_iterator>
1230 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1231 equal_range(
const _Key& __k)
const
1233 _Const_Link_type __x = _M_begin();
1234 _Const_Link_type __y = _M_end();
1237 if (_M_impl._M_key_compare(_S_key(__x), __k))
1238 __x = _S_right(__x);
1239 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1240 __y = __x, __x = _S_left(__x);
1243 _Const_Link_type __xu(__x), __yu(__y);
1244 __y = __x, __x = _S_left(__x);
1245 __xu = _S_right(__xu);
1246 return pair<const_iterator,
1247 const_iterator>(_M_lower_bound(__x, __y, __k),
1248 _M_upper_bound(__xu, __yu, __k));
1251 return pair<const_iterator, const_iterator>(const_iterator(__y),
1252 const_iterator(__y));
1255 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1256 typename _Compare,
typename _Alloc>
1258 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1259 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __t)
1263 if (__t._M_root() != 0)
1265 _M_root() = __t._M_root();
1266 _M_leftmost() = __t._M_leftmost();
1267 _M_rightmost() = __t._M_rightmost();
1268 _M_root()->_M_parent = _M_end();
1271 __t._M_leftmost() = __t._M_end();
1272 __t._M_rightmost() = __t._M_end();
1275 else if (__t._M_root() == 0)
1277 __t._M_root() = _M_root();
1278 __t._M_leftmost() = _M_leftmost();
1279 __t._M_rightmost() = _M_rightmost();
1280 __t._M_root()->_M_parent = __t._M_end();
1283 _M_leftmost() = _M_end();
1284 _M_rightmost() = _M_end();
1288 std::swap(_M_root(),__t._M_root());
1289 std::swap(_M_leftmost(),__t._M_leftmost());
1290 std::swap(_M_rightmost(),__t._M_rightmost());
1292 _M_root()->_M_parent = _M_end();
1293 __t._M_root()->_M_parent = __t._M_end();
1296 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
1297 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
1301 std::__alloc_swap<_Node_allocator>::
1302 _S_do_it(_M_get_Node_allocator(), __t._M_get_Node_allocator());
1305 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1306 typename _Compare,
typename _Alloc>
1307 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1308 _Compare, _Alloc>::_Base_ptr,
1309 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1310 _Compare, _Alloc>::_Base_ptr>
1311 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1312 _M_get_insert_unique_pos(
const key_type& __k)
1314 typedef pair<_Base_ptr, _Base_ptr> _Res;
1315 _Link_type __x = _M_begin();
1316 _Link_type __y = _M_end();
1321 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
1322 __x = __comp ? _S_left(__x) : _S_right(__x);
1324 iterator __j = iterator(__y);
1328 return _Res(__x, __y);
1332 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
1333 return _Res(__x, __y);
1334 return _Res(__j._M_node, 0);
1337 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1338 typename _Compare,
typename _Alloc>
1339 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1340 _Compare, _Alloc>::_Base_ptr,
1341 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1342 _Compare, _Alloc>::_Base_ptr>
1343 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1344 _M_get_insert_equal_pos(
const key_type& __k)
1346 typedef pair<_Base_ptr, _Base_ptr> _Res;
1347 _Link_type __x = _M_begin();
1348 _Link_type __y = _M_end();
1352 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
1353 _S_left(__x) : _S_right(__x);
1355 return _Res(__x, __y);
1358 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1359 typename _Compare,
typename _Alloc>
1360 #if __cplusplus >= 201103L
1361 template<
typename _Arg>
1363 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1364 _Compare, _Alloc>::iterator,
bool>
1365 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1366 #if __cplusplus >= 201103L
1367 _M_insert_unique(_Arg&& __v)
1369 _M_insert_unique(
const _Val& __v)
1372 typedef pair<iterator, bool> _Res;
1373 pair<_Base_ptr, _Base_ptr> __res
1374 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
1377 return _Res(_M_insert_(__res.first, __res.second,
1378 _GLIBCXX_FORWARD(_Arg, __v)),
1381 return _Res(iterator(static_cast<_Link_type>(__res.first)),
false);
1384 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1385 typename _Compare,
typename _Alloc>
1386 #if __cplusplus >= 201103L
1387 template<
typename _Arg>
1389 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1390 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1391 #if __cplusplus >= 201103L
1392 _M_insert_equal(_Arg&& __v)
1394 _M_insert_equal(
const _Val& __v)
1397 pair<_Base_ptr, _Base_ptr> __res
1398 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
1399 return _M_insert_(__res.first, __res.second, _GLIBCXX_FORWARD(_Arg, __v));
1402 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1403 typename _Compare,
typename _Alloc>
1404 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1405 _Compare, _Alloc>::_Base_ptr,
1406 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1407 _Compare, _Alloc>::_Base_ptr>
1408 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1409 _M_get_insert_hint_unique_pos(const_iterator __position,
1410 const key_type& __k)
1412 iterator __pos = __position._M_const_cast();
1413 typedef pair<_Base_ptr, _Base_ptr> _Res;
1416 if (__pos._M_node == _M_end())
1419 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
1420 return _Res(0, _M_rightmost());
1422 return _M_get_insert_unique_pos(__k);
1424 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
1427 iterator __before = __pos;
1428 if (__pos._M_node == _M_leftmost())
1429 return _Res(_M_leftmost(), _M_leftmost());
1430 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
1432 if (_S_right(__before._M_node) == 0)
1433 return _Res(0, __before._M_node);
1435 return _Res(__pos._M_node, __pos._M_node);
1438 return _M_get_insert_unique_pos(__k);
1440 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
1443 iterator __after = __pos;
1444 if (__pos._M_node == _M_rightmost())
1445 return _Res(0, _M_rightmost());
1446 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
1448 if (_S_right(__pos._M_node) == 0)
1449 return _Res(0, __pos._M_node);
1451 return _Res(__after._M_node, __after._M_node);
1454 return _M_get_insert_unique_pos(__k);
1458 return _Res(__pos._M_node, 0);
1461 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1462 typename _Compare,
typename _Alloc>
1463 #if __cplusplus >= 201103L
1464 template<
typename _Arg>
1466 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1467 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1468 #if __cplusplus >= 201103L
1469 _M_insert_unique_(const_iterator __position, _Arg&& __v)
1471 _M_insert_unique_(const_iterator __position,
const _Val& __v)
1474 pair<_Base_ptr, _Base_ptr> __res
1475 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
1478 return _M_insert_(__res.first, __res.second,
1479 _GLIBCXX_FORWARD(_Arg, __v));
1480 return iterator(static_cast<_Link_type>(__res.first));
1483 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1484 typename _Compare,
typename _Alloc>
1485 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1486 _Compare, _Alloc>::_Base_ptr,
1487 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1488 _Compare, _Alloc>::_Base_ptr>
1489 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1490 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
1492 iterator __pos = __position._M_const_cast();
1493 typedef pair<_Base_ptr, _Base_ptr> _Res;
1496 if (__pos._M_node == _M_end())
1499 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
1500 return _Res(0, _M_rightmost());
1502 return _M_get_insert_equal_pos(__k);
1504 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
1507 iterator __before = __pos;
1508 if (__pos._M_node == _M_leftmost())
1509 return _Res(_M_leftmost(), _M_leftmost());
1510 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
1512 if (_S_right(__before._M_node) == 0)
1513 return _Res(0, __before._M_node);
1515 return _Res(__pos._M_node, __pos._M_node);
1518 return _M_get_insert_equal_pos(__k);
1523 iterator __after = __pos;
1524 if (__pos._M_node == _M_rightmost())
1525 return _Res(0, _M_rightmost());
1526 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
1528 if (_S_right(__pos._M_node) == 0)
1529 return _Res(0, __pos._M_node);
1531 return _Res(__after._M_node, __after._M_node);
1538 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1539 typename _Compare,
typename _Alloc>
1540 #if __cplusplus >= 201103L
1541 template<
typename _Arg>
1543 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1544 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1545 #if __cplusplus >= 201103L
1546 _M_insert_equal_(const_iterator __position, _Arg&& __v)
1548 _M_insert_equal_(const_iterator __position,
const _Val& __v)
1551 pair<_Base_ptr, _Base_ptr> __res
1552 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
1555 return _M_insert_(__res.first, __res.second,
1556 _GLIBCXX_FORWARD(_Arg, __v));
1558 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
1561 #if __cplusplus >= 201103L
1562 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1563 typename _Compare,
typename _Alloc>
1564 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1565 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1566 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
1568 bool __insert_left = (__x != 0 || __p == _M_end()
1569 || _M_impl._M_key_compare(_S_key(__z),
1572 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1573 this->_M_impl._M_header);
1574 ++_M_impl._M_node_count;
1575 return iterator(__z);
1578 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1579 typename _Compare,
typename _Alloc>
1580 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1581 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1582 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
1584 bool __insert_left = (__p == _M_end()
1585 || !_M_impl._M_key_compare(_S_key(__p),
1588 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1589 this->_M_impl._M_header);
1590 ++_M_impl._M_node_count;
1591 return iterator(__z);
1594 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1595 typename _Compare,
typename _Alloc>
1596 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1597 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1598 _M_insert_equal_lower_node(_Link_type __z)
1600 _Link_type __x = _M_begin();
1601 _Link_type __y = _M_end();
1605 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
1606 _S_left(__x) : _S_right(__x);
1608 return _M_insert_lower_node(__y, __z);
1611 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1612 typename _Compare,
typename _Alloc>
1613 template<
typename... _Args>
1614 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1615 _Compare, _Alloc>::iterator,
bool>
1616 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1617 _M_emplace_unique(_Args&&... __args)
1619 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1623 typedef pair<iterator, bool> _Res;
1624 auto __res = _M_get_insert_unique_pos(_S_key(__z));
1626 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
1628 _M_destroy_node(__z);
1629 return _Res(iterator(static_cast<_Link_type>(__res.first)),
false);
1633 _M_destroy_node(__z);
1634 __throw_exception_again;
1638 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1639 typename _Compare,
typename _Alloc>
1640 template<
typename... _Args>
1641 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1642 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1643 _M_emplace_equal(_Args&&... __args)
1645 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1649 auto __res = _M_get_insert_equal_pos(_S_key(__z));
1650 return _M_insert_node(__res.first, __res.second, __z);
1654 _M_destroy_node(__z);
1655 __throw_exception_again;
1659 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1660 typename _Compare,
typename _Alloc>
1661 template<
typename... _Args>
1662 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1663 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1664 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
1666 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1670 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
1673 return _M_insert_node(__res.first, __res.second, __z);
1675 _M_destroy_node(__z);
1676 return iterator(static_cast<_Link_type>(__res.first));
1680 _M_destroy_node(__z);
1681 __throw_exception_again;
1685 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1686 typename _Compare,
typename _Alloc>
1687 template<
typename... _Args>
1688 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1689 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1690 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
1692 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1696 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
1699 return _M_insert_node(__res.first, __res.second, __z);
1701 return _M_insert_equal_lower_node(__z);
1705 _M_destroy_node(__z);
1706 __throw_exception_again;
1711 template<
typename _Key,
typename _Val,
typename _KoV,
1712 typename _Cmp,
typename _Alloc>
1715 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
1716 _M_insert_unique(_II __first, _II __last)
1718 for (; __first != __last; ++__first)
1719 _M_insert_unique_(
end(), *__first);
1722 template<
typename _Key,
typename _Val,
typename _KoV,
1723 typename _Cmp,
typename _Alloc>
1726 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
1727 _M_insert_equal(_II __first, _II __last)
1729 for (; __first != __last; ++__first)
1730 _M_insert_equal_(
end(), *__first);
1733 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1734 typename _Compare,
typename _Alloc>
1736 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1737 _M_erase_aux(const_iterator __position)
1740 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
1741 (const_cast<_Base_ptr>(__position._M_node),
1742 this->_M_impl._M_header));
1743 _M_destroy_node(__y);
1744 --_M_impl._M_node_count;
1747 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1748 typename _Compare,
typename _Alloc>
1750 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1751 _M_erase_aux(const_iterator __first, const_iterator __last)
1753 if (__first ==
begin() && __last ==
end())
1756 while (__first != __last)
1760 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1761 typename _Compare,
typename _Alloc>
1762 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
1763 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1764 erase(
const _Key& __x)
1766 pair<iterator, iterator> __p = equal_range(__x);
1767 const size_type __old_size =
size();
1768 erase(__p.first, __p.second);
1769 return __old_size -
size();
1772 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1773 typename _Compare,
typename _Alloc>
1775 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1776 erase(
const _Key* __first,
const _Key* __last)
1778 while (__first != __last)
1782 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1783 typename _Compare,
typename _Alloc>
1784 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1785 _Compare, _Alloc>::iterator
1786 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1787 find(
const _Key& __k)
1789 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
1790 return (__j ==
end()
1791 || _M_impl._M_key_compare(__k,
1792 _S_key(__j._M_node))) ?
end() : __j;
1795 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1796 typename _Compare,
typename _Alloc>
1797 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1798 _Compare, _Alloc>::const_iterator
1799 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1800 find(
const _Key& __k)
const
1802 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
1803 return (__j ==
end()
1804 || _M_impl._M_key_compare(__k,
1805 _S_key(__j._M_node))) ?
end() : __j;
1808 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1809 typename _Compare,
typename _Alloc>
1810 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
1812 count(
const _Key& __k)
const
1814 pair<const_iterator, const_iterator> __p = equal_range(__k);
1819 _GLIBCXX_PURE
unsigned int
1820 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
1821 const _Rb_tree_node_base* __root)
throw ();
1823 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1824 typename _Compare,
typename _Alloc>
1826 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const
1828 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
1829 return _M_impl._M_node_count == 0 &&
begin() ==
end()
1830 && this->_M_impl._M_header._M_left == _M_end()
1831 && this->_M_impl._M_header._M_right == _M_end();
1833 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
1834 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
1836 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
1837 _Const_Link_type __L = _S_left(__x);
1838 _Const_Link_type __R = _S_right(__x);
1840 if (__x->_M_color == _S_red)
1841 if ((__L && __L->_M_color == _S_red)
1842 || (__R && __R->_M_color == _S_red))
1845 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
1847 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
1850 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
1854 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
1856 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
1861 _GLIBCXX_END_NAMESPACE_VERSION