61 #pragma GCC system_header
68 #if __cplusplus >= 201103L
71 #if __cplusplus > 201402L
75 namespace std _GLIBCXX_VISIBILITY(default)
77 _GLIBCXX_BEGIN_NAMESPACE_VERSION
79 #if __cplusplus > 201103L
80 # define __cpp_lib_generic_associative_lookup 201304
99 enum _Rb_tree_color { _S_red =
false, _S_black =
true };
101 struct _Rb_tree_node_base
103 typedef _Rb_tree_node_base* _Base_ptr;
104 typedef const _Rb_tree_node_base* _Const_Base_ptr;
106 _Rb_tree_color _M_color;
112 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
114 while (__x->_M_left != 0) __x = __x->_M_left;
118 static _Const_Base_ptr
119 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
121 while (__x->_M_left != 0) __x = __x->_M_left;
126 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
128 while (__x->_M_right != 0) __x = __x->_M_right;
132 static _Const_Base_ptr
133 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
135 while (__x->_M_right != 0) __x = __x->_M_right;
141 template<
typename _Key_compare>
142 struct _Rb_tree_key_compare
144 _Key_compare _M_key_compare;
146 _Rb_tree_key_compare()
147 _GLIBCXX_NOEXCEPT_IF(
148 is_nothrow_default_constructible<_Key_compare>::value)
152 _Rb_tree_key_compare(
const _Key_compare& __comp)
153 : _M_key_compare(__comp)
156 #if __cplusplus >= 201103L
158 _Rb_tree_key_compare(
const _Rb_tree_key_compare&) =
default;
160 _Rb_tree_key_compare(_Rb_tree_key_compare&& __x)
161 noexcept(is_nothrow_copy_constructible<_Key_compare>::value)
162 : _M_key_compare(__x._M_key_compare)
168 struct _Rb_tree_header
170 _Rb_tree_node_base _M_header;
171 size_t _M_node_count;
173 _Rb_tree_header() _GLIBCXX_NOEXCEPT
175 _M_header._M_color = _S_red;
179 #if __cplusplus >= 201103L
180 _Rb_tree_header(_Rb_tree_header&& __x) noexcept
182 if (__x._M_header._M_parent !=
nullptr)
186 _M_header._M_color = _S_red;
193 _M_move_data(_Rb_tree_header& __from)
195 _M_header._M_color = __from._M_header._M_color;
196 _M_header._M_parent = __from._M_header._M_parent;
197 _M_header._M_left = __from._M_header._M_left;
198 _M_header._M_right = __from._M_header._M_right;
199 _M_header._M_parent->_M_parent = &_M_header;
200 _M_node_count = __from._M_node_count;
208 _M_header._M_parent = 0;
209 _M_header._M_left = &_M_header;
210 _M_header._M_right = &_M_header;
215 template<
typename _Val>
216 struct _Rb_tree_node :
public _Rb_tree_node_base
218 typedef _Rb_tree_node<_Val>* _Link_type;
220 #if __cplusplus < 201103L
231 __gnu_cxx::__aligned_membuf<_Val> _M_storage;
235 {
return _M_storage._M_ptr(); }
239 {
return _M_storage._M_ptr(); }
243 _GLIBCXX_PURE _Rb_tree_node_base*
244 _Rb_tree_increment(_Rb_tree_node_base* __x)
throw ();
246 _GLIBCXX_PURE
const _Rb_tree_node_base*
247 _Rb_tree_increment(
const _Rb_tree_node_base* __x)
throw ();
249 _GLIBCXX_PURE _Rb_tree_node_base*
250 _Rb_tree_decrement(_Rb_tree_node_base* __x)
throw ();
252 _GLIBCXX_PURE
const _Rb_tree_node_base*
253 _Rb_tree_decrement(
const _Rb_tree_node_base* __x)
throw ();
255 template<
typename _Tp>
256 struct _Rb_tree_iterator
258 typedef _Tp value_type;
259 typedef _Tp& reference;
260 typedef _Tp* pointer;
262 typedef bidirectional_iterator_tag iterator_category;
263 typedef ptrdiff_t difference_type;
265 typedef _Rb_tree_iterator<_Tp> _Self;
266 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
267 typedef _Rb_tree_node<_Tp>* _Link_type;
269 _Rb_tree_iterator() _GLIBCXX_NOEXCEPT
273 _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
278 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
281 operator->() const _GLIBCXX_NOEXCEPT
282 {
return static_cast<_Link_type
> (_M_node)->_M_valptr(); }
285 operator++() _GLIBCXX_NOEXCEPT
287 _M_node = _Rb_tree_increment(_M_node);
292 operator++(
int) _GLIBCXX_NOEXCEPT
295 _M_node = _Rb_tree_increment(_M_node);
300 operator--() _GLIBCXX_NOEXCEPT
302 _M_node = _Rb_tree_decrement(_M_node);
307 operator--(
int) _GLIBCXX_NOEXCEPT
310 _M_node = _Rb_tree_decrement(_M_node);
315 operator==(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
316 {
return __x._M_node == __y._M_node; }
318 #if ! __cpp_lib_three_way_comparison
320 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
321 {
return __x._M_node != __y._M_node; }
327 template<
typename _Tp>
328 struct _Rb_tree_const_iterator
330 typedef _Tp value_type;
331 typedef const _Tp& reference;
332 typedef const _Tp* pointer;
334 typedef _Rb_tree_iterator<_Tp> iterator;
336 typedef bidirectional_iterator_tag iterator_category;
337 typedef ptrdiff_t difference_type;
339 typedef _Rb_tree_const_iterator<_Tp> _Self;
340 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
341 typedef const _Rb_tree_node<_Tp>* _Link_type;
343 _Rb_tree_const_iterator() _GLIBCXX_NOEXCEPT
347 _Rb_tree_const_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
350 _Rb_tree_const_iterator(
const iterator& __it) _GLIBCXX_NOEXCEPT
351 : _M_node(__it._M_node) { }
354 _M_const_cast() const _GLIBCXX_NOEXCEPT
355 {
return iterator(
const_cast<typename iterator::_Base_ptr
>(_M_node)); }
359 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
362 operator->() const _GLIBCXX_NOEXCEPT
363 {
return static_cast<_Link_type
>(_M_node)->_M_valptr(); }
366 operator++() _GLIBCXX_NOEXCEPT
368 _M_node = _Rb_tree_increment(_M_node);
373 operator++(
int) _GLIBCXX_NOEXCEPT
376 _M_node = _Rb_tree_increment(_M_node);
381 operator--() _GLIBCXX_NOEXCEPT
383 _M_node = _Rb_tree_decrement(_M_node);
388 operator--(
int) _GLIBCXX_NOEXCEPT
391 _M_node = _Rb_tree_decrement(_M_node);
396 operator==(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
397 {
return __x._M_node == __y._M_node; }
399 #if ! __cpp_lib_three_way_comparison
401 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
402 {
return __x._M_node != __y._M_node; }
409 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
410 _Rb_tree_node_base* __x,
411 _Rb_tree_node_base* __p,
412 _Rb_tree_node_base& __header)
throw ();
415 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
416 _Rb_tree_node_base& __header)
throw ();
418 #if __cplusplus >= 201402L
419 template<
typename _Cmp,
typename _SfinaeType,
typename = __
void_t<>>
420 struct __has_is_transparent
423 template<
typename _Cmp,
typename _SfinaeType>
424 struct __has_is_transparent<_Cmp, _SfinaeType,
425 __void_t<typename _Cmp::is_transparent>>
426 {
typedef void type; };
428 template<
typename _Cmp,
typename _SfinaeType>
429 using __has_is_transparent_t
430 =
typename __has_is_transparent<_Cmp, _SfinaeType>::type;
433 #if __cplusplus > 201402L
434 template<
typename _Tree1,
typename _Cmp2>
435 struct _Rb_tree_merge_helper { };
438 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
439 typename _Compare,
typename _Alloc = allocator<_Val> >
443 rebind<_Rb_tree_node<_Val> >::other _Node_allocator;
448 typedef _Rb_tree_node_base* _Base_ptr;
449 typedef const _Rb_tree_node_base* _Const_Base_ptr;
450 typedef _Rb_tree_node<_Val>* _Link_type;
451 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
456 struct _Reuse_or_alloc_node
458 _Reuse_or_alloc_node(_Rb_tree& __t)
459 : _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t)
463 _M_root->_M_parent = 0;
465 if (_M_nodes->_M_left)
466 _M_nodes = _M_nodes->_M_left;
472 #if __cplusplus >= 201103L
473 _Reuse_or_alloc_node(
const _Reuse_or_alloc_node&) =
delete;
476 ~_Reuse_or_alloc_node()
477 { _M_t._M_erase(
static_cast<_Link_type
>(_M_root)); }
479 template<
typename _Arg>
481 #if __cplusplus < 201103L
482 operator()(
const _Arg& __arg)
484 operator()(_Arg&& __arg)
487 _Link_type __node =
static_cast<_Link_type
>(_M_extract());
490 _M_t._M_destroy_node(__node);
491 _M_t._M_construct_node(__node, _GLIBCXX_FORWARD(_Arg, __arg));
495 return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg));
505 _Base_ptr __node = _M_nodes;
506 _M_nodes = _M_nodes->_M_parent;
509 if (_M_nodes->_M_right == __node)
511 _M_nodes->_M_right = 0;
513 if (_M_nodes->_M_left)
515 _M_nodes = _M_nodes->_M_left;
517 while (_M_nodes->_M_right)
518 _M_nodes = _M_nodes->_M_right;
520 if (_M_nodes->_M_left)
521 _M_nodes = _M_nodes->_M_left;
525 _M_nodes->_M_left = 0;
542 _Alloc_node(_Rb_tree& __t)
545 template<
typename _Arg>
547 #if __cplusplus < 201103L
548 operator()(
const _Arg& __arg)
const
550 operator()(_Arg&& __arg)
const
552 {
return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg)); }
559 typedef _Key key_type;
560 typedef _Val value_type;
561 typedef value_type* pointer;
562 typedef const value_type* const_pointer;
563 typedef value_type& reference;
564 typedef const value_type& const_reference;
565 typedef size_t size_type;
566 typedef ptrdiff_t difference_type;
567 typedef _Alloc allocator_type;
570 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
571 {
return this->_M_impl; }
573 const _Node_allocator&
574 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
575 {
return this->_M_impl; }
578 get_allocator() const _GLIBCXX_NOEXCEPT
579 {
return allocator_type(_M_get_Node_allocator()); }
587 _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
590 #if __cplusplus < 201103L
592 _M_construct_node(_Link_type __node,
const value_type& __x)
595 { get_allocator().construct(__node->_M_valptr(), __x); }
599 __throw_exception_again;
604 _M_create_node(
const value_type& __x)
606 _Link_type __tmp = _M_get_node();
607 _M_construct_node(__tmp, __x);
611 template<
typename... _Args>
613 _M_construct_node(_Link_type __node, _Args&&... __args)
617 ::new(__node) _Rb_tree_node<_Val>;
618 _Alloc_traits::construct(_M_get_Node_allocator(),
620 std::forward<_Args>(__args)...);
624 __node->~_Rb_tree_node<_Val>();
626 __throw_exception_again;
630 template<
typename... _Args>
632 _M_create_node(_Args&&... __args)
634 _Link_type __tmp = _M_get_node();
635 _M_construct_node(__tmp, std::forward<_Args>(__args)...);
641 _M_destroy_node(_Link_type __p) _GLIBCXX_NOEXCEPT
643 #if __cplusplus < 201103L
644 get_allocator().destroy(__p->_M_valptr());
646 _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr());
647 __p->~_Rb_tree_node<_Val>();
652 _M_drop_node(_Link_type __p) _GLIBCXX_NOEXCEPT
654 _M_destroy_node(__p);
658 template<
typename _NodeGen>
660 _M_clone_node(_Const_Link_type __x, _NodeGen& __node_gen)
662 _Link_type __tmp = __node_gen(*__x->_M_valptr());
663 __tmp->_M_color = __x->_M_color;
670 #if _GLIBCXX_INLINE_VERSION
671 template<
typename _Key_compare>
674 template<
typename _Key_compare,
675 bool = __is_pod(_Key_compare)>
678 :
public _Node_allocator
679 ,
public _Rb_tree_key_compare<_Key_compare>
680 ,
public _Rb_tree_header
682 typedef _Rb_tree_key_compare<_Key_compare> _Base_key_compare;
685 _GLIBCXX_NOEXCEPT_IF(
686 is_nothrow_default_constructible<_Node_allocator>::value
687 && is_nothrow_default_constructible<_Base_key_compare>::value )
691 _Rb_tree_impl(
const _Rb_tree_impl& __x)
692 : _Node_allocator(_Alloc_traits::_S_select_on_copy(__x))
693 , _Base_key_compare(__x._M_key_compare)
696 #if __cplusplus < 201103L
697 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
698 : _Node_allocator(__a), _Base_key_compare(__comp)
701 _Rb_tree_impl(_Rb_tree_impl&&)
702 noexcept( is_nothrow_move_constructible<_Base_key_compare>::value )
706 _Rb_tree_impl(_Node_allocator&& __a)
707 : _Node_allocator(
std::
move(__a))
710 _Rb_tree_impl(_Rb_tree_impl&& __x, _Node_allocator&& __a)
711 : _Node_allocator(
std::
move(__a)),
712 _Base_key_compare(
std::
move(__x)),
713 _Rb_tree_header(
std::
move(__x))
716 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
717 : _Node_allocator(
std::
move(__a)), _Base_key_compare(__comp)
722 _Rb_tree_impl<_Compare> _M_impl;
726 _M_root() _GLIBCXX_NOEXCEPT
727 {
return this->_M_impl._M_header._M_parent; }
730 _M_root() const _GLIBCXX_NOEXCEPT
731 {
return this->_M_impl._M_header._M_parent; }
734 _M_leftmost() _GLIBCXX_NOEXCEPT
735 {
return this->_M_impl._M_header._M_left; }
738 _M_leftmost() const _GLIBCXX_NOEXCEPT
739 {
return this->_M_impl._M_header._M_left; }
742 _M_rightmost() _GLIBCXX_NOEXCEPT
743 {
return this->_M_impl._M_header._M_right; }
746 _M_rightmost() const _GLIBCXX_NOEXCEPT
747 {
return this->_M_impl._M_header._M_right; }
750 _M_begin() _GLIBCXX_NOEXCEPT
751 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
754 _M_begin() const _GLIBCXX_NOEXCEPT
756 return static_cast<_Const_Link_type
>
757 (this->_M_impl._M_header._M_parent);
761 _M_end() _GLIBCXX_NOEXCEPT
762 {
return &this->_M_impl._M_header; }
765 _M_end() const _GLIBCXX_NOEXCEPT
766 {
return &this->_M_impl._M_header; }
769 _S_key(_Const_Link_type __x)
771 #if __cplusplus >= 201103L
774 static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
775 "comparison object must be invocable "
776 "with two arguments of key type");
777 # if __cplusplus >= 201703L
780 if constexpr (__is_invocable<_Compare&, const _Key&, const _Key&>{})
782 is_invocable_v<const _Compare&, const _Key&, const _Key&>,
783 "comparison object must be invocable as const");
787 return _KeyOfValue()(*__x->_M_valptr());
791 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
792 {
return static_cast<_Link_type
>(__x->_M_left); }
794 static _Const_Link_type
795 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
796 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
799 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
800 {
return static_cast<_Link_type
>(__x->_M_right); }
802 static _Const_Link_type
803 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
804 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
807 _S_key(_Const_Base_ptr __x)
808 {
return _S_key(
static_cast<_Const_Link_type
>(__x)); }
811 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
812 {
return _Rb_tree_node_base::_S_minimum(__x); }
814 static _Const_Base_ptr
815 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
816 {
return _Rb_tree_node_base::_S_minimum(__x); }
819 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
820 {
return _Rb_tree_node_base::_S_maximum(__x); }
822 static _Const_Base_ptr
823 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
824 {
return _Rb_tree_node_base::_S_maximum(__x); }
827 typedef _Rb_tree_iterator<value_type> iterator;
828 typedef _Rb_tree_const_iterator<value_type> const_iterator;
833 #if __cplusplus > 201402L
834 using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
835 using insert_return_type = _Node_insert_return<
836 conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
840 pair<_Base_ptr, _Base_ptr>
841 _M_get_insert_unique_pos(
const key_type& __k);
843 pair<_Base_ptr, _Base_ptr>
844 _M_get_insert_equal_pos(
const key_type& __k);
846 pair<_Base_ptr, _Base_ptr>
847 _M_get_insert_hint_unique_pos(const_iterator __pos,
848 const key_type& __k);
850 pair<_Base_ptr, _Base_ptr>
851 _M_get_insert_hint_equal_pos(const_iterator __pos,
852 const key_type& __k);
855 #if __cplusplus >= 201103L
856 template<
typename _Arg,
typename _NodeGen>
858 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
861 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
863 template<
typename _Arg>
865 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
867 template<
typename _Arg>
869 _M_insert_equal_lower(_Arg&& __x);
872 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
875 _M_insert_equal_lower_node(_Link_type __z);
877 template<
typename _NodeGen>
879 _M_insert_(_Base_ptr __x, _Base_ptr __y,
880 const value_type& __v, _NodeGen&);
885 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
888 _M_insert_equal_lower(
const value_type& __x);
891 template<
typename _NodeGen>
893 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen&);
895 template<
typename _NodeGen>
897 _M_copy(
const _Rb_tree& __x, _NodeGen& __gen)
899 _Link_type __root = _M_copy(__x._M_begin(), _M_end(), __gen);
900 _M_leftmost() = _S_minimum(__root);
901 _M_rightmost() = _S_maximum(__root);
902 _M_impl._M_node_count = __x._M_impl._M_node_count;
907 _M_copy(
const _Rb_tree& __x)
909 _Alloc_node __an(*
this);
910 return _M_copy(__x, __an);
914 _M_erase(_Link_type __x);
917 _M_lower_bound(_Link_type __x, _Base_ptr __y,
921 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
922 const _Key& __k)
const;
925 _M_upper_bound(_Link_type __x, _Base_ptr __y,
929 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
930 const _Key& __k)
const;
934 #if __cplusplus < 201103L
937 _Rb_tree() =
default;
940 _Rb_tree(
const _Compare& __comp,
941 const allocator_type& __a = allocator_type())
942 : _M_impl(__comp, _Node_allocator(__a)) { }
944 _Rb_tree(
const _Rb_tree& __x)
945 : _M_impl(__x._M_impl)
947 if (__x._M_root() != 0)
948 _M_root() = _M_copy(__x);
951 #if __cplusplus >= 201103L
952 _Rb_tree(
const allocator_type& __a)
953 : _M_impl(_Node_allocator(__a))
956 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
957 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
959 if (__x._M_root() !=
nullptr)
960 _M_root() = _M_copy(__x);
963 _Rb_tree(_Rb_tree&&) =
default;
965 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
966 : _Rb_tree(
std::
move(__x), _Node_allocator(__a))
970 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
true_type)
971 noexcept(is_nothrow_default_constructible<_Compare>::value)
975 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
false_type)
976 : _M_impl(__x._M_impl._M_key_compare,
std::
move(__a))
978 if (__x._M_root() !=
nullptr)
983 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
985 _Rb_tree(std::declval<_Rb_tree&&>(), std::declval<_Node_allocator&&>(),
986 std::declval<typename _Alloc_traits::is_always_equal>())) )
988 typename _Alloc_traits::is_always_equal{})
992 ~_Rb_tree() _GLIBCXX_NOEXCEPT
993 { _M_erase(_M_begin()); }
996 operator=(
const _Rb_tree& __x);
1001 {
return _M_impl._M_key_compare; }
1004 begin() _GLIBCXX_NOEXCEPT
1005 {
return iterator(this->_M_impl._M_header._M_left); }
1008 begin() const _GLIBCXX_NOEXCEPT
1009 {
return const_iterator(this->_M_impl._M_header._M_left); }
1012 end() _GLIBCXX_NOEXCEPT
1013 {
return iterator(&this->_M_impl._M_header); }
1016 end() const _GLIBCXX_NOEXCEPT
1017 {
return const_iterator(&this->_M_impl._M_header); }
1020 rbegin() _GLIBCXX_NOEXCEPT
1021 {
return reverse_iterator(
end()); }
1023 const_reverse_iterator
1024 rbegin() const _GLIBCXX_NOEXCEPT
1025 {
return const_reverse_iterator(
end()); }
1028 rend() _GLIBCXX_NOEXCEPT
1029 {
return reverse_iterator(
begin()); }
1031 const_reverse_iterator
1032 rend() const _GLIBCXX_NOEXCEPT
1033 {
return const_reverse_iterator(
begin()); }
1035 _GLIBCXX_NODISCARD
bool
1036 empty() const _GLIBCXX_NOEXCEPT
1037 {
return _M_impl._M_node_count == 0; }
1040 size() const _GLIBCXX_NOEXCEPT
1041 {
return _M_impl._M_node_count; }
1044 max_size() const _GLIBCXX_NOEXCEPT
1049 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value);
1052 #if __cplusplus >= 201103L
1053 template<
typename _Arg>
1054 pair<iterator, bool>
1055 _M_insert_unique(_Arg&& __x);
1057 template<
typename _Arg>
1059 _M_insert_equal(_Arg&& __x);
1061 template<
typename _Arg,
typename _NodeGen>
1063 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1065 template<
typename _Arg>
1067 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
1069 _Alloc_node __an(*
this);
1070 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
1073 template<
typename _Arg,
typename _NodeGen>
1075 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1077 template<
typename _Arg>
1079 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
1081 _Alloc_node __an(*
this);
1082 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
1085 template<
typename... _Args>
1086 pair<iterator, bool>
1087 _M_emplace_unique(_Args&&... __args);
1089 template<
typename... _Args>
1091 _M_emplace_equal(_Args&&... __args);
1093 template<
typename... _Args>
1095 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
1097 template<
typename... _Args>
1099 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
1101 template<
typename _Iter>
1102 using __same_value_type
1103 = is_same<value_type, typename iterator_traits<_Iter>::value_type>;
1105 template<
typename _InputIterator>
1106 __enable_if_t<__same_value_type<_InputIterator>::value>
1107 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1109 _Alloc_node __an(*
this);
1110 for (; __first != __last; ++__first)
1111 _M_insert_unique_(
end(), *__first, __an);
1114 template<
typename _InputIterator>
1115 __enable_if_t<!__same_value_type<_InputIterator>::value>
1116 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1118 for (; __first != __last; ++__first)
1119 _M_emplace_unique(*__first);
1122 template<
typename _InputIterator>
1123 __enable_if_t<__same_value_type<_InputIterator>::value>
1124 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1126 _Alloc_node __an(*
this);
1127 for (; __first != __last; ++__first)
1128 _M_insert_equal_(
end(), *__first, __an);
1131 template<
typename _InputIterator>
1132 __enable_if_t<!__same_value_type<_InputIterator>::value>
1133 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1135 _Alloc_node __an(*
this);
1136 for (; __first != __last; ++__first)
1137 _M_emplace_equal(*__first);
1140 pair<iterator, bool>
1141 _M_insert_unique(
const value_type& __x);
1144 _M_insert_equal(
const value_type& __x);
1146 template<
typename _NodeGen>
1148 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
1152 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
1154 _Alloc_node __an(*
this);
1155 return _M_insert_unique_(__pos, __x, __an);
1158 template<
typename _NodeGen>
1160 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1163 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1165 _Alloc_node __an(*
this);
1166 return _M_insert_equal_(__pos, __x, __an);
1169 template<
typename _InputIterator>
1171 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1173 _Alloc_node __an(*
this);
1174 for (; __first != __last; ++__first)
1175 _M_insert_unique_(
end(), *__first, __an);
1178 template<
typename _InputIterator>
1180 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1182 _Alloc_node __an(*
this);
1183 for (; __first != __last; ++__first)
1184 _M_insert_equal_(
end(), *__first, __an);
1190 _M_erase_aux(const_iterator __position);
1193 _M_erase_aux(const_iterator __first, const_iterator __last);
1196 #if __cplusplus >= 201103L
1199 _GLIBCXX_ABI_TAG_CXX11
1201 erase(const_iterator __position)
1203 __glibcxx_assert(__position !=
end());
1204 const_iterator __result = __position;
1206 _M_erase_aux(__position);
1207 return __result._M_const_cast();
1211 _GLIBCXX_ABI_TAG_CXX11
1213 erase(iterator __position)
1215 __glibcxx_assert(__position !=
end());
1216 iterator __result = __position;
1218 _M_erase_aux(__position);
1223 erase(iterator __position)
1225 __glibcxx_assert(__position !=
end());
1226 _M_erase_aux(__position);
1230 erase(const_iterator __position)
1232 __glibcxx_assert(__position !=
end());
1233 _M_erase_aux(__position);
1238 erase(
const key_type& __x);
1240 #if __cplusplus >= 201103L
1243 _GLIBCXX_ABI_TAG_CXX11
1245 erase(const_iterator __first, const_iterator __last)
1247 _M_erase_aux(__first, __last);
1248 return __last._M_const_cast();
1252 erase(iterator __first, iterator __last)
1253 { _M_erase_aux(__first, __last); }
1256 erase(const_iterator __first, const_iterator __last)
1257 { _M_erase_aux(__first, __last); }
1261 clear() _GLIBCXX_NOEXCEPT
1263 _M_erase(_M_begin());
1269 find(
const key_type& __k);
1272 find(
const key_type& __k)
const;
1275 count(
const key_type& __k)
const;
1278 lower_bound(
const key_type& __k)
1279 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1282 lower_bound(
const key_type& __k)
const
1283 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1286 upper_bound(
const key_type& __k)
1287 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1290 upper_bound(
const key_type& __k)
const
1291 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1293 pair<iterator, iterator>
1294 equal_range(
const key_type& __k);
1296 pair<const_iterator, const_iterator>
1297 equal_range(
const key_type& __k)
const;
1299 #if __cplusplus >= 201402L
1300 template<
typename _Kt,
1301 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1303 _M_find_tr(
const _Kt& __k)
1305 const _Rb_tree* __const_this =
this;
1306 return __const_this->_M_find_tr(__k)._M_const_cast();
1309 template<
typename _Kt,
1310 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1312 _M_find_tr(
const _Kt& __k)
const
1314 auto __j = _M_lower_bound_tr(__k);
1315 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1320 template<
typename _Kt,
1321 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1323 _M_count_tr(
const _Kt& __k)
const
1325 auto __p = _M_equal_range_tr(__k);
1329 template<
typename _Kt,
1330 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1332 _M_lower_bound_tr(
const _Kt& __k)
1334 const _Rb_tree* __const_this =
this;
1335 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1338 template<
typename _Kt,
1339 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1341 _M_lower_bound_tr(
const _Kt& __k)
const
1343 auto __x = _M_begin();
1344 auto __y = _M_end();
1346 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1352 __x = _S_right(__x);
1353 return const_iterator(__y);
1356 template<
typename _Kt,
1357 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1359 _M_upper_bound_tr(
const _Kt& __k)
1361 const _Rb_tree* __const_this =
this;
1362 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1365 template<
typename _Kt,
1366 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1368 _M_upper_bound_tr(
const _Kt& __k)
const
1370 auto __x = _M_begin();
1371 auto __y = _M_end();
1373 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1379 __x = _S_right(__x);
1380 return const_iterator(__y);
1383 template<
typename _Kt,
1384 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1385 pair<iterator, iterator>
1386 _M_equal_range_tr(
const _Kt& __k)
1388 const _Rb_tree* __const_this =
this;
1389 auto __ret = __const_this->_M_equal_range_tr(__k);
1390 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1393 template<
typename _Kt,
1394 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1395 pair<const_iterator, const_iterator>
1396 _M_equal_range_tr(
const _Kt& __k)
const
1398 auto __low = _M_lower_bound_tr(__k);
1399 auto __high = __low;
1400 auto& __cmp = _M_impl._M_key_compare;
1401 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1403 return { __low, __high };
1409 __rb_verify()
const;
1411 #if __cplusplus >= 201103L
1413 operator=(_Rb_tree&&)
1414 noexcept(_Alloc_traits::_S_nothrow_move()
1415 && is_nothrow_move_assignable<_Compare>::value);
1417 template<typename _Iterator>
1419 _M_assign_unique(_Iterator, _Iterator);
1421 template<typename _Iterator>
1423 _M_assign_equal(_Iterator, _Iterator);
1429 { _M_impl._M_move_data(__x._M_impl); }
1446 #if __cplusplus > 201402L
1450 _M_reinsert_node_unique(node_type&& __nh)
1452 insert_return_type __ret;
1454 __ret.position =
end();
1457 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1459 auto __res = _M_get_insert_unique_pos(__nh._M_key());
1463 = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1464 __nh._M_ptr =
nullptr;
1465 __ret.inserted =
true;
1470 __ret.position = iterator(__res.first);
1471 __ret.inserted =
false;
1479 _M_reinsert_node_equal(node_type&& __nh)
1486 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1487 auto __res = _M_get_insert_equal_pos(__nh._M_key());
1489 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1491 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1492 __nh._M_ptr =
nullptr;
1499 _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh)
1506 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1507 auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key());
1510 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1511 __nh._M_ptr =
nullptr;
1514 __ret = iterator(__res.first);
1521 _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh)
1528 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1529 auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key());
1531 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1533 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1534 __nh._M_ptr =
nullptr;
1541 extract(const_iterator __pos)
1543 auto __ptr = _Rb_tree_rebalance_for_erase(
1544 __pos._M_const_cast()._M_node, _M_impl._M_header);
1545 --_M_impl._M_node_count;
1546 return {
static_cast<_Link_type
>(__ptr), _M_get_Node_allocator() };
1551 extract(
const key_type& __k)
1554 auto __pos = find(__k);
1556 __nh = extract(const_iterator(__pos));
1560 template<
typename _Compare2>
1561 using _Compatible_tree
1562 = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>;
1564 template<
typename,
typename>
1565 friend class _Rb_tree_merge_helper;
1568 template<
typename _Compare2>
1570 _M_merge_unique(_Compatible_tree<_Compare2>& __src) noexcept
1572 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1573 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1576 auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos));
1579 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1580 auto __ptr = _Rb_tree_rebalance_for_erase(
1581 __pos._M_node, __src_impl._M_header);
1582 --__src_impl._M_node_count;
1583 _M_insert_node(__res.first, __res.second,
1584 static_cast<_Link_type
>(__ptr));
1590 template<
typename _Compare2>
1592 _M_merge_equal(_Compatible_tree<_Compare2>& __src) noexcept
1594 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1595 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1598 auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos));
1601 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1602 auto __ptr = _Rb_tree_rebalance_for_erase(
1603 __pos._M_node, __src_impl._M_header);
1604 --__src_impl._M_node_count;
1605 _M_insert_node(__res.first, __res.second,
1606 static_cast<_Link_type
>(__ptr));
1613 operator==(
const _Rb_tree& __x,
const _Rb_tree& __y)
1615 return __x.size() == __y.size()
1616 &&
std::equal(__x.begin(), __x.end(), __y.begin());
1619 #if __cpp_lib_three_way_comparison
1621 operator<=>(
const _Rb_tree& __x,
const _Rb_tree& __y)
1623 if constexpr (requires {
typename __detail::__synth3way_t<_Val>; })
1624 return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
1625 __y.begin(), __y.end(),
1626 __detail::__synth3way);
1630 operator<(
const _Rb_tree& __x,
const _Rb_tree& __y)
1633 __y.begin(), __y.end());
1636 friend bool _GLIBCXX_DEPRECATED
1637 operator!=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1638 {
return !(__x == __y); }
1640 friend bool _GLIBCXX_DEPRECATED
1641 operator>(
const _Rb_tree& __x,
const _Rb_tree& __y)
1642 {
return __y < __x; }
1644 friend bool _GLIBCXX_DEPRECATED
1645 operator<=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1646 {
return !(__y < __x); }
1648 friend bool _GLIBCXX_DEPRECATED
1649 operator>=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1650 {
return !(__x < __y); }
1654 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1655 typename _Compare,
typename _Alloc>
1657 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1658 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1661 #if __cplusplus >= 201103L
1662 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1663 typename _Compare,
typename _Alloc>
1665 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1668 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1672 _Alloc_node __an(*
this);
1674 [&__an](
const value_type& __cval)
1676 auto& __val =
const_cast<value_type&
>(__cval);
1679 _M_root() = _M_copy(__x, __lbd);
1683 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1684 typename _Compare,
typename _Alloc>
1686 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1687 _M_move_assign(_Rb_tree& __x,
true_type)
1690 if (__x._M_root() !=
nullptr)
1692 std::__alloc_on_move(_M_get_Node_allocator(),
1693 __x._M_get_Node_allocator());
1696 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1697 typename _Compare,
typename _Alloc>
1699 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1702 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1703 return _M_move_assign(__x,
true_type{});
1707 _Reuse_or_alloc_node __roan(*
this);
1709 if (__x._M_root() !=
nullptr)
1712 [&__roan](
const value_type& __cval)
1714 auto& __val =
const_cast<value_type&
>(__cval);
1717 _M_root() = _M_copy(__x, __lbd);
1722 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1723 typename _Compare,
typename _Alloc>
1724 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1725 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1726 operator=(_Rb_tree&& __x)
1727 noexcept(_Alloc_traits::_S_nothrow_move()
1728 && is_nothrow_move_assignable<_Compare>::value)
1730 _M_impl._M_key_compare =
std::move(__x._M_impl._M_key_compare);
1731 _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>());
1735 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1736 typename _Compare,
typename _Alloc>
1737 template<
typename _Iterator>
1739 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1740 _M_assign_unique(_Iterator __first, _Iterator __last)
1742 _Reuse_or_alloc_node __roan(*
this);
1744 for (; __first != __last; ++__first)
1745 _M_insert_unique_(
end(), *__first, __roan);
1748 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1749 typename _Compare,
typename _Alloc>
1750 template<
typename _Iterator>
1752 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1753 _M_assign_equal(_Iterator __first, _Iterator __last)
1755 _Reuse_or_alloc_node __roan(*
this);
1757 for (; __first != __last; ++__first)
1758 _M_insert_equal_(
end(), *__first, __roan);
1762 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1763 typename _Compare,
typename _Alloc>
1764 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1765 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1766 operator=(
const _Rb_tree& __x)
1771 #if __cplusplus >= 201103L
1772 if (_Alloc_traits::_S_propagate_on_copy_assign())
1774 auto& __this_alloc = this->_M_get_Node_allocator();
1775 auto& __that_alloc = __x._M_get_Node_allocator();
1776 if (!_Alloc_traits::_S_always_equal()
1777 && __this_alloc != __that_alloc)
1782 std::__alloc_on_copy(__this_alloc, __that_alloc);
1787 _Reuse_or_alloc_node __roan(*
this);
1789 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1790 if (__x._M_root() != 0)
1791 _M_root() = _M_copy(__x, __roan);
1797 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1798 typename _Compare,
typename _Alloc>
1799 #if __cplusplus >= 201103L
1800 template<
typename _Arg,
typename _NodeGen>
1802 template<
typename _NodeGen>
1804 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1805 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1806 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1807 #
if __cplusplus >= 201103L
1812 _NodeGen& __node_gen)
1814 bool __insert_left = (__x != 0 || __p == _M_end()
1815 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1818 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1820 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1821 this->_M_impl._M_header);
1822 ++_M_impl._M_node_count;
1823 return iterator(__z);
1826 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1827 typename _Compare,
typename _Alloc>
1828 #if __cplusplus >= 201103L
1829 template<
typename _Arg>
1831 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1832 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1833 #if __cplusplus >= 201103L
1834 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1836 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1839 bool __insert_left = (__p == _M_end()
1840 || !_M_impl._M_key_compare(_S_key(__p),
1841 _KeyOfValue()(__v)));
1843 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1845 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1846 this->_M_impl._M_header);
1847 ++_M_impl._M_node_count;
1848 return iterator(__z);
1851 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1852 typename _Compare,
typename _Alloc>
1853 #if __cplusplus >= 201103L
1854 template<
typename _Arg>
1856 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1857 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1858 #if __cplusplus >= 201103L
1859 _M_insert_equal_lower(_Arg&& __v)
1861 _M_insert_equal_lower(
const _Val& __v)
1864 _Link_type __x = _M_begin();
1865 _Base_ptr __y = _M_end();
1869 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1870 _S_left(__x) : _S_right(__x);
1872 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1875 template<
typename _Key,
typename _Val,
typename _KoV,
1876 typename _Compare,
typename _Alloc>
1877 template<
typename _NodeGen>
1878 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1879 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1880 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1883 _Link_type __top = _M_clone_node(__x, __node_gen);
1884 __top->_M_parent = __p;
1889 __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen);
1895 _Link_type __y = _M_clone_node(__x, __node_gen);
1897 __y->_M_parent = __p;
1899 __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen);
1907 __throw_exception_again;
1912 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1913 typename _Compare,
typename _Alloc>
1915 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1916 _M_erase(_Link_type __x)
1921 _M_erase(_S_right(__x));
1922 _Link_type __y = _S_left(__x);
1928 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1929 typename _Compare,
typename _Alloc>
1930 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1931 _Compare, _Alloc>::iterator
1932 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1933 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1937 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1938 __y = __x, __x = _S_left(__x);
1940 __x = _S_right(__x);
1941 return iterator(__y);
1944 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1945 typename _Compare,
typename _Alloc>
1946 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1947 _Compare, _Alloc>::const_iterator
1948 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1949 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1950 const _Key& __k)
const
1953 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1954 __y = __x, __x = _S_left(__x);
1956 __x = _S_right(__x);
1957 return const_iterator(__y);
1960 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1961 typename _Compare,
typename _Alloc>
1962 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1963 _Compare, _Alloc>::iterator
1964 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1965 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1969 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1970 __y = __x, __x = _S_left(__x);
1972 __x = _S_right(__x);
1973 return iterator(__y);
1976 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1977 typename _Compare,
typename _Alloc>
1978 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1979 _Compare, _Alloc>::const_iterator
1980 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1981 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1982 const _Key& __k)
const
1985 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1986 __y = __x, __x = _S_left(__x);
1988 __x = _S_right(__x);
1989 return const_iterator(__y);
1992 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1993 typename _Compare,
typename _Alloc>
1994 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1995 _Compare, _Alloc>::iterator,
1996 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1997 _Compare, _Alloc>::iterator>
1998 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1999 equal_range(
const _Key& __k)
2001 _Link_type __x = _M_begin();
2002 _Base_ptr __y = _M_end();
2005 if (_M_impl._M_key_compare(_S_key(__x), __k))
2006 __x = _S_right(__x);
2007 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2008 __y = __x, __x = _S_left(__x);
2011 _Link_type __xu(__x);
2012 _Base_ptr __yu(__y);
2013 __y = __x, __x = _S_left(__x);
2014 __xu = _S_right(__xu);
2015 return pair<iterator,
2016 iterator>(_M_lower_bound(__x, __y, __k),
2017 _M_upper_bound(__xu, __yu, __k));
2020 return pair<iterator, iterator>(iterator(__y),
2024 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2025 typename _Compare,
typename _Alloc>
2026 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2027 _Compare, _Alloc>::const_iterator,
2028 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2029 _Compare, _Alloc>::const_iterator>
2030 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2031 equal_range(
const _Key& __k)
const
2033 _Const_Link_type __x = _M_begin();
2034 _Const_Base_ptr __y = _M_end();
2037 if (_M_impl._M_key_compare(_S_key(__x), __k))
2038 __x = _S_right(__x);
2039 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2040 __y = __x, __x = _S_left(__x);
2043 _Const_Link_type __xu(__x);
2044 _Const_Base_ptr __yu(__y);
2045 __y = __x, __x = _S_left(__x);
2046 __xu = _S_right(__xu);
2047 return pair<const_iterator,
2048 const_iterator>(_M_lower_bound(__x, __y, __k),
2049 _M_upper_bound(__xu, __yu, __k));
2052 return pair<const_iterator, const_iterator>(const_iterator(__y),
2053 const_iterator(__y));
2056 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2057 typename _Compare,
typename _Alloc>
2059 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2061 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
2065 if (__t._M_root() != 0)
2066 _M_impl._M_move_data(__t._M_impl);
2068 else if (__t._M_root() == 0)
2069 __t._M_impl._M_move_data(_M_impl);
2072 std::swap(_M_root(),__t._M_root());
2073 std::swap(_M_leftmost(),__t._M_leftmost());
2074 std::swap(_M_rightmost(),__t._M_rightmost());
2076 _M_root()->_M_parent = _M_end();
2077 __t._M_root()->_M_parent = __t._M_end();
2078 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
2081 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
2083 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
2084 __t._M_get_Node_allocator());
2087 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2088 typename _Compare,
typename _Alloc>
2089 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2090 _Compare, _Alloc>::_Base_ptr,
2091 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2092 _Compare, _Alloc>::_Base_ptr>
2093 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2094 _M_get_insert_unique_pos(
const key_type& __k)
2096 typedef pair<_Base_ptr, _Base_ptr> _Res;
2097 _Link_type __x = _M_begin();
2098 _Base_ptr __y = _M_end();
2103 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
2104 __x = __comp ? _S_left(__x) : _S_right(__x);
2106 iterator __j = iterator(__y);
2110 return _Res(__x, __y);
2114 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
2115 return _Res(__x, __y);
2116 return _Res(__j._M_node, 0);
2119 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2120 typename _Compare,
typename _Alloc>
2121 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2122 _Compare, _Alloc>::_Base_ptr,
2123 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2124 _Compare, _Alloc>::_Base_ptr>
2125 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2126 _M_get_insert_equal_pos(
const key_type& __k)
2128 typedef pair<_Base_ptr, _Base_ptr> _Res;
2129 _Link_type __x = _M_begin();
2130 _Base_ptr __y = _M_end();
2134 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
2135 _S_left(__x) : _S_right(__x);
2137 return _Res(__x, __y);
2140 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2141 typename _Compare,
typename _Alloc>
2142 #if __cplusplus >= 201103L
2143 template<
typename _Arg>
2145 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2146 _Compare, _Alloc>::iterator,
bool>
2147 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2148 #if __cplusplus >= 201103L
2149 _M_insert_unique(_Arg&& __v)
2151 _M_insert_unique(
const _Val& __v)
2154 typedef pair<iterator, bool> _Res;
2155 pair<_Base_ptr, _Base_ptr> __res
2156 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
2160 _Alloc_node __an(*
this);
2161 return _Res(_M_insert_(__res.first, __res.second,
2162 _GLIBCXX_FORWARD(_Arg, __v), __an),
2166 return _Res(iterator(__res.first),
false);
2169 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2170 typename _Compare,
typename _Alloc>
2171 #if __cplusplus >= 201103L
2172 template<
typename _Arg>
2174 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2175 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2176 #if __cplusplus >= 201103L
2177 _M_insert_equal(_Arg&& __v)
2179 _M_insert_equal(
const _Val& __v)
2182 pair<_Base_ptr, _Base_ptr> __res
2183 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
2184 _Alloc_node __an(*
this);
2185 return _M_insert_(__res.first, __res.second,
2186 _GLIBCXX_FORWARD(_Arg, __v), __an);
2189 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2190 typename _Compare,
typename _Alloc>
2191 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2192 _Compare, _Alloc>::_Base_ptr,
2193 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2194 _Compare, _Alloc>::_Base_ptr>
2195 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2196 _M_get_insert_hint_unique_pos(const_iterator __position,
2197 const key_type& __k)
2199 iterator __pos = __position._M_const_cast();
2200 typedef pair<_Base_ptr, _Base_ptr> _Res;
2203 if (__pos._M_node == _M_end())
2206 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
2207 return _Res(0, _M_rightmost());
2209 return _M_get_insert_unique_pos(__k);
2211 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
2214 iterator __before = __pos;
2215 if (__pos._M_node == _M_leftmost())
2216 return _Res(_M_leftmost(), _M_leftmost());
2217 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
2219 if (_S_right(__before._M_node) == 0)
2220 return _Res(0, __before._M_node);
2222 return _Res(__pos._M_node, __pos._M_node);
2225 return _M_get_insert_unique_pos(__k);
2227 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2230 iterator __after = __pos;
2231 if (__pos._M_node == _M_rightmost())
2232 return _Res(0, _M_rightmost());
2233 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
2235 if (_S_right(__pos._M_node) == 0)
2236 return _Res(0, __pos._M_node);
2238 return _Res(__after._M_node, __after._M_node);
2241 return _M_get_insert_unique_pos(__k);
2245 return _Res(__pos._M_node, 0);
2248 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2249 typename _Compare,
typename _Alloc>
2250 #if __cplusplus >= 201103L
2251 template<
typename _Arg,
typename _NodeGen>
2253 template<
typename _NodeGen>
2255 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2256 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2257 _M_insert_unique_(const_iterator __position,
2258 #
if __cplusplus >= 201103L
2263 _NodeGen& __node_gen)
2265 pair<_Base_ptr, _Base_ptr> __res
2266 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2269 return _M_insert_(__res.first, __res.second,
2270 _GLIBCXX_FORWARD(_Arg, __v),
2272 return iterator(__res.first);
2275 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2276 typename _Compare,
typename _Alloc>
2277 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2278 _Compare, _Alloc>::_Base_ptr,
2279 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2280 _Compare, _Alloc>::_Base_ptr>
2281 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2282 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2284 iterator __pos = __position._M_const_cast();
2285 typedef pair<_Base_ptr, _Base_ptr> _Res;
2288 if (__pos._M_node == _M_end())
2291 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2292 return _Res(0, _M_rightmost());
2294 return _M_get_insert_equal_pos(__k);
2296 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2299 iterator __before = __pos;
2300 if (__pos._M_node == _M_leftmost())
2301 return _Res(_M_leftmost(), _M_leftmost());
2302 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2304 if (_S_right(__before._M_node) == 0)
2305 return _Res(0, __before._M_node);
2307 return _Res(__pos._M_node, __pos._M_node);
2310 return _M_get_insert_equal_pos(__k);
2315 iterator __after = __pos;
2316 if (__pos._M_node == _M_rightmost())
2317 return _Res(0, _M_rightmost());
2318 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2320 if (_S_right(__pos._M_node) == 0)
2321 return _Res(0, __pos._M_node);
2323 return _Res(__after._M_node, __after._M_node);
2330 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2331 typename _Compare,
typename _Alloc>
2332 #if __cplusplus >= 201103L
2333 template<
typename _Arg,
typename _NodeGen>
2335 template<
typename _NodeGen>
2337 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2338 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2339 _M_insert_equal_(const_iterator __position,
2340 #
if __cplusplus >= 201103L
2345 _NodeGen& __node_gen)
2347 pair<_Base_ptr, _Base_ptr> __res
2348 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2351 return _M_insert_(__res.first, __res.second,
2352 _GLIBCXX_FORWARD(_Arg, __v),
2355 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2358 #if __cplusplus >= 201103L
2359 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2360 typename _Compare,
typename _Alloc>
2361 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2362 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2363 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2365 bool __insert_left = (__x != 0 || __p == _M_end()
2366 || _M_impl._M_key_compare(_S_key(__z),
2369 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2370 this->_M_impl._M_header);
2371 ++_M_impl._M_node_count;
2372 return iterator(__z);
2375 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2376 typename _Compare,
typename _Alloc>
2377 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2378 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2379 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2381 bool __insert_left = (__p == _M_end()
2382 || !_M_impl._M_key_compare(_S_key(__p),
2385 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2386 this->_M_impl._M_header);
2387 ++_M_impl._M_node_count;
2388 return iterator(__z);
2391 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2392 typename _Compare,
typename _Alloc>
2393 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2394 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2395 _M_insert_equal_lower_node(_Link_type __z)
2397 _Link_type __x = _M_begin();
2398 _Base_ptr __y = _M_end();
2402 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2403 _S_left(__x) : _S_right(__x);
2405 return _M_insert_lower_node(__y, __z);
2408 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2409 typename _Compare,
typename _Alloc>
2410 template<
typename... _Args>
2411 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2412 _Compare, _Alloc>::iterator,
bool>
2413 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2414 _M_emplace_unique(_Args&&... __args)
2416 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2420 typedef pair<iterator, bool> _Res;
2421 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2423 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2426 return _Res(iterator(__res.first),
false);
2431 __throw_exception_again;
2435 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2436 typename _Compare,
typename _Alloc>
2437 template<
typename... _Args>
2438 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2439 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2440 _M_emplace_equal(_Args&&... __args)
2442 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2446 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2447 return _M_insert_node(__res.first, __res.second, __z);
2452 __throw_exception_again;
2456 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2457 typename _Compare,
typename _Alloc>
2458 template<
typename... _Args>
2459 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2460 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2461 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2463 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2467 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2470 return _M_insert_node(__res.first, __res.second, __z);
2473 return iterator(__res.first);
2478 __throw_exception_again;
2482 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2483 typename _Compare,
typename _Alloc>
2484 template<
typename... _Args>
2485 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2486 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2487 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2489 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2493 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2496 return _M_insert_node(__res.first, __res.second, __z);
2498 return _M_insert_equal_lower_node(__z);
2503 __throw_exception_again;
2509 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2510 typename _Compare,
typename _Alloc>
2512 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2513 _M_erase_aux(const_iterator __position)
2516 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
2517 (
const_cast<_Base_ptr
>(__position._M_node),
2518 this->_M_impl._M_header));
2520 --_M_impl._M_node_count;
2523 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2524 typename _Compare,
typename _Alloc>
2526 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2527 _M_erase_aux(const_iterator __first, const_iterator __last)
2529 if (__first ==
begin() && __last ==
end())
2532 while (__first != __last)
2533 _M_erase_aux(__first++);
2536 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2537 typename _Compare,
typename _Alloc>
2538 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2539 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2540 erase(
const _Key& __x)
2542 pair<iterator, iterator> __p = equal_range(__x);
2543 const size_type __old_size = size();
2544 _M_erase_aux(__p.first, __p.second);
2545 return __old_size - size();
2548 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2549 typename _Compare,
typename _Alloc>
2550 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2551 _Compare, _Alloc>::iterator
2552 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2553 find(
const _Key& __k)
2555 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2556 return (__j ==
end()
2557 || _M_impl._M_key_compare(__k,
2558 _S_key(__j._M_node))) ?
end() : __j;
2561 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2562 typename _Compare,
typename _Alloc>
2563 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2564 _Compare, _Alloc>::const_iterator
2565 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2566 find(
const _Key& __k)
const
2568 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2569 return (__j ==
end()
2570 || _M_impl._M_key_compare(__k,
2571 _S_key(__j._M_node))) ?
end() : __j;
2574 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2575 typename _Compare,
typename _Alloc>
2576 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2577 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2578 count(
const _Key& __k)
const
2580 pair<const_iterator, const_iterator> __p = equal_range(__k);
2585 _GLIBCXX_PURE
unsigned int
2586 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2587 const _Rb_tree_node_base* __root)
throw ();
2589 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2590 typename _Compare,
typename _Alloc>
2592 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const
2594 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2595 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2596 && this->_M_impl._M_header._M_left == _M_end()
2597 && this->_M_impl._M_header._M_right == _M_end();
2599 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2600 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2602 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
2603 _Const_Link_type __L = _S_left(__x);
2604 _Const_Link_type __R = _S_right(__x);
2606 if (__x->_M_color == _S_red)
2607 if ((__L && __L->_M_color == _S_red)
2608 || (__R && __R->_M_color == _S_red))
2611 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2613 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2616 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2620 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2622 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2627 #if __cplusplus > 201402L
2629 template<
typename _Key,
typename _Val,
typename _Sel,
typename _Cmp1,
2630 typename _Alloc,
typename _Cmp2>
2631 struct _Rb_tree_merge_helper<_Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>,
2635 friend class _Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>;
2638 _S_get_impl(_Rb_tree<_Key, _Val, _Sel, _Cmp2, _Alloc>& __tree)
2639 {
return __tree._M_impl; }
2643 _GLIBCXX_END_NAMESPACE_VERSION