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 _GLIBCXX_NOEXCEPT
316 {
return _M_node == __x._M_node; }
319 operator!=(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
320 {
return _M_node != __x._M_node; }
325 template<
typename _Tp>
326 struct _Rb_tree_const_iterator
328 typedef _Tp value_type;
329 typedef const _Tp& reference;
330 typedef const _Tp* pointer;
332 typedef _Rb_tree_iterator<_Tp> iterator;
334 typedef bidirectional_iterator_tag iterator_category;
335 typedef ptrdiff_t difference_type;
337 typedef _Rb_tree_const_iterator<_Tp> _Self;
338 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
339 typedef const _Rb_tree_node<_Tp>* _Link_type;
341 _Rb_tree_const_iterator() _GLIBCXX_NOEXCEPT
345 _Rb_tree_const_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
348 _Rb_tree_const_iterator(
const iterator& __it) _GLIBCXX_NOEXCEPT
349 : _M_node(__it._M_node) { }
352 _M_const_cast() const _GLIBCXX_NOEXCEPT
353 {
return iterator(const_cast<typename iterator::_Base_ptr>(_M_node)); }
357 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
360 operator->() const _GLIBCXX_NOEXCEPT
361 {
return static_cast<_Link_type
>(_M_node)->_M_valptr(); }
364 operator++() _GLIBCXX_NOEXCEPT
366 _M_node = _Rb_tree_increment(_M_node);
371 operator++(
int) _GLIBCXX_NOEXCEPT
374 _M_node = _Rb_tree_increment(_M_node);
379 operator--() _GLIBCXX_NOEXCEPT
381 _M_node = _Rb_tree_decrement(_M_node);
386 operator--(
int) _GLIBCXX_NOEXCEPT
389 _M_node = _Rb_tree_decrement(_M_node);
394 operator==(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
395 {
return _M_node == __x._M_node; }
398 operator!=(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
399 {
return _M_node != __x._M_node; }
404 template<
typename _Val>
406 operator==(
const _Rb_tree_iterator<_Val>& __x,
407 const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
408 {
return __x._M_node == __y._M_node; }
410 template<
typename _Val>
412 operator!=(
const _Rb_tree_iterator<_Val>& __x,
413 const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
414 {
return __x._M_node != __y._M_node; }
417 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
418 _Rb_tree_node_base* __x,
419 _Rb_tree_node_base* __p,
420 _Rb_tree_node_base& __header)
throw ();
423 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
424 _Rb_tree_node_base& __header)
throw ();
426 #if __cplusplus > 201103L 427 template<
typename _Cmp,
typename _SfinaeType,
typename = __
void_t<>>
428 struct __has_is_transparent
431 template<
typename _Cmp,
typename _SfinaeType>
432 struct __has_is_transparent<_Cmp, _SfinaeType,
433 __void_t<typename _Cmp::is_transparent>>
434 {
typedef void type; };
437 #if __cplusplus > 201402L 438 template<
typename _Tree1,
typename _Cmp2>
439 struct _Rb_tree_merge_helper { };
442 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
443 typename _Compare,
typename _Alloc = allocator<_Val> >
447 rebind<_Rb_tree_node<_Val> >::other _Node_allocator;
452 typedef _Rb_tree_node_base* _Base_ptr;
453 typedef const _Rb_tree_node_base* _Const_Base_ptr;
454 typedef _Rb_tree_node<_Val>* _Link_type;
455 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
460 struct _Reuse_or_alloc_node
462 _Reuse_or_alloc_node(_Rb_tree& __t)
463 : _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t)
467 _M_root->_M_parent = 0;
469 if (_M_nodes->_M_left)
470 _M_nodes = _M_nodes->_M_left;
476 #if __cplusplus >= 201103L 477 _Reuse_or_alloc_node(
const _Reuse_or_alloc_node&) =
delete;
480 ~_Reuse_or_alloc_node()
481 { _M_t._M_erase(static_cast<_Link_type>(_M_root)); }
483 template<
typename _Arg>
485 #if __cplusplus < 201103L 486 operator()(
const _Arg& __arg)
488 operator()(_Arg&& __arg)
491 _Link_type __node =
static_cast<_Link_type
>(_M_extract());
494 _M_t._M_destroy_node(__node);
495 _M_t._M_construct_node(__node, _GLIBCXX_FORWARD(_Arg, __arg));
499 return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg));
509 _Base_ptr __node = _M_nodes;
510 _M_nodes = _M_nodes->_M_parent;
513 if (_M_nodes->_M_right == __node)
515 _M_nodes->_M_right = 0;
517 if (_M_nodes->_M_left)
519 _M_nodes = _M_nodes->_M_left;
521 while (_M_nodes->_M_right)
522 _M_nodes = _M_nodes->_M_right;
524 if (_M_nodes->_M_left)
525 _M_nodes = _M_nodes->_M_left;
529 _M_nodes->_M_left = 0;
546 _Alloc_node(_Rb_tree& __t)
549 template<
typename _Arg>
551 #if __cplusplus < 201103L 552 operator()(
const _Arg& __arg)
const 554 operator()(_Arg&& __arg)
const 556 {
return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg)); }
563 typedef _Key key_type;
564 typedef _Val value_type;
565 typedef value_type* pointer;
566 typedef const value_type* const_pointer;
567 typedef value_type& reference;
568 typedef const value_type& const_reference;
569 typedef size_t size_type;
570 typedef ptrdiff_t difference_type;
571 typedef _Alloc allocator_type;
574 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
575 {
return this->_M_impl; }
577 const _Node_allocator&
578 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
579 {
return this->_M_impl; }
582 get_allocator() const _GLIBCXX_NOEXCEPT
583 {
return allocator_type(_M_get_Node_allocator()); }
591 _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
594 #if __cplusplus < 201103L 596 _M_construct_node(_Link_type __node,
const value_type& __x)
599 { get_allocator().construct(__node->_M_valptr(), __x); }
603 __throw_exception_again;
608 _M_create_node(
const value_type& __x)
610 _Link_type __tmp = _M_get_node();
611 _M_construct_node(__tmp, __x);
616 _M_destroy_node(_Link_type __p)
617 { get_allocator().destroy(__p->_M_valptr()); }
619 template<
typename... _Args>
621 _M_construct_node(_Link_type __node, _Args&&... __args)
625 ::new(__node) _Rb_tree_node<_Val>;
626 _Alloc_traits::construct(_M_get_Node_allocator(),
628 std::forward<_Args>(__args)...);
632 __node->~_Rb_tree_node<_Val>();
634 __throw_exception_again;
638 template<
typename... _Args>
640 _M_create_node(_Args&&... __args)
642 _Link_type __tmp = _M_get_node();
643 _M_construct_node(__tmp, std::forward<_Args>(__args)...);
648 _M_destroy_node(_Link_type __p) noexcept
650 _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr());
651 __p->~_Rb_tree_node<_Val>();
656 _M_drop_node(_Link_type __p) _GLIBCXX_NOEXCEPT
658 _M_destroy_node(__p);
662 template<
typename _NodeGen>
664 _M_clone_node(_Const_Link_type __x, _NodeGen& __node_gen)
666 _Link_type __tmp = __node_gen(*__x->_M_valptr());
667 __tmp->_M_color = __x->_M_color;
674 #if _GLIBCXX_INLINE_VERSION 675 template<
typename _Key_compare>
678 template<
typename _Key_compare,
679 bool = __is_pod(_Key_compare)>
682 :
public _Node_allocator
683 ,
public _Rb_tree_key_compare<_Key_compare>
684 ,
public _Rb_tree_header
686 typedef _Rb_tree_key_compare<_Key_compare> _Base_key_compare;
689 _GLIBCXX_NOEXCEPT_IF(
690 is_nothrow_default_constructible<_Node_allocator>::value
691 && is_nothrow_default_constructible<_Base_key_compare>::value )
695 _Rb_tree_impl(
const _Rb_tree_impl& __x)
696 : _Node_allocator(_Alloc_traits::_S_select_on_copy(__x))
697 , _Base_key_compare(__x._M_key_compare)
700 #if __cplusplus < 201103L 701 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
702 : _Node_allocator(__a), _Base_key_compare(__comp)
705 _Rb_tree_impl(_Rb_tree_impl&&) =
default;
707 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
708 : _Node_allocator(
std::move(__a)), _Base_key_compare(__comp)
713 _Rb_tree_impl<_Compare> _M_impl;
717 _M_root() _GLIBCXX_NOEXCEPT
718 {
return this->_M_impl._M_header._M_parent; }
721 _M_root() const _GLIBCXX_NOEXCEPT
722 {
return this->_M_impl._M_header._M_parent; }
725 _M_leftmost() _GLIBCXX_NOEXCEPT
726 {
return this->_M_impl._M_header._M_left; }
729 _M_leftmost() const _GLIBCXX_NOEXCEPT
730 {
return this->_M_impl._M_header._M_left; }
733 _M_rightmost() _GLIBCXX_NOEXCEPT
734 {
return this->_M_impl._M_header._M_right; }
737 _M_rightmost() const _GLIBCXX_NOEXCEPT
738 {
return this->_M_impl._M_header._M_right; }
741 _M_begin() _GLIBCXX_NOEXCEPT
742 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
745 _M_begin() const _GLIBCXX_NOEXCEPT
747 return static_cast<_Const_Link_type
> 748 (this->_M_impl._M_header._M_parent);
752 _M_end() _GLIBCXX_NOEXCEPT
753 {
return &this->_M_impl._M_header; }
756 _M_end() const _GLIBCXX_NOEXCEPT
757 {
return &this->_M_impl._M_header; }
759 static const_reference
760 _S_value(_Const_Link_type __x)
761 {
return *__x->_M_valptr(); }
764 _S_key(_Const_Link_type __x)
765 {
return _KeyOfValue()(_S_value(__x)); }
768 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
769 {
return static_cast<_Link_type
>(__x->_M_left); }
771 static _Const_Link_type
772 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
773 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
776 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
777 {
return static_cast<_Link_type
>(__x->_M_right); }
779 static _Const_Link_type
780 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
781 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
783 static const_reference
784 _S_value(_Const_Base_ptr __x)
785 {
return *
static_cast<_Const_Link_type
>(__x)->_M_valptr(); }
788 _S_key(_Const_Base_ptr __x)
789 {
return _KeyOfValue()(_S_value(__x)); }
792 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
793 {
return _Rb_tree_node_base::_S_minimum(__x); }
795 static _Const_Base_ptr
796 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
797 {
return _Rb_tree_node_base::_S_minimum(__x); }
800 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
801 {
return _Rb_tree_node_base::_S_maximum(__x); }
803 static _Const_Base_ptr
804 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
805 {
return _Rb_tree_node_base::_S_maximum(__x); }
808 typedef _Rb_tree_iterator<value_type> iterator;
809 typedef _Rb_tree_const_iterator<value_type> const_iterator;
814 #if __cplusplus > 201402L 815 using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
816 using insert_return_type = _Node_insert_return<
817 conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
821 pair<_Base_ptr, _Base_ptr>
822 _M_get_insert_unique_pos(
const key_type& __k);
824 pair<_Base_ptr, _Base_ptr>
825 _M_get_insert_equal_pos(
const key_type& __k);
827 pair<_Base_ptr, _Base_ptr>
828 _M_get_insert_hint_unique_pos(const_iterator __pos,
829 const key_type& __k);
831 pair<_Base_ptr, _Base_ptr>
832 _M_get_insert_hint_equal_pos(const_iterator __pos,
833 const key_type& __k);
836 #if __cplusplus >= 201103L 837 template<
typename _Arg,
typename _NodeGen>
839 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
842 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
844 template<
typename _Arg>
846 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
848 template<
typename _Arg>
850 _M_insert_equal_lower(_Arg&& __x);
853 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
856 _M_insert_equal_lower_node(_Link_type __z);
858 template<
typename _NodeGen>
860 _M_insert_(_Base_ptr __x, _Base_ptr __y,
861 const value_type& __v, _NodeGen&);
866 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
869 _M_insert_equal_lower(
const value_type& __x);
872 template<
typename _NodeGen>
874 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen&);
876 template<
typename _NodeGen>
878 _M_copy(
const _Rb_tree& __x, _NodeGen& __gen)
880 _Link_type __root = _M_copy(__x._M_begin(), _M_end(), __gen);
881 _M_leftmost() = _S_minimum(__root);
882 _M_rightmost() = _S_maximum(__root);
883 _M_impl._M_node_count = __x._M_impl._M_node_count;
888 _M_copy(
const _Rb_tree& __x)
890 _Alloc_node __an(*
this);
891 return _M_copy(__x, __an);
895 _M_erase(_Link_type __x);
898 _M_lower_bound(_Link_type __x, _Base_ptr __y,
902 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
903 const _Key& __k)
const;
906 _M_upper_bound(_Link_type __x, _Base_ptr __y,
910 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
911 const _Key& __k)
const;
915 #if __cplusplus < 201103L 918 _Rb_tree() =
default;
921 _Rb_tree(
const _Compare& __comp,
922 const allocator_type& __a = allocator_type())
923 : _M_impl(__comp, _Node_allocator(__a)) { }
925 _Rb_tree(
const _Rb_tree& __x)
926 : _M_impl(__x._M_impl)
928 if (__x._M_root() != 0)
929 _M_root() = _M_copy(__x);
932 #if __cplusplus >= 201103L 933 _Rb_tree(
const allocator_type& __a)
934 : _M_impl(_Compare(), _Node_allocator(__a))
937 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
938 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
940 if (__x._M_root() !=
nullptr)
941 _M_root() = _M_copy(__x);
944 _Rb_tree(_Rb_tree&&) =
default;
946 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
947 : _Rb_tree(
std::move(__x), _Node_allocator(__a))
950 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a);
953 ~_Rb_tree() _GLIBCXX_NOEXCEPT
955 _M_erase(_M_begin());
957 #if __cplusplus >= 201103L 958 static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
959 "comparison object must be invocable " 960 "with two arguments of key type");
961 # if __cplusplus >= 201703L 964 static_assert(is_invocable_v<const _Compare&, const _Key&, const _Key&>,
965 "comparison object must be invocable as const");
971 operator=(
const _Rb_tree& __x);
976 {
return _M_impl._M_key_compare; }
979 begin() _GLIBCXX_NOEXCEPT
980 {
return iterator(this->_M_impl._M_header._M_left); }
983 begin() const _GLIBCXX_NOEXCEPT
984 {
return const_iterator(this->_M_impl._M_header._M_left); }
987 end() _GLIBCXX_NOEXCEPT
988 {
return iterator(&this->_M_impl._M_header); }
991 end() const _GLIBCXX_NOEXCEPT
992 {
return const_iterator(&this->_M_impl._M_header); }
995 rbegin() _GLIBCXX_NOEXCEPT
996 {
return reverse_iterator(
end()); }
998 const_reverse_iterator
999 rbegin() const _GLIBCXX_NOEXCEPT
1000 {
return const_reverse_iterator(
end()); }
1003 rend() _GLIBCXX_NOEXCEPT
1004 {
return reverse_iterator(
begin()); }
1006 const_reverse_iterator
1007 rend() const _GLIBCXX_NOEXCEPT
1008 {
return const_reverse_iterator(
begin()); }
1011 empty() const _GLIBCXX_NOEXCEPT
1012 {
return _M_impl._M_node_count == 0; }
1015 size() const _GLIBCXX_NOEXCEPT
1016 {
return _M_impl._M_node_count; }
1019 max_size() const _GLIBCXX_NOEXCEPT
1024 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value);
1027 #if __cplusplus >= 201103L 1028 template<
typename _Arg>
1029 pair<iterator, bool>
1030 _M_insert_unique(_Arg&& __x);
1032 template<
typename _Arg>
1034 _M_insert_equal(_Arg&& __x);
1036 template<
typename _Arg,
typename _NodeGen>
1038 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1040 template<
typename _Arg>
1042 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
1044 _Alloc_node __an(*
this);
1045 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
1048 template<
typename _Arg,
typename _NodeGen>
1050 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1052 template<
typename _Arg>
1054 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
1056 _Alloc_node __an(*
this);
1057 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
1060 template<
typename... _Args>
1061 pair<iterator, bool>
1062 _M_emplace_unique(_Args&&... __args);
1064 template<
typename... _Args>
1066 _M_emplace_equal(_Args&&... __args);
1068 template<
typename... _Args>
1070 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
1072 template<
typename... _Args>
1074 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
1076 pair<iterator, bool>
1077 _M_insert_unique(
const value_type& __x);
1080 _M_insert_equal(
const value_type& __x);
1082 template<
typename _NodeGen>
1084 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
1088 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
1090 _Alloc_node __an(*
this);
1091 return _M_insert_unique_(__pos, __x, __an);
1094 template<
typename _NodeGen>
1096 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1099 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1101 _Alloc_node __an(*
this);
1102 return _M_insert_equal_(__pos, __x, __an);
1106 template<
typename _InputIterator>
1108 _M_insert_unique(_InputIterator __first, _InputIterator __last);
1110 template<
typename _InputIterator>
1112 _M_insert_equal(_InputIterator __first, _InputIterator __last);
1116 _M_erase_aux(const_iterator __position);
1119 _M_erase_aux(const_iterator __first, const_iterator __last);
1122 #if __cplusplus >= 201103L 1125 _GLIBCXX_ABI_TAG_CXX11
1127 erase(const_iterator __position)
1129 __glibcxx_assert(__position !=
end());
1130 const_iterator __result = __position;
1132 _M_erase_aux(__position);
1133 return __result._M_const_cast();
1137 _GLIBCXX_ABI_TAG_CXX11
1139 erase(iterator __position)
1141 __glibcxx_assert(__position !=
end());
1142 iterator __result = __position;
1144 _M_erase_aux(__position);
1149 erase(iterator __position)
1151 __glibcxx_assert(__position !=
end());
1152 _M_erase_aux(__position);
1156 erase(const_iterator __position)
1158 __glibcxx_assert(__position !=
end());
1159 _M_erase_aux(__position);
1163 erase(
const key_type& __x);
1165 #if __cplusplus >= 201103L 1168 _GLIBCXX_ABI_TAG_CXX11
1170 erase(const_iterator __first, const_iterator __last)
1172 _M_erase_aux(__first, __last);
1173 return __last._M_const_cast();
1177 erase(iterator __first, iterator __last)
1178 { _M_erase_aux(__first, __last); }
1181 erase(const_iterator __first, const_iterator __last)
1182 { _M_erase_aux(__first, __last); }
1185 erase(
const key_type* __first,
const key_type* __last);
1188 clear() _GLIBCXX_NOEXCEPT
1190 _M_erase(_M_begin());
1196 find(
const key_type& __k);
1199 find(
const key_type& __k)
const;
1202 count(
const key_type& __k)
const;
1205 lower_bound(
const key_type& __k)
1206 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1209 lower_bound(
const key_type& __k)
const 1210 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1213 upper_bound(
const key_type& __k)
1214 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1217 upper_bound(
const key_type& __k)
const 1218 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1220 pair<iterator, iterator>
1221 equal_range(
const key_type& __k);
1223 pair<const_iterator, const_iterator>
1224 equal_range(
const key_type& __k)
const;
1226 #if __cplusplus > 201103L 1227 template<
typename _Kt,
1229 typename __has_is_transparent<_Compare, _Kt>::type>
1231 _M_find_tr(
const _Kt& __k)
1233 const _Rb_tree* __const_this =
this;
1234 return __const_this->_M_find_tr(__k)._M_const_cast();
1237 template<
typename _Kt,
1239 typename __has_is_transparent<_Compare, _Kt>::type>
1241 _M_find_tr(
const _Kt& __k)
const 1243 auto __j = _M_lower_bound_tr(__k);
1244 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1249 template<
typename _Kt,
1251 typename __has_is_transparent<_Compare, _Kt>::type>
1253 _M_count_tr(
const _Kt& __k)
const 1255 auto __p = _M_equal_range_tr(__k);
1259 template<
typename _Kt,
1261 typename __has_is_transparent<_Compare, _Kt>::type>
1263 _M_lower_bound_tr(
const _Kt& __k)
1265 const _Rb_tree* __const_this =
this;
1266 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1269 template<
typename _Kt,
1271 typename __has_is_transparent<_Compare, _Kt>::type>
1273 _M_lower_bound_tr(
const _Kt& __k)
const 1275 auto __x = _M_begin();
1276 auto __y = _M_end();
1278 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1284 __x = _S_right(__x);
1285 return const_iterator(__y);
1288 template<
typename _Kt,
1290 typename __has_is_transparent<_Compare, _Kt>::type>
1292 _M_upper_bound_tr(
const _Kt& __k)
1294 const _Rb_tree* __const_this =
this;
1295 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1298 template<
typename _Kt,
1300 typename __has_is_transparent<_Compare, _Kt>::type>
1302 _M_upper_bound_tr(
const _Kt& __k)
const 1304 auto __x = _M_begin();
1305 auto __y = _M_end();
1307 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1313 __x = _S_right(__x);
1314 return const_iterator(__y);
1317 template<
typename _Kt,
1319 typename __has_is_transparent<_Compare, _Kt>::type>
1320 pair<iterator, iterator>
1321 _M_equal_range_tr(
const _Kt& __k)
1323 const _Rb_tree* __const_this =
this;
1324 auto __ret = __const_this->_M_equal_range_tr(__k);
1325 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1328 template<
typename _Kt,
1330 typename __has_is_transparent<_Compare, _Kt>::type>
1331 pair<const_iterator, const_iterator>
1332 _M_equal_range_tr(
const _Kt& __k)
const 1334 auto __low = _M_lower_bound_tr(__k);
1335 auto __high = __low;
1336 auto& __cmp = _M_impl._M_key_compare;
1337 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1339 return { __low, __high };
1345 __rb_verify()
const;
1347 #if __cplusplus >= 201103L 1349 operator=(_Rb_tree&&)
1350 noexcept(_Alloc_traits::_S_nothrow_move()
1351 && is_nothrow_move_assignable<_Compare>::value);
1353 template<typename _Iterator>
1355 _M_assign_unique(_Iterator, _Iterator);
1357 template<typename _Iterator>
1359 _M_assign_equal(_Iterator, _Iterator);
1365 { _M_impl._M_move_data(__x._M_impl); }
1382 #if __cplusplus > 201402L 1386 _M_reinsert_node_unique(node_type&& __nh)
1388 insert_return_type __ret;
1390 __ret.position =
end();
1393 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1395 auto __res = _M_get_insert_unique_pos(__nh._M_key());
1399 = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1400 __nh._M_ptr =
nullptr;
1401 __ret.inserted =
true;
1405 __ret.node = std::move(__nh);
1406 __ret.position = iterator(__res.first);
1407 __ret.inserted =
false;
1415 _M_reinsert_node_equal(node_type&& __nh)
1422 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1423 auto __res = _M_get_insert_equal_pos(__nh._M_key());
1425 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1427 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1428 __nh._M_ptr =
nullptr;
1435 _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh)
1442 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1443 auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key());
1446 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1447 __nh._M_ptr =
nullptr;
1450 __ret = iterator(__res.first);
1457 _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh)
1464 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1465 auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key());
1467 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1469 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1470 __nh._M_ptr =
nullptr;
1477 extract(const_iterator __pos)
1479 auto __ptr = _Rb_tree_rebalance_for_erase(
1480 __pos._M_const_cast()._M_node, _M_impl._M_header);
1481 --_M_impl._M_node_count;
1482 return {
static_cast<_Link_type
>(__ptr), _M_get_Node_allocator() };
1487 extract(
const key_type& __k)
1490 auto __pos = find(__k);
1492 __nh = extract(const_iterator(__pos));
1496 template<
typename _Compare2>
1497 using _Compatible_tree
1498 = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>;
1500 template<
typename,
typename>
1501 friend class _Rb_tree_merge_helper;
1504 template<
typename _Compare2>
1506 _M_merge_unique(_Compatible_tree<_Compare2>& __src) noexcept
1508 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1509 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1512 auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos));
1515 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1516 auto __ptr = _Rb_tree_rebalance_for_erase(
1517 __pos._M_node, __src_impl._M_header);
1518 --__src_impl._M_node_count;
1519 _M_insert_node(__res.first, __res.second,
1520 static_cast<_Link_type>(__ptr));
1526 template<
typename _Compare2>
1528 _M_merge_equal(_Compatible_tree<_Compare2>& __src) noexcept
1530 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1531 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1534 auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos));
1537 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1538 auto __ptr = _Rb_tree_rebalance_for_erase(
1539 __pos._M_node, __src_impl._M_header);
1540 --__src_impl._M_node_count;
1541 _M_insert_node(__res.first, __res.second,
1542 static_cast<_Link_type>(__ptr));
1549 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1550 typename _Compare,
typename _Alloc>
1552 operator==(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1553 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1555 return __x.size() == __y.size()
1556 &&
std::equal(__x.begin(), __x.end(), __y.begin());
1559 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1560 typename _Compare,
typename _Alloc>
1562 operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1563 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1566 __y.begin(), __y.end());
1569 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1570 typename _Compare,
typename _Alloc>
1572 operator!=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1573 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1574 {
return !(__x == __y); }
1576 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1577 typename _Compare,
typename _Alloc>
1579 operator>(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1580 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1581 {
return __y < __x; }
1583 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1584 typename _Compare,
typename _Alloc>
1586 operator<=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1587 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1588 {
return !(__y < __x); }
1590 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1591 typename _Compare,
typename _Alloc>
1593 operator>=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1594 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1595 {
return !(__x < __y); }
1597 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1598 typename _Compare,
typename _Alloc>
1600 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1601 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1604 #if __cplusplus >= 201103L 1605 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1606 typename _Compare,
typename _Alloc>
1607 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1608 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
1609 : _M_impl(__x._M_impl._M_key_compare,
std::move(__a))
1611 using __eq =
typename _Alloc_traits::is_always_equal;
1612 if (__x._M_root() !=
nullptr)
1613 _M_move_data(__x, __eq());
1616 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1617 typename _Compare,
typename _Alloc>
1619 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1622 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1626 _Alloc_node __an(*
this);
1628 [&__an](
const value_type& __cval)
1630 auto& __val =
const_cast<value_type&
>(__cval);
1633 _M_root() = _M_copy(__x, __lbd);
1637 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1638 typename _Compare,
typename _Alloc>
1640 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1641 _M_move_assign(_Rb_tree& __x,
true_type)
1644 if (__x._M_root() !=
nullptr)
1646 std::__alloc_on_move(_M_get_Node_allocator(),
1647 __x._M_get_Node_allocator());
1650 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1651 typename _Compare,
typename _Alloc>
1653 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1656 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1657 return _M_move_assign(__x,
true_type{});
1661 _Reuse_or_alloc_node __roan(*
this);
1663 if (__x._M_root() !=
nullptr)
1666 [&__roan](
const value_type& __cval)
1668 auto& __val =
const_cast<value_type&
>(__cval);
1671 _M_root() = _M_copy(__x, __lbd);
1676 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1677 typename _Compare,
typename _Alloc>
1678 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1679 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1680 operator=(_Rb_tree&& __x)
1681 noexcept(_Alloc_traits::_S_nothrow_move()
1682 && is_nothrow_move_assignable<_Compare>::value)
1684 _M_impl._M_key_compare = std::move(__x._M_impl._M_key_compare);
1685 _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>());
1689 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1690 typename _Compare,
typename _Alloc>
1691 template<
typename _Iterator>
1693 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1694 _M_assign_unique(_Iterator __first, _Iterator __last)
1696 _Reuse_or_alloc_node __roan(*
this);
1698 for (; __first != __last; ++__first)
1699 _M_insert_unique_(
end(), *__first, __roan);
1702 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1703 typename _Compare,
typename _Alloc>
1704 template<
typename _Iterator>
1706 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1707 _M_assign_equal(_Iterator __first, _Iterator __last)
1709 _Reuse_or_alloc_node __roan(*
this);
1711 for (; __first != __last; ++__first)
1712 _M_insert_equal_(
end(), *__first, __roan);
1716 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1717 typename _Compare,
typename _Alloc>
1718 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1719 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1720 operator=(
const _Rb_tree& __x)
1725 #if __cplusplus >= 201103L 1726 if (_Alloc_traits::_S_propagate_on_copy_assign())
1728 auto& __this_alloc = this->_M_get_Node_allocator();
1729 auto& __that_alloc = __x._M_get_Node_allocator();
1730 if (!_Alloc_traits::_S_always_equal()
1731 && __this_alloc != __that_alloc)
1736 std::__alloc_on_copy(__this_alloc, __that_alloc);
1741 _Reuse_or_alloc_node __roan(*
this);
1743 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1744 if (__x._M_root() != 0)
1745 _M_root() = _M_copy(__x, __roan);
1751 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1752 typename _Compare,
typename _Alloc>
1753 #if __cplusplus >= 201103L 1754 template<
typename _Arg,
typename _NodeGen>
1756 template<
typename _NodeGen>
1758 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1759 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1760 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1761 #
if __cplusplus >= 201103L
1766 _NodeGen& __node_gen)
1768 bool __insert_left = (__x != 0 || __p == _M_end()
1769 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1772 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1774 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1775 this->_M_impl._M_header);
1776 ++_M_impl._M_node_count;
1777 return iterator(__z);
1780 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1781 typename _Compare,
typename _Alloc>
1782 #if __cplusplus >= 201103L 1783 template<
typename _Arg>
1785 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1786 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1787 #if __cplusplus >= 201103L 1788 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1790 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1793 bool __insert_left = (__p == _M_end()
1794 || !_M_impl._M_key_compare(_S_key(__p),
1795 _KeyOfValue()(__v)));
1797 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1799 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1800 this->_M_impl._M_header);
1801 ++_M_impl._M_node_count;
1802 return iterator(__z);
1805 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1806 typename _Compare,
typename _Alloc>
1807 #if __cplusplus >= 201103L 1808 template<
typename _Arg>
1810 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1811 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1812 #if __cplusplus >= 201103L 1813 _M_insert_equal_lower(_Arg&& __v)
1815 _M_insert_equal_lower(
const _Val& __v)
1818 _Link_type __x = _M_begin();
1819 _Base_ptr __y = _M_end();
1823 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1824 _S_left(__x) : _S_right(__x);
1826 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1829 template<
typename _Key,
typename _Val,
typename _KoV,
1830 typename _Compare,
typename _Alloc>
1831 template<
typename _NodeGen>
1832 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1833 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1834 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1837 _Link_type __top = _M_clone_node(__x, __node_gen);
1838 __top->_M_parent = __p;
1843 __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen);
1849 _Link_type __y = _M_clone_node(__x, __node_gen);
1851 __y->_M_parent = __p;
1853 __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen);
1861 __throw_exception_again;
1866 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1867 typename _Compare,
typename _Alloc>
1869 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1870 _M_erase(_Link_type __x)
1875 _M_erase(_S_right(__x));
1876 _Link_type __y = _S_left(__x);
1882 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1883 typename _Compare,
typename _Alloc>
1884 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1885 _Compare, _Alloc>::iterator
1886 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1887 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1891 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1892 __y = __x, __x = _S_left(__x);
1894 __x = _S_right(__x);
1895 return iterator(__y);
1898 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1899 typename _Compare,
typename _Alloc>
1900 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1901 _Compare, _Alloc>::const_iterator
1902 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1903 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1904 const _Key& __k)
const 1907 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1908 __y = __x, __x = _S_left(__x);
1910 __x = _S_right(__x);
1911 return const_iterator(__y);
1914 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1915 typename _Compare,
typename _Alloc>
1916 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1917 _Compare, _Alloc>::iterator
1918 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1919 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1923 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1924 __y = __x, __x = _S_left(__x);
1926 __x = _S_right(__x);
1927 return iterator(__y);
1930 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1931 typename _Compare,
typename _Alloc>
1932 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1933 _Compare, _Alloc>::const_iterator
1934 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1935 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1936 const _Key& __k)
const 1939 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1940 __y = __x, __x = _S_left(__x);
1942 __x = _S_right(__x);
1943 return const_iterator(__y);
1946 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1947 typename _Compare,
typename _Alloc>
1948 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1949 _Compare, _Alloc>::iterator,
1950 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1951 _Compare, _Alloc>::iterator>
1952 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1953 equal_range(
const _Key& __k)
1955 _Link_type __x = _M_begin();
1956 _Base_ptr __y = _M_end();
1959 if (_M_impl._M_key_compare(_S_key(__x), __k))
1960 __x = _S_right(__x);
1961 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1962 __y = __x, __x = _S_left(__x);
1965 _Link_type __xu(__x);
1966 _Base_ptr __yu(__y);
1967 __y = __x, __x = _S_left(__x);
1968 __xu = _S_right(__xu);
1969 return pair<iterator,
1970 iterator>(_M_lower_bound(__x, __y, __k),
1971 _M_upper_bound(__xu, __yu, __k));
1974 return pair<iterator, iterator>(iterator(__y),
1978 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1979 typename _Compare,
typename _Alloc>
1980 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1981 _Compare, _Alloc>::const_iterator,
1982 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1983 _Compare, _Alloc>::const_iterator>
1984 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1985 equal_range(
const _Key& __k)
const 1987 _Const_Link_type __x = _M_begin();
1988 _Const_Base_ptr __y = _M_end();
1991 if (_M_impl._M_key_compare(_S_key(__x), __k))
1992 __x = _S_right(__x);
1993 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1994 __y = __x, __x = _S_left(__x);
1997 _Const_Link_type __xu(__x);
1998 _Const_Base_ptr __yu(__y);
1999 __y = __x, __x = _S_left(__x);
2000 __xu = _S_right(__xu);
2001 return pair<const_iterator,
2002 const_iterator>(_M_lower_bound(__x, __y, __k),
2003 _M_upper_bound(__xu, __yu, __k));
2006 return pair<const_iterator, const_iterator>(const_iterator(__y),
2007 const_iterator(__y));
2010 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2011 typename _Compare,
typename _Alloc>
2013 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2015 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
2019 if (__t._M_root() != 0)
2020 _M_impl._M_move_data(__t._M_impl);
2022 else if (__t._M_root() == 0)
2023 __t._M_impl._M_move_data(_M_impl);
2026 std::swap(_M_root(),__t._M_root());
2027 std::swap(_M_leftmost(),__t._M_leftmost());
2028 std::swap(_M_rightmost(),__t._M_rightmost());
2030 _M_root()->_M_parent = _M_end();
2031 __t._M_root()->_M_parent = __t._M_end();
2032 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
2035 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
2037 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
2038 __t._M_get_Node_allocator());
2041 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2042 typename _Compare,
typename _Alloc>
2043 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2044 _Compare, _Alloc>::_Base_ptr,
2045 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2046 _Compare, _Alloc>::_Base_ptr>
2047 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2048 _M_get_insert_unique_pos(
const key_type& __k)
2050 typedef pair<_Base_ptr, _Base_ptr> _Res;
2051 _Link_type __x = _M_begin();
2052 _Base_ptr __y = _M_end();
2057 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
2058 __x = __comp ? _S_left(__x) : _S_right(__x);
2060 iterator __j = iterator(__y);
2064 return _Res(__x, __y);
2068 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
2069 return _Res(__x, __y);
2070 return _Res(__j._M_node, 0);
2073 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2074 typename _Compare,
typename _Alloc>
2075 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2076 _Compare, _Alloc>::_Base_ptr,
2077 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2078 _Compare, _Alloc>::_Base_ptr>
2079 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2080 _M_get_insert_equal_pos(
const key_type& __k)
2082 typedef pair<_Base_ptr, _Base_ptr> _Res;
2083 _Link_type __x = _M_begin();
2084 _Base_ptr __y = _M_end();
2088 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
2089 _S_left(__x) : _S_right(__x);
2091 return _Res(__x, __y);
2094 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2095 typename _Compare,
typename _Alloc>
2096 #if __cplusplus >= 201103L 2097 template<
typename _Arg>
2099 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2100 _Compare, _Alloc>::iterator,
bool>
2101 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2102 #if __cplusplus >= 201103L 2103 _M_insert_unique(_Arg&& __v)
2105 _M_insert_unique(
const _Val& __v)
2108 typedef pair<iterator, bool> _Res;
2109 pair<_Base_ptr, _Base_ptr> __res
2110 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
2114 _Alloc_node __an(*
this);
2115 return _Res(_M_insert_(__res.first, __res.second,
2116 _GLIBCXX_FORWARD(_Arg, __v), __an),
2120 return _Res(iterator(__res.first),
false);
2123 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2124 typename _Compare,
typename _Alloc>
2125 #if __cplusplus >= 201103L 2126 template<
typename _Arg>
2128 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2129 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2130 #if __cplusplus >= 201103L 2131 _M_insert_equal(_Arg&& __v)
2133 _M_insert_equal(
const _Val& __v)
2136 pair<_Base_ptr, _Base_ptr> __res
2137 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
2138 _Alloc_node __an(*
this);
2139 return _M_insert_(__res.first, __res.second,
2140 _GLIBCXX_FORWARD(_Arg, __v), __an);
2143 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2144 typename _Compare,
typename _Alloc>
2145 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2146 _Compare, _Alloc>::_Base_ptr,
2147 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2148 _Compare, _Alloc>::_Base_ptr>
2149 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2150 _M_get_insert_hint_unique_pos(const_iterator __position,
2151 const key_type& __k)
2153 iterator __pos = __position._M_const_cast();
2154 typedef pair<_Base_ptr, _Base_ptr> _Res;
2157 if (__pos._M_node == _M_end())
2160 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
2161 return _Res(0, _M_rightmost());
2163 return _M_get_insert_unique_pos(__k);
2165 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
2168 iterator __before = __pos;
2169 if (__pos._M_node == _M_leftmost())
2170 return _Res(_M_leftmost(), _M_leftmost());
2171 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
2173 if (_S_right(__before._M_node) == 0)
2174 return _Res(0, __before._M_node);
2176 return _Res(__pos._M_node, __pos._M_node);
2179 return _M_get_insert_unique_pos(__k);
2181 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2184 iterator __after = __pos;
2185 if (__pos._M_node == _M_rightmost())
2186 return _Res(0, _M_rightmost());
2187 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
2189 if (_S_right(__pos._M_node) == 0)
2190 return _Res(0, __pos._M_node);
2192 return _Res(__after._M_node, __after._M_node);
2195 return _M_get_insert_unique_pos(__k);
2199 return _Res(__pos._M_node, 0);
2202 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2203 typename _Compare,
typename _Alloc>
2204 #if __cplusplus >= 201103L 2205 template<
typename _Arg,
typename _NodeGen>
2207 template<
typename _NodeGen>
2209 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2210 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2211 _M_insert_unique_(const_iterator __position,
2212 #
if __cplusplus >= 201103L
2217 _NodeGen& __node_gen)
2219 pair<_Base_ptr, _Base_ptr> __res
2220 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2223 return _M_insert_(__res.first, __res.second,
2224 _GLIBCXX_FORWARD(_Arg, __v),
2226 return iterator(__res.first);
2229 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2230 typename _Compare,
typename _Alloc>
2231 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2232 _Compare, _Alloc>::_Base_ptr,
2233 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2234 _Compare, _Alloc>::_Base_ptr>
2235 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2236 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2238 iterator __pos = __position._M_const_cast();
2239 typedef pair<_Base_ptr, _Base_ptr> _Res;
2242 if (__pos._M_node == _M_end())
2245 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2246 return _Res(0, _M_rightmost());
2248 return _M_get_insert_equal_pos(__k);
2250 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2253 iterator __before = __pos;
2254 if (__pos._M_node == _M_leftmost())
2255 return _Res(_M_leftmost(), _M_leftmost());
2256 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2258 if (_S_right(__before._M_node) == 0)
2259 return _Res(0, __before._M_node);
2261 return _Res(__pos._M_node, __pos._M_node);
2264 return _M_get_insert_equal_pos(__k);
2269 iterator __after = __pos;
2270 if (__pos._M_node == _M_rightmost())
2271 return _Res(0, _M_rightmost());
2272 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2274 if (_S_right(__pos._M_node) == 0)
2275 return _Res(0, __pos._M_node);
2277 return _Res(__after._M_node, __after._M_node);
2284 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2285 typename _Compare,
typename _Alloc>
2286 #if __cplusplus >= 201103L 2287 template<
typename _Arg,
typename _NodeGen>
2289 template<
typename _NodeGen>
2291 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2292 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2293 _M_insert_equal_(const_iterator __position,
2294 #
if __cplusplus >= 201103L
2299 _NodeGen& __node_gen)
2301 pair<_Base_ptr, _Base_ptr> __res
2302 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2305 return _M_insert_(__res.first, __res.second,
2306 _GLIBCXX_FORWARD(_Arg, __v),
2309 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2312 #if __cplusplus >= 201103L 2313 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2314 typename _Compare,
typename _Alloc>
2315 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2316 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2317 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2319 bool __insert_left = (__x != 0 || __p == _M_end()
2320 || _M_impl._M_key_compare(_S_key(__z),
2323 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2324 this->_M_impl._M_header);
2325 ++_M_impl._M_node_count;
2326 return iterator(__z);
2329 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2330 typename _Compare,
typename _Alloc>
2331 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2332 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2333 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2335 bool __insert_left = (__p == _M_end()
2336 || !_M_impl._M_key_compare(_S_key(__p),
2339 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2340 this->_M_impl._M_header);
2341 ++_M_impl._M_node_count;
2342 return iterator(__z);
2345 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2346 typename _Compare,
typename _Alloc>
2347 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2348 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2349 _M_insert_equal_lower_node(_Link_type __z)
2351 _Link_type __x = _M_begin();
2352 _Base_ptr __y = _M_end();
2356 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2357 _S_left(__x) : _S_right(__x);
2359 return _M_insert_lower_node(__y, __z);
2362 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2363 typename _Compare,
typename _Alloc>
2364 template<
typename... _Args>
2365 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2366 _Compare, _Alloc>::iterator,
bool>
2367 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2368 _M_emplace_unique(_Args&&... __args)
2370 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2374 typedef pair<iterator, bool> _Res;
2375 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2377 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2380 return _Res(iterator(__res.first),
false);
2385 __throw_exception_again;
2389 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2390 typename _Compare,
typename _Alloc>
2391 template<
typename... _Args>
2392 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2393 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2394 _M_emplace_equal(_Args&&... __args)
2396 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2400 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2401 return _M_insert_node(__res.first, __res.second, __z);
2406 __throw_exception_again;
2410 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2411 typename _Compare,
typename _Alloc>
2412 template<
typename... _Args>
2413 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2414 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2415 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2417 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2421 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2424 return _M_insert_node(__res.first, __res.second, __z);
2427 return iterator(__res.first);
2432 __throw_exception_again;
2436 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2437 typename _Compare,
typename _Alloc>
2438 template<
typename... _Args>
2439 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2440 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2441 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2443 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2447 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2450 return _M_insert_node(__res.first, __res.second, __z);
2452 return _M_insert_equal_lower_node(__z);
2457 __throw_exception_again;
2462 template<
typename _Key,
typename _Val,
typename _KoV,
2463 typename _Cmp,
typename _Alloc>
2466 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
2467 _M_insert_unique(_II __first, _II __last)
2469 _Alloc_node __an(*
this);
2470 for (; __first != __last; ++__first)
2471 _M_insert_unique_(
end(), *__first, __an);
2474 template<
typename _Key,
typename _Val,
typename _KoV,
2475 typename _Cmp,
typename _Alloc>
2478 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
2479 _M_insert_equal(_II __first, _II __last)
2481 _Alloc_node __an(*
this);
2482 for (; __first != __last; ++__first)
2483 _M_insert_equal_(
end(), *__first, __an);
2486 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2487 typename _Compare,
typename _Alloc>
2489 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2490 _M_erase_aux(const_iterator __position)
2493 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
2494 (const_cast<_Base_ptr>(__position._M_node),
2495 this->_M_impl._M_header));
2497 --_M_impl._M_node_count;
2500 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2501 typename _Compare,
typename _Alloc>
2503 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2504 _M_erase_aux(const_iterator __first, const_iterator __last)
2506 if (__first ==
begin() && __last ==
end())
2509 while (__first != __last)
2510 _M_erase_aux(__first++);
2513 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2514 typename _Compare,
typename _Alloc>
2515 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2516 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2517 erase(
const _Key& __x)
2519 pair<iterator, iterator> __p = equal_range(__x);
2520 const size_type __old_size = size();
2521 _M_erase_aux(__p.first, __p.second);
2522 return __old_size - size();
2525 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2526 typename _Compare,
typename _Alloc>
2528 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2529 erase(
const _Key* __first,
const _Key* __last)
2531 while (__first != __last)
2535 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2536 typename _Compare,
typename _Alloc>
2537 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2538 _Compare, _Alloc>::iterator
2539 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2540 find(
const _Key& __k)
2542 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2543 return (__j ==
end()
2544 || _M_impl._M_key_compare(__k,
2545 _S_key(__j._M_node))) ?
end() : __j;
2548 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2549 typename _Compare,
typename _Alloc>
2550 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2551 _Compare, _Alloc>::const_iterator
2552 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2553 find(
const _Key& __k)
const 2555 const_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, _Compare, _Alloc>::size_type
2564 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2565 count(
const _Key& __k)
const 2567 pair<const_iterator, const_iterator> __p = equal_range(__k);
2572 _GLIBCXX_PURE
unsigned int 2573 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2574 const _Rb_tree_node_base* __root)
throw ();
2576 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2577 typename _Compare,
typename _Alloc>
2579 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const 2581 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2582 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2583 && this->_M_impl._M_header._M_left == _M_end()
2584 && this->_M_impl._M_header._M_right == _M_end();
2586 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2587 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2589 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
2590 _Const_Link_type __L = _S_left(__x);
2591 _Const_Link_type __R = _S_right(__x);
2593 if (__x->_M_color == _S_red)
2594 if ((__L && __L->_M_color == _S_red)
2595 || (__R && __R->_M_color == _S_red))
2598 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2600 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2603 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2607 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2609 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2614 #if __cplusplus > 201402L 2616 template<
typename _Key,
typename _Val,
typename _Sel,
typename _Cmp1,
2617 typename _Alloc,
typename _Cmp2>
2618 struct _Rb_tree_merge_helper<_Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>,
2622 friend class _Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>;
2625 _S_get_impl(_Rb_tree<_Key, _Val, _Sel, _Cmp2, _Alloc>& __tree)
2626 {
return __tree._M_impl; }
2630 _GLIBCXX_END_NAMESPACE_VERSION
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
_GLIBCXX17_CONSTEXPR auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
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.
static pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
ISO C++ entities toplevel namespace is std.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
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.
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
_GLIBCXX17_CONSTEXPR auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.