61 #pragma GCC system_header 68 #if __cplusplus >= 201103L 72 namespace std _GLIBCXX_VISIBILITY(default)
74 _GLIBCXX_BEGIN_NAMESPACE_VERSION
92 enum _Rb_tree_color { _S_red =
false, _S_black =
true };
94 struct _Rb_tree_node_base
96 typedef _Rb_tree_node_base* _Base_ptr;
97 typedef const _Rb_tree_node_base* _Const_Base_ptr;
99 _Rb_tree_color _M_color;
105 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
107 while (__x->_M_left != 0) __x = __x->_M_left;
111 static _Const_Base_ptr
112 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
114 while (__x->_M_left != 0) __x = __x->_M_left;
119 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
121 while (__x->_M_right != 0) __x = __x->_M_right;
125 static _Const_Base_ptr
126 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
128 while (__x->_M_right != 0) __x = __x->_M_right;
133 template<
typename _Val>
134 struct _Rb_tree_node :
public _Rb_tree_node_base
136 typedef _Rb_tree_node<_Val>* _Link_type;
138 #if __cplusplus < 201103L 149 __gnu_cxx::__aligned_membuf<_Val> _M_storage;
153 {
return _M_storage._M_ptr(); }
157 {
return _M_storage._M_ptr(); }
161 _GLIBCXX_PURE _Rb_tree_node_base*
162 _Rb_tree_increment(_Rb_tree_node_base* __x)
throw ();
164 _GLIBCXX_PURE
const _Rb_tree_node_base*
165 _Rb_tree_increment(
const _Rb_tree_node_base* __x)
throw ();
167 _GLIBCXX_PURE _Rb_tree_node_base*
168 _Rb_tree_decrement(_Rb_tree_node_base* __x)
throw ();
170 _GLIBCXX_PURE
const _Rb_tree_node_base*
171 _Rb_tree_decrement(
const _Rb_tree_node_base* __x)
throw ();
173 template<
typename _Tp>
174 struct _Rb_tree_iterator
176 typedef _Tp value_type;
177 typedef _Tp& reference;
178 typedef _Tp* pointer;
180 typedef bidirectional_iterator_tag iterator_category;
181 typedef ptrdiff_t difference_type;
183 typedef _Rb_tree_iterator<_Tp> _Self;
184 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
185 typedef _Rb_tree_node<_Tp>* _Link_type;
187 _Rb_tree_iterator() _GLIBCXX_NOEXCEPT
191 _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
196 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
199 operator->() const _GLIBCXX_NOEXCEPT
200 {
return static_cast<_Link_type
> (_M_node)->_M_valptr(); }
203 operator++() _GLIBCXX_NOEXCEPT
205 _M_node = _Rb_tree_increment(_M_node);
210 operator++(
int) _GLIBCXX_NOEXCEPT
213 _M_node = _Rb_tree_increment(_M_node);
218 operator--() _GLIBCXX_NOEXCEPT
220 _M_node = _Rb_tree_decrement(_M_node);
225 operator--(
int) _GLIBCXX_NOEXCEPT
228 _M_node = _Rb_tree_decrement(_M_node);
233 operator==(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
234 {
return _M_node == __x._M_node; }
237 operator!=(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
238 {
return _M_node != __x._M_node; }
243 template<
typename _Tp>
244 struct _Rb_tree_const_iterator
246 typedef _Tp value_type;
247 typedef const _Tp& reference;
248 typedef const _Tp* pointer;
250 typedef _Rb_tree_iterator<_Tp> iterator;
252 typedef bidirectional_iterator_tag iterator_category;
253 typedef ptrdiff_t difference_type;
255 typedef _Rb_tree_const_iterator<_Tp> _Self;
256 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
257 typedef const _Rb_tree_node<_Tp>* _Link_type;
259 _Rb_tree_const_iterator() _GLIBCXX_NOEXCEPT
263 _Rb_tree_const_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
266 _Rb_tree_const_iterator(
const iterator& __it) _GLIBCXX_NOEXCEPT
267 : _M_node(__it._M_node) { }
270 _M_const_cast() const _GLIBCXX_NOEXCEPT
271 {
return iterator(const_cast<typename iterator::_Base_ptr>(_M_node)); }
275 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
278 operator->() const _GLIBCXX_NOEXCEPT
279 {
return static_cast<_Link_type
>(_M_node)->_M_valptr(); }
282 operator++() _GLIBCXX_NOEXCEPT
284 _M_node = _Rb_tree_increment(_M_node);
289 operator++(
int) _GLIBCXX_NOEXCEPT
292 _M_node = _Rb_tree_increment(_M_node);
297 operator--() _GLIBCXX_NOEXCEPT
299 _M_node = _Rb_tree_decrement(_M_node);
304 operator--(
int) _GLIBCXX_NOEXCEPT
307 _M_node = _Rb_tree_decrement(_M_node);
312 operator==(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
313 {
return _M_node == __x._M_node; }
316 operator!=(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
317 {
return _M_node != __x._M_node; }
322 template<
typename _Val>
324 operator==(
const _Rb_tree_iterator<_Val>& __x,
325 const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
326 {
return __x._M_node == __y._M_node; }
328 template<
typename _Val>
330 operator!=(
const _Rb_tree_iterator<_Val>& __x,
331 const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
332 {
return __x._M_node != __y._M_node; }
335 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
336 _Rb_tree_node_base* __x,
337 _Rb_tree_node_base* __p,
338 _Rb_tree_node_base& __header)
throw ();
341 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
342 _Rb_tree_node_base& __header)
throw ();
345 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
346 typename _Compare,
typename _Alloc = allocator<_Val> >
350 rebind<_Rb_tree_node<_Val> >::other _Node_allocator;
355 typedef _Rb_tree_node_base* _Base_ptr;
356 typedef const _Rb_tree_node_base* _Const_Base_ptr;
357 typedef _Rb_tree_node<_Val>* _Link_type;
358 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
363 struct _Reuse_or_alloc_node
365 _Reuse_or_alloc_node(_Rb_tree& __t)
366 : _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t)
370 _M_root->_M_parent = 0;
372 if (_M_nodes->_M_left)
373 _M_nodes = _M_nodes->_M_left;
379 #if __cplusplus >= 201103L 380 _Reuse_or_alloc_node(
const _Reuse_or_alloc_node&) =
delete;
383 ~_Reuse_or_alloc_node()
384 { _M_t._M_erase(static_cast<_Link_type>(_M_root)); }
386 template<
typename _Arg>
388 #if __cplusplus < 201103L 389 operator()(
const _Arg& __arg)
391 operator()(_Arg&& __arg)
394 _Link_type __node =
static_cast<_Link_type
>(_M_extract());
397 _M_t._M_destroy_node(__node);
398 _M_t._M_construct_node(__node, _GLIBCXX_FORWARD(_Arg, __arg));
402 return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg));
412 _Base_ptr __node = _M_nodes;
413 _M_nodes = _M_nodes->_M_parent;
416 if (_M_nodes->_M_right == __node)
418 _M_nodes->_M_right = 0;
420 if (_M_nodes->_M_left)
422 _M_nodes = _M_nodes->_M_left;
424 while (_M_nodes->_M_right)
425 _M_nodes = _M_nodes->_M_right;
427 if (_M_nodes->_M_left)
428 _M_nodes = _M_nodes->_M_left;
432 _M_nodes->_M_left = 0;
449 _Alloc_node(_Rb_tree& __t)
452 template<
typename _Arg>
454 #if __cplusplus < 201103L 455 operator()(
const _Arg& __arg)
const 457 operator()(_Arg&& __arg) const
459 {
return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg)); }
466 typedef _Key key_type;
467 typedef _Val value_type;
468 typedef value_type* pointer;
469 typedef const value_type* const_pointer;
470 typedef value_type& reference;
471 typedef const value_type& const_reference;
472 typedef size_t size_type;
473 typedef ptrdiff_t difference_type;
474 typedef _Alloc allocator_type;
477 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
478 {
return *
static_cast<_Node_allocator*
>(&this->_M_impl); }
480 const _Node_allocator&
481 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
482 {
return *
static_cast<const _Node_allocator*
>(&this->_M_impl); }
485 get_allocator() const _GLIBCXX_NOEXCEPT
486 {
return allocator_type(_M_get_Node_allocator()); }
491 {
return _Alloc_traits::allocate(_M_get_Node_allocator(), 1); }
494 _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
495 { _Alloc_traits::deallocate(_M_get_Node_allocator(), __p, 1); }
497 #if __cplusplus < 201103L 499 _M_construct_node(_Link_type __node,
const value_type& __x)
502 { get_allocator().construct(__node->_M_valptr(), __x); }
506 __throw_exception_again;
511 _M_create_node(
const value_type& __x)
513 _Link_type __tmp = _M_get_node();
514 _M_construct_node(__tmp, __x);
519 _M_destroy_node(_Link_type __p)
520 { get_allocator().destroy(__p->_M_valptr()); }
522 template<
typename... _Args>
524 _M_construct_node(_Link_type __node, _Args&&... __args)
528 ::new(__node) _Rb_tree_node<_Val>;
529 _Alloc_traits::construct(_M_get_Node_allocator(),
535 __node->~_Rb_tree_node<_Val>();
537 __throw_exception_again;
541 template<
typename... _Args>
543 _M_create_node(_Args&&... __args)
545 _Link_type __tmp = _M_get_node();
546 _M_construct_node(__tmp, std::forward<_Args>(__args)...);
551 _M_destroy_node(_Link_type __p) noexcept
553 _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr());
554 __p->~_Rb_tree_node<_Val>();
559 _M_drop_node(_Link_type __p) _GLIBCXX_NOEXCEPT
561 _M_destroy_node(__p);
565 template<
typename _NodeGen>
567 _M_clone_node(_Const_Link_type __x, _NodeGen& __node_gen)
569 _Link_type __tmp = __node_gen(*__x->_M_valptr());
570 __tmp->_M_color = __x->_M_color;
578 template<
typename _Key_compare,
579 bool = __is_pod(_Key_compare)>
580 struct _Rb_tree_impl :
public _Node_allocator
582 _Key_compare _M_key_compare;
583 _Rb_tree_node_base _M_header;
584 size_type _M_node_count;
587 : _Node_allocator(), _M_key_compare(), _M_header(),
591 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
592 : _Node_allocator(__a), _M_key_compare(__comp), _M_header(),
596 #if __cplusplus >= 201103L 597 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
598 : _Node_allocator(
std::move(__a)), _M_key_compare(__comp),
599 _M_header(), _M_node_count(0)
606 this->_M_header._M_parent = 0;
607 this->_M_header._M_left = &this->_M_header;
608 this->_M_header._M_right = &this->_M_header;
609 this->_M_node_count = 0;
616 this->_M_header._M_color = _S_red;
617 this->_M_header._M_parent = 0;
618 this->_M_header._M_left = &this->_M_header;
619 this->_M_header._M_right = &this->_M_header;
623 _Rb_tree_impl<_Compare> _M_impl;
627 _M_root() _GLIBCXX_NOEXCEPT
628 {
return this->_M_impl._M_header._M_parent; }
631 _M_root() const _GLIBCXX_NOEXCEPT
632 {
return this->_M_impl._M_header._M_parent; }
635 _M_leftmost() _GLIBCXX_NOEXCEPT
636 {
return this->_M_impl._M_header._M_left; }
639 _M_leftmost() const _GLIBCXX_NOEXCEPT
640 {
return this->_M_impl._M_header._M_left; }
643 _M_rightmost() _GLIBCXX_NOEXCEPT
644 {
return this->_M_impl._M_header._M_right; }
647 _M_rightmost() const _GLIBCXX_NOEXCEPT
648 {
return this->_M_impl._M_header._M_right; }
651 _M_begin() _GLIBCXX_NOEXCEPT
652 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
655 _M_begin() const _GLIBCXX_NOEXCEPT
657 return static_cast<_Const_Link_type
> 658 (this->_M_impl._M_header._M_parent);
662 _M_end() _GLIBCXX_NOEXCEPT
663 {
return reinterpret_cast<_Link_type
>(&this->_M_impl._M_header); }
666 _M_end() const _GLIBCXX_NOEXCEPT
667 {
return reinterpret_cast<_Const_Link_type
>(&this->_M_impl._M_header); }
669 static const_reference
670 _S_value(_Const_Link_type __x)
671 {
return *__x->_M_valptr(); }
674 _S_key(_Const_Link_type __x)
675 {
return _KeyOfValue()(_S_value(__x)); }
678 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
679 {
return static_cast<_Link_type
>(__x->_M_left); }
681 static _Const_Link_type
682 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
683 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
686 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
687 {
return static_cast<_Link_type
>(__x->_M_right); }
689 static _Const_Link_type
690 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
691 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
693 static const_reference
694 _S_value(_Const_Base_ptr __x)
695 {
return *
static_cast<_Const_Link_type
>(__x)->_M_valptr(); }
698 _S_key(_Const_Base_ptr __x)
699 {
return _KeyOfValue()(_S_value(__x)); }
702 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
703 {
return _Rb_tree_node_base::_S_minimum(__x); }
705 static _Const_Base_ptr
706 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
707 {
return _Rb_tree_node_base::_S_minimum(__x); }
710 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
711 {
return _Rb_tree_node_base::_S_maximum(__x); }
713 static _Const_Base_ptr
714 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
715 {
return _Rb_tree_node_base::_S_maximum(__x); }
718 typedef _Rb_tree_iterator<value_type> iterator;
719 typedef _Rb_tree_const_iterator<value_type> const_iterator;
725 pair<_Base_ptr, _Base_ptr>
726 _M_get_insert_unique_pos(
const key_type& __k);
728 pair<_Base_ptr, _Base_ptr>
729 _M_get_insert_equal_pos(
const key_type& __k);
731 pair<_Base_ptr, _Base_ptr>
732 _M_get_insert_hint_unique_pos(const_iterator __pos,
733 const key_type& __k);
735 pair<_Base_ptr, _Base_ptr>
736 _M_get_insert_hint_equal_pos(const_iterator __pos,
737 const key_type& __k);
739 #if __cplusplus >= 201103L 740 template<
typename _Arg,
typename _NodeGen>
742 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
745 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
747 template<
typename _Arg>
749 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
751 template<
typename _Arg>
753 _M_insert_equal_lower(_Arg&& __x);
756 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
759 _M_insert_equal_lower_node(_Link_type __z);
761 template<
typename _NodeGen>
763 _M_insert_(_Base_ptr __x, _Base_ptr __y,
764 const value_type& __v, _NodeGen&);
769 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
772 _M_insert_equal_lower(
const value_type& __x);
775 template<
typename _NodeGen>
777 _M_copy(_Const_Link_type __x, _Link_type __p, _NodeGen&);
780 _M_copy(_Const_Link_type __x, _Link_type __p)
782 _Alloc_node __an(*
this);
783 return _M_copy(__x, __p, __an);
787 _M_erase(_Link_type __x);
790 _M_lower_bound(_Link_type __x, _Link_type __y,
794 _M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
795 const _Key& __k)
const;
798 _M_upper_bound(_Link_type __x, _Link_type __y,
802 _M_upper_bound(_Const_Link_type __x, _Const_Link_type __y,
803 const _Key& __k)
const;
809 _Rb_tree(
const _Compare& __comp,
810 const allocator_type& __a = allocator_type())
811 : _M_impl(__comp, _Node_allocator(__a)) { }
813 _Rb_tree(
const _Rb_tree& __x)
814 : _M_impl(__x._M_impl._M_key_compare,
815 _Alloc_traits::_S_select_on_copy(__x._M_get_Node_allocator()))
817 if (__x._M_root() != 0)
819 _M_root() = _M_copy(__x._M_begin(), _M_end());
820 _M_leftmost() = _S_minimum(_M_root());
821 _M_rightmost() = _S_maximum(_M_root());
822 _M_impl._M_node_count = __x._M_impl._M_node_count;
826 #if __cplusplus >= 201103L 827 _Rb_tree(
const allocator_type& __a)
828 : _M_impl(_Compare(), _Node_allocator(__a))
831 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
832 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
834 if (__x._M_root() !=
nullptr)
836 _M_root() = _M_copy(__x._M_begin(), _M_end());
837 _M_leftmost() = _S_minimum(_M_root());
838 _M_rightmost() = _S_maximum(_M_root());
839 _M_impl._M_node_count = __x._M_impl._M_node_count;
843 _Rb_tree(_Rb_tree&& __x)
844 : _M_impl(__x._M_impl._M_key_compare, __x._M_get_Node_allocator())
846 if (__x._M_root() != 0)
850 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
851 : _Rb_tree(
std::move(__x), _Node_allocator(__a))
854 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a);
857 ~_Rb_tree() _GLIBCXX_NOEXCEPT
858 { _M_erase(_M_begin()); }
861 operator=(
const _Rb_tree& __x);
866 {
return _M_impl._M_key_compare; }
869 begin() _GLIBCXX_NOEXCEPT
870 {
return iterator(this->_M_impl._M_header._M_left); }
873 begin() const _GLIBCXX_NOEXCEPT
874 {
return const_iterator(this->_M_impl._M_header._M_left); }
877 end() _GLIBCXX_NOEXCEPT
878 {
return iterator(&this->_M_impl._M_header); }
881 end() const _GLIBCXX_NOEXCEPT
882 {
return const_iterator(&this->_M_impl._M_header); }
885 rbegin() _GLIBCXX_NOEXCEPT
886 {
return reverse_iterator(
end()); }
888 const_reverse_iterator
889 rbegin() const _GLIBCXX_NOEXCEPT
890 {
return const_reverse_iterator(
end()); }
893 rend() _GLIBCXX_NOEXCEPT
894 {
return reverse_iterator(
begin()); }
896 const_reverse_iterator
897 rend() const _GLIBCXX_NOEXCEPT
898 {
return const_reverse_iterator(
begin()); }
901 empty() const _GLIBCXX_NOEXCEPT
902 {
return _M_impl._M_node_count == 0; }
905 size() const _GLIBCXX_NOEXCEPT
906 {
return _M_impl._M_node_count; }
909 max_size() const _GLIBCXX_NOEXCEPT
910 {
return _Alloc_traits::max_size(_M_get_Node_allocator()); }
913 #if __cplusplus >= 201103L 914 swap(_Rb_tree& __t) noexcept(_Alloc_traits::_S_nothrow_swap());
920 #if __cplusplus >= 201103L 921 template<
typename _Arg>
923 _M_insert_unique(_Arg&& __x);
925 template<
typename _Arg>
927 _M_insert_equal(_Arg&& __x);
929 template<
typename _Arg,
typename _NodeGen>
931 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
933 template<
typename _Arg>
935 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
937 _Alloc_node __an(*
this);
938 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
941 template<
typename _Arg,
typename _NodeGen>
943 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
945 template<
typename _Arg>
947 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
949 _Alloc_node __an(*
this);
950 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
953 template<
typename... _Args>
955 _M_emplace_unique(_Args&&... __args);
957 template<
typename... _Args>
959 _M_emplace_equal(_Args&&... __args);
961 template<
typename... _Args>
963 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
965 template<
typename... _Args>
967 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
970 _M_insert_unique(
const value_type& __x);
973 _M_insert_equal(
const value_type& __x);
975 template<
typename _NodeGen>
977 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
981 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
983 _Alloc_node __an(*
this);
984 return _M_insert_unique_(__pos, __x, __an);
987 template<
typename _NodeGen>
989 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
992 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
994 _Alloc_node __an(*
this);
995 return _M_insert_equal_(__pos, __x, __an);
999 template<
typename _InputIterator>
1001 _M_insert_unique(_InputIterator __first, _InputIterator __last);
1003 template<
typename _InputIterator>
1005 _M_insert_equal(_InputIterator __first, _InputIterator __last);
1009 _M_erase_aux(const_iterator __position);
1012 _M_erase_aux(const_iterator __first, const_iterator __last);
1015 #if __cplusplus >= 201103L 1018 _GLIBCXX_ABI_TAG_CXX11
1020 erase(const_iterator __position)
1022 const_iterator __result = __position;
1024 _M_erase_aux(__position);
1025 return __result._M_const_cast();
1029 _GLIBCXX_ABI_TAG_CXX11
1031 erase(iterator __position)
1033 iterator __result = __position;
1035 _M_erase_aux(__position);
1040 erase(iterator __position)
1041 { _M_erase_aux(__position); }
1044 erase(const_iterator __position)
1045 { _M_erase_aux(__position); }
1048 erase(
const key_type& __x);
1050 #if __cplusplus >= 201103L 1053 _GLIBCXX_ABI_TAG_CXX11
1055 erase(const_iterator __first, const_iterator __last)
1057 _M_erase_aux(__first, __last);
1058 return __last._M_const_cast();
1062 erase(iterator __first, iterator __last)
1063 { _M_erase_aux(__first, __last); }
1066 erase(const_iterator __first, const_iterator __last)
1067 { _M_erase_aux(__first, __last); }
1070 erase(
const key_type* __first,
const key_type* __last);
1073 clear() _GLIBCXX_NOEXCEPT
1075 _M_erase(_M_begin());
1081 find(
const key_type& __k);
1084 find(
const key_type& __k)
const;
1087 count(
const key_type& __k)
const;
1090 lower_bound(
const key_type& __k)
1091 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1094 lower_bound(
const key_type& __k)
const 1095 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1098 upper_bound(
const key_type& __k)
1099 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1102 upper_bound(
const key_type& __k)
const 1103 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1105 pair<iterator, iterator>
1106 equal_range(
const key_type& __k);
1108 pair<const_iterator, const_iterator>
1109 equal_range(
const key_type& __k)
const;
1111 #if __cplusplus > 201103L 1112 template<
typename _Cmp,
typename _Kt,
typename = __
void_t<>>
1113 struct __is_transparent { };
1115 template<
typename _Cmp,
typename _Kt>
1117 __is_transparent<_Cmp, _Kt, __void_t<typename _Cmp::is_transparent>>
1118 {
typedef void type; };
1120 static auto _S_iter(_Link_type __x) {
return iterator(__x); }
1122 static auto _S_iter(_Const_Link_type __x) {
return const_iterator(__x); }
1124 template<
typename _Cmp,
typename _Link,
typename _Kt>
1126 _S_lower_bound_tr(_Cmp& __cmp, _Link __x, _Link __y,
const _Kt& __k)
1129 if (!__cmp(_S_key(__x), __k))
1130 __y = __x, __x = _S_left(__x);
1132 __x = _S_right(__x);
1133 return _S_iter(__y);
1136 template<
typename _Cmp,
typename _Link,
typename _Kt>
1138 _S_upper_bound_tr(_Cmp& __cmp, _Link __x, _Link __y,
const _Kt& __k)
1141 if (__cmp(__k, _S_key(__x)))
1142 __y = __x, __x = _S_left(__x);
1144 __x = _S_right(__x);
1145 return _S_iter(__y);
1148 template<
typename _Kt,
1149 typename _Req =
typename __is_transparent<_Compare, _Kt>::type>
1151 _M_find_tr(
const _Kt& __k)
1153 auto& __cmp = _M_impl._M_key_compare;
1154 auto __j = _S_lower_bound_tr(__cmp, _M_begin(), _M_end(), __k);
1155 return (__j ==
end() || __cmp(__k, _S_key(__j._M_node)))
1159 template<
typename _Kt,
1160 typename _Req =
typename __is_transparent<_Compare, _Kt>::type>
1162 _M_find_tr(
const _Kt& __k)
const 1164 auto& __cmp = _M_impl._M_key_compare;
1165 auto __j = _S_lower_bound_tr(__cmp, _M_begin(), _M_end(), __k);
1166 return (__j ==
end() || __cmp(__k, _S_key(__j._M_node)))
1170 template<
typename _Kt,
1171 typename _Req =
typename __is_transparent<_Compare, _Kt>::type>
1173 _M_count_tr(
const _Kt& __k)
const 1175 auto __p = _M_equal_range_tr(__k);
1179 template<
typename _Kt,
1180 typename _Req =
typename __is_transparent<_Compare, _Kt>::type>
1182 _M_lower_bound_tr(
const _Kt& __k)
1184 auto& __cmp = _M_impl._M_key_compare;
1185 return _S_lower_bound_tr(__cmp, _M_begin(), _M_end(), __k);
1188 template<
typename _Kt,
1189 typename _Req =
typename __is_transparent<_Compare, _Kt>::type>
1191 _M_lower_bound_tr(
const _Kt& __k)
const 1193 auto& __cmp = _M_impl._M_key_compare;
1194 return _S_lower_bound_tr(__cmp, _M_begin(), _M_end(), __k);
1197 template<
typename _Kt,
1198 typename _Req =
typename __is_transparent<_Compare, _Kt>::type>
1200 _M_upper_bound_tr(
const _Kt& __k)
1202 auto& __cmp = _M_impl._M_key_compare;
1203 return _S_upper_bound_tr(__cmp, _M_begin(), _M_end(), __k);
1206 template<
typename _Kt,
1207 typename _Req =
typename __is_transparent<_Compare, _Kt>::type>
1209 _M_upper_bound_tr(
const _Kt& __k)
const 1211 auto& __cmp = _M_impl._M_key_compare;
1212 return _S_upper_bound_tr(__cmp, _M_begin(), _M_end(), __k);
1215 template<
typename _Kt,
1216 typename _Req =
typename __is_transparent<_Compare, _Kt>::type>
1217 pair<iterator, iterator>
1218 _M_equal_range_tr(
const _Kt& __k)
1220 auto __low = _M_lower_bound_tr(__k);
1221 auto __high = __low;
1222 auto& __cmp = _M_impl._M_key_compare;
1223 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1225 return { __low, __high };
1228 template<
typename _Kt,
1229 typename _Req =
typename __is_transparent<_Compare, _Kt>::type>
1230 pair<const_iterator, const_iterator>
1231 _M_equal_range_tr(
const _Kt& __k)
const 1233 auto __low = _M_lower_bound_tr(__k);
1234 auto __high = __low;
1235 auto& __cmp = _M_impl._M_key_compare;
1236 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1238 return { __low, __high };
1244 __rb_verify()
const;
1246 #if __cplusplus >= 201103L 1248 operator=(_Rb_tree&&) noexcept(_Alloc_traits::_S_nothrow_move());
1250 template<typename _Iterator>
1252 _M_assign_unique(_Iterator, _Iterator);
1254 template<typename _Iterator>
1256 _M_assign_equal(_Iterator, _Iterator);
1270 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1271 typename _Compare,
typename _Alloc>
1273 operator==(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1274 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1276 return __x.size() == __y.size()
1277 &&
std::equal(__x.begin(), __x.end(), __y.begin());
1280 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1281 typename _Compare,
typename _Alloc>
1283 operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1284 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1287 __y.begin(), __y.end());
1290 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1291 typename _Compare,
typename _Alloc>
1293 operator!=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1294 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1295 {
return !(__x == __y); }
1297 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1298 typename _Compare,
typename _Alloc>
1300 operator>(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1301 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1302 {
return __y < __x; }
1304 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1305 typename _Compare,
typename _Alloc>
1307 operator<=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1308 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1309 {
return !(__y < __x); }
1311 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1312 typename _Compare,
typename _Alloc>
1314 operator>=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1315 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1316 {
return !(__x < __y); }
1318 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1319 typename _Compare,
typename _Alloc>
1321 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1322 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1325 #if __cplusplus >= 201103L 1326 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1327 typename _Compare,
typename _Alloc>
1328 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1329 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
1330 : _M_impl(__x._M_impl._M_key_compare,
std::move(__a))
1332 using __eq = integral_constant<bool, _Alloc_traits::_S_always_equal()>;
1333 if (__x._M_root() !=
nullptr)
1334 _M_move_data(__x, __eq());
1337 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1338 typename _Compare,
typename _Alloc>
1340 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1343 _M_root() = __x._M_root();
1344 _M_leftmost() = __x._M_leftmost();
1345 _M_rightmost() = __x._M_rightmost();
1346 _M_root()->_M_parent = _M_end();
1349 __x._M_leftmost() = __x._M_end();
1350 __x._M_rightmost() = __x._M_end();
1352 this->_M_impl._M_node_count = __x._M_impl._M_node_count;
1353 __x._M_impl._M_node_count = 0;
1356 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1357 typename _Compare,
typename _Alloc>
1359 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1362 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1366 _Alloc_node __an(*
this);
1368 [&__an](
const value_type& __cval)
1370 auto& __val =
const_cast<value_type&
>(__cval);
1373 _M_root() = _M_copy(__x._M_begin(), _M_end(), __lbd);
1374 _M_leftmost() = _S_minimum(_M_root());
1375 _M_rightmost() = _S_maximum(_M_root());
1376 _M_impl._M_node_count = __x._M_impl._M_node_count;
1380 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1381 typename _Compare,
typename _Alloc>
1382 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1383 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1384 operator=(_Rb_tree&& __x)
1385 noexcept(_Alloc_traits::_S_nothrow_move())
1387 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1388 if (_Alloc_traits::_S_propagate_on_move_assign()
1389 || _Alloc_traits::_S_always_equal()
1390 || _M_get_Node_allocator() == __x._M_get_Node_allocator())
1393 if (__x._M_root() !=
nullptr)
1395 std::__alloc_on_move(_M_get_Node_allocator(),
1396 __x._M_get_Node_allocator());
1402 _Reuse_or_alloc_node __roan(*
this);
1404 if (__x._M_root() !=
nullptr)
1407 [&__roan](
const value_type& __cval)
1409 auto& __val =
const_cast<value_type&
>(__cval);
1412 _M_root() = _M_copy(__x._M_begin(), _M_end(), __lbd);
1413 _M_leftmost() = _S_minimum(_M_root());
1414 _M_rightmost() = _S_maximum(_M_root());
1415 _M_impl._M_node_count = __x._M_impl._M_node_count;
1421 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1422 typename _Compare,
typename _Alloc>
1423 template<
typename _Iterator>
1425 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1426 _M_assign_unique(_Iterator __first, _Iterator __last)
1428 _Reuse_or_alloc_node __roan(*
this);
1430 for (; __first != __last; ++__first)
1431 _M_insert_unique_(
end(), *__first, __roan);
1434 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1435 typename _Compare,
typename _Alloc>
1436 template<
typename _Iterator>
1438 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1439 _M_assign_equal(_Iterator __first, _Iterator __last)
1441 _Reuse_or_alloc_node __roan(*
this);
1443 for (; __first != __last; ++__first)
1444 _M_insert_equal_(
end(), *__first, __roan);
1448 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1449 typename _Compare,
typename _Alloc>
1450 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1451 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1452 operator=(
const _Rb_tree& __x)
1457 #if __cplusplus >= 201103L 1458 if (_Alloc_traits::_S_propagate_on_copy_assign())
1460 auto& __this_alloc = this->_M_get_Node_allocator();
1461 auto& __that_alloc = __x._M_get_Node_allocator();
1462 if (!_Alloc_traits::_S_always_equal()
1463 && __this_alloc != __that_alloc)
1468 std::__alloc_on_copy(__this_alloc, __that_alloc);
1473 _Reuse_or_alloc_node __roan(*
this);
1475 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1476 if (__x._M_root() != 0)
1478 _M_root() = _M_copy(__x._M_begin(), _M_end(), __roan);
1479 _M_leftmost() = _S_minimum(_M_root());
1480 _M_rightmost() = _S_maximum(_M_root());
1481 _M_impl._M_node_count = __x._M_impl._M_node_count;
1488 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1489 typename _Compare,
typename _Alloc>
1490 #if __cplusplus >= 201103L 1491 template<
typename _Arg,
typename _NodeGen>
1493 template<
typename _NodeGen>
1495 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1496 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1497 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1498 #
if __cplusplus >= 201103L
1503 _NodeGen& __node_gen)
1505 bool __insert_left = (__x != 0 || __p == _M_end()
1506 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1509 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1511 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1512 this->_M_impl._M_header);
1513 ++_M_impl._M_node_count;
1514 return iterator(__z);
1517 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1518 typename _Compare,
typename _Alloc>
1519 #if __cplusplus >= 201103L 1520 template<
typename _Arg>
1522 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1523 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1524 #if __cplusplus >= 201103L 1525 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1527 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1530 bool __insert_left = (__p == _M_end()
1531 || !_M_impl._M_key_compare(_S_key(__p),
1532 _KeyOfValue()(__v)));
1534 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1536 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1537 this->_M_impl._M_header);
1538 ++_M_impl._M_node_count;
1539 return iterator(__z);
1542 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1543 typename _Compare,
typename _Alloc>
1544 #if __cplusplus >= 201103L 1545 template<
typename _Arg>
1547 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1548 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1549 #if __cplusplus >= 201103L 1550 _M_insert_equal_lower(_Arg&& __v)
1552 _M_insert_equal_lower(
const _Val& __v)
1555 _Link_type __x = _M_begin();
1556 _Link_type __y = _M_end();
1560 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1561 _S_left(__x) : _S_right(__x);
1563 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1566 template<
typename _Key,
typename _Val,
typename _KoV,
1567 typename _Compare,
typename _Alloc>
1568 template<
typename _NodeGen>
1569 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1570 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1571 _M_copy(_Const_Link_type __x, _Link_type __p, _NodeGen& __node_gen)
1574 _Link_type __top = _M_clone_node(__x, __node_gen);
1575 __top->_M_parent = __p;
1580 __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen);
1586 _Link_type __y = _M_clone_node(__x, __node_gen);
1588 __y->_M_parent = __p;
1590 __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen);
1598 __throw_exception_again;
1603 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1604 typename _Compare,
typename _Alloc>
1606 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1607 _M_erase(_Link_type __x)
1612 _M_erase(_S_right(__x));
1613 _Link_type __y = _S_left(__x);
1619 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1620 typename _Compare,
typename _Alloc>
1621 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1622 _Compare, _Alloc>::iterator
1623 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1624 _M_lower_bound(_Link_type __x, _Link_type __y,
1628 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1629 __y = __x, __x = _S_left(__x);
1631 __x = _S_right(__x);
1632 return iterator(__y);
1635 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1636 typename _Compare,
typename _Alloc>
1637 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1638 _Compare, _Alloc>::const_iterator
1639 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1640 _M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
1641 const _Key& __k)
const 1644 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1645 __y = __x, __x = _S_left(__x);
1647 __x = _S_right(__x);
1648 return const_iterator(__y);
1651 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1652 typename _Compare,
typename _Alloc>
1653 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1654 _Compare, _Alloc>::iterator
1655 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1656 _M_upper_bound(_Link_type __x, _Link_type __y,
1660 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1661 __y = __x, __x = _S_left(__x);
1663 __x = _S_right(__x);
1664 return iterator(__y);
1667 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1668 typename _Compare,
typename _Alloc>
1669 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1670 _Compare, _Alloc>::const_iterator
1671 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1672 _M_upper_bound(_Const_Link_type __x, _Const_Link_type __y,
1673 const _Key& __k)
const 1676 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1677 __y = __x, __x = _S_left(__x);
1679 __x = _S_right(__x);
1680 return const_iterator(__y);
1683 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1684 typename _Compare,
typename _Alloc>
1685 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1686 _Compare, _Alloc>::iterator,
1687 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1688 _Compare, _Alloc>::iterator>
1689 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1690 equal_range(
const _Key& __k)
1692 _Link_type __x = _M_begin();
1693 _Link_type __y = _M_end();
1696 if (_M_impl._M_key_compare(_S_key(__x), __k))
1697 __x = _S_right(__x);
1698 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1699 __y = __x, __x = _S_left(__x);
1702 _Link_type __xu(__x), __yu(__y);
1703 __y = __x, __x = _S_left(__x);
1704 __xu = _S_right(__xu);
1705 return pair<iterator,
1706 iterator>(_M_lower_bound(__x, __y, __k),
1707 _M_upper_bound(__xu, __yu, __k));
1710 return pair<iterator, iterator>(iterator(__y),
1714 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1715 typename _Compare,
typename _Alloc>
1716 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1717 _Compare, _Alloc>::const_iterator,
1718 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1719 _Compare, _Alloc>::const_iterator>
1720 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1721 equal_range(
const _Key& __k)
const 1723 _Const_Link_type __x = _M_begin();
1724 _Const_Link_type __y = _M_end();
1727 if (_M_impl._M_key_compare(_S_key(__x), __k))
1728 __x = _S_right(__x);
1729 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1730 __y = __x, __x = _S_left(__x);
1733 _Const_Link_type __xu(__x), __yu(__y);
1734 __y = __x, __x = _S_left(__x);
1735 __xu = _S_right(__xu);
1736 return pair<const_iterator,
1737 const_iterator>(_M_lower_bound(__x, __y, __k),
1738 _M_upper_bound(__xu, __yu, __k));
1741 return pair<const_iterator, const_iterator>(const_iterator(__y),
1742 const_iterator(__y));
1745 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1746 typename _Compare,
typename _Alloc>
1748 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1749 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __t)
1750 #if __cplusplus >= 201103L 1751 noexcept(_Alloc_traits::_S_nothrow_swap())
1756 if (__t._M_root() != 0)
1758 _M_root() = __t._M_root();
1759 _M_leftmost() = __t._M_leftmost();
1760 _M_rightmost() = __t._M_rightmost();
1761 _M_root()->_M_parent = _M_end();
1762 _M_impl._M_node_count = __t._M_impl._M_node_count;
1764 __t._M_impl._M_reset();
1767 else if (__t._M_root() == 0)
1769 __t._M_root() = _M_root();
1770 __t._M_leftmost() = _M_leftmost();
1771 __t._M_rightmost() = _M_rightmost();
1772 __t._M_root()->_M_parent = __t._M_end();
1773 __t._M_impl._M_node_count = _M_impl._M_node_count;
1779 std::swap(_M_root(),__t._M_root());
1780 std::swap(_M_leftmost(),__t._M_leftmost());
1781 std::swap(_M_rightmost(),__t._M_rightmost());
1783 _M_root()->_M_parent = _M_end();
1784 __t._M_root()->_M_parent = __t._M_end();
1785 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
1788 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
1790 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
1791 __t._M_get_Node_allocator());
1794 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1795 typename _Compare,
typename _Alloc>
1796 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1797 _Compare, _Alloc>::_Base_ptr,
1798 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1799 _Compare, _Alloc>::_Base_ptr>
1800 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1801 _M_get_insert_unique_pos(
const key_type& __k)
1803 typedef pair<_Base_ptr, _Base_ptr> _Res;
1804 _Link_type __x = _M_begin();
1805 _Link_type __y = _M_end();
1810 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
1811 __x = __comp ? _S_left(__x) : _S_right(__x);
1813 iterator __j = iterator(__y);
1817 return _Res(__x, __y);
1821 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
1822 return _Res(__x, __y);
1823 return _Res(__j._M_node, 0);
1826 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1827 typename _Compare,
typename _Alloc>
1828 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1829 _Compare, _Alloc>::_Base_ptr,
1830 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1831 _Compare, _Alloc>::_Base_ptr>
1832 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1833 _M_get_insert_equal_pos(
const key_type& __k)
1835 typedef pair<_Base_ptr, _Base_ptr> _Res;
1836 _Link_type __x = _M_begin();
1837 _Link_type __y = _M_end();
1841 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
1842 _S_left(__x) : _S_right(__x);
1844 return _Res(__x, __y);
1847 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1848 typename _Compare,
typename _Alloc>
1849 #if __cplusplus >= 201103L 1850 template<
typename _Arg>
1852 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1853 _Compare, _Alloc>::iterator,
bool>
1854 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1855 #if __cplusplus >= 201103L 1856 _M_insert_unique(_Arg&& __v)
1858 _M_insert_unique(
const _Val& __v)
1861 typedef pair<iterator, bool> _Res;
1862 pair<_Base_ptr, _Base_ptr> __res
1863 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
1867 _Alloc_node __an(*
this);
1868 return _Res(_M_insert_(__res.first, __res.second,
1869 _GLIBCXX_FORWARD(_Arg, __v), __an),
1873 return _Res(iterator(static_cast<_Link_type>(__res.first)),
false);
1876 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1877 typename _Compare,
typename _Alloc>
1878 #if __cplusplus >= 201103L 1879 template<
typename _Arg>
1881 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1882 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1883 #if __cplusplus >= 201103L 1884 _M_insert_equal(_Arg&& __v)
1886 _M_insert_equal(
const _Val& __v)
1889 pair<_Base_ptr, _Base_ptr> __res
1890 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
1891 _Alloc_node __an(*
this);
1892 return _M_insert_(__res.first, __res.second,
1893 _GLIBCXX_FORWARD(_Arg, __v), __an);
1896 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1897 typename _Compare,
typename _Alloc>
1898 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1899 _Compare, _Alloc>::_Base_ptr,
1900 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1901 _Compare, _Alloc>::_Base_ptr>
1902 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1903 _M_get_insert_hint_unique_pos(const_iterator __position,
1904 const key_type& __k)
1906 iterator __pos = __position._M_const_cast();
1907 typedef pair<_Base_ptr, _Base_ptr> _Res;
1910 if (__pos._M_node == _M_end())
1913 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
1914 return _Res(0, _M_rightmost());
1916 return _M_get_insert_unique_pos(__k);
1918 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
1921 iterator __before = __pos;
1922 if (__pos._M_node == _M_leftmost())
1923 return _Res(_M_leftmost(), _M_leftmost());
1924 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
1926 if (_S_right(__before._M_node) == 0)
1927 return _Res(0, __before._M_node);
1929 return _Res(__pos._M_node, __pos._M_node);
1932 return _M_get_insert_unique_pos(__k);
1934 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
1937 iterator __after = __pos;
1938 if (__pos._M_node == _M_rightmost())
1939 return _Res(0, _M_rightmost());
1940 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
1942 if (_S_right(__pos._M_node) == 0)
1943 return _Res(0, __pos._M_node);
1945 return _Res(__after._M_node, __after._M_node);
1948 return _M_get_insert_unique_pos(__k);
1952 return _Res(__pos._M_node, 0);
1955 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1956 typename _Compare,
typename _Alloc>
1957 #if __cplusplus >= 201103L 1958 template<
typename _Arg,
typename _NodeGen>
1960 template<
typename _NodeGen>
1962 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1963 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1964 _M_insert_unique_(const_iterator __position,
1965 #
if __cplusplus >= 201103L
1970 _NodeGen& __node_gen)
1972 pair<_Base_ptr, _Base_ptr> __res
1973 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
1976 return _M_insert_(__res.first, __res.second,
1977 _GLIBCXX_FORWARD(_Arg, __v),
1979 return iterator(static_cast<_Link_type>(__res.first));
1982 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1983 typename _Compare,
typename _Alloc>
1984 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1985 _Compare, _Alloc>::_Base_ptr,
1986 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1987 _Compare, _Alloc>::_Base_ptr>
1988 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1989 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
1991 iterator __pos = __position._M_const_cast();
1992 typedef pair<_Base_ptr, _Base_ptr> _Res;
1995 if (__pos._M_node == _M_end())
1998 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
1999 return _Res(0, _M_rightmost());
2001 return _M_get_insert_equal_pos(__k);
2003 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2006 iterator __before = __pos;
2007 if (__pos._M_node == _M_leftmost())
2008 return _Res(_M_leftmost(), _M_leftmost());
2009 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2011 if (_S_right(__before._M_node) == 0)
2012 return _Res(0, __before._M_node);
2014 return _Res(__pos._M_node, __pos._M_node);
2017 return _M_get_insert_equal_pos(__k);
2022 iterator __after = __pos;
2023 if (__pos._M_node == _M_rightmost())
2024 return _Res(0, _M_rightmost());
2025 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2027 if (_S_right(__pos._M_node) == 0)
2028 return _Res(0, __pos._M_node);
2030 return _Res(__after._M_node, __after._M_node);
2037 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2038 typename _Compare,
typename _Alloc>
2039 #if __cplusplus >= 201103L 2040 template<
typename _Arg,
typename _NodeGen>
2042 template<
typename _NodeGen>
2044 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2045 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2046 _M_insert_equal_(const_iterator __position,
2047 #
if __cplusplus >= 201103L
2052 _NodeGen& __node_gen)
2054 pair<_Base_ptr, _Base_ptr> __res
2055 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2058 return _M_insert_(__res.first, __res.second,
2059 _GLIBCXX_FORWARD(_Arg, __v),
2062 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2065 #if __cplusplus >= 201103L 2066 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2067 typename _Compare,
typename _Alloc>
2068 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2069 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2070 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2072 bool __insert_left = (__x != 0 || __p == _M_end()
2073 || _M_impl._M_key_compare(_S_key(__z),
2076 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2077 this->_M_impl._M_header);
2078 ++_M_impl._M_node_count;
2079 return iterator(__z);
2082 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2083 typename _Compare,
typename _Alloc>
2084 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2085 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2086 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2088 bool __insert_left = (__p == _M_end()
2089 || !_M_impl._M_key_compare(_S_key(__p),
2092 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2093 this->_M_impl._M_header);
2094 ++_M_impl._M_node_count;
2095 return iterator(__z);
2098 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2099 typename _Compare,
typename _Alloc>
2100 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2101 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2102 _M_insert_equal_lower_node(_Link_type __z)
2104 _Link_type __x = _M_begin();
2105 _Link_type __y = _M_end();
2109 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2110 _S_left(__x) : _S_right(__x);
2112 return _M_insert_lower_node(__y, __z);
2115 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2116 typename _Compare,
typename _Alloc>
2117 template<
typename... _Args>
2118 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2119 _Compare, _Alloc>::iterator,
bool>
2120 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2121 _M_emplace_unique(_Args&&... __args)
2123 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2127 typedef pair<iterator, bool> _Res;
2128 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2130 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2133 return _Res(iterator(static_cast<_Link_type>(__res.first)),
false);
2138 __throw_exception_again;
2142 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2143 typename _Compare,
typename _Alloc>
2144 template<
typename... _Args>
2145 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2146 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2147 _M_emplace_equal(_Args&&... __args)
2149 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2153 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2154 return _M_insert_node(__res.first, __res.second, __z);
2159 __throw_exception_again;
2163 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2164 typename _Compare,
typename _Alloc>
2165 template<
typename... _Args>
2166 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2167 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2168 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2170 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2174 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2177 return _M_insert_node(__res.first, __res.second, __z);
2180 return iterator(static_cast<_Link_type>(__res.first));
2185 __throw_exception_again;
2189 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2190 typename _Compare,
typename _Alloc>
2191 template<
typename... _Args>
2192 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2193 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2194 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2196 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2200 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2203 return _M_insert_node(__res.first, __res.second, __z);
2205 return _M_insert_equal_lower_node(__z);
2210 __throw_exception_again;
2215 template<
typename _Key,
typename _Val,
typename _KoV,
2216 typename _Cmp,
typename _Alloc>
2219 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
2220 _M_insert_unique(_II __first, _II __last)
2222 _Alloc_node __an(*
this);
2223 for (; __first != __last; ++__first)
2224 _M_insert_unique_(
end(), *__first, __an);
2227 template<
typename _Key,
typename _Val,
typename _KoV,
2228 typename _Cmp,
typename _Alloc>
2231 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
2232 _M_insert_equal(_II __first, _II __last)
2234 _Alloc_node __an(*
this);
2235 for (; __first != __last; ++__first)
2236 _M_insert_equal_(
end(), *__first, __an);
2239 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2240 typename _Compare,
typename _Alloc>
2242 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2243 _M_erase_aux(const_iterator __position)
2246 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
2247 (const_cast<_Base_ptr>(__position._M_node),
2248 this->_M_impl._M_header));
2250 --_M_impl._M_node_count;
2253 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2254 typename _Compare,
typename _Alloc>
2256 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2257 _M_erase_aux(const_iterator __first, const_iterator __last)
2259 if (__first ==
begin() && __last ==
end())
2262 while (__first != __last)
2266 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2267 typename _Compare,
typename _Alloc>
2268 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2269 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2270 erase(
const _Key& __x)
2272 pair<iterator, iterator> __p = equal_range(__x);
2273 const size_type __old_size =
size();
2274 erase(__p.first, __p.second);
2275 return __old_size -
size();
2278 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2279 typename _Compare,
typename _Alloc>
2281 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2282 erase(
const _Key* __first,
const _Key* __last)
2284 while (__first != __last)
2288 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2289 typename _Compare,
typename _Alloc>
2290 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2291 _Compare, _Alloc>::iterator
2292 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2293 find(
const _Key& __k)
2295 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2296 return (__j ==
end()
2297 || _M_impl._M_key_compare(__k,
2298 _S_key(__j._M_node))) ?
end() : __j;
2301 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2302 typename _Compare,
typename _Alloc>
2303 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2304 _Compare, _Alloc>::const_iterator
2305 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2306 find(
const _Key& __k)
const 2308 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2309 return (__j ==
end()
2310 || _M_impl._M_key_compare(__k,
2311 _S_key(__j._M_node))) ?
end() : __j;
2314 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2315 typename _Compare,
typename _Alloc>
2316 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2317 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2318 count(
const _Key& __k)
const 2320 pair<const_iterator, const_iterator> __p = equal_range(__k);
2325 _GLIBCXX_PURE
unsigned int 2326 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2327 const _Rb_tree_node_base* __root)
throw ();
2329 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2330 typename _Compare,
typename _Alloc>
2332 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const 2334 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2335 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2336 && this->_M_impl._M_header._M_left == _M_end()
2337 && this->_M_impl._M_header._M_right == _M_end();
2339 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2340 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2342 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
2343 _Const_Link_type __L = _S_left(__x);
2344 _Const_Link_type __R = _S_right(__x);
2346 if (__x->_M_color == _S_red)
2347 if ((__L && __L->_M_color == _S_red)
2348 || (__R && __R->_M_color == _S_red))
2351 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2353 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2356 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2360 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2362 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2367 _GLIBCXX_END_NAMESPACE_VERSION
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
iterator begin()
As per Table mumble.
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
iterator end()
As per Table mumble.
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.
size_type size() const
As per Table mumble.
ISO C++ entities toplevel namespace is std.
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++0x allocators.
auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.