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()); }
584 {
return _Alloc_traits::allocate(_M_get_Node_allocator(), 1); }
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&&) =
default;
704 _Rb_tree_impl(_Node_allocator&& __a)
705 : _Node_allocator(std::
move(__a))
708 _Rb_tree_impl(_Rb_tree_impl&& __x, _Node_allocator&& __a)
709 : _Node_allocator(std::
move(__a)),
710 _Base_key_compare(std::
move(__x)),
711 _Rb_tree_header(std::
move(__x))
714 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
715 : _Node_allocator(std::
move(__a)), _Base_key_compare(__comp)
720 _Rb_tree_impl<_Compare> _M_impl;
724 _M_root() _GLIBCXX_NOEXCEPT
725 {
return this->_M_impl._M_header._M_parent; }
728 _M_root() const _GLIBCXX_NOEXCEPT
729 {
return this->_M_impl._M_header._M_parent; }
732 _M_leftmost() _GLIBCXX_NOEXCEPT
733 {
return this->_M_impl._M_header._M_left; }
736 _M_leftmost() const _GLIBCXX_NOEXCEPT
737 {
return this->_M_impl._M_header._M_left; }
740 _M_rightmost() _GLIBCXX_NOEXCEPT
741 {
return this->_M_impl._M_header._M_right; }
744 _M_rightmost() const _GLIBCXX_NOEXCEPT
745 {
return this->_M_impl._M_header._M_right; }
748 _M_begin() _GLIBCXX_NOEXCEPT
749 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
752 _M_begin() const _GLIBCXX_NOEXCEPT
754 return static_cast<_Const_Link_type
>
755 (this->_M_impl._M_header._M_parent);
759 _M_end() _GLIBCXX_NOEXCEPT
760 {
return &this->_M_impl._M_header; }
763 _M_end() const _GLIBCXX_NOEXCEPT
764 {
return &this->_M_impl._M_header; }
767 _S_key(_Const_Link_type __x)
769 #if __cplusplus >= 201103L
772 static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
773 "comparison object must be invocable "
774 "with two arguments of key type");
775 # if __cplusplus >= 201703L
778 if constexpr (__is_invocable<_Compare&, const _Key&, const _Key&>{})
780 is_invocable_v<const _Compare&, const _Key&, const _Key&>,
781 "comparison object must be invocable as const");
785 return _KeyOfValue()(*__x->_M_valptr());
789 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
790 {
return static_cast<_Link_type
>(__x->_M_left); }
792 static _Const_Link_type
793 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
794 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
797 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
798 {
return static_cast<_Link_type
>(__x->_M_right); }
800 static _Const_Link_type
801 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
802 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
805 _S_key(_Const_Base_ptr __x)
806 {
return _S_key(static_cast<_Const_Link_type>(__x)); }
809 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
810 {
return _Rb_tree_node_base::_S_minimum(__x); }
812 static _Const_Base_ptr
813 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
814 {
return _Rb_tree_node_base::_S_minimum(__x); }
817 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
818 {
return _Rb_tree_node_base::_S_maximum(__x); }
820 static _Const_Base_ptr
821 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
822 {
return _Rb_tree_node_base::_S_maximum(__x); }
825 typedef _Rb_tree_iterator<value_type> iterator;
826 typedef _Rb_tree_const_iterator<value_type> const_iterator;
831 #if __cplusplus > 201402L
832 using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
833 using insert_return_type = _Node_insert_return<
834 conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
838 pair<_Base_ptr, _Base_ptr>
839 _M_get_insert_unique_pos(
const key_type& __k);
841 pair<_Base_ptr, _Base_ptr>
842 _M_get_insert_equal_pos(
const key_type& __k);
844 pair<_Base_ptr, _Base_ptr>
845 _M_get_insert_hint_unique_pos(const_iterator __pos,
846 const key_type& __k);
848 pair<_Base_ptr, _Base_ptr>
849 _M_get_insert_hint_equal_pos(const_iterator __pos,
850 const key_type& __k);
853 #if __cplusplus >= 201103L
854 template<
typename _Arg,
typename _NodeGen>
856 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
859 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
861 template<
typename _Arg>
863 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
865 template<
typename _Arg>
867 _M_insert_equal_lower(_Arg&& __x);
870 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
873 _M_insert_equal_lower_node(_Link_type __z);
875 template<
typename _NodeGen>
877 _M_insert_(_Base_ptr __x, _Base_ptr __y,
878 const value_type& __v, _NodeGen&);
883 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
886 _M_insert_equal_lower(
const value_type& __x);
889 template<
typename _NodeGen>
891 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen&);
893 template<
typename _NodeGen>
895 _M_copy(
const _Rb_tree& __x, _NodeGen& __gen)
897 _Link_type __root = _M_copy(__x._M_begin(), _M_end(), __gen);
898 _M_leftmost() = _S_minimum(__root);
899 _M_rightmost() = _S_maximum(__root);
900 _M_impl._M_node_count = __x._M_impl._M_node_count;
905 _M_copy(
const _Rb_tree& __x)
907 _Alloc_node __an(*
this);
908 return _M_copy(__x, __an);
912 _M_erase(_Link_type __x);
915 _M_lower_bound(_Link_type __x, _Base_ptr __y,
919 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
920 const _Key& __k)
const;
923 _M_upper_bound(_Link_type __x, _Base_ptr __y,
927 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
928 const _Key& __k)
const;
932 #if __cplusplus < 201103L
935 _Rb_tree() =
default;
938 _Rb_tree(
const _Compare& __comp,
939 const allocator_type& __a = allocator_type())
940 : _M_impl(__comp, _Node_allocator(__a)) { }
942 _Rb_tree(
const _Rb_tree& __x)
943 : _M_impl(__x._M_impl)
945 if (__x._M_root() != 0)
946 _M_root() = _M_copy(__x);
949 #if __cplusplus >= 201103L
950 _Rb_tree(
const allocator_type& __a)
951 : _M_impl(_Node_allocator(__a))
954 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
955 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
957 if (__x._M_root() !=
nullptr)
958 _M_root() = _M_copy(__x);
961 _Rb_tree(_Rb_tree&&) =
default;
963 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
964 : _Rb_tree(std::
move(__x), _Node_allocator(__a))
968 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
true_type)
969 noexcept(is_nothrow_default_constructible<_Compare>::value)
970 : _M_impl(std::
move(__x._M_impl), std::
move(__a))
973 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
false_type)
974 : _M_impl(__x._M_impl._M_key_compare, std::
move(__a))
976 if (__x._M_root() !=
nullptr)
981 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
983 _Rb_tree(std::declval<_Rb_tree&&>(), std::declval<_Node_allocator&&>(),
984 std::declval<typename _Alloc_traits::is_always_equal>())) )
985 : _Rb_tree(std::
move(__x), std::
move(__a),
986 typename _Alloc_traits::is_always_equal{})
990 ~_Rb_tree() _GLIBCXX_NOEXCEPT
991 { _M_erase(_M_begin()); }
994 operator=(
const _Rb_tree& __x);
999 {
return _M_impl._M_key_compare; }
1002 begin() _GLIBCXX_NOEXCEPT
1003 {
return iterator(this->_M_impl._M_header._M_left); }
1006 begin() const _GLIBCXX_NOEXCEPT
1007 {
return const_iterator(this->_M_impl._M_header._M_left); }
1010 end() _GLIBCXX_NOEXCEPT
1011 {
return iterator(&this->_M_impl._M_header); }
1014 end() const _GLIBCXX_NOEXCEPT
1015 {
return const_iterator(&this->_M_impl._M_header); }
1018 rbegin() _GLIBCXX_NOEXCEPT
1019 {
return reverse_iterator(
end()); }
1021 const_reverse_iterator
1022 rbegin() const _GLIBCXX_NOEXCEPT
1023 {
return const_reverse_iterator(
end()); }
1026 rend() _GLIBCXX_NOEXCEPT
1027 {
return reverse_iterator(
begin()); }
1029 const_reverse_iterator
1030 rend() const _GLIBCXX_NOEXCEPT
1031 {
return const_reverse_iterator(
begin()); }
1033 _GLIBCXX_NODISCARD
bool
1034 empty() const _GLIBCXX_NOEXCEPT
1035 {
return _M_impl._M_node_count == 0; }
1038 size() const _GLIBCXX_NOEXCEPT
1039 {
return _M_impl._M_node_count; }
1042 max_size() const _GLIBCXX_NOEXCEPT
1047 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value);
1050 #if __cplusplus >= 201103L
1051 template<
typename _Arg>
1052 pair<iterator, bool>
1053 _M_insert_unique(_Arg&& __x);
1055 template<
typename _Arg>
1057 _M_insert_equal(_Arg&& __x);
1059 template<
typename _Arg,
typename _NodeGen>
1061 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1063 template<
typename _Arg>
1065 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
1067 _Alloc_node __an(*
this);
1068 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
1071 template<
typename _Arg,
typename _NodeGen>
1073 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1075 template<
typename _Arg>
1077 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
1079 _Alloc_node __an(*
this);
1080 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
1083 template<
typename... _Args>
1084 pair<iterator, bool>
1085 _M_emplace_unique(_Args&&... __args);
1087 template<
typename... _Args>
1089 _M_emplace_equal(_Args&&... __args);
1091 template<
typename... _Args>
1093 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
1095 template<
typename... _Args>
1097 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
1099 template<
typename _Iter>
1100 using __same_value_type
1101 = is_same<value_type, typename iterator_traits<_Iter>::value_type>;
1103 template<
typename _InputIterator>
1104 __enable_if_t<__same_value_type<_InputIterator>::value>
1105 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1107 _Alloc_node __an(*
this);
1108 for (; __first != __last; ++__first)
1109 _M_insert_unique_(
end(), *__first, __an);
1112 template<
typename _InputIterator>
1113 __enable_if_t<!__same_value_type<_InputIterator>::value>
1114 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1116 for (; __first != __last; ++__first)
1117 _M_emplace_unique(*__first);
1120 template<
typename _InputIterator>
1121 __enable_if_t<__same_value_type<_InputIterator>::value>
1122 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1124 _Alloc_node __an(*
this);
1125 for (; __first != __last; ++__first)
1126 _M_insert_equal_(
end(), *__first, __an);
1129 template<
typename _InputIterator>
1130 __enable_if_t<!__same_value_type<_InputIterator>::value>
1131 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1133 _Alloc_node __an(*
this);
1134 for (; __first != __last; ++__first)
1135 _M_emplace_equal(*__first);
1138 pair<iterator, bool>
1139 _M_insert_unique(
const value_type& __x);
1142 _M_insert_equal(
const value_type& __x);
1144 template<
typename _NodeGen>
1146 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
1150 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
1152 _Alloc_node __an(*
this);
1153 return _M_insert_unique_(__pos, __x, __an);
1156 template<
typename _NodeGen>
1158 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1161 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1163 _Alloc_node __an(*
this);
1164 return _M_insert_equal_(__pos, __x, __an);
1167 template<
typename _InputIterator>
1169 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1171 _Alloc_node __an(*
this);
1172 for (; __first != __last; ++__first)
1173 _M_insert_unique_(
end(), *__first, __an);
1176 template<
typename _InputIterator>
1178 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1180 _Alloc_node __an(*
this);
1181 for (; __first != __last; ++__first)
1182 _M_insert_equal_(
end(), *__first, __an);
1188 _M_erase_aux(const_iterator __position);
1191 _M_erase_aux(const_iterator __first, const_iterator __last);
1194 #if __cplusplus >= 201103L
1197 _GLIBCXX_ABI_TAG_CXX11
1199 erase(const_iterator __position)
1201 __glibcxx_assert(__position !=
end());
1202 const_iterator __result = __position;
1204 _M_erase_aux(__position);
1205 return __result._M_const_cast();
1209 _GLIBCXX_ABI_TAG_CXX11
1211 erase(iterator __position)
1213 __glibcxx_assert(__position !=
end());
1214 iterator __result = __position;
1216 _M_erase_aux(__position);
1221 erase(iterator __position)
1223 __glibcxx_assert(__position !=
end());
1224 _M_erase_aux(__position);
1228 erase(const_iterator __position)
1230 __glibcxx_assert(__position !=
end());
1231 _M_erase_aux(__position);
1236 erase(
const key_type& __x);
1238 #if __cplusplus >= 201103L
1241 _GLIBCXX_ABI_TAG_CXX11
1243 erase(const_iterator __first, const_iterator __last)
1245 _M_erase_aux(__first, __last);
1246 return __last._M_const_cast();
1250 erase(iterator __first, iterator __last)
1251 { _M_erase_aux(__first, __last); }
1254 erase(const_iterator __first, const_iterator __last)
1255 { _M_erase_aux(__first, __last); }
1259 clear() _GLIBCXX_NOEXCEPT
1261 _M_erase(_M_begin());
1267 find(
const key_type& __k);
1270 find(
const key_type& __k)
const;
1273 count(
const key_type& __k)
const;
1276 lower_bound(
const key_type& __k)
1277 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1280 lower_bound(
const key_type& __k)
const
1281 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1284 upper_bound(
const key_type& __k)
1285 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1288 upper_bound(
const key_type& __k)
const
1289 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1291 pair<iterator, iterator>
1292 equal_range(
const key_type& __k);
1294 pair<const_iterator, const_iterator>
1295 equal_range(
const key_type& __k)
const;
1297 #if __cplusplus >= 201402L
1298 template<
typename _Kt,
1299 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1301 _M_find_tr(
const _Kt& __k)
1303 const _Rb_tree* __const_this =
this;
1304 return __const_this->_M_find_tr(__k)._M_const_cast();
1307 template<
typename _Kt,
1308 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1310 _M_find_tr(
const _Kt& __k)
const
1312 auto __j = _M_lower_bound_tr(__k);
1313 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1318 template<
typename _Kt,
1319 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1321 _M_count_tr(
const _Kt& __k)
const
1323 auto __p = _M_equal_range_tr(__k);
1327 template<
typename _Kt,
1328 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1330 _M_lower_bound_tr(
const _Kt& __k)
1332 const _Rb_tree* __const_this =
this;
1333 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1336 template<
typename _Kt,
1337 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1339 _M_lower_bound_tr(
const _Kt& __k)
const
1341 auto __x = _M_begin();
1342 auto __y = _M_end();
1344 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1350 __x = _S_right(__x);
1351 return const_iterator(__y);
1354 template<
typename _Kt,
1355 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1357 _M_upper_bound_tr(
const _Kt& __k)
1359 const _Rb_tree* __const_this =
this;
1360 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1363 template<
typename _Kt,
1364 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1366 _M_upper_bound_tr(
const _Kt& __k)
const
1368 auto __x = _M_begin();
1369 auto __y = _M_end();
1371 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1377 __x = _S_right(__x);
1378 return const_iterator(__y);
1381 template<
typename _Kt,
1382 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1383 pair<iterator, iterator>
1384 _M_equal_range_tr(
const _Kt& __k)
1386 const _Rb_tree* __const_this =
this;
1387 auto __ret = __const_this->_M_equal_range_tr(__k);
1388 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1391 template<
typename _Kt,
1392 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1393 pair<const_iterator, const_iterator>
1394 _M_equal_range_tr(
const _Kt& __k)
const
1396 auto __low = _M_lower_bound_tr(__k);
1397 auto __high = __low;
1398 auto& __cmp = _M_impl._M_key_compare;
1399 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1401 return { __low, __high };
1407 __rb_verify()
const;
1409 #if __cplusplus >= 201103L
1411 operator=(_Rb_tree&&)
1412 noexcept(_Alloc_traits::_S_nothrow_move()
1413 && is_nothrow_move_assignable<_Compare>::value);
1415 template<typename _Iterator>
1417 _M_assign_unique(_Iterator, _Iterator);
1419 template<typename _Iterator>
1421 _M_assign_equal(_Iterator, _Iterator);
1427 { _M_impl._M_move_data(__x._M_impl); }
1436 _M_move_assign(_Rb_tree&, true_type);
1444 #if __cplusplus > 201402L
1448 _M_reinsert_node_unique(node_type&& __nh)
1450 insert_return_type __ret;
1452 __ret.position =
end();
1455 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1457 auto __res = _M_get_insert_unique_pos(__nh._M_key());
1461 = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1462 __nh._M_ptr =
nullptr;
1463 __ret.inserted =
true;
1468 __ret.position = iterator(__res.first);
1469 __ret.inserted =
false;
1477 _M_reinsert_node_equal(node_type&& __nh)
1484 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1485 auto __res = _M_get_insert_equal_pos(__nh._M_key());
1487 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1489 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1490 __nh._M_ptr =
nullptr;
1497 _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh)
1504 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1505 auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key());
1508 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1509 __nh._M_ptr =
nullptr;
1512 __ret = iterator(__res.first);
1519 _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh)
1526 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1527 auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key());
1529 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1531 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1532 __nh._M_ptr =
nullptr;
1539 extract(const_iterator __pos)
1541 auto __ptr = _Rb_tree_rebalance_for_erase(
1542 __pos._M_const_cast()._M_node, _M_impl._M_header);
1543 --_M_impl._M_node_count;
1544 return {
static_cast<_Link_type
>(__ptr), _M_get_Node_allocator() };
1549 extract(
const key_type& __k)
1552 auto __pos = find(__k);
1554 __nh = extract(const_iterator(__pos));
1558 template<
typename _Compare2>
1559 using _Compatible_tree
1560 = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>;
1562 template<
typename,
typename>
1563 friend class _Rb_tree_merge_helper;
1566 template<
typename _Compare2>
1568 _M_merge_unique(_Compatible_tree<_Compare2>& __src) noexcept
1570 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1571 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1574 auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos));
1577 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1578 auto __ptr = _Rb_tree_rebalance_for_erase(
1579 __pos._M_node, __src_impl._M_header);
1580 --__src_impl._M_node_count;
1581 _M_insert_node(__res.first, __res.second,
1582 static_cast<_Link_type>(__ptr));
1588 template<
typename _Compare2>
1590 _M_merge_equal(_Compatible_tree<_Compare2>& __src) noexcept
1592 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1593 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1596 auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos));
1599 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1600 auto __ptr = _Rb_tree_rebalance_for_erase(
1601 __pos._M_node, __src_impl._M_header);
1602 --__src_impl._M_node_count;
1603 _M_insert_node(__res.first, __res.second,
1604 static_cast<_Link_type>(__ptr));
1611 operator==(
const _Rb_tree& __x,
const _Rb_tree& __y)
1613 return __x.size() == __y.size()
1614 &&
std::equal(__x.begin(), __x.end(), __y.begin());
1617 #if __cpp_lib_three_way_comparison
1619 operator<=>(
const _Rb_tree& __x,
const _Rb_tree& __y)
1621 if constexpr (requires {
typename __detail::__synth3way_t<_Val>; })
1622 return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
1623 __y.begin(), __y.end(),
1624 __detail::__synth3way);
1628 operator<(
const _Rb_tree& __x,
const _Rb_tree& __y)
1631 __y.begin(), __y.end());
1634 friend bool _GLIBCXX_DEPRECATED
1635 operator!=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1636 {
return !(__x == __y); }
1638 friend bool _GLIBCXX_DEPRECATED
1639 operator>(
const _Rb_tree& __x,
const _Rb_tree& __y)
1640 {
return __y < __x; }
1642 friend bool _GLIBCXX_DEPRECATED
1643 operator<=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1644 {
return !(__y < __x); }
1646 friend bool _GLIBCXX_DEPRECATED
1647 operator>=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1648 {
return !(__x < __y); }
1652 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1653 typename _Compare,
typename _Alloc>
1655 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1656 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1659 #if __cplusplus >= 201103L
1660 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1661 typename _Compare,
typename _Alloc>
1663 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1666 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1670 _Alloc_node __an(*
this);
1672 [&__an](
const value_type& __cval)
1674 auto& __val =
const_cast<value_type&
>(__cval);
1677 _M_root() = _M_copy(__x, __lbd);
1681 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1682 typename _Compare,
typename _Alloc>
1684 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1685 _M_move_assign(_Rb_tree& __x, true_type)
1688 if (__x._M_root() !=
nullptr)
1690 std::__alloc_on_move(_M_get_Node_allocator(),
1691 __x._M_get_Node_allocator());
1694 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1695 typename _Compare,
typename _Alloc>
1697 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1700 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1701 return _M_move_assign(__x, true_type{});
1705 _Reuse_or_alloc_node __roan(*
this);
1707 if (__x._M_root() !=
nullptr)
1710 [&__roan](
const value_type& __cval)
1712 auto& __val =
const_cast<value_type&
>(__cval);
1715 _M_root() = _M_copy(__x, __lbd);
1720 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1721 typename _Compare,
typename _Alloc>
1722 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1723 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1724 operator=(_Rb_tree&& __x)
1725 noexcept(_Alloc_traits::_S_nothrow_move()
1726 && is_nothrow_move_assignable<_Compare>::value)
1728 _M_impl._M_key_compare =
std::move(__x._M_impl._M_key_compare);
1729 _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>());
1733 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1734 typename _Compare,
typename _Alloc>
1735 template<
typename _Iterator>
1737 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1738 _M_assign_unique(_Iterator __first, _Iterator __last)
1740 _Reuse_or_alloc_node __roan(*
this);
1742 for (; __first != __last; ++__first)
1743 _M_insert_unique_(
end(), *__first, __roan);
1746 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1747 typename _Compare,
typename _Alloc>
1748 template<
typename _Iterator>
1750 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1751 _M_assign_equal(_Iterator __first, _Iterator __last)
1753 _Reuse_or_alloc_node __roan(*
this);
1755 for (; __first != __last; ++__first)
1756 _M_insert_equal_(
end(), *__first, __roan);
1760 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1761 typename _Compare,
typename _Alloc>
1762 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1763 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1764 operator=(
const _Rb_tree& __x)
1769 #if __cplusplus >= 201103L
1770 if (_Alloc_traits::_S_propagate_on_copy_assign())
1772 auto& __this_alloc = this->_M_get_Node_allocator();
1773 auto& __that_alloc = __x._M_get_Node_allocator();
1774 if (!_Alloc_traits::_S_always_equal()
1775 && __this_alloc != __that_alloc)
1780 std::__alloc_on_copy(__this_alloc, __that_alloc);
1785 _Reuse_or_alloc_node __roan(*
this);
1787 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1788 if (__x._M_root() != 0)
1789 _M_root() = _M_copy(__x, __roan);
1795 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1796 typename _Compare,
typename _Alloc>
1797 #if __cplusplus >= 201103L
1798 template<
typename _Arg,
typename _NodeGen>
1800 template<
typename _NodeGen>
1802 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1803 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1804 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1805 #
if __cplusplus >= 201103L
1810 _NodeGen& __node_gen)
1812 bool __insert_left = (__x != 0 || __p == _M_end()
1813 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1816 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1818 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1819 this->_M_impl._M_header);
1820 ++_M_impl._M_node_count;
1821 return iterator(__z);
1824 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1825 typename _Compare,
typename _Alloc>
1826 #if __cplusplus >= 201103L
1827 template<
typename _Arg>
1829 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1830 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1831 #if __cplusplus >= 201103L
1832 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1834 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1837 bool __insert_left = (__p == _M_end()
1838 || !_M_impl._M_key_compare(_S_key(__p),
1839 _KeyOfValue()(__v)));
1841 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1843 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1844 this->_M_impl._M_header);
1845 ++_M_impl._M_node_count;
1846 return iterator(__z);
1849 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1850 typename _Compare,
typename _Alloc>
1851 #if __cplusplus >= 201103L
1852 template<
typename _Arg>
1854 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1855 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1856 #if __cplusplus >= 201103L
1857 _M_insert_equal_lower(_Arg&& __v)
1859 _M_insert_equal_lower(
const _Val& __v)
1862 _Link_type __x = _M_begin();
1863 _Base_ptr __y = _M_end();
1867 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1868 _S_left(__x) : _S_right(__x);
1870 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1873 template<
typename _Key,
typename _Val,
typename _KoV,
1874 typename _Compare,
typename _Alloc>
1875 template<
typename _NodeGen>
1876 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1877 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1878 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1881 _Link_type __top = _M_clone_node(__x, __node_gen);
1882 __top->_M_parent = __p;
1887 __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen);
1893 _Link_type __y = _M_clone_node(__x, __node_gen);
1895 __y->_M_parent = __p;
1897 __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen);
1905 __throw_exception_again;
1910 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1911 typename _Compare,
typename _Alloc>
1913 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1914 _M_erase(_Link_type __x)
1919 _M_erase(_S_right(__x));
1920 _Link_type __y = _S_left(__x);
1926 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1927 typename _Compare,
typename _Alloc>
1928 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1929 _Compare, _Alloc>::iterator
1930 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1931 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1935 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1936 __y = __x, __x = _S_left(__x);
1938 __x = _S_right(__x);
1939 return iterator(__y);
1942 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1943 typename _Compare,
typename _Alloc>
1944 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1945 _Compare, _Alloc>::const_iterator
1946 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1947 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1948 const _Key& __k)
const
1951 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1952 __y = __x, __x = _S_left(__x);
1954 __x = _S_right(__x);
1955 return const_iterator(__y);
1958 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1959 typename _Compare,
typename _Alloc>
1960 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1961 _Compare, _Alloc>::iterator
1962 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1963 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1967 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1968 __y = __x, __x = _S_left(__x);
1970 __x = _S_right(__x);
1971 return iterator(__y);
1974 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1975 typename _Compare,
typename _Alloc>
1976 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1977 _Compare, _Alloc>::const_iterator
1978 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1979 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1980 const _Key& __k)
const
1983 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1984 __y = __x, __x = _S_left(__x);
1986 __x = _S_right(__x);
1987 return const_iterator(__y);
1990 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1991 typename _Compare,
typename _Alloc>
1992 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1993 _Compare, _Alloc>::iterator,
1994 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1995 _Compare, _Alloc>::iterator>
1996 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1997 equal_range(
const _Key& __k)
1999 _Link_type __x = _M_begin();
2000 _Base_ptr __y = _M_end();
2003 if (_M_impl._M_key_compare(_S_key(__x), __k))
2004 __x = _S_right(__x);
2005 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2006 __y = __x, __x = _S_left(__x);
2009 _Link_type __xu(__x);
2010 _Base_ptr __yu(__y);
2011 __y = __x, __x = _S_left(__x);
2012 __xu = _S_right(__xu);
2013 return pair<iterator,
2014 iterator>(_M_lower_bound(__x, __y, __k),
2015 _M_upper_bound(__xu, __yu, __k));
2018 return pair<iterator, iterator>(iterator(__y),
2022 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2023 typename _Compare,
typename _Alloc>
2024 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2025 _Compare, _Alloc>::const_iterator,
2026 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2027 _Compare, _Alloc>::const_iterator>
2028 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2029 equal_range(
const _Key& __k)
const
2031 _Const_Link_type __x = _M_begin();
2032 _Const_Base_ptr __y = _M_end();
2035 if (_M_impl._M_key_compare(_S_key(__x), __k))
2036 __x = _S_right(__x);
2037 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2038 __y = __x, __x = _S_left(__x);
2041 _Const_Link_type __xu(__x);
2042 _Const_Base_ptr __yu(__y);
2043 __y = __x, __x = _S_left(__x);
2044 __xu = _S_right(__xu);
2045 return pair<const_iterator,
2046 const_iterator>(_M_lower_bound(__x, __y, __k),
2047 _M_upper_bound(__xu, __yu, __k));
2050 return pair<const_iterator, const_iterator>(const_iterator(__y),
2051 const_iterator(__y));
2054 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2055 typename _Compare,
typename _Alloc>
2057 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2059 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
2063 if (__t._M_root() != 0)
2064 _M_impl._M_move_data(__t._M_impl);
2066 else if (__t._M_root() == 0)
2067 __t._M_impl._M_move_data(_M_impl);
2070 std::swap(_M_root(),__t._M_root());
2071 std::swap(_M_leftmost(),__t._M_leftmost());
2072 std::swap(_M_rightmost(),__t._M_rightmost());
2074 _M_root()->_M_parent = _M_end();
2075 __t._M_root()->_M_parent = __t._M_end();
2076 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
2079 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
2081 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
2082 __t._M_get_Node_allocator());
2085 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2086 typename _Compare,
typename _Alloc>
2087 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2088 _Compare, _Alloc>::_Base_ptr,
2089 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2090 _Compare, _Alloc>::_Base_ptr>
2091 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2092 _M_get_insert_unique_pos(
const key_type& __k)
2094 typedef pair<_Base_ptr, _Base_ptr> _Res;
2095 _Link_type __x = _M_begin();
2096 _Base_ptr __y = _M_end();
2101 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
2102 __x = __comp ? _S_left(__x) : _S_right(__x);
2104 iterator __j = iterator(__y);
2108 return _Res(__x, __y);
2112 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
2113 return _Res(__x, __y);
2114 return _Res(__j._M_node, 0);
2117 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2118 typename _Compare,
typename _Alloc>
2119 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2120 _Compare, _Alloc>::_Base_ptr,
2121 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2122 _Compare, _Alloc>::_Base_ptr>
2123 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2124 _M_get_insert_equal_pos(
const key_type& __k)
2126 typedef pair<_Base_ptr, _Base_ptr> _Res;
2127 _Link_type __x = _M_begin();
2128 _Base_ptr __y = _M_end();
2132 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
2133 _S_left(__x) : _S_right(__x);
2135 return _Res(__x, __y);
2138 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2139 typename _Compare,
typename _Alloc>
2140 #if __cplusplus >= 201103L
2141 template<
typename _Arg>
2143 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2144 _Compare, _Alloc>::iterator,
bool>
2145 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2146 #if __cplusplus >= 201103L
2147 _M_insert_unique(_Arg&& __v)
2149 _M_insert_unique(
const _Val& __v)
2152 typedef pair<iterator, bool> _Res;
2153 pair<_Base_ptr, _Base_ptr> __res
2154 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
2158 _Alloc_node __an(*
this);
2159 return _Res(_M_insert_(__res.first, __res.second,
2160 _GLIBCXX_FORWARD(_Arg, __v), __an),
2164 return _Res(iterator(__res.first),
false);
2167 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2168 typename _Compare,
typename _Alloc>
2169 #if __cplusplus >= 201103L
2170 template<
typename _Arg>
2172 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2173 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2174 #if __cplusplus >= 201103L
2175 _M_insert_equal(_Arg&& __v)
2177 _M_insert_equal(
const _Val& __v)
2180 pair<_Base_ptr, _Base_ptr> __res
2181 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
2182 _Alloc_node __an(*
this);
2183 return _M_insert_(__res.first, __res.second,
2184 _GLIBCXX_FORWARD(_Arg, __v), __an);
2187 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2188 typename _Compare,
typename _Alloc>
2189 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2190 _Compare, _Alloc>::_Base_ptr,
2191 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2192 _Compare, _Alloc>::_Base_ptr>
2193 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2194 _M_get_insert_hint_unique_pos(const_iterator __position,
2195 const key_type& __k)
2197 iterator __pos = __position._M_const_cast();
2198 typedef pair<_Base_ptr, _Base_ptr> _Res;
2201 if (__pos._M_node == _M_end())
2204 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
2205 return _Res(0, _M_rightmost());
2207 return _M_get_insert_unique_pos(__k);
2209 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
2212 iterator __before = __pos;
2213 if (__pos._M_node == _M_leftmost())
2214 return _Res(_M_leftmost(), _M_leftmost());
2215 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
2217 if (_S_right(__before._M_node) == 0)
2218 return _Res(0, __before._M_node);
2220 return _Res(__pos._M_node, __pos._M_node);
2223 return _M_get_insert_unique_pos(__k);
2225 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2228 iterator __after = __pos;
2229 if (__pos._M_node == _M_rightmost())
2230 return _Res(0, _M_rightmost());
2231 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
2233 if (_S_right(__pos._M_node) == 0)
2234 return _Res(0, __pos._M_node);
2236 return _Res(__after._M_node, __after._M_node);
2239 return _M_get_insert_unique_pos(__k);
2243 return _Res(__pos._M_node, 0);
2246 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2247 typename _Compare,
typename _Alloc>
2248 #if __cplusplus >= 201103L
2249 template<
typename _Arg,
typename _NodeGen>
2251 template<
typename _NodeGen>
2253 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2254 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2255 _M_insert_unique_(const_iterator __position,
2256 #
if __cplusplus >= 201103L
2261 _NodeGen& __node_gen)
2263 pair<_Base_ptr, _Base_ptr> __res
2264 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2267 return _M_insert_(__res.first, __res.second,
2268 _GLIBCXX_FORWARD(_Arg, __v),
2270 return iterator(__res.first);
2273 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2274 typename _Compare,
typename _Alloc>
2275 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2276 _Compare, _Alloc>::_Base_ptr,
2277 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2278 _Compare, _Alloc>::_Base_ptr>
2279 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2280 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2282 iterator __pos = __position._M_const_cast();
2283 typedef pair<_Base_ptr, _Base_ptr> _Res;
2286 if (__pos._M_node == _M_end())
2289 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2290 return _Res(0, _M_rightmost());
2292 return _M_get_insert_equal_pos(__k);
2294 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2297 iterator __before = __pos;
2298 if (__pos._M_node == _M_leftmost())
2299 return _Res(_M_leftmost(), _M_leftmost());
2300 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2302 if (_S_right(__before._M_node) == 0)
2303 return _Res(0, __before._M_node);
2305 return _Res(__pos._M_node, __pos._M_node);
2308 return _M_get_insert_equal_pos(__k);
2313 iterator __after = __pos;
2314 if (__pos._M_node == _M_rightmost())
2315 return _Res(0, _M_rightmost());
2316 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2318 if (_S_right(__pos._M_node) == 0)
2319 return _Res(0, __pos._M_node);
2321 return _Res(__after._M_node, __after._M_node);
2328 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2329 typename _Compare,
typename _Alloc>
2330 #if __cplusplus >= 201103L
2331 template<
typename _Arg,
typename _NodeGen>
2333 template<
typename _NodeGen>
2335 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2336 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2337 _M_insert_equal_(const_iterator __position,
2338 #
if __cplusplus >= 201103L
2343 _NodeGen& __node_gen)
2345 pair<_Base_ptr, _Base_ptr> __res
2346 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2349 return _M_insert_(__res.first, __res.second,
2350 _GLIBCXX_FORWARD(_Arg, __v),
2353 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2356 #if __cplusplus >= 201103L
2357 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2358 typename _Compare,
typename _Alloc>
2359 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2360 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2361 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2363 bool __insert_left = (__x != 0 || __p == _M_end()
2364 || _M_impl._M_key_compare(_S_key(__z),
2367 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2368 this->_M_impl._M_header);
2369 ++_M_impl._M_node_count;
2370 return iterator(__z);
2373 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2374 typename _Compare,
typename _Alloc>
2375 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2376 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2377 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2379 bool __insert_left = (__p == _M_end()
2380 || !_M_impl._M_key_compare(_S_key(__p),
2383 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2384 this->_M_impl._M_header);
2385 ++_M_impl._M_node_count;
2386 return iterator(__z);
2389 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2390 typename _Compare,
typename _Alloc>
2391 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2392 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2393 _M_insert_equal_lower_node(_Link_type __z)
2395 _Link_type __x = _M_begin();
2396 _Base_ptr __y = _M_end();
2400 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2401 _S_left(__x) : _S_right(__x);
2403 return _M_insert_lower_node(__y, __z);
2406 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2407 typename _Compare,
typename _Alloc>
2408 template<
typename... _Args>
2409 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2410 _Compare, _Alloc>::iterator,
bool>
2411 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2412 _M_emplace_unique(_Args&&... __args)
2414 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2418 typedef pair<iterator, bool> _Res;
2419 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2421 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2424 return _Res(iterator(__res.first),
false);
2429 __throw_exception_again;
2433 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2434 typename _Compare,
typename _Alloc>
2435 template<
typename... _Args>
2436 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2437 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2438 _M_emplace_equal(_Args&&... __args)
2440 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2444 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2445 return _M_insert_node(__res.first, __res.second, __z);
2450 __throw_exception_again;
2454 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2455 typename _Compare,
typename _Alloc>
2456 template<
typename... _Args>
2457 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2458 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2459 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2461 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2465 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2468 return _M_insert_node(__res.first, __res.second, __z);
2471 return iterator(__res.first);
2476 __throw_exception_again;
2480 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2481 typename _Compare,
typename _Alloc>
2482 template<
typename... _Args>
2483 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2484 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2485 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2487 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2491 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2494 return _M_insert_node(__res.first, __res.second, __z);
2496 return _M_insert_equal_lower_node(__z);
2501 __throw_exception_again;
2507 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2508 typename _Compare,
typename _Alloc>
2510 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2511 _M_erase_aux(const_iterator __position)
2514 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
2515 (const_cast<_Base_ptr>(__position._M_node),
2516 this->_M_impl._M_header));
2518 --_M_impl._M_node_count;
2521 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2522 typename _Compare,
typename _Alloc>
2524 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2525 _M_erase_aux(const_iterator __first, const_iterator __last)
2527 if (__first ==
begin() && __last ==
end())
2530 while (__first != __last)
2531 _M_erase_aux(__first++);
2534 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2535 typename _Compare,
typename _Alloc>
2536 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2537 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2538 erase(
const _Key& __x)
2540 pair<iterator, iterator> __p = equal_range(__x);
2541 const size_type __old_size = size();
2542 _M_erase_aux(__p.first, __p.second);
2543 return __old_size - size();
2546 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2547 typename _Compare,
typename _Alloc>
2548 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2549 _Compare, _Alloc>::iterator
2550 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2551 find(
const _Key& __k)
2553 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2554 return (__j ==
end()
2555 || _M_impl._M_key_compare(__k,
2556 _S_key(__j._M_node))) ?
end() : __j;
2559 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2560 typename _Compare,
typename _Alloc>
2561 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2562 _Compare, _Alloc>::const_iterator
2563 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2564 find(
const _Key& __k)
const
2566 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2567 return (__j ==
end()
2568 || _M_impl._M_key_compare(__k,
2569 _S_key(__j._M_node))) ?
end() : __j;
2572 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2573 typename _Compare,
typename _Alloc>
2574 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2575 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2576 count(
const _Key& __k)
const
2578 pair<const_iterator, const_iterator> __p = equal_range(__k);
2583 _GLIBCXX_PURE
unsigned int
2584 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2585 const _Rb_tree_node_base* __root)
throw ();
2587 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2588 typename _Compare,
typename _Alloc>
2590 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const
2592 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2593 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2594 && this->_M_impl._M_header._M_left == _M_end()
2595 && this->_M_impl._M_header._M_right == _M_end();
2597 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2598 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2600 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
2601 _Const_Link_type __L = _S_left(__x);
2602 _Const_Link_type __R = _S_right(__x);
2604 if (__x->_M_color == _S_red)
2605 if ((__L && __L->_M_color == _S_red)
2606 || (__R && __R->_M_color == _S_red))
2609 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2611 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2614 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2618 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2620 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2625 #if __cplusplus > 201402L
2627 template<
typename _Key,
typename _Val,
typename _Sel,
typename _Cmp1,
2628 typename _Alloc,
typename _Cmp2>
2629 struct _Rb_tree_merge_helper<_Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>,
2633 friend class _Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>;
2636 _S_get_impl(_Rb_tree<_Key, _Val, _Sel, _Cmp2, _Alloc>& __tree)
2637 {
return __tree._M_impl; }
2641 _GLIBCXX_END_NAMESPACE_VERSION
constexpr auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
_Tp * begin(valarray< _Tp > &__va)
Return an iterator pointing to the first element of the valarray.
static constexpr size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
constexpr conditional< __move_if_noexcept_cond< _Tp >::value, const _Tp &, _Tp && >::type move_if_noexcept(_Tp &__x) noexcept
Conditionally convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
static constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
constexpr bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
Uniform interface to C++98 and C++11 allocators.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
constexpr bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
_Tp * end(valarray< _Tp > &__va)
Return an iterator pointing to one past the last element of the valarray.
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.