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)
766 #if __cplusplus >= 201103L 769 static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
770 "comparison object must be invocable " 771 "with two arguments of key type");
772 # if __cplusplus >= 201703L 775 if constexpr (__is_invocable<_Compare&, const _Key&, const _Key&>{})
777 is_invocable_v<const _Compare&, const _Key&, const _Key&>,
778 "comparison object must be invocable as const");
782 return _KeyOfValue()(*__x->_M_valptr());
786 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
787 {
return static_cast<_Link_type>(__x->_M_left); }
789 static _Const_Link_type
790 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
791 {
return static_cast<_Const_Link_type>(__x->_M_left); }
794 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
795 {
return static_cast<_Link_type>(__x->_M_right); }
797 static _Const_Link_type
798 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
799 {
return static_cast<_Const_Link_type>(__x->_M_right); }
801 static const_reference
802 _S_value(_Const_Base_ptr __x)
803 {
return *static_cast<_Const_Link_type>(__x)->_M_valptr(); }
806 _S_key(_Const_Base_ptr __x)
807 {
return _S_key(static_cast<_Const_Link_type>(__x)); }
810 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
811 {
return _Rb_tree_node_base::_S_minimum(__x); }
813 static _Const_Base_ptr
814 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
815 {
return _Rb_tree_node_base::_S_minimum(__x); }
818 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
819 {
return _Rb_tree_node_base::_S_maximum(__x); }
821 static _Const_Base_ptr
822 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
823 {
return _Rb_tree_node_base::_S_maximum(__x); }
826 typedef _Rb_tree_iterator<value_type> iterator;
827 typedef _Rb_tree_const_iterator<value_type> const_iterator;
832 #if __cplusplus > 201402L 833 using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
834 using insert_return_type = _Node_insert_return<
835 conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
839 pair<_Base_ptr, _Base_ptr>
840 _M_get_insert_unique_pos(
const key_type& __k);
842 pair<_Base_ptr, _Base_ptr>
843 _M_get_insert_equal_pos(
const key_type& __k);
845 pair<_Base_ptr, _Base_ptr>
846 _M_get_insert_hint_unique_pos(const_iterator __pos,
847 const key_type& __k);
849 pair<_Base_ptr, _Base_ptr>
850 _M_get_insert_hint_equal_pos(const_iterator __pos,
851 const key_type& __k);
854 #if __cplusplus >= 201103L 855 template<
typename _Arg,
typename _NodeGen>
857 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
860 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
862 template<
typename _Arg>
864 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
866 template<
typename _Arg>
868 _M_insert_equal_lower(_Arg&& __x);
871 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
874 _M_insert_equal_lower_node(_Link_type __z);
876 template<
typename _NodeGen>
878 _M_insert_(_Base_ptr __x, _Base_ptr __y,
879 const value_type& __v, _NodeGen&);
884 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
887 _M_insert_equal_lower(
const value_type& __x);
890 template<
typename _NodeGen>
892 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen&);
894 template<
typename _NodeGen>
896 _M_copy(
const _Rb_tree& __x, _NodeGen& __gen)
898 _Link_type __root = _M_copy(__x._M_begin(), _M_end(), __gen);
899 _M_leftmost() = _S_minimum(__root);
900 _M_rightmost() = _S_maximum(__root);
901 _M_impl._M_node_count = __x._M_impl._M_node_count;
906 _M_copy(
const _Rb_tree& __x)
908 _Alloc_node __an(*
this);
909 return _M_copy(__x, __an);
913 _M_erase(_Link_type __x);
916 _M_lower_bound(_Link_type __x, _Base_ptr __y,
920 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
921 const _Key& __k)
const;
924 _M_upper_bound(_Link_type __x, _Base_ptr __y,
928 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
929 const _Key& __k)
const;
933 #if __cplusplus < 201103L 936 _Rb_tree() =
default;
939 _Rb_tree(
const _Compare& __comp,
940 const allocator_type& __a = allocator_type())
941 : _M_impl(__comp, _Node_allocator(__a)) { }
943 _Rb_tree(
const _Rb_tree& __x)
944 : _M_impl(__x._M_impl)
946 if (__x._M_root() != 0)
947 _M_root() = _M_copy(__x);
950 #if __cplusplus >= 201103L 951 _Rb_tree(
const allocator_type& __a)
952 : _M_impl(_Compare(), _Node_allocator(__a))
955 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
956 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
958 if (__x._M_root() !=
nullptr)
959 _M_root() = _M_copy(__x);
962 _Rb_tree(_Rb_tree&&) =
default;
964 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
965 : _Rb_tree(
std::move(__x), _Node_allocator(__a))
968 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a);
971 ~_Rb_tree() _GLIBCXX_NOEXCEPT
972 { _M_erase(_M_begin()); }
975 operator=(
const _Rb_tree& __x);
980 {
return _M_impl._M_key_compare; }
983 begin() _GLIBCXX_NOEXCEPT
984 {
return iterator(this->_M_impl._M_header._M_left); }
987 begin() const _GLIBCXX_NOEXCEPT
988 {
return const_iterator(this->_M_impl._M_header._M_left); }
991 end() _GLIBCXX_NOEXCEPT
992 {
return iterator(&this->_M_impl._M_header); }
995 end() const _GLIBCXX_NOEXCEPT
996 {
return const_iterator(&this->_M_impl._M_header); }
999 rbegin() _GLIBCXX_NOEXCEPT
1000 {
return reverse_iterator(
end()); }
1002 const_reverse_iterator
1003 rbegin() const _GLIBCXX_NOEXCEPT
1004 {
return const_reverse_iterator(
end()); }
1007 rend() _GLIBCXX_NOEXCEPT
1008 {
return reverse_iterator(
begin()); }
1010 const_reverse_iterator
1011 rend() const _GLIBCXX_NOEXCEPT
1012 {
return const_reverse_iterator(
begin()); }
1015 empty() const _GLIBCXX_NOEXCEPT
1016 {
return _M_impl._M_node_count == 0; }
1019 size() const _GLIBCXX_NOEXCEPT
1020 {
return _M_impl._M_node_count; }
1023 max_size() const _GLIBCXX_NOEXCEPT
1028 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value);
1031 #if __cplusplus >= 201103L 1032 template<
typename _Arg>
1033 pair<iterator, bool>
1034 _M_insert_unique(_Arg&& __x);
1036 template<
typename _Arg>
1038 _M_insert_equal(_Arg&& __x);
1040 template<
typename _Arg,
typename _NodeGen>
1042 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1044 template<
typename _Arg>
1046 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
1048 _Alloc_node __an(*
this);
1049 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
1052 template<
typename _Arg,
typename _NodeGen>
1054 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1056 template<
typename _Arg>
1058 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
1060 _Alloc_node __an(*
this);
1061 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
1064 template<
typename... _Args>
1065 pair<iterator, bool>
1066 _M_emplace_unique(_Args&&... __args);
1068 template<
typename... _Args>
1070 _M_emplace_equal(_Args&&... __args);
1072 template<
typename... _Args>
1074 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
1076 template<
typename... _Args>
1078 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
1080 pair<iterator, bool>
1081 _M_insert_unique(
const value_type& __x);
1084 _M_insert_equal(
const value_type& __x);
1086 template<
typename _NodeGen>
1088 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
1092 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
1094 _Alloc_node __an(*
this);
1095 return _M_insert_unique_(__pos, __x, __an);
1098 template<
typename _NodeGen>
1100 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1103 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1105 _Alloc_node __an(*
this);
1106 return _M_insert_equal_(__pos, __x, __an);
1110 template<
typename _InputIterator>
1112 _M_insert_unique(_InputIterator __first, _InputIterator __last);
1114 template<
typename _InputIterator>
1116 _M_insert_equal(_InputIterator __first, _InputIterator __last);
1120 _M_erase_aux(const_iterator __position);
1123 _M_erase_aux(const_iterator __first, const_iterator __last);
1126 #if __cplusplus >= 201103L 1129 _GLIBCXX_ABI_TAG_CXX11
1131 erase(const_iterator __position)
1133 __glibcxx_assert(__position !=
end());
1134 const_iterator __result = __position;
1136 _M_erase_aux(__position);
1137 return __result._M_const_cast();
1141 _GLIBCXX_ABI_TAG_CXX11
1143 erase(iterator __position)
1145 __glibcxx_assert(__position !=
end());
1146 iterator __result = __position;
1148 _M_erase_aux(__position);
1153 erase(iterator __position)
1155 __glibcxx_assert(__position !=
end());
1156 _M_erase_aux(__position);
1160 erase(const_iterator __position)
1162 __glibcxx_assert(__position !=
end());
1163 _M_erase_aux(__position);
1167 erase(
const key_type& __x);
1169 #if __cplusplus >= 201103L 1172 _GLIBCXX_ABI_TAG_CXX11
1174 erase(const_iterator __first, const_iterator __last)
1176 _M_erase_aux(__first, __last);
1177 return __last._M_const_cast();
1181 erase(iterator __first, iterator __last)
1182 { _M_erase_aux(__first, __last); }
1185 erase(const_iterator __first, const_iterator __last)
1186 { _M_erase_aux(__first, __last); }
1189 erase(
const key_type* __first,
const key_type* __last);
1192 clear() _GLIBCXX_NOEXCEPT
1194 _M_erase(_M_begin());
1200 find(
const key_type& __k);
1203 find(
const key_type& __k)
const;
1206 count(
const key_type& __k)
const;
1209 lower_bound(
const key_type& __k)
1210 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1213 lower_bound(
const key_type& __k)
const 1214 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1217 upper_bound(
const key_type& __k)
1218 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1221 upper_bound(
const key_type& __k)
const 1222 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1224 pair<iterator, iterator>
1225 equal_range(
const key_type& __k);
1227 pair<const_iterator, const_iterator>
1228 equal_range(
const key_type& __k)
const;
1230 #if __cplusplus > 201103L 1231 template<
typename _Kt,
1233 typename __has_is_transparent<_Compare, _Kt>::type>
1235 _M_find_tr(
const _Kt& __k)
1237 const _Rb_tree* __const_this =
this;
1238 return __const_this->_M_find_tr(__k)._M_const_cast();
1241 template<
typename _Kt,
1243 typename __has_is_transparent<_Compare, _Kt>::type>
1245 _M_find_tr(
const _Kt& __k)
const 1247 auto __j = _M_lower_bound_tr(__k);
1248 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1253 template<
typename _Kt,
1255 typename __has_is_transparent<_Compare, _Kt>::type>
1257 _M_count_tr(
const _Kt& __k)
const 1259 auto __p = _M_equal_range_tr(__k);
1263 template<
typename _Kt,
1265 typename __has_is_transparent<_Compare, _Kt>::type>
1267 _M_lower_bound_tr(
const _Kt& __k)
1269 const _Rb_tree* __const_this =
this;
1270 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1273 template<
typename _Kt,
1275 typename __has_is_transparent<_Compare, _Kt>::type>
1277 _M_lower_bound_tr(
const _Kt& __k)
const 1279 auto __x = _M_begin();
1280 auto __y = _M_end();
1282 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1288 __x = _S_right(__x);
1289 return const_iterator(__y);
1292 template<
typename _Kt,
1294 typename __has_is_transparent<_Compare, _Kt>::type>
1296 _M_upper_bound_tr(
const _Kt& __k)
1298 const _Rb_tree* __const_this =
this;
1299 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1302 template<
typename _Kt,
1304 typename __has_is_transparent<_Compare, _Kt>::type>
1306 _M_upper_bound_tr(
const _Kt& __k)
const 1308 auto __x = _M_begin();
1309 auto __y = _M_end();
1311 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1317 __x = _S_right(__x);
1318 return const_iterator(__y);
1321 template<
typename _Kt,
1323 typename __has_is_transparent<_Compare, _Kt>::type>
1324 pair<iterator, iterator>
1325 _M_equal_range_tr(
const _Kt& __k)
1327 const _Rb_tree* __const_this =
this;
1328 auto __ret = __const_this->_M_equal_range_tr(__k);
1329 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1332 template<
typename _Kt,
1334 typename __has_is_transparent<_Compare, _Kt>::type>
1335 pair<const_iterator, const_iterator>
1336 _M_equal_range_tr(
const _Kt& __k)
const 1338 auto __low = _M_lower_bound_tr(__k);
1339 auto __high = __low;
1340 auto& __cmp = _M_impl._M_key_compare;
1341 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1343 return { __low, __high };
1349 __rb_verify()
const;
1351 #if __cplusplus >= 201103L 1353 operator=(_Rb_tree&&)
1354 noexcept(_Alloc_traits::_S_nothrow_move()
1355 && is_nothrow_move_assignable<_Compare>::value);
1357 template<typename _Iterator>
1359 _M_assign_unique(_Iterator, _Iterator);
1361 template<typename _Iterator>
1363 _M_assign_equal(_Iterator, _Iterator);
1369 { _M_impl._M_move_data(__x._M_impl); }
1386 #if __cplusplus > 201402L 1390 _M_reinsert_node_unique(node_type&& __nh)
1392 insert_return_type __ret;
1394 __ret.position =
end();
1397 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1399 auto __res = _M_get_insert_unique_pos(__nh._M_key());
1403 = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1404 __nh._M_ptr =
nullptr;
1405 __ret.inserted =
true;
1409 __ret.node = std::move(__nh);
1410 __ret.position = iterator(__res.first);
1411 __ret.inserted =
false;
1419 _M_reinsert_node_equal(node_type&& __nh)
1426 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1427 auto __res = _M_get_insert_equal_pos(__nh._M_key());
1429 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1431 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1432 __nh._M_ptr =
nullptr;
1439 _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh)
1446 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1447 auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key());
1450 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1451 __nh._M_ptr =
nullptr;
1454 __ret = iterator(__res.first);
1461 _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh)
1468 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1469 auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key());
1471 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1473 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1474 __nh._M_ptr =
nullptr;
1481 extract(const_iterator __pos)
1483 auto __ptr = _Rb_tree_rebalance_for_erase(
1484 __pos._M_const_cast()._M_node, _M_impl._M_header);
1485 --_M_impl._M_node_count;
1486 return { static_cast<_Link_type>(__ptr), _M_get_Node_allocator() };
1491 extract(
const key_type& __k)
1494 auto __pos = find(__k);
1496 __nh = extract(const_iterator(__pos));
1500 template<
typename _Compare2>
1501 using _Compatible_tree
1502 = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>;
1504 template<
typename,
typename>
1505 friend class _Rb_tree_merge_helper;
1508 template<
typename _Compare2>
1510 _M_merge_unique(_Compatible_tree<_Compare2>& __src) noexcept
1512 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1513 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1516 auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos));
1519 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1520 auto __ptr = _Rb_tree_rebalance_for_erase(
1521 __pos._M_node, __src_impl._M_header);
1522 --__src_impl._M_node_count;
1523 _M_insert_node(__res.first, __res.second,
1524 static_cast<_Link_type>(__ptr));
1530 template<
typename _Compare2>
1532 _M_merge_equal(_Compatible_tree<_Compare2>& __src) noexcept
1534 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1535 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1538 auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos));
1541 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1542 auto __ptr = _Rb_tree_rebalance_for_erase(
1543 __pos._M_node, __src_impl._M_header);
1544 --__src_impl._M_node_count;
1545 _M_insert_node(__res.first, __res.second,
1546 static_cast<_Link_type>(__ptr));
1553 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1554 typename _Compare,
typename _Alloc>
1556 operator==(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1557 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1559 return __x.size() == __y.size()
1560 &&
std::equal(__x.begin(), __x.end(), __y.begin());
1563 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1564 typename _Compare,
typename _Alloc>
1566 operator<(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1567 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1570 __y.begin(), __y.end());
1573 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1574 typename _Compare,
typename _Alloc>
1576 operator!=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1577 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1578 {
return !(__x == __y); }
1580 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1581 typename _Compare,
typename _Alloc>
1583 operator>(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1584 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1585 {
return __y < __x; }
1587 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1588 typename _Compare,
typename _Alloc>
1590 operator<=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1591 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1592 {
return !(__y < __x); }
1594 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1595 typename _Compare,
typename _Alloc>
1597 operator>=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1598 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1599 {
return !(__x < __y); }
1601 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1602 typename _Compare,
typename _Alloc>
1604 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1605 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1608 #if __cplusplus >= 201103L 1609 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1610 typename _Compare,
typename _Alloc>
1611 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1612 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
1613 : _M_impl(__x._M_impl._M_key_compare,
std::move(__a))
1615 using __eq =
typename _Alloc_traits::is_always_equal;
1616 if (__x._M_root() !=
nullptr)
1617 _M_move_data(__x, __eq());
1620 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1621 typename _Compare,
typename _Alloc>
1623 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1626 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1630 _Alloc_node __an(*
this);
1632 [&__an](
const value_type& __cval)
1634 auto& __val = const_cast<value_type&>(__cval);
1637 _M_root() = _M_copy(__x, __lbd);
1641 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1642 typename _Compare,
typename _Alloc>
1644 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1645 _M_move_assign(_Rb_tree& __x,
true_type)
1648 if (__x._M_root() !=
nullptr)
1650 std::__alloc_on_move(_M_get_Node_allocator(),
1651 __x._M_get_Node_allocator());
1654 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1655 typename _Compare,
typename _Alloc>
1657 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1660 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1661 return _M_move_assign(__x,
true_type{});
1665 _Reuse_or_alloc_node __roan(*
this);
1667 if (__x._M_root() !=
nullptr)
1670 [&__roan](
const value_type& __cval)
1672 auto& __val = const_cast<value_type&>(__cval);
1675 _M_root() = _M_copy(__x, __lbd);
1680 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1681 typename _Compare,
typename _Alloc>
1682 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1683 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1684 operator=(_Rb_tree&& __x)
1685 noexcept(_Alloc_traits::_S_nothrow_move()
1686 && is_nothrow_move_assignable<_Compare>::value)
1688 _M_impl._M_key_compare = std::move(__x._M_impl._M_key_compare);
1689 _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>());
1693 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1694 typename _Compare,
typename _Alloc>
1695 template<
typename _Iterator>
1697 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1698 _M_assign_unique(_Iterator __first, _Iterator __last)
1700 _Reuse_or_alloc_node __roan(*
this);
1702 for (; __first != __last; ++__first)
1703 _M_insert_unique_(
end(), *__first, __roan);
1706 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1707 typename _Compare,
typename _Alloc>
1708 template<
typename _Iterator>
1710 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1711 _M_assign_equal(_Iterator __first, _Iterator __last)
1713 _Reuse_or_alloc_node __roan(*
this);
1715 for (; __first != __last; ++__first)
1716 _M_insert_equal_(
end(), *__first, __roan);
1720 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1721 typename _Compare,
typename _Alloc>
1722 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1723 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1724 operator=(
const _Rb_tree& __x)
1729 #if __cplusplus >= 201103L 1730 if (_Alloc_traits::_S_propagate_on_copy_assign())
1732 auto& __this_alloc = this->_M_get_Node_allocator();
1733 auto& __that_alloc = __x._M_get_Node_allocator();
1734 if (!_Alloc_traits::_S_always_equal()
1735 && __this_alloc != __that_alloc)
1740 std::__alloc_on_copy(__this_alloc, __that_alloc);
1745 _Reuse_or_alloc_node __roan(*
this);
1747 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1748 if (__x._M_root() != 0)
1749 _M_root() = _M_copy(__x, __roan);
1755 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1756 typename _Compare,
typename _Alloc>
1757 #if __cplusplus >= 201103L 1758 template<
typename _Arg,
typename _NodeGen>
1760 template<
typename _NodeGen>
1762 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1763 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1764 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1765 #
if __cplusplus >= 201103L
1770 _NodeGen& __node_gen)
1772 bool __insert_left = (__x != 0 || __p == _M_end()
1773 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1776 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1778 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1779 this->_M_impl._M_header);
1780 ++_M_impl._M_node_count;
1781 return iterator(__z);
1784 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1785 typename _Compare,
typename _Alloc>
1786 #if __cplusplus >= 201103L 1787 template<
typename _Arg>
1789 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1790 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1791 #if __cplusplus >= 201103L 1792 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1794 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1797 bool __insert_left = (__p == _M_end()
1798 || !_M_impl._M_key_compare(_S_key(__p),
1799 _KeyOfValue()(__v)));
1801 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1803 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1804 this->_M_impl._M_header);
1805 ++_M_impl._M_node_count;
1806 return iterator(__z);
1809 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1810 typename _Compare,
typename _Alloc>
1811 #if __cplusplus >= 201103L 1812 template<
typename _Arg>
1814 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1815 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1816 #if __cplusplus >= 201103L 1817 _M_insert_equal_lower(_Arg&& __v)
1819 _M_insert_equal_lower(
const _Val& __v)
1822 _Link_type __x = _M_begin();
1823 _Base_ptr __y = _M_end();
1827 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1828 _S_left(__x) : _S_right(__x);
1830 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1833 template<
typename _Key,
typename _Val,
typename _KoV,
1834 typename _Compare,
typename _Alloc>
1835 template<
typename _NodeGen>
1836 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1837 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1838 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1841 _Link_type __top = _M_clone_node(__x, __node_gen);
1842 __top->_M_parent = __p;
1847 __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen);
1853 _Link_type __y = _M_clone_node(__x, __node_gen);
1855 __y->_M_parent = __p;
1857 __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen);
1865 __throw_exception_again;
1870 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1871 typename _Compare,
typename _Alloc>
1873 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1874 _M_erase(_Link_type __x)
1879 _M_erase(_S_right(__x));
1880 _Link_type __y = _S_left(__x);
1886 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1887 typename _Compare,
typename _Alloc>
1888 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1889 _Compare, _Alloc>::iterator
1890 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1891 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1895 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1896 __y = __x, __x = _S_left(__x);
1898 __x = _S_right(__x);
1899 return iterator(__y);
1902 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1903 typename _Compare,
typename _Alloc>
1904 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1905 _Compare, _Alloc>::const_iterator
1906 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1907 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1908 const _Key& __k)
const 1911 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1912 __y = __x, __x = _S_left(__x);
1914 __x = _S_right(__x);
1915 return const_iterator(__y);
1918 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1919 typename _Compare,
typename _Alloc>
1920 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1921 _Compare, _Alloc>::iterator
1922 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1923 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1927 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1928 __y = __x, __x = _S_left(__x);
1930 __x = _S_right(__x);
1931 return iterator(__y);
1934 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1935 typename _Compare,
typename _Alloc>
1936 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1937 _Compare, _Alloc>::const_iterator
1938 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1939 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1940 const _Key& __k)
const 1943 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1944 __y = __x, __x = _S_left(__x);
1946 __x = _S_right(__x);
1947 return const_iterator(__y);
1950 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1951 typename _Compare,
typename _Alloc>
1952 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1953 _Compare, _Alloc>::iterator,
1954 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1955 _Compare, _Alloc>::iterator>
1956 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1957 equal_range(
const _Key& __k)
1959 _Link_type __x = _M_begin();
1960 _Base_ptr __y = _M_end();
1963 if (_M_impl._M_key_compare(_S_key(__x), __k))
1964 __x = _S_right(__x);
1965 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1966 __y = __x, __x = _S_left(__x);
1969 _Link_type __xu(__x);
1970 _Base_ptr __yu(__y);
1971 __y = __x, __x = _S_left(__x);
1972 __xu = _S_right(__xu);
1973 return pair<iterator,
1974 iterator>(_M_lower_bound(__x, __y, __k),
1975 _M_upper_bound(__xu, __yu, __k));
1978 return pair<iterator, iterator>(iterator(__y),
1982 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1983 typename _Compare,
typename _Alloc>
1984 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1985 _Compare, _Alloc>::const_iterator,
1986 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1987 _Compare, _Alloc>::const_iterator>
1988 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1989 equal_range(
const _Key& __k)
const 1991 _Const_Link_type __x = _M_begin();
1992 _Const_Base_ptr __y = _M_end();
1995 if (_M_impl._M_key_compare(_S_key(__x), __k))
1996 __x = _S_right(__x);
1997 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1998 __y = __x, __x = _S_left(__x);
2001 _Const_Link_type __xu(__x);
2002 _Const_Base_ptr __yu(__y);
2003 __y = __x, __x = _S_left(__x);
2004 __xu = _S_right(__xu);
2005 return pair<const_iterator,
2006 const_iterator>(_M_lower_bound(__x, __y, __k),
2007 _M_upper_bound(__xu, __yu, __k));
2010 return pair<const_iterator, const_iterator>(const_iterator(__y),
2011 const_iterator(__y));
2014 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2015 typename _Compare,
typename _Alloc>
2017 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2019 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
2023 if (__t._M_root() != 0)
2024 _M_impl._M_move_data(__t._M_impl);
2026 else if (__t._M_root() == 0)
2027 __t._M_impl._M_move_data(_M_impl);
2030 std::swap(_M_root(),__t._M_root());
2031 std::swap(_M_leftmost(),__t._M_leftmost());
2032 std::swap(_M_rightmost(),__t._M_rightmost());
2034 _M_root()->_M_parent = _M_end();
2035 __t._M_root()->_M_parent = __t._M_end();
2036 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
2039 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
2041 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
2042 __t._M_get_Node_allocator());
2045 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2046 typename _Compare,
typename _Alloc>
2047 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2048 _Compare, _Alloc>::_Base_ptr,
2049 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2050 _Compare, _Alloc>::_Base_ptr>
2051 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2052 _M_get_insert_unique_pos(
const key_type& __k)
2054 typedef pair<_Base_ptr, _Base_ptr> _Res;
2055 _Link_type __x = _M_begin();
2056 _Base_ptr __y = _M_end();
2061 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
2062 __x = __comp ? _S_left(__x) : _S_right(__x);
2064 iterator __j = iterator(__y);
2068 return _Res(__x, __y);
2072 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
2073 return _Res(__x, __y);
2074 return _Res(__j._M_node, 0);
2077 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2078 typename _Compare,
typename _Alloc>
2079 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2080 _Compare, _Alloc>::_Base_ptr,
2081 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2082 _Compare, _Alloc>::_Base_ptr>
2083 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2084 _M_get_insert_equal_pos(
const key_type& __k)
2086 typedef pair<_Base_ptr, _Base_ptr> _Res;
2087 _Link_type __x = _M_begin();
2088 _Base_ptr __y = _M_end();
2092 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
2093 _S_left(__x) : _S_right(__x);
2095 return _Res(__x, __y);
2098 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2099 typename _Compare,
typename _Alloc>
2100 #if __cplusplus >= 201103L 2101 template<
typename _Arg>
2103 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2104 _Compare, _Alloc>::iterator,
bool>
2105 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2106 #if __cplusplus >= 201103L 2107 _M_insert_unique(_Arg&& __v)
2109 _M_insert_unique(
const _Val& __v)
2112 typedef pair<iterator, bool> _Res;
2113 pair<_Base_ptr, _Base_ptr> __res
2114 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
2118 _Alloc_node __an(*
this);
2119 return _Res(_M_insert_(__res.first, __res.second,
2120 _GLIBCXX_FORWARD(_Arg, __v), __an),
2124 return _Res(iterator(__res.first),
false);
2127 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2128 typename _Compare,
typename _Alloc>
2129 #if __cplusplus >= 201103L 2130 template<
typename _Arg>
2132 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2133 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2134 #if __cplusplus >= 201103L 2135 _M_insert_equal(_Arg&& __v)
2137 _M_insert_equal(
const _Val& __v)
2140 pair<_Base_ptr, _Base_ptr> __res
2141 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
2142 _Alloc_node __an(*
this);
2143 return _M_insert_(__res.first, __res.second,
2144 _GLIBCXX_FORWARD(_Arg, __v), __an);
2147 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2148 typename _Compare,
typename _Alloc>
2149 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2150 _Compare, _Alloc>::_Base_ptr,
2151 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2152 _Compare, _Alloc>::_Base_ptr>
2153 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2154 _M_get_insert_hint_unique_pos(const_iterator __position,
2155 const key_type& __k)
2157 iterator __pos = __position._M_const_cast();
2158 typedef pair<_Base_ptr, _Base_ptr> _Res;
2161 if (__pos._M_node == _M_end())
2164 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
2165 return _Res(0, _M_rightmost());
2167 return _M_get_insert_unique_pos(__k);
2169 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
2172 iterator __before = __pos;
2173 if (__pos._M_node == _M_leftmost())
2174 return _Res(_M_leftmost(), _M_leftmost());
2175 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
2177 if (_S_right(__before._M_node) == 0)
2178 return _Res(0, __before._M_node);
2180 return _Res(__pos._M_node, __pos._M_node);
2183 return _M_get_insert_unique_pos(__k);
2185 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2188 iterator __after = __pos;
2189 if (__pos._M_node == _M_rightmost())
2190 return _Res(0, _M_rightmost());
2191 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
2193 if (_S_right(__pos._M_node) == 0)
2194 return _Res(0, __pos._M_node);
2196 return _Res(__after._M_node, __after._M_node);
2199 return _M_get_insert_unique_pos(__k);
2203 return _Res(__pos._M_node, 0);
2206 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2207 typename _Compare,
typename _Alloc>
2208 #if __cplusplus >= 201103L 2209 template<
typename _Arg,
typename _NodeGen>
2211 template<
typename _NodeGen>
2213 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2214 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2215 _M_insert_unique_(const_iterator __position,
2216 #
if __cplusplus >= 201103L
2221 _NodeGen& __node_gen)
2223 pair<_Base_ptr, _Base_ptr> __res
2224 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2227 return _M_insert_(__res.first, __res.second,
2228 _GLIBCXX_FORWARD(_Arg, __v),
2230 return iterator(__res.first);
2233 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2234 typename _Compare,
typename _Alloc>
2235 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2236 _Compare, _Alloc>::_Base_ptr,
2237 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2238 _Compare, _Alloc>::_Base_ptr>
2239 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2240 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2242 iterator __pos = __position._M_const_cast();
2243 typedef pair<_Base_ptr, _Base_ptr> _Res;
2246 if (__pos._M_node == _M_end())
2249 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2250 return _Res(0, _M_rightmost());
2252 return _M_get_insert_equal_pos(__k);
2254 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2257 iterator __before = __pos;
2258 if (__pos._M_node == _M_leftmost())
2259 return _Res(_M_leftmost(), _M_leftmost());
2260 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2262 if (_S_right(__before._M_node) == 0)
2263 return _Res(0, __before._M_node);
2265 return _Res(__pos._M_node, __pos._M_node);
2268 return _M_get_insert_equal_pos(__k);
2273 iterator __after = __pos;
2274 if (__pos._M_node == _M_rightmost())
2275 return _Res(0, _M_rightmost());
2276 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2278 if (_S_right(__pos._M_node) == 0)
2279 return _Res(0, __pos._M_node);
2281 return _Res(__after._M_node, __after._M_node);
2288 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2289 typename _Compare,
typename _Alloc>
2290 #if __cplusplus >= 201103L 2291 template<
typename _Arg,
typename _NodeGen>
2293 template<
typename _NodeGen>
2295 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2296 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2297 _M_insert_equal_(const_iterator __position,
2298 #
if __cplusplus >= 201103L
2303 _NodeGen& __node_gen)
2305 pair<_Base_ptr, _Base_ptr> __res
2306 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2309 return _M_insert_(__res.first, __res.second,
2310 _GLIBCXX_FORWARD(_Arg, __v),
2313 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2316 #if __cplusplus >= 201103L 2317 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2318 typename _Compare,
typename _Alloc>
2319 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2320 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2321 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2323 bool __insert_left = (__x != 0 || __p == _M_end()
2324 || _M_impl._M_key_compare(_S_key(__z),
2327 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2328 this->_M_impl._M_header);
2329 ++_M_impl._M_node_count;
2330 return iterator(__z);
2333 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2334 typename _Compare,
typename _Alloc>
2335 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2336 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2337 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2339 bool __insert_left = (__p == _M_end()
2340 || !_M_impl._M_key_compare(_S_key(__p),
2343 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2344 this->_M_impl._M_header);
2345 ++_M_impl._M_node_count;
2346 return iterator(__z);
2349 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2350 typename _Compare,
typename _Alloc>
2351 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2352 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2353 _M_insert_equal_lower_node(_Link_type __z)
2355 _Link_type __x = _M_begin();
2356 _Base_ptr __y = _M_end();
2360 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2361 _S_left(__x) : _S_right(__x);
2363 return _M_insert_lower_node(__y, __z);
2366 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2367 typename _Compare,
typename _Alloc>
2368 template<
typename... _Args>
2369 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2370 _Compare, _Alloc>::iterator,
bool>
2371 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2372 _M_emplace_unique(_Args&&... __args)
2374 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2378 typedef pair<iterator, bool> _Res;
2379 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2381 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2384 return _Res(iterator(__res.first),
false);
2389 __throw_exception_again;
2393 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2394 typename _Compare,
typename _Alloc>
2395 template<
typename... _Args>
2396 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2397 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2398 _M_emplace_equal(_Args&&... __args)
2400 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2404 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2405 return _M_insert_node(__res.first, __res.second, __z);
2410 __throw_exception_again;
2414 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2415 typename _Compare,
typename _Alloc>
2416 template<
typename... _Args>
2417 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2418 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2419 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2421 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2425 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2428 return _M_insert_node(__res.first, __res.second, __z);
2431 return iterator(__res.first);
2436 __throw_exception_again;
2440 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2441 typename _Compare,
typename _Alloc>
2442 template<
typename... _Args>
2443 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2444 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2445 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2447 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2451 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2454 return _M_insert_node(__res.first, __res.second, __z);
2456 return _M_insert_equal_lower_node(__z);
2461 __throw_exception_again;
2466 template<
typename _Key,
typename _Val,
typename _KoV,
2467 typename _Cmp,
typename _Alloc>
2470 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
2471 _M_insert_unique(_II __first, _II __last)
2473 _Alloc_node __an(*
this);
2474 for (; __first != __last; ++__first)
2475 _M_insert_unique_(
end(), *__first, __an);
2478 template<
typename _Key,
typename _Val,
typename _KoV,
2479 typename _Cmp,
typename _Alloc>
2482 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
2483 _M_insert_equal(_II __first, _II __last)
2485 _Alloc_node __an(*
this);
2486 for (; __first != __last; ++__first)
2487 _M_insert_equal_(
end(), *__first, __an);
2490 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2491 typename _Compare,
typename _Alloc>
2493 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2494 _M_erase_aux(const_iterator __position)
2497 static_cast<_Link_type>(_Rb_tree_rebalance_for_erase
2498 (const_cast<_Base_ptr>(__position._M_node),
2499 this->_M_impl._M_header));
2501 --_M_impl._M_node_count;
2504 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2505 typename _Compare,
typename _Alloc>
2507 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2508 _M_erase_aux(const_iterator __first, const_iterator __last)
2510 if (__first ==
begin() && __last ==
end())
2513 while (__first != __last)
2514 _M_erase_aux(__first++);
2517 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2518 typename _Compare,
typename _Alloc>
2519 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2520 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2521 erase(
const _Key& __x)
2523 pair<iterator, iterator> __p = equal_range(__x);
2524 const size_type __old_size = size();
2525 _M_erase_aux(__p.first, __p.second);
2526 return __old_size - size();
2529 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2530 typename _Compare,
typename _Alloc>
2532 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2533 erase(
const _Key* __first,
const _Key* __last)
2535 while (__first != __last)
2539 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2540 typename _Compare,
typename _Alloc>
2541 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2542 _Compare, _Alloc>::iterator
2543 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2544 find(
const _Key& __k)
2546 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2547 return (__j ==
end()
2548 || _M_impl._M_key_compare(__k,
2549 _S_key(__j._M_node))) ?
end() : __j;
2552 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2553 typename _Compare,
typename _Alloc>
2554 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2555 _Compare, _Alloc>::const_iterator
2556 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2557 find(
const _Key& __k)
const 2559 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2560 return (__j ==
end()
2561 || _M_impl._M_key_compare(__k,
2562 _S_key(__j._M_node))) ?
end() : __j;
2565 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2566 typename _Compare,
typename _Alloc>
2567 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2568 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2569 count(
const _Key& __k)
const 2571 pair<const_iterator, const_iterator> __p = equal_range(__k);
2576 _GLIBCXX_PURE
unsigned int 2577 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2578 const _Rb_tree_node_base* __root)
throw ();
2580 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2581 typename _Compare,
typename _Alloc>
2583 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const 2585 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2586 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2587 && this->_M_impl._M_header._M_left == _M_end()
2588 && this->_M_impl._M_header._M_right == _M_end();
2590 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2591 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2593 _Const_Link_type __x = static_cast<_Const_Link_type>(__it._M_node);
2594 _Const_Link_type __L = _S_left(__x);
2595 _Const_Link_type __R = _S_right(__x);
2597 if (__x->_M_color == _S_red)
2598 if ((__L && __L->_M_color == _S_red)
2599 || (__R && __R->_M_color == _S_red))
2602 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2604 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2607 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2611 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2613 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2618 #if __cplusplus > 201402L 2620 template<
typename _Key,
typename _Val,
typename _Sel,
typename _Cmp1,
2621 typename _Alloc,
typename _Cmp2>
2622 struct _Rb_tree_merge_helper<_Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>,
2626 friend class _Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>;
2629 _S_get_impl(_Rb_tree<_Key, _Val, _Sel, _Cmp2, _Alloc>& __tree)
2630 {
return __tree._M_impl; }
2634 _GLIBCXX_END_NAMESPACE_VERSION
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
static pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
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.
ISO C++ entities toplevel namespace is std.
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list.
Uniform interface to C++98 and C++11 allocators.
_GLIBCXX17_CONSTEXPR auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
_GLIBCXX17_CONSTEXPR auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.