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; }
319 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
320 {
return __x._M_node != __y._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 _Self& __y) _GLIBCXX_NOEXCEPT
395 {
return __x._M_node == __y._M_node; }
398 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
399 {
return __x._M_node != __y._M_node; }
405 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
406 _Rb_tree_node_base* __x,
407 _Rb_tree_node_base* __p,
408 _Rb_tree_node_base& __header)
throw ();
411 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
412 _Rb_tree_node_base& __header)
throw ();
414 #if __cplusplus >= 201402L 415 template<
typename _Cmp,
typename _SfinaeType,
typename = __
void_t<>>
416 struct __has_is_transparent
419 template<
typename _Cmp,
typename _SfinaeType>
420 struct __has_is_transparent<_Cmp, _SfinaeType,
421 __void_t<typename _Cmp::is_transparent>>
422 {
typedef void type; };
424 template<
typename _Cmp,
typename _SfinaeType>
425 using __has_is_transparent_t
426 =
typename __has_is_transparent<_Cmp, _SfinaeType>::type;
429 #if __cplusplus > 201402L 430 template<
typename _Tree1,
typename _Cmp2>
431 struct _Rb_tree_merge_helper { };
434 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
435 typename _Compare,
typename _Alloc = allocator<_Val> >
439 rebind<_Rb_tree_node<_Val> >::other _Node_allocator;
443 #if __cplusplus >= 201103L 444 static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
445 "comparison object must be invocable with two arguments of key type");
446 # if __cplusplus >= 201703L 449 static_assert(is_invocable_v<const _Compare&, const _Key&, const _Key&>,
450 "comparison object must be invocable as const");
455 typedef _Rb_tree_node_base* _Base_ptr;
456 typedef const _Rb_tree_node_base* _Const_Base_ptr;
457 typedef _Rb_tree_node<_Val>* _Link_type;
458 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
463 struct _Reuse_or_alloc_node
465 _Reuse_or_alloc_node(_Rb_tree& __t)
466 : _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t)
470 _M_root->_M_parent = 0;
472 if (_M_nodes->_M_left)
473 _M_nodes = _M_nodes->_M_left;
479 #if __cplusplus >= 201103L 480 _Reuse_or_alloc_node(
const _Reuse_or_alloc_node&) =
delete;
483 ~_Reuse_or_alloc_node()
484 { _M_t._M_erase(static_cast<_Link_type>(_M_root)); }
486 template<
typename _Arg>
488 #if __cplusplus < 201103L 489 operator()(
const _Arg& __arg)
491 operator()(_Arg&& __arg)
494 _Link_type __node = static_cast<_Link_type>(_M_extract());
497 _M_t._M_destroy_node(__node);
498 _M_t._M_construct_node(__node, _GLIBCXX_FORWARD(_Arg, __arg));
502 return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg));
512 _Base_ptr __node = _M_nodes;
513 _M_nodes = _M_nodes->_M_parent;
516 if (_M_nodes->_M_right == __node)
518 _M_nodes->_M_right = 0;
520 if (_M_nodes->_M_left)
522 _M_nodes = _M_nodes->_M_left;
524 while (_M_nodes->_M_right)
525 _M_nodes = _M_nodes->_M_right;
527 if (_M_nodes->_M_left)
528 _M_nodes = _M_nodes->_M_left;
532 _M_nodes->_M_left = 0;
549 _Alloc_node(_Rb_tree& __t)
552 template<
typename _Arg>
554 #if __cplusplus < 201103L 555 operator()(
const _Arg& __arg)
const 557 operator()(_Arg&& __arg)
const 559 {
return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg)); }
566 typedef _Key key_type;
567 typedef _Val value_type;
568 typedef value_type* pointer;
569 typedef const value_type* const_pointer;
570 typedef value_type& reference;
571 typedef const value_type& const_reference;
572 typedef size_t size_type;
573 typedef ptrdiff_t difference_type;
574 typedef _Alloc allocator_type;
577 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
578 {
return this->_M_impl; }
580 const _Node_allocator&
581 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
582 {
return this->_M_impl; }
585 get_allocator() const _GLIBCXX_NOEXCEPT
586 {
return allocator_type(_M_get_Node_allocator()); }
594 _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
597 #if __cplusplus < 201103L 599 _M_construct_node(_Link_type __node,
const value_type& __x)
602 { get_allocator().construct(__node->_M_valptr(), __x); }
606 __throw_exception_again;
611 _M_create_node(
const value_type& __x)
613 _Link_type __tmp = _M_get_node();
614 _M_construct_node(__tmp, __x);
618 template<
typename... _Args>
620 _M_construct_node(_Link_type __node, _Args&&... __args)
624 ::new(__node) _Rb_tree_node<_Val>;
625 _Alloc_traits::construct(_M_get_Node_allocator(),
627 std::forward<_Args>(__args)...);
631 __node->~_Rb_tree_node<_Val>();
633 __throw_exception_again;
637 template<
typename... _Args>
639 _M_create_node(_Args&&... __args)
641 _Link_type __tmp = _M_get_node();
642 _M_construct_node(__tmp, std::forward<_Args>(__args)...);
648 _M_destroy_node(_Link_type __p) _GLIBCXX_NOEXCEPT
650 #if __cplusplus < 201103L 651 get_allocator().destroy(__p->_M_valptr());
653 _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr());
654 __p->~_Rb_tree_node<_Val>();
659 _M_drop_node(_Link_type __p) _GLIBCXX_NOEXCEPT
661 _M_destroy_node(__p);
665 template<
typename _NodeGen>
667 _M_clone_node(_Const_Link_type __x, _NodeGen& __node_gen)
669 _Link_type __tmp = __node_gen(*__x->_M_valptr());
670 __tmp->_M_color = __x->_M_color;
677 #if _GLIBCXX_INLINE_VERSION 678 template<
typename _Key_compare>
681 template<
typename _Key_compare,
682 bool = __is_pod(_Key_compare)>
685 :
public _Node_allocator
686 ,
public _Rb_tree_key_compare<_Key_compare>
687 ,
public _Rb_tree_header
689 typedef _Rb_tree_key_compare<_Key_compare> _Base_key_compare;
692 _GLIBCXX_NOEXCEPT_IF(
693 is_nothrow_default_constructible<_Node_allocator>::value
694 && is_nothrow_default_constructible<_Base_key_compare>::value )
698 _Rb_tree_impl(
const _Rb_tree_impl& __x)
699 : _Node_allocator(_Alloc_traits::_S_select_on_copy(__x))
700 , _Base_key_compare(__x._M_key_compare)
703 #if __cplusplus < 201103L 704 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
705 : _Node_allocator(__a), _Base_key_compare(__comp)
708 _Rb_tree_impl(_Rb_tree_impl&&) =
default;
711 _Rb_tree_impl(_Node_allocator&& __a)
712 : _Node_allocator(
std::move(__a))
715 _Rb_tree_impl(_Rb_tree_impl&& __x, _Node_allocator&& __a)
716 : _Node_allocator(
std::move(__a)),
717 _Base_key_compare(
std::move(__x)),
718 _Rb_tree_header(
std::move(__x))
721 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
722 : _Node_allocator(
std::move(__a)), _Base_key_compare(__comp)
727 _Rb_tree_impl<_Compare> _M_impl;
731 _M_root() _GLIBCXX_NOEXCEPT
732 {
return this->_M_impl._M_header._M_parent; }
735 _M_root() const _GLIBCXX_NOEXCEPT
736 {
return this->_M_impl._M_header._M_parent; }
739 _M_leftmost() _GLIBCXX_NOEXCEPT
740 {
return this->_M_impl._M_header._M_left; }
743 _M_leftmost() const _GLIBCXX_NOEXCEPT
744 {
return this->_M_impl._M_header._M_left; }
747 _M_rightmost() _GLIBCXX_NOEXCEPT
748 {
return this->_M_impl._M_header._M_right; }
751 _M_rightmost() const _GLIBCXX_NOEXCEPT
752 {
return this->_M_impl._M_header._M_right; }
755 _M_begin() _GLIBCXX_NOEXCEPT
756 {
return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); }
759 _M_begin() const _GLIBCXX_NOEXCEPT
761 return static_cast<_Const_Link_type>
762 (this->_M_impl._M_header._M_parent);
766 _M_end() _GLIBCXX_NOEXCEPT
767 {
return &this->_M_impl._M_header; }
770 _M_end() const _GLIBCXX_NOEXCEPT
771 {
return &this->_M_impl._M_header; }
773 static const_reference
774 _S_value(_Const_Link_type __x)
775 {
return *__x->_M_valptr(); }
778 _S_key(_Const_Link_type __x)
779 {
return _KeyOfValue()(_S_value(__x)); }
782 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
783 {
return static_cast<_Link_type>(__x->_M_left); }
785 static _Const_Link_type
786 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
787 {
return static_cast<_Const_Link_type>(__x->_M_left); }
790 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
791 {
return static_cast<_Link_type>(__x->_M_right); }
793 static _Const_Link_type
794 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
795 {
return static_cast<_Const_Link_type>(__x->_M_right); }
797 static const_reference
798 _S_value(_Const_Base_ptr __x)
799 {
return *static_cast<_Const_Link_type>(__x)->_M_valptr(); }
802 _S_key(_Const_Base_ptr __x)
803 {
return _KeyOfValue()(_S_value(__x)); }
806 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
807 {
return _Rb_tree_node_base::_S_minimum(__x); }
809 static _Const_Base_ptr
810 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
811 {
return _Rb_tree_node_base::_S_minimum(__x); }
814 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
815 {
return _Rb_tree_node_base::_S_maximum(__x); }
817 static _Const_Base_ptr
818 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
819 {
return _Rb_tree_node_base::_S_maximum(__x); }
822 typedef _Rb_tree_iterator<value_type> iterator;
823 typedef _Rb_tree_const_iterator<value_type> const_iterator;
828 #if __cplusplus > 201402L 829 using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
830 using insert_return_type = _Node_insert_return<
831 conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
835 pair<_Base_ptr, _Base_ptr>
836 _M_get_insert_unique_pos(
const key_type& __k);
838 pair<_Base_ptr, _Base_ptr>
839 _M_get_insert_equal_pos(
const key_type& __k);
841 pair<_Base_ptr, _Base_ptr>
842 _M_get_insert_hint_unique_pos(const_iterator __pos,
843 const key_type& __k);
845 pair<_Base_ptr, _Base_ptr>
846 _M_get_insert_hint_equal_pos(const_iterator __pos,
847 const key_type& __k);
850 #if __cplusplus >= 201103L 851 template<
typename _Arg,
typename _NodeGen>
853 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
856 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
858 template<
typename _Arg>
860 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
862 template<
typename _Arg>
864 _M_insert_equal_lower(_Arg&& __x);
867 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
870 _M_insert_equal_lower_node(_Link_type __z);
872 template<
typename _NodeGen>
874 _M_insert_(_Base_ptr __x, _Base_ptr __y,
875 const value_type& __v, _NodeGen&);
880 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
883 _M_insert_equal_lower(
const value_type& __x);
886 template<
typename _NodeGen>
888 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen&);
890 template<
typename _NodeGen>
892 _M_copy(
const _Rb_tree& __x, _NodeGen& __gen)
894 _Link_type __root = _M_copy(__x._M_begin(), _M_end(), __gen);
895 _M_leftmost() = _S_minimum(__root);
896 _M_rightmost() = _S_maximum(__root);
897 _M_impl._M_node_count = __x._M_impl._M_node_count;
902 _M_copy(
const _Rb_tree& __x)
904 _Alloc_node __an(*
this);
905 return _M_copy(__x, __an);
909 _M_erase(_Link_type __x);
912 _M_lower_bound(_Link_type __x, _Base_ptr __y,
916 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
917 const _Key& __k)
const;
920 _M_upper_bound(_Link_type __x, _Base_ptr __y,
924 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
925 const _Key& __k)
const;
929 #if __cplusplus < 201103L 932 _Rb_tree() =
default;
935 _Rb_tree(
const _Compare& __comp,
936 const allocator_type& __a = allocator_type())
937 : _M_impl(__comp, _Node_allocator(__a)) { }
939 _Rb_tree(
const _Rb_tree& __x)
940 : _M_impl(__x._M_impl)
942 if (__x._M_root() != 0)
943 _M_root() = _M_copy(__x);
946 #if __cplusplus >= 201103L 947 _Rb_tree(
const allocator_type& __a)
948 : _M_impl(_Node_allocator(__a))
951 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
952 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
954 if (__x._M_root() !=
nullptr)
955 _M_root() = _M_copy(__x);
958 _Rb_tree(_Rb_tree&&) =
default;
960 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
961 : _Rb_tree(
std::move(__x), _Node_allocator(__a))
965 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
true_type)
966 noexcept(is_nothrow_default_constructible<_Compare>::value)
967 : _M_impl(
std::move(__x._M_impl),
std::move(__a))
970 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
false_type)
971 : _M_impl(__x._M_impl._M_key_compare,
std::move(__a))
973 if (__x._M_root() !=
nullptr)
978 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
980 _Rb_tree(std::declval<_Rb_tree&&>(), std::declval<_Node_allocator&&>(),
981 std::declval<typename _Alloc_traits::is_always_equal>())) )
982 : _Rb_tree(
std::move(__x),
std::move(__a),
983 typename _Alloc_traits::is_always_equal{})
987 ~_Rb_tree() _GLIBCXX_NOEXCEPT
988 { _M_erase(_M_begin()); }
991 operator=(
const _Rb_tree& __x);
996 {
return _M_impl._M_key_compare; }
999 begin() _GLIBCXX_NOEXCEPT
1000 {
return iterator(this->_M_impl._M_header._M_left); }
1003 begin() const _GLIBCXX_NOEXCEPT
1004 {
return const_iterator(this->_M_impl._M_header._M_left); }
1007 end() _GLIBCXX_NOEXCEPT
1008 {
return iterator(&this->_M_impl._M_header); }
1011 end() const _GLIBCXX_NOEXCEPT
1012 {
return const_iterator(&this->_M_impl._M_header); }
1015 rbegin() _GLIBCXX_NOEXCEPT
1016 {
return reverse_iterator(
end()); }
1018 const_reverse_iterator
1019 rbegin() const _GLIBCXX_NOEXCEPT
1020 {
return const_reverse_iterator(
end()); }
1023 rend() _GLIBCXX_NOEXCEPT
1024 {
return reverse_iterator(
begin()); }
1026 const_reverse_iterator
1027 rend() const _GLIBCXX_NOEXCEPT
1028 {
return const_reverse_iterator(
begin()); }
1030 _GLIBCXX_NODISCARD
bool 1031 empty() const _GLIBCXX_NOEXCEPT
1032 {
return _M_impl._M_node_count == 0; }
1035 size() const _GLIBCXX_NOEXCEPT
1036 {
return _M_impl._M_node_count; }
1039 max_size() const _GLIBCXX_NOEXCEPT
1044 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value);
1047 #if __cplusplus >= 201103L 1048 template<
typename _Arg>
1049 pair<iterator, bool>
1050 _M_insert_unique(_Arg&& __x);
1052 template<
typename _Arg>
1054 _M_insert_equal(_Arg&& __x);
1056 template<
typename _Arg,
typename _NodeGen>
1058 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1060 template<
typename _Arg>
1062 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
1064 _Alloc_node __an(*
this);
1065 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
1068 template<
typename _Arg,
typename _NodeGen>
1070 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1072 template<
typename _Arg>
1074 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
1076 _Alloc_node __an(*
this);
1077 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
1080 template<
typename... _Args>
1081 pair<iterator, bool>
1082 _M_emplace_unique(_Args&&... __args);
1084 template<
typename... _Args>
1086 _M_emplace_equal(_Args&&... __args);
1088 template<
typename... _Args>
1090 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
1092 template<
typename... _Args>
1094 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
1096 template<
typename _Iter>
1097 using __same_value_type
1098 = is_same<value_type, typename iterator_traits<_Iter>::value_type>;
1100 template<
typename _InputIterator>
1101 __enable_if_t<__same_value_type<_InputIterator>::value>
1102 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1104 _Alloc_node __an(*
this);
1105 for (; __first != __last; ++__first)
1106 _M_insert_unique_(
end(), *__first, __an);
1109 template<
typename _InputIterator>
1110 __enable_if_t<!__same_value_type<_InputIterator>::value>
1111 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1113 for (; __first != __last; ++__first)
1114 _M_emplace_unique(*__first);
1117 template<
typename _InputIterator>
1118 __enable_if_t<__same_value_type<_InputIterator>::value>
1119 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1121 _Alloc_node __an(*
this);
1122 for (; __first != __last; ++__first)
1123 _M_insert_equal_(
end(), *__first, __an);
1126 template<
typename _InputIterator>
1127 __enable_if_t<!__same_value_type<_InputIterator>::value>
1128 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1130 _Alloc_node __an(*
this);
1131 for (; __first != __last; ++__first)
1132 _M_emplace_equal(*__first);
1135 pair<iterator, bool>
1136 _M_insert_unique(
const value_type& __x);
1139 _M_insert_equal(
const value_type& __x);
1141 template<
typename _NodeGen>
1143 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
1147 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
1149 _Alloc_node __an(*
this);
1150 return _M_insert_unique_(__pos, __x, __an);
1153 template<
typename _NodeGen>
1155 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1158 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1160 _Alloc_node __an(*
this);
1161 return _M_insert_equal_(__pos, __x, __an);
1164 template<
typename _InputIterator>
1166 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1168 _Alloc_node __an(*
this);
1169 for (; __first != __last; ++__first)
1170 _M_insert_unique_(
end(), *__first, __an);
1173 template<
typename _InputIterator>
1175 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1177 _Alloc_node __an(*
this);
1178 for (; __first != __last; ++__first)
1179 _M_insert_equal_(
end(), *__first, __an);
1185 _M_erase_aux(const_iterator __position);
1188 _M_erase_aux(const_iterator __first, const_iterator __last);
1191 #if __cplusplus >= 201103L 1194 _GLIBCXX_ABI_TAG_CXX11
1196 erase(const_iterator __position)
1198 __glibcxx_assert(__position !=
end());
1199 const_iterator __result = __position;
1201 _M_erase_aux(__position);
1202 return __result._M_const_cast();
1206 _GLIBCXX_ABI_TAG_CXX11
1208 erase(iterator __position)
1210 __glibcxx_assert(__position !=
end());
1211 iterator __result = __position;
1213 _M_erase_aux(__position);
1218 erase(iterator __position)
1220 __glibcxx_assert(__position !=
end());
1221 _M_erase_aux(__position);
1225 erase(const_iterator __position)
1227 __glibcxx_assert(__position !=
end());
1228 _M_erase_aux(__position);
1232 erase(
const key_type& __x);
1234 #if __cplusplus >= 201103L 1237 _GLIBCXX_ABI_TAG_CXX11
1239 erase(const_iterator __first, const_iterator __last)
1241 _M_erase_aux(__first, __last);
1242 return __last._M_const_cast();
1246 erase(iterator __first, iterator __last)
1247 { _M_erase_aux(__first, __last); }
1250 erase(const_iterator __first, const_iterator __last)
1251 { _M_erase_aux(__first, __last); }
1254 erase(
const key_type* __first,
const key_type* __last);
1257 clear() _GLIBCXX_NOEXCEPT
1259 _M_erase(_M_begin());
1265 find(
const key_type& __k);
1268 find(
const key_type& __k)
const;
1271 count(
const key_type& __k)
const;
1274 lower_bound(
const key_type& __k)
1275 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1278 lower_bound(
const key_type& __k)
const 1279 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1282 upper_bound(
const key_type& __k)
1283 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1286 upper_bound(
const key_type& __k)
const 1287 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1289 pair<iterator, iterator>
1290 equal_range(
const key_type& __k);
1292 pair<const_iterator, const_iterator>
1293 equal_range(
const key_type& __k)
const;
1295 #if __cplusplus >= 201402L 1296 template<
typename _Kt,
1297 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1299 _M_find_tr(
const _Kt& __k)
1301 const _Rb_tree* __const_this =
this;
1302 return __const_this->_M_find_tr(__k)._M_const_cast();
1305 template<
typename _Kt,
1306 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1308 _M_find_tr(
const _Kt& __k)
const 1310 auto __j = _M_lower_bound_tr(__k);
1311 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1316 template<
typename _Kt,
1317 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1319 _M_count_tr(
const _Kt& __k)
const 1321 auto __p = _M_equal_range_tr(__k);
1325 template<
typename _Kt,
1326 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1328 _M_lower_bound_tr(
const _Kt& __k)
1330 const _Rb_tree* __const_this =
this;
1331 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1334 template<
typename _Kt,
1335 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1337 _M_lower_bound_tr(
const _Kt& __k)
const 1339 auto __x = _M_begin();
1340 auto __y = _M_end();
1342 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1348 __x = _S_right(__x);
1349 return const_iterator(__y);
1352 template<
typename _Kt,
1353 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1355 _M_upper_bound_tr(
const _Kt& __k)
1357 const _Rb_tree* __const_this =
this;
1358 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1361 template<
typename _Kt,
1362 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1364 _M_upper_bound_tr(
const _Kt& __k)
const 1366 auto __x = _M_begin();
1367 auto __y = _M_end();
1369 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1375 __x = _S_right(__x);
1376 return const_iterator(__y);
1379 template<
typename _Kt,
1380 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1381 pair<iterator, iterator>
1382 _M_equal_range_tr(
const _Kt& __k)
1384 const _Rb_tree* __const_this =
this;
1385 auto __ret = __const_this->_M_equal_range_tr(__k);
1386 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1389 template<
typename _Kt,
1390 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1391 pair<const_iterator, const_iterator>
1392 _M_equal_range_tr(
const _Kt& __k)
const 1394 auto __low = _M_lower_bound_tr(__k);
1395 auto __high = __low;
1396 auto& __cmp = _M_impl._M_key_compare;
1397 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1399 return { __low, __high };
1405 __rb_verify()
const;
1407 #if __cplusplus >= 201103L 1409 operator=(_Rb_tree&&)
1410 noexcept(_Alloc_traits::_S_nothrow_move()
1411 && is_nothrow_move_assignable<_Compare>::value);
1413 template<typename _Iterator>
1415 _M_assign_unique(_Iterator, _Iterator);
1417 template<typename _Iterator>
1419 _M_assign_equal(_Iterator, _Iterator);
1425 { _M_impl._M_move_data(__x._M_impl); }
1442 #if __cplusplus > 201402L 1446 _M_reinsert_node_unique(node_type&& __nh)
1448 insert_return_type __ret;
1450 __ret.position =
end();
1453 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1455 auto __res = _M_get_insert_unique_pos(__nh._M_key());
1459 = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1460 __nh._M_ptr =
nullptr;
1461 __ret.inserted =
true;
1465 __ret.node = std::move(__nh);
1466 __ret.position = iterator(__res.first);
1467 __ret.inserted =
false;
1475 _M_reinsert_node_equal(node_type&& __nh)
1482 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1483 auto __res = _M_get_insert_equal_pos(__nh._M_key());
1485 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1487 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1488 __nh._M_ptr =
nullptr;
1495 _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh)
1502 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1503 auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key());
1506 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1507 __nh._M_ptr =
nullptr;
1510 __ret = iterator(__res.first);
1517 _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh)
1524 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1525 auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key());
1527 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1529 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1530 __nh._M_ptr =
nullptr;
1537 extract(const_iterator __pos)
1539 auto __ptr = _Rb_tree_rebalance_for_erase(
1540 __pos._M_const_cast()._M_node, _M_impl._M_header);
1541 --_M_impl._M_node_count;
1542 return { static_cast<_Link_type>(__ptr), _M_get_Node_allocator() };
1547 extract(
const key_type& __k)
1550 auto __pos = find(__k);
1552 __nh = extract(const_iterator(__pos));
1556 template<
typename _Compare2>
1557 using _Compatible_tree
1558 = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>;
1560 template<
typename,
typename>
1561 friend class _Rb_tree_merge_helper;
1564 template<
typename _Compare2>
1566 _M_merge_unique(_Compatible_tree<_Compare2>& __src) noexcept
1568 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1569 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1572 auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos));
1575 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1576 auto __ptr = _Rb_tree_rebalance_for_erase(
1577 __pos._M_node, __src_impl._M_header);
1578 --__src_impl._M_node_count;
1579 _M_insert_node(__res.first, __res.second,
1580 static_cast<_Link_type>(__ptr));
1586 template<
typename _Compare2>
1588 _M_merge_equal(_Compatible_tree<_Compare2>& __src) noexcept
1590 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1591 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1594 auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos));
1597 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1598 auto __ptr = _Rb_tree_rebalance_for_erase(
1599 __pos._M_node, __src_impl._M_header);
1600 --__src_impl._M_node_count;
1601 _M_insert_node(__res.first, __res.second,
1602 static_cast<_Link_type>(__ptr));
1609 operator==(
const _Rb_tree& __x,
const _Rb_tree& __y)
1611 return __x.size() == __y.size()
1612 &&
std::equal(__x.begin(), __x.end(), __y.begin());
1616 operator<(
const _Rb_tree& __x,
const _Rb_tree& __y)
1619 __y.begin(), __y.end());
1622 friend bool _GLIBCXX_DEPRECATED
1623 operator!=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1624 {
return !(__x == __y); }
1626 friend bool _GLIBCXX_DEPRECATED
1627 operator>(
const _Rb_tree& __x,
const _Rb_tree& __y)
1628 {
return __y < __x; }
1630 friend bool _GLIBCXX_DEPRECATED
1631 operator<=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1632 {
return !(__y < __x); }
1634 friend bool _GLIBCXX_DEPRECATED
1635 operator>=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1636 {
return !(__x < __y); }
1639 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1640 typename _Compare,
typename _Alloc>
1642 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1643 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1646 #if __cplusplus >= 201103L 1647 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1648 typename _Compare,
typename _Alloc>
1650 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1653 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1657 _Alloc_node __an(*
this);
1659 [&__an](
const value_type& __cval)
1661 auto& __val = const_cast<value_type&>(__cval);
1664 _M_root() = _M_copy(__x, __lbd);
1668 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1669 typename _Compare,
typename _Alloc>
1671 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1672 _M_move_assign(_Rb_tree& __x,
true_type)
1675 if (__x._M_root() !=
nullptr)
1677 std::__alloc_on_move(_M_get_Node_allocator(),
1678 __x._M_get_Node_allocator());
1681 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1682 typename _Compare,
typename _Alloc>
1684 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1687 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1688 return _M_move_assign(__x,
true_type{});
1692 _Reuse_or_alloc_node __roan(*
this);
1694 if (__x._M_root() !=
nullptr)
1697 [&__roan](
const value_type& __cval)
1699 auto& __val = const_cast<value_type&>(__cval);
1702 _M_root() = _M_copy(__x, __lbd);
1707 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1708 typename _Compare,
typename _Alloc>
1709 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1710 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1711 operator=(_Rb_tree&& __x)
1712 noexcept(_Alloc_traits::_S_nothrow_move()
1713 && is_nothrow_move_assignable<_Compare>::value)
1715 _M_impl._M_key_compare = std::move(__x._M_impl._M_key_compare);
1716 _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>());
1720 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1721 typename _Compare,
typename _Alloc>
1722 template<
typename _Iterator>
1724 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1725 _M_assign_unique(_Iterator __first, _Iterator __last)
1727 _Reuse_or_alloc_node __roan(*
this);
1729 for (; __first != __last; ++__first)
1730 _M_insert_unique_(
end(), *__first, __roan);
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_equal(_Iterator __first, _Iterator __last)
1740 _Reuse_or_alloc_node __roan(*
this);
1742 for (; __first != __last; ++__first)
1743 _M_insert_equal_(
end(), *__first, __roan);
1747 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1748 typename _Compare,
typename _Alloc>
1749 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1750 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1751 operator=(
const _Rb_tree& __x)
1756 #if __cplusplus >= 201103L 1757 if (_Alloc_traits::_S_propagate_on_copy_assign())
1759 auto& __this_alloc = this->_M_get_Node_allocator();
1760 auto& __that_alloc = __x._M_get_Node_allocator();
1761 if (!_Alloc_traits::_S_always_equal()
1762 && __this_alloc != __that_alloc)
1767 std::__alloc_on_copy(__this_alloc, __that_alloc);
1772 _Reuse_or_alloc_node __roan(*
this);
1774 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1775 if (__x._M_root() != 0)
1776 _M_root() = _M_copy(__x, __roan);
1782 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1783 typename _Compare,
typename _Alloc>
1784 #if __cplusplus >= 201103L 1785 template<
typename _Arg,
typename _NodeGen>
1787 template<
typename _NodeGen>
1789 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1790 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1791 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1792 #
if __cplusplus >= 201103L
1797 _NodeGen& __node_gen)
1799 bool __insert_left = (__x != 0 || __p == _M_end()
1800 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1803 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1805 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1806 this->_M_impl._M_header);
1807 ++_M_impl._M_node_count;
1808 return iterator(__z);
1811 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1812 typename _Compare,
typename _Alloc>
1813 #if __cplusplus >= 201103L 1814 template<
typename _Arg>
1816 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1817 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1818 #if __cplusplus >= 201103L 1819 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1821 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1824 bool __insert_left = (__p == _M_end()
1825 || !_M_impl._M_key_compare(_S_key(__p),
1826 _KeyOfValue()(__v)));
1828 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1830 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1831 this->_M_impl._M_header);
1832 ++_M_impl._M_node_count;
1833 return iterator(__z);
1836 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1837 typename _Compare,
typename _Alloc>
1838 #if __cplusplus >= 201103L 1839 template<
typename _Arg>
1841 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1842 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1843 #if __cplusplus >= 201103L 1844 _M_insert_equal_lower(_Arg&& __v)
1846 _M_insert_equal_lower(
const _Val& __v)
1849 _Link_type __x = _M_begin();
1850 _Base_ptr __y = _M_end();
1854 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1855 _S_left(__x) : _S_right(__x);
1857 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1860 template<
typename _Key,
typename _Val,
typename _KoV,
1861 typename _Compare,
typename _Alloc>
1862 template<
typename _NodeGen>
1863 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1864 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1865 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1868 _Link_type __top = _M_clone_node(__x, __node_gen);
1869 __top->_M_parent = __p;
1874 __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen);
1880 _Link_type __y = _M_clone_node(__x, __node_gen);
1882 __y->_M_parent = __p;
1884 __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen);
1892 __throw_exception_again;
1897 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1898 typename _Compare,
typename _Alloc>
1900 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1901 _M_erase(_Link_type __x)
1906 _M_erase(_S_right(__x));
1907 _Link_type __y = _S_left(__x);
1913 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1914 typename _Compare,
typename _Alloc>
1915 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1916 _Compare, _Alloc>::iterator
1917 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1918 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1922 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1923 __y = __x, __x = _S_left(__x);
1925 __x = _S_right(__x);
1926 return iterator(__y);
1929 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1930 typename _Compare,
typename _Alloc>
1931 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1932 _Compare, _Alloc>::const_iterator
1933 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1934 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1935 const _Key& __k)
const 1938 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1939 __y = __x, __x = _S_left(__x);
1941 __x = _S_right(__x);
1942 return const_iterator(__y);
1945 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1946 typename _Compare,
typename _Alloc>
1947 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1948 _Compare, _Alloc>::iterator
1949 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1950 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1954 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1955 __y = __x, __x = _S_left(__x);
1957 __x = _S_right(__x);
1958 return iterator(__y);
1961 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1962 typename _Compare,
typename _Alloc>
1963 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1964 _Compare, _Alloc>::const_iterator
1965 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1966 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1967 const _Key& __k)
const 1970 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1971 __y = __x, __x = _S_left(__x);
1973 __x = _S_right(__x);
1974 return const_iterator(__y);
1977 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1978 typename _Compare,
typename _Alloc>
1979 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1980 _Compare, _Alloc>::iterator,
1981 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1982 _Compare, _Alloc>::iterator>
1983 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1984 equal_range(
const _Key& __k)
1986 _Link_type __x = _M_begin();
1987 _Base_ptr __y = _M_end();
1990 if (_M_impl._M_key_compare(_S_key(__x), __k))
1991 __x = _S_right(__x);
1992 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1993 __y = __x, __x = _S_left(__x);
1996 _Link_type __xu(__x);
1997 _Base_ptr __yu(__y);
1998 __y = __x, __x = _S_left(__x);
1999 __xu = _S_right(__xu);
2000 return pair<iterator,
2001 iterator>(_M_lower_bound(__x, __y, __k),
2002 _M_upper_bound(__xu, __yu, __k));
2005 return pair<iterator, iterator>(iterator(__y),
2009 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2010 typename _Compare,
typename _Alloc>
2011 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2012 _Compare, _Alloc>::const_iterator,
2013 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2014 _Compare, _Alloc>::const_iterator>
2015 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2016 equal_range(
const _Key& __k)
const 2018 _Const_Link_type __x = _M_begin();
2019 _Const_Base_ptr __y = _M_end();
2022 if (_M_impl._M_key_compare(_S_key(__x), __k))
2023 __x = _S_right(__x);
2024 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2025 __y = __x, __x = _S_left(__x);
2028 _Const_Link_type __xu(__x);
2029 _Const_Base_ptr __yu(__y);
2030 __y = __x, __x = _S_left(__x);
2031 __xu = _S_right(__xu);
2032 return pair<const_iterator,
2033 const_iterator>(_M_lower_bound(__x, __y, __k),
2034 _M_upper_bound(__xu, __yu, __k));
2037 return pair<const_iterator, const_iterator>(const_iterator(__y),
2038 const_iterator(__y));
2041 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2042 typename _Compare,
typename _Alloc>
2044 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2046 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
2050 if (__t._M_root() != 0)
2051 _M_impl._M_move_data(__t._M_impl);
2053 else if (__t._M_root() == 0)
2054 __t._M_impl._M_move_data(_M_impl);
2057 std::swap(_M_root(),__t._M_root());
2058 std::swap(_M_leftmost(),__t._M_leftmost());
2059 std::swap(_M_rightmost(),__t._M_rightmost());
2061 _M_root()->_M_parent = _M_end();
2062 __t._M_root()->_M_parent = __t._M_end();
2063 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
2066 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
2068 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
2069 __t._M_get_Node_allocator());
2072 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2073 typename _Compare,
typename _Alloc>
2074 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2075 _Compare, _Alloc>::_Base_ptr,
2076 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2077 _Compare, _Alloc>::_Base_ptr>
2078 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2079 _M_get_insert_unique_pos(
const key_type& __k)
2081 typedef pair<_Base_ptr, _Base_ptr> _Res;
2082 _Link_type __x = _M_begin();
2083 _Base_ptr __y = _M_end();
2088 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
2089 __x = __comp ? _S_left(__x) : _S_right(__x);
2091 iterator __j = iterator(__y);
2095 return _Res(__x, __y);
2099 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
2100 return _Res(__x, __y);
2101 return _Res(__j._M_node, 0);
2104 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2105 typename _Compare,
typename _Alloc>
2106 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2107 _Compare, _Alloc>::_Base_ptr,
2108 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2109 _Compare, _Alloc>::_Base_ptr>
2110 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2111 _M_get_insert_equal_pos(
const key_type& __k)
2113 typedef pair<_Base_ptr, _Base_ptr> _Res;
2114 _Link_type __x = _M_begin();
2115 _Base_ptr __y = _M_end();
2119 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
2120 _S_left(__x) : _S_right(__x);
2122 return _Res(__x, __y);
2125 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2126 typename _Compare,
typename _Alloc>
2127 #if __cplusplus >= 201103L 2128 template<
typename _Arg>
2130 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2131 _Compare, _Alloc>::iterator,
bool>
2132 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2133 #if __cplusplus >= 201103L 2134 _M_insert_unique(_Arg&& __v)
2136 _M_insert_unique(
const _Val& __v)
2139 typedef pair<iterator, bool> _Res;
2140 pair<_Base_ptr, _Base_ptr> __res
2141 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
2145 _Alloc_node __an(*
this);
2146 return _Res(_M_insert_(__res.first, __res.second,
2147 _GLIBCXX_FORWARD(_Arg, __v), __an),
2151 return _Res(iterator(__res.first),
false);
2154 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2155 typename _Compare,
typename _Alloc>
2156 #if __cplusplus >= 201103L 2157 template<
typename _Arg>
2159 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2160 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2161 #if __cplusplus >= 201103L 2162 _M_insert_equal(_Arg&& __v)
2164 _M_insert_equal(
const _Val& __v)
2167 pair<_Base_ptr, _Base_ptr> __res
2168 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
2169 _Alloc_node __an(*
this);
2170 return _M_insert_(__res.first, __res.second,
2171 _GLIBCXX_FORWARD(_Arg, __v), __an);
2174 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2175 typename _Compare,
typename _Alloc>
2176 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2177 _Compare, _Alloc>::_Base_ptr,
2178 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2179 _Compare, _Alloc>::_Base_ptr>
2180 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2181 _M_get_insert_hint_unique_pos(const_iterator __position,
2182 const key_type& __k)
2184 iterator __pos = __position._M_const_cast();
2185 typedef pair<_Base_ptr, _Base_ptr> _Res;
2188 if (__pos._M_node == _M_end())
2191 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
2192 return _Res(0, _M_rightmost());
2194 return _M_get_insert_unique_pos(__k);
2196 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
2199 iterator __before = __pos;
2200 if (__pos._M_node == _M_leftmost())
2201 return _Res(_M_leftmost(), _M_leftmost());
2202 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
2204 if (_S_right(__before._M_node) == 0)
2205 return _Res(0, __before._M_node);
2207 return _Res(__pos._M_node, __pos._M_node);
2210 return _M_get_insert_unique_pos(__k);
2212 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2215 iterator __after = __pos;
2216 if (__pos._M_node == _M_rightmost())
2217 return _Res(0, _M_rightmost());
2218 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
2220 if (_S_right(__pos._M_node) == 0)
2221 return _Res(0, __pos._M_node);
2223 return _Res(__after._M_node, __after._M_node);
2226 return _M_get_insert_unique_pos(__k);
2230 return _Res(__pos._M_node, 0);
2233 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2234 typename _Compare,
typename _Alloc>
2235 #if __cplusplus >= 201103L 2236 template<
typename _Arg,
typename _NodeGen>
2238 template<
typename _NodeGen>
2240 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2241 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2242 _M_insert_unique_(const_iterator __position,
2243 #
if __cplusplus >= 201103L
2248 _NodeGen& __node_gen)
2250 pair<_Base_ptr, _Base_ptr> __res
2251 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2254 return _M_insert_(__res.first, __res.second,
2255 _GLIBCXX_FORWARD(_Arg, __v),
2257 return iterator(__res.first);
2260 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2261 typename _Compare,
typename _Alloc>
2262 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2263 _Compare, _Alloc>::_Base_ptr,
2264 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2265 _Compare, _Alloc>::_Base_ptr>
2266 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2267 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2269 iterator __pos = __position._M_const_cast();
2270 typedef pair<_Base_ptr, _Base_ptr> _Res;
2273 if (__pos._M_node == _M_end())
2276 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2277 return _Res(0, _M_rightmost());
2279 return _M_get_insert_equal_pos(__k);
2281 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2284 iterator __before = __pos;
2285 if (__pos._M_node == _M_leftmost())
2286 return _Res(_M_leftmost(), _M_leftmost());
2287 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2289 if (_S_right(__before._M_node) == 0)
2290 return _Res(0, __before._M_node);
2292 return _Res(__pos._M_node, __pos._M_node);
2295 return _M_get_insert_equal_pos(__k);
2300 iterator __after = __pos;
2301 if (__pos._M_node == _M_rightmost())
2302 return _Res(0, _M_rightmost());
2303 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2305 if (_S_right(__pos._M_node) == 0)
2306 return _Res(0, __pos._M_node);
2308 return _Res(__after._M_node, __after._M_node);
2315 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2316 typename _Compare,
typename _Alloc>
2317 #if __cplusplus >= 201103L 2318 template<
typename _Arg,
typename _NodeGen>
2320 template<
typename _NodeGen>
2322 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2323 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2324 _M_insert_equal_(const_iterator __position,
2325 #
if __cplusplus >= 201103L
2330 _NodeGen& __node_gen)
2332 pair<_Base_ptr, _Base_ptr> __res
2333 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2336 return _M_insert_(__res.first, __res.second,
2337 _GLIBCXX_FORWARD(_Arg, __v),
2340 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2343 #if __cplusplus >= 201103L 2344 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2345 typename _Compare,
typename _Alloc>
2346 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2347 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2348 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2350 bool __insert_left = (__x != 0 || __p == _M_end()
2351 || _M_impl._M_key_compare(_S_key(__z),
2354 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2355 this->_M_impl._M_header);
2356 ++_M_impl._M_node_count;
2357 return iterator(__z);
2360 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2361 typename _Compare,
typename _Alloc>
2362 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2363 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2364 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2366 bool __insert_left = (__p == _M_end()
2367 || !_M_impl._M_key_compare(_S_key(__p),
2370 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2371 this->_M_impl._M_header);
2372 ++_M_impl._M_node_count;
2373 return iterator(__z);
2376 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2377 typename _Compare,
typename _Alloc>
2378 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2379 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2380 _M_insert_equal_lower_node(_Link_type __z)
2382 _Link_type __x = _M_begin();
2383 _Base_ptr __y = _M_end();
2387 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2388 _S_left(__x) : _S_right(__x);
2390 return _M_insert_lower_node(__y, __z);
2393 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2394 typename _Compare,
typename _Alloc>
2395 template<
typename... _Args>
2396 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2397 _Compare, _Alloc>::iterator,
bool>
2398 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2399 _M_emplace_unique(_Args&&... __args)
2401 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2405 typedef pair<iterator, bool> _Res;
2406 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2408 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2411 return _Res(iterator(__res.first),
false);
2416 __throw_exception_again;
2420 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2421 typename _Compare,
typename _Alloc>
2422 template<
typename... _Args>
2423 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2424 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2425 _M_emplace_equal(_Args&&... __args)
2427 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2431 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2432 return _M_insert_node(__res.first, __res.second, __z);
2437 __throw_exception_again;
2441 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2442 typename _Compare,
typename _Alloc>
2443 template<
typename... _Args>
2444 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2445 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2446 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2448 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2452 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2455 return _M_insert_node(__res.first, __res.second, __z);
2458 return iterator(__res.first);
2463 __throw_exception_again;
2467 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2468 typename _Compare,
typename _Alloc>
2469 template<
typename... _Args>
2470 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2471 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2472 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2474 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2478 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2481 return _M_insert_node(__res.first, __res.second, __z);
2483 return _M_insert_equal_lower_node(__z);
2488 __throw_exception_again;
2494 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2495 typename _Compare,
typename _Alloc>
2497 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2498 _M_erase_aux(const_iterator __position)
2501 static_cast<_Link_type>(_Rb_tree_rebalance_for_erase
2502 (const_cast<_Base_ptr>(__position._M_node),
2503 this->_M_impl._M_header));
2505 --_M_impl._M_node_count;
2508 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2509 typename _Compare,
typename _Alloc>
2511 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2512 _M_erase_aux(const_iterator __first, const_iterator __last)
2514 if (__first ==
begin() && __last ==
end())
2517 while (__first != __last)
2518 _M_erase_aux(__first++);
2521 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2522 typename _Compare,
typename _Alloc>
2523 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2524 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2525 erase(
const _Key& __x)
2527 pair<iterator, iterator> __p = equal_range(__x);
2528 const size_type __old_size = size();
2529 _M_erase_aux(__p.first, __p.second);
2530 return __old_size - size();
2533 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2534 typename _Compare,
typename _Alloc>
2536 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2537 erase(
const _Key* __first,
const _Key* __last)
2539 while (__first != __last)
2543 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2544 typename _Compare,
typename _Alloc>
2545 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2546 _Compare, _Alloc>::iterator
2547 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2548 find(
const _Key& __k)
2550 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2551 return (__j ==
end()
2552 || _M_impl._M_key_compare(__k,
2553 _S_key(__j._M_node))) ?
end() : __j;
2556 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2557 typename _Compare,
typename _Alloc>
2558 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2559 _Compare, _Alloc>::const_iterator
2560 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2561 find(
const _Key& __k)
const 2563 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2564 return (__j ==
end()
2565 || _M_impl._M_key_compare(__k,
2566 _S_key(__j._M_node))) ?
end() : __j;
2569 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2570 typename _Compare,
typename _Alloc>
2571 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2572 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2573 count(
const _Key& __k)
const 2575 pair<const_iterator, const_iterator> __p = equal_range(__k);
2580 _GLIBCXX_PURE
unsigned int 2581 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2582 const _Rb_tree_node_base* __root)
throw ();
2584 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2585 typename _Compare,
typename _Alloc>
2587 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const 2589 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2590 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2591 && this->_M_impl._M_header._M_left == _M_end()
2592 && this->_M_impl._M_header._M_right == _M_end();
2594 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2595 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2597 _Const_Link_type __x = static_cast<_Const_Link_type>(__it._M_node);
2598 _Const_Link_type __L = _S_left(__x);
2599 _Const_Link_type __R = _S_right(__x);
2601 if (__x->_M_color == _S_red)
2602 if ((__L && __L->_M_color == _S_red)
2603 || (__R && __R->_M_color == _S_red))
2606 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2608 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2611 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2615 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2617 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2622 #if __cplusplus > 201402L 2624 template<
typename _Key,
typename _Val,
typename _Sel,
typename _Cmp1,
2625 typename _Alloc,
typename _Cmp2>
2626 struct _Rb_tree_merge_helper<_Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>,
2630 friend class _Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>;
2633 _S_get_impl(_Rb_tree<_Key, _Val, _Sel, _Cmp2, _Alloc>& __tree)
2634 {
return __tree._M_impl; }
2638 _GLIBCXX_END_NAMESPACE_VERSION
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
static _GLIBCXX_NODISCARD pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
ISO C++ entities toplevel namespace is std.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
_GLIBCXX20_CONSTEXPR 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.
_GLIBCXX17_CONSTEXPR auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
Uniform interface to C++98 and C++11 allocators.
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.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.