61 #pragma GCC system_header 68 #if __cplusplus >= 201103L 72 namespace std _GLIBCXX_VISIBILITY(default)
74 _GLIBCXX_BEGIN_NAMESPACE_VERSION
76 #if __cplusplus > 201103L 77 # define __cpp_lib_generic_associative_lookup 201304 96 enum _Rb_tree_color { _S_red =
false, _S_black =
true };
98 struct _Rb_tree_node_base
100 typedef _Rb_tree_node_base* _Base_ptr;
101 typedef const _Rb_tree_node_base* _Const_Base_ptr;
103 _Rb_tree_color _M_color;
109 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
111 while (__x->_M_left != 0) __x = __x->_M_left;
115 static _Const_Base_ptr
116 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
118 while (__x->_M_left != 0) __x = __x->_M_left;
123 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
125 while (__x->_M_right != 0) __x = __x->_M_right;
129 static _Const_Base_ptr
130 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
132 while (__x->_M_right != 0) __x = __x->_M_right;
137 template<
typename _Val>
138 struct _Rb_tree_node :
public _Rb_tree_node_base
140 typedef _Rb_tree_node<_Val>* _Link_type;
142 #if __cplusplus < 201103L 153 __gnu_cxx::__aligned_membuf<_Val> _M_storage;
157 {
return _M_storage._M_ptr(); }
161 {
return _M_storage._M_ptr(); }
165 _GLIBCXX_PURE _Rb_tree_node_base*
166 _Rb_tree_increment(_Rb_tree_node_base* __x)
throw ();
168 _GLIBCXX_PURE
const _Rb_tree_node_base*
169 _Rb_tree_increment(
const _Rb_tree_node_base* __x)
throw ();
171 _GLIBCXX_PURE _Rb_tree_node_base*
172 _Rb_tree_decrement(_Rb_tree_node_base* __x)
throw ();
174 _GLIBCXX_PURE
const _Rb_tree_node_base*
175 _Rb_tree_decrement(
const _Rb_tree_node_base* __x)
throw ();
177 template<
typename _Tp>
178 struct _Rb_tree_iterator
180 typedef _Tp value_type;
181 typedef _Tp& reference;
182 typedef _Tp* pointer;
184 typedef bidirectional_iterator_tag iterator_category;
185 typedef ptrdiff_t difference_type;
187 typedef _Rb_tree_iterator<_Tp> _Self;
188 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
189 typedef _Rb_tree_node<_Tp>* _Link_type;
191 _Rb_tree_iterator() _GLIBCXX_NOEXCEPT
195 _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
200 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
203 operator->() const _GLIBCXX_NOEXCEPT
204 {
return static_cast<_Link_type
> (_M_node)->_M_valptr(); }
207 operator++() _GLIBCXX_NOEXCEPT
209 _M_node = _Rb_tree_increment(_M_node);
214 operator++(
int) _GLIBCXX_NOEXCEPT
217 _M_node = _Rb_tree_increment(_M_node);
222 operator--() _GLIBCXX_NOEXCEPT
224 _M_node = _Rb_tree_decrement(_M_node);
229 operator--(
int) _GLIBCXX_NOEXCEPT
232 _M_node = _Rb_tree_decrement(_M_node);
237 operator==(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
238 {
return _M_node == __x._M_node; }
241 operator!=(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
242 {
return _M_node != __x._M_node; }
247 template<
typename _Tp>
248 struct _Rb_tree_const_iterator
250 typedef _Tp value_type;
251 typedef const _Tp& reference;
252 typedef const _Tp* pointer;
254 typedef _Rb_tree_iterator<_Tp> iterator;
256 typedef bidirectional_iterator_tag iterator_category;
257 typedef ptrdiff_t difference_type;
259 typedef _Rb_tree_const_iterator<_Tp> _Self;
260 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
261 typedef const _Rb_tree_node<_Tp>* _Link_type;
263 _Rb_tree_const_iterator() _GLIBCXX_NOEXCEPT
267 _Rb_tree_const_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
270 _Rb_tree_const_iterator(
const iterator& __it) _GLIBCXX_NOEXCEPT
271 : _M_node(__it._M_node) { }
274 _M_const_cast() const _GLIBCXX_NOEXCEPT
275 {
return iterator(const_cast<typename iterator::_Base_ptr>(_M_node)); }
279 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
282 operator->() const _GLIBCXX_NOEXCEPT
283 {
return static_cast<_Link_type
>(_M_node)->_M_valptr(); }
286 operator++() _GLIBCXX_NOEXCEPT
288 _M_node = _Rb_tree_increment(_M_node);
293 operator++(
int) _GLIBCXX_NOEXCEPT
296 _M_node = _Rb_tree_increment(_M_node);
301 operator--() _GLIBCXX_NOEXCEPT
303 _M_node = _Rb_tree_decrement(_M_node);
308 operator--(
int) _GLIBCXX_NOEXCEPT
311 _M_node = _Rb_tree_decrement(_M_node);
316 operator==(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
317 {
return _M_node == __x._M_node; }
320 operator!=(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
321 {
return _M_node != __x._M_node; }
326 template<
typename _Val>
328 operator==(
const _Rb_tree_iterator<_Val>& __x,
329 const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
330 {
return __x._M_node == __y._M_node; }
332 template<
typename _Val>
334 operator!=(
const _Rb_tree_iterator<_Val>& __x,
335 const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
336 {
return __x._M_node != __y._M_node; }
339 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
340 _Rb_tree_node_base* __x,
341 _Rb_tree_node_base* __p,
342 _Rb_tree_node_base& __header)
throw ();
345 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
346 _Rb_tree_node_base& __header)
throw ();
348 #if __cplusplus > 201103L 349 template<
typename _Cmp,
typename _SfinaeType,
typename = __
void_t<>>
350 struct __has_is_transparent
353 template<
typename _Cmp,
typename _SfinaeType>
354 struct __has_is_transparent<_Cmp, _SfinaeType,
355 __void_t<typename _Cmp::is_transparent>>
356 {
typedef void type; };
359 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
360 typename _Compare,
typename _Alloc = allocator<_Val> >
364 rebind<_Rb_tree_node<_Val> >::other _Node_allocator;
369 typedef _Rb_tree_node_base* _Base_ptr;
370 typedef const _Rb_tree_node_base* _Const_Base_ptr;
371 typedef _Rb_tree_node<_Val>* _Link_type;
372 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
377 struct _Reuse_or_alloc_node
379 _Reuse_or_alloc_node(_Rb_tree& __t)
380 : _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t)
384 _M_root->_M_parent = 0;
386 if (_M_nodes->_M_left)
387 _M_nodes = _M_nodes->_M_left;
393 #if __cplusplus >= 201103L 394 _Reuse_or_alloc_node(
const _Reuse_or_alloc_node&) =
delete;
397 ~_Reuse_or_alloc_node()
398 { _M_t._M_erase(static_cast<_Link_type>(_M_root)); }
400 template<
typename _Arg>
402 #if __cplusplus < 201103L 403 operator()(
const _Arg& __arg)
405 operator()(_Arg&& __arg)
408 _Link_type __node =
static_cast<_Link_type
>(_M_extract());
411 _M_t._M_destroy_node(__node);
412 _M_t._M_construct_node(__node, _GLIBCXX_FORWARD(_Arg, __arg));
416 return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg));
426 _Base_ptr __node = _M_nodes;
427 _M_nodes = _M_nodes->_M_parent;
430 if (_M_nodes->_M_right == __node)
432 _M_nodes->_M_right = 0;
434 if (_M_nodes->_M_left)
436 _M_nodes = _M_nodes->_M_left;
438 while (_M_nodes->_M_right)
439 _M_nodes = _M_nodes->_M_right;
441 if (_M_nodes->_M_left)
442 _M_nodes = _M_nodes->_M_left;
446 _M_nodes->_M_left = 0;
463 _Alloc_node(_Rb_tree& __t)
466 template<
typename _Arg>
468 #if __cplusplus < 201103L 469 operator()(
const _Arg& __arg)
const 471 operator()(_Arg&& __arg) const
473 {
return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg)); }
480 typedef _Key key_type;
481 typedef _Val value_type;
482 typedef value_type* pointer;
483 typedef const value_type* const_pointer;
484 typedef value_type& reference;
485 typedef const value_type& const_reference;
486 typedef size_t size_type;
487 typedef ptrdiff_t difference_type;
488 typedef _Alloc allocator_type;
491 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
492 {
return *
static_cast<_Node_allocator*
>(&this->_M_impl); }
494 const _Node_allocator&
495 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
496 {
return *
static_cast<const _Node_allocator*
>(&this->_M_impl); }
499 get_allocator() const _GLIBCXX_NOEXCEPT
500 {
return allocator_type(_M_get_Node_allocator()); }
505 {
return _Alloc_traits::allocate(_M_get_Node_allocator(), 1); }
508 _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
509 { _Alloc_traits::deallocate(_M_get_Node_allocator(), __p, 1); }
511 #if __cplusplus < 201103L 513 _M_construct_node(_Link_type __node,
const value_type& __x)
516 { get_allocator().construct(__node->_M_valptr(), __x); }
520 __throw_exception_again;
525 _M_create_node(
const value_type& __x)
527 _Link_type __tmp = _M_get_node();
528 _M_construct_node(__tmp, __x);
533 _M_destroy_node(_Link_type __p)
534 { get_allocator().destroy(__p->_M_valptr()); }
536 template<
typename... _Args>
538 _M_construct_node(_Link_type __node, _Args&&... __args)
542 ::new(__node) _Rb_tree_node<_Val>;
543 _Alloc_traits::construct(_M_get_Node_allocator(),
549 __node->~_Rb_tree_node<_Val>();
551 __throw_exception_again;
555 template<
typename... _Args>
557 _M_create_node(_Args&&... __args)
559 _Link_type __tmp = _M_get_node();
560 _M_construct_node(__tmp, std::forward<_Args>(__args)...);
565 _M_destroy_node(_Link_type __p) noexcept
567 _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr());
568 __p->~_Rb_tree_node<_Val>();
573 _M_drop_node(_Link_type __p) _GLIBCXX_NOEXCEPT
575 _M_destroy_node(__p);
579 template<
typename _NodeGen>
581 _M_clone_node(_Const_Link_type __x, _NodeGen& __node_gen)
583 _Link_type __tmp = __node_gen(*__x->_M_valptr());
584 __tmp->_M_color = __x->_M_color;
592 template<
typename _Key_compare,
593 bool = __is_pod(_Key_compare)>
594 struct _Rb_tree_impl :
public _Node_allocator
596 _Key_compare _M_key_compare;
597 _Rb_tree_node_base _M_header;
598 size_type _M_node_count;
601 : _Node_allocator(), _M_key_compare(), _M_header(),
605 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
606 : _Node_allocator(__a), _M_key_compare(__comp), _M_header(),
610 #if __cplusplus >= 201103L 611 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
612 : _Node_allocator(
std::move(__a)), _M_key_compare(__comp),
613 _M_header(), _M_node_count(0)
620 this->_M_header._M_parent = 0;
621 this->_M_header._M_left = &this->_M_header;
622 this->_M_header._M_right = &this->_M_header;
623 this->_M_node_count = 0;
630 this->_M_header._M_color = _S_red;
631 this->_M_header._M_parent = 0;
632 this->_M_header._M_left = &this->_M_header;
633 this->_M_header._M_right = &this->_M_header;
637 _Rb_tree_impl<_Compare> _M_impl;
641 _M_root() _GLIBCXX_NOEXCEPT
642 {
return this->_M_impl._M_header._M_parent; }
645 _M_root() const _GLIBCXX_NOEXCEPT
646 {
return this->_M_impl._M_header._M_parent; }
649 _M_leftmost() _GLIBCXX_NOEXCEPT
650 {
return this->_M_impl._M_header._M_left; }
653 _M_leftmost() const _GLIBCXX_NOEXCEPT
654 {
return this->_M_impl._M_header._M_left; }
657 _M_rightmost() _GLIBCXX_NOEXCEPT
658 {
return this->_M_impl._M_header._M_right; }
661 _M_rightmost() const _GLIBCXX_NOEXCEPT
662 {
return this->_M_impl._M_header._M_right; }
665 _M_begin() _GLIBCXX_NOEXCEPT
666 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
669 _M_begin() const _GLIBCXX_NOEXCEPT
671 return static_cast<_Const_Link_type
> 672 (this->_M_impl._M_header._M_parent);
676 _M_end() _GLIBCXX_NOEXCEPT
677 {
return &this->_M_impl._M_header; }
680 _M_end() const _GLIBCXX_NOEXCEPT
681 {
return &this->_M_impl._M_header; }
683 static const_reference
684 _S_value(_Const_Link_type __x)
685 {
return *__x->_M_valptr(); }
688 _S_key(_Const_Link_type __x)
689 {
return _KeyOfValue()(_S_value(__x)); }
692 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
693 {
return static_cast<_Link_type
>(__x->_M_left); }
695 static _Const_Link_type
696 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
697 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
700 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
701 {
return static_cast<_Link_type
>(__x->_M_right); }
703 static _Const_Link_type
704 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
705 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
707 static const_reference
708 _S_value(_Const_Base_ptr __x)
709 {
return *
static_cast<_Const_Link_type
>(__x)->_M_valptr(); }
712 _S_key(_Const_Base_ptr __x)
713 {
return _KeyOfValue()(_S_value(__x)); }
716 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
717 {
return _Rb_tree_node_base::_S_minimum(__x); }
719 static _Const_Base_ptr
720 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
721 {
return _Rb_tree_node_base::_S_minimum(__x); }
724 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
725 {
return _Rb_tree_node_base::_S_maximum(__x); }
727 static _Const_Base_ptr
728 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
729 {
return _Rb_tree_node_base::_S_maximum(__x); }
732 typedef _Rb_tree_iterator<value_type> iterator;
733 typedef _Rb_tree_const_iterator<value_type> const_iterator;
738 pair<_Base_ptr, _Base_ptr>
739 _M_get_insert_unique_pos(
const key_type& __k);
741 pair<_Base_ptr, _Base_ptr>
742 _M_get_insert_equal_pos(
const key_type& __k);
744 pair<_Base_ptr, _Base_ptr>
745 _M_get_insert_hint_unique_pos(const_iterator __pos,
746 const key_type& __k);
748 pair<_Base_ptr, _Base_ptr>
749 _M_get_insert_hint_equal_pos(const_iterator __pos,
750 const key_type& __k);
753 #if __cplusplus >= 201103L 754 template<
typename _Arg,
typename _NodeGen>
756 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
759 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
761 template<
typename _Arg>
763 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
765 template<
typename _Arg>
767 _M_insert_equal_lower(_Arg&& __x);
770 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
773 _M_insert_equal_lower_node(_Link_type __z);
775 template<
typename _NodeGen>
777 _M_insert_(_Base_ptr __x, _Base_ptr __y,
778 const value_type& __v, _NodeGen&);
783 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
786 _M_insert_equal_lower(
const value_type& __x);
789 template<
typename _NodeGen>
791 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen&);
794 _M_copy(_Const_Link_type __x, _Base_ptr __p)
796 _Alloc_node __an(*
this);
797 return _M_copy(__x, __p, __an);
801 _M_erase(_Link_type __x);
804 _M_lower_bound(_Link_type __x, _Base_ptr __y,
808 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
809 const _Key& __k)
const;
812 _M_upper_bound(_Link_type __x, _Base_ptr __y,
816 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
817 const _Key& __k)
const;
823 _Rb_tree(
const _Compare& __comp,
824 const allocator_type& __a = allocator_type())
825 : _M_impl(__comp, _Node_allocator(__a)) { }
827 _Rb_tree(
const _Rb_tree& __x)
828 : _M_impl(__x._M_impl._M_key_compare,
829 _Alloc_traits::_S_select_on_copy(__x._M_get_Node_allocator()))
831 if (__x._M_root() != 0)
833 _M_root() = _M_copy(__x._M_begin(), _M_end());
834 _M_leftmost() = _S_minimum(_M_root());
835 _M_rightmost() = _S_maximum(_M_root());
836 _M_impl._M_node_count = __x._M_impl._M_node_count;
840 #if __cplusplus >= 201103L 841 _Rb_tree(
const allocator_type& __a)
842 : _M_impl(_Compare(), _Node_allocator(__a))
845 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
846 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
848 if (__x._M_root() !=
nullptr)
850 _M_root() = _M_copy(__x._M_begin(), _M_end());
851 _M_leftmost() = _S_minimum(_M_root());
852 _M_rightmost() = _S_maximum(_M_root());
853 _M_impl._M_node_count = __x._M_impl._M_node_count;
857 _Rb_tree(_Rb_tree&& __x)
858 : _M_impl(__x._M_impl._M_key_compare,
859 std::move(__x._M_get_Node_allocator()))
861 if (__x._M_root() != 0)
865 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
866 : _Rb_tree(
std::move(__x), _Node_allocator(__a))
869 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a);
872 ~_Rb_tree() _GLIBCXX_NOEXCEPT
873 { _M_erase(_M_begin()); }
876 operator=(
const _Rb_tree& __x);
881 {
return _M_impl._M_key_compare; }
884 begin() _GLIBCXX_NOEXCEPT
885 {
return iterator(this->_M_impl._M_header._M_left); }
888 begin() const _GLIBCXX_NOEXCEPT
889 {
return const_iterator(this->_M_impl._M_header._M_left); }
892 end() _GLIBCXX_NOEXCEPT
893 {
return iterator(&this->_M_impl._M_header); }
896 end() const _GLIBCXX_NOEXCEPT
897 {
return const_iterator(&this->_M_impl._M_header); }
900 rbegin() _GLIBCXX_NOEXCEPT
901 {
return reverse_iterator(
end()); }
903 const_reverse_iterator
904 rbegin() const _GLIBCXX_NOEXCEPT
905 {
return const_reverse_iterator(
end()); }
908 rend() _GLIBCXX_NOEXCEPT
909 {
return reverse_iterator(
begin()); }
911 const_reverse_iterator
912 rend() const _GLIBCXX_NOEXCEPT
913 {
return const_reverse_iterator(
begin()); }
916 empty() const _GLIBCXX_NOEXCEPT
917 {
return _M_impl._M_node_count == 0; }
920 size() const _GLIBCXX_NOEXCEPT
921 {
return _M_impl._M_node_count; }
924 max_size() const _GLIBCXX_NOEXCEPT
925 {
return _Alloc_traits::max_size(_M_get_Node_allocator()); }
929 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value);
932 #if __cplusplus >= 201103L 933 template<
typename _Arg>
935 _M_insert_unique(_Arg&& __x);
937 template<
typename _Arg>
939 _M_insert_equal(_Arg&& __x);
941 template<
typename _Arg,
typename _NodeGen>
943 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
945 template<
typename _Arg>
947 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
949 _Alloc_node __an(*
this);
950 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
953 template<
typename _Arg,
typename _NodeGen>
955 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
957 template<
typename _Arg>
959 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
961 _Alloc_node __an(*
this);
962 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
965 template<
typename... _Args>
967 _M_emplace_unique(_Args&&... __args);
969 template<
typename... _Args>
971 _M_emplace_equal(_Args&&... __args);
973 template<
typename... _Args>
975 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
977 template<
typename... _Args>
979 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
982 _M_insert_unique(
const value_type& __x);
985 _M_insert_equal(
const value_type& __x);
987 template<
typename _NodeGen>
989 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
993 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
995 _Alloc_node __an(*
this);
996 return _M_insert_unique_(__pos, __x, __an);
999 template<
typename _NodeGen>
1001 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1004 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1006 _Alloc_node __an(*
this);
1007 return _M_insert_equal_(__pos, __x, __an);
1011 template<
typename _InputIterator>
1013 _M_insert_unique(_InputIterator __first, _InputIterator __last);
1015 template<
typename _InputIterator>
1017 _M_insert_equal(_InputIterator __first, _InputIterator __last);
1021 _M_erase_aux(const_iterator __position);
1024 _M_erase_aux(const_iterator __first, const_iterator __last);
1027 #if __cplusplus >= 201103L 1030 _GLIBCXX_ABI_TAG_CXX11
1032 erase(const_iterator __position)
1034 const_iterator __result = __position;
1036 _M_erase_aux(__position);
1037 return __result._M_const_cast();
1041 _GLIBCXX_ABI_TAG_CXX11
1043 erase(iterator __position)
1045 iterator __result = __position;
1047 _M_erase_aux(__position);
1052 erase(iterator __position)
1053 { _M_erase_aux(__position); }
1056 erase(const_iterator __position)
1057 { _M_erase_aux(__position); }
1060 erase(
const key_type& __x);
1062 #if __cplusplus >= 201103L 1065 _GLIBCXX_ABI_TAG_CXX11
1067 erase(const_iterator __first, const_iterator __last)
1069 _M_erase_aux(__first, __last);
1070 return __last._M_const_cast();
1074 erase(iterator __first, iterator __last)
1075 { _M_erase_aux(__first, __last); }
1078 erase(const_iterator __first, const_iterator __last)
1079 { _M_erase_aux(__first, __last); }
1082 erase(
const key_type* __first,
const key_type* __last);
1085 clear() _GLIBCXX_NOEXCEPT
1087 _M_erase(_M_begin());
1093 find(
const key_type& __k);
1096 find(
const key_type& __k)
const;
1099 count(
const key_type& __k)
const;
1102 lower_bound(
const key_type& __k)
1103 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1106 lower_bound(
const key_type& __k)
const 1107 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1110 upper_bound(
const key_type& __k)
1111 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1114 upper_bound(
const key_type& __k)
const 1115 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1117 pair<iterator, iterator>
1118 equal_range(
const key_type& __k);
1120 pair<const_iterator, const_iterator>
1121 equal_range(
const key_type& __k)
const;
1123 #if __cplusplus > 201103L 1124 template<
typename _Kt,
1126 typename __has_is_transparent<_Compare, _Kt>::type>
1128 _M_find_tr(
const _Kt& __k)
1130 const _Rb_tree* __const_this =
this;
1131 return __const_this->_M_find_tr(__k)._M_const_cast();
1134 template<
typename _Kt,
1136 typename __has_is_transparent<_Compare, _Kt>::type>
1138 _M_find_tr(
const _Kt& __k)
const 1140 auto __j = _M_lower_bound_tr(__k);
1141 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1146 template<
typename _Kt,
1148 typename __has_is_transparent<_Compare, _Kt>::type>
1150 _M_count_tr(
const _Kt& __k)
const 1152 auto __p = _M_equal_range_tr(__k);
1156 template<
typename _Kt,
1158 typename __has_is_transparent<_Compare, _Kt>::type>
1160 _M_lower_bound_tr(
const _Kt& __k)
1162 const _Rb_tree* __const_this =
this;
1163 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1166 template<
typename _Kt,
1168 typename __has_is_transparent<_Compare, _Kt>::type>
1170 _M_lower_bound_tr(
const _Kt& __k)
const 1172 auto __x = _M_begin();
1173 auto __y = _M_end();
1175 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1181 __x = _S_right(__x);
1182 return const_iterator(__y);
1185 template<
typename _Kt,
1187 typename __has_is_transparent<_Compare, _Kt>::type>
1189 _M_upper_bound_tr(
const _Kt& __k)
1191 const _Rb_tree* __const_this =
this;
1192 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1195 template<
typename _Kt,
1197 typename __has_is_transparent<_Compare, _Kt>::type>
1199 _M_upper_bound_tr(
const _Kt& __k)
const 1201 auto __x = _M_begin();
1202 auto __y = _M_end();
1204 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1210 __x = _S_right(__x);
1211 return const_iterator(__y);
1214 template<
typename _Kt,
1216 typename __has_is_transparent<_Compare, _Kt>::type>
1217 pair<iterator, iterator>
1218 _M_equal_range_tr(
const _Kt& __k)
1220 const _Rb_tree* __const_this =
this;
1221 auto __ret = __const_this->_M_equal_range_tr(__k);
1222 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1225 template<
typename _Kt,
1227 typename __has_is_transparent<_Compare, _Kt>::type>
1228 pair<const_iterator, const_iterator>
1229 _M_equal_range_tr(
const _Kt& __k)
const 1231 auto __low = _M_lower_bound_tr(__k);
1232 auto __high = __low;
1233 auto& __cmp = _M_impl._M_key_compare;
1234 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1236 return { __low, __high };
1242 __rb_verify()
const;
1244 #if __cplusplus >= 201103L 1246 operator=(_Rb_tree&&)
1247 noexcept(_Alloc_traits::_S_nothrow_move()
1248 && is_nothrow_move_assignable<_Compare>::value);
1250 template<typename _Iterator>
1252 _M_assign_unique(_Iterator, _Iterator);
1254 template<typename _Iterator>
1256 _M_assign_equal(_Iterator, _Iterator);
1270 _M_move_assign(_Rb_tree&,
std::true_type);
1275 _M_move_assign(_Rb_tree&,
std::false_type);
1279 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1280 typename _Compare,
typename _Alloc>
1282 operator==(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1283 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1285 return __x.size() == __y.size()
1286 &&
std::equal(__x.begin(), __x.end(), __y.begin());
1289 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1290 typename _Compare,
typename _Alloc>
1292 operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1293 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1296 __y.begin(), __y.end());
1299 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1300 typename _Compare,
typename _Alloc>
1302 operator!=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1303 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1304 {
return !(__x == __y); }
1306 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1307 typename _Compare,
typename _Alloc>
1309 operator>(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1310 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1311 {
return __y < __x; }
1313 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1314 typename _Compare,
typename _Alloc>
1316 operator<=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1317 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1318 {
return !(__y < __x); }
1320 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1321 typename _Compare,
typename _Alloc>
1323 operator>=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1324 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1325 {
return !(__x < __y); }
1327 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1328 typename _Compare,
typename _Alloc>
1330 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1331 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1334 #if __cplusplus >= 201103L 1335 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1336 typename _Compare,
typename _Alloc>
1337 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1338 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
1339 : _M_impl(__x._M_impl._M_key_compare,
std::move(__a))
1341 using __eq =
typename _Alloc_traits::is_always_equal;
1342 if (__x._M_root() !=
nullptr)
1343 _M_move_data(__x, __eq());
1346 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1347 typename _Compare,
typename _Alloc>
1349 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1352 _M_root() = __x._M_root();
1353 _M_leftmost() = __x._M_leftmost();
1354 _M_rightmost() = __x._M_rightmost();
1355 _M_root()->_M_parent = _M_end();
1358 __x._M_leftmost() = __x._M_end();
1359 __x._M_rightmost() = __x._M_end();
1361 this->_M_impl._M_node_count = __x._M_impl._M_node_count;
1362 __x._M_impl._M_node_count = 0;
1365 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1366 typename _Compare,
typename _Alloc>
1368 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1371 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1375 _Alloc_node __an(*
this);
1377 [&__an](
const value_type& __cval)
1379 auto& __val =
const_cast<value_type&
>(__cval);
1382 _M_root() = _M_copy(__x._M_begin(), _M_end(), __lbd);
1383 _M_leftmost() = _S_minimum(_M_root());
1384 _M_rightmost() = _S_maximum(_M_root());
1385 _M_impl._M_node_count = __x._M_impl._M_node_count;
1389 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1390 typename _Compare,
typename _Alloc>
1392 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1393 _M_move_assign(_Rb_tree& __x,
true_type)
1396 if (__x._M_root() !=
nullptr)
1398 std::__alloc_on_move(_M_get_Node_allocator(),
1399 __x._M_get_Node_allocator());
1402 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1403 typename _Compare,
typename _Alloc>
1405 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1408 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1409 return _M_move_assign(__x,
true_type{});
1413 _Reuse_or_alloc_node __roan(*
this);
1415 if (__x._M_root() !=
nullptr)
1418 [&__roan](
const value_type& __cval)
1420 auto& __val =
const_cast<value_type&
>(__cval);
1423 _M_root() = _M_copy(__x._M_begin(), _M_end(), __lbd);
1424 _M_leftmost() = _S_minimum(_M_root());
1425 _M_rightmost() = _S_maximum(_M_root());
1426 _M_impl._M_node_count = __x._M_impl._M_node_count;
1431 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1432 typename _Compare,
typename _Alloc>
1433 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1434 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1435 operator=(_Rb_tree&& __x)
1436 noexcept(_Alloc_traits::_S_nothrow_move()
1437 && is_nothrow_move_assignable<_Compare>::value)
1439 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1440 constexpr
bool __move_storage =
1441 _Alloc_traits::_S_propagate_on_move_assign()
1442 || _Alloc_traits::_S_always_equal();
1443 _M_move_assign(__x, __bool_constant<__move_storage>());
1447 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1448 typename _Compare,
typename _Alloc>
1449 template<
typename _Iterator>
1451 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1452 _M_assign_unique(_Iterator __first, _Iterator __last)
1454 _Reuse_or_alloc_node __roan(*
this);
1456 for (; __first != __last; ++__first)
1457 _M_insert_unique_(
end(), *__first, __roan);
1460 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1461 typename _Compare,
typename _Alloc>
1462 template<
typename _Iterator>
1464 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1465 _M_assign_equal(_Iterator __first, _Iterator __last)
1467 _Reuse_or_alloc_node __roan(*
this);
1469 for (; __first != __last; ++__first)
1470 _M_insert_equal_(
end(), *__first, __roan);
1474 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1475 typename _Compare,
typename _Alloc>
1476 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1477 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1478 operator=(
const _Rb_tree& __x)
1483 #if __cplusplus >= 201103L 1484 if (_Alloc_traits::_S_propagate_on_copy_assign())
1486 auto& __this_alloc = this->_M_get_Node_allocator();
1487 auto& __that_alloc = __x._M_get_Node_allocator();
1488 if (!_Alloc_traits::_S_always_equal()
1489 && __this_alloc != __that_alloc)
1494 std::__alloc_on_copy(__this_alloc, __that_alloc);
1499 _Reuse_or_alloc_node __roan(*
this);
1501 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1502 if (__x._M_root() != 0)
1504 _M_root() = _M_copy(__x._M_begin(), _M_end(), __roan);
1505 _M_leftmost() = _S_minimum(_M_root());
1506 _M_rightmost() = _S_maximum(_M_root());
1507 _M_impl._M_node_count = __x._M_impl._M_node_count;
1514 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1515 typename _Compare,
typename _Alloc>
1516 #if __cplusplus >= 201103L 1517 template<
typename _Arg,
typename _NodeGen>
1519 template<
typename _NodeGen>
1521 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1522 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1523 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1524 #
if __cplusplus >= 201103L
1529 _NodeGen& __node_gen)
1531 bool __insert_left = (__x != 0 || __p == _M_end()
1532 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1535 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1537 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1538 this->_M_impl._M_header);
1539 ++_M_impl._M_node_count;
1540 return iterator(__z);
1543 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1544 typename _Compare,
typename _Alloc>
1545 #if __cplusplus >= 201103L 1546 template<
typename _Arg>
1548 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1549 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1550 #if __cplusplus >= 201103L 1551 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1553 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1556 bool __insert_left = (__p == _M_end()
1557 || !_M_impl._M_key_compare(_S_key(__p),
1558 _KeyOfValue()(__v)));
1560 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1562 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1563 this->_M_impl._M_header);
1564 ++_M_impl._M_node_count;
1565 return iterator(__z);
1568 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1569 typename _Compare,
typename _Alloc>
1570 #if __cplusplus >= 201103L 1571 template<
typename _Arg>
1573 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1574 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1575 #if __cplusplus >= 201103L 1576 _M_insert_equal_lower(_Arg&& __v)
1578 _M_insert_equal_lower(
const _Val& __v)
1581 _Link_type __x = _M_begin();
1582 _Base_ptr __y = _M_end();
1586 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1587 _S_left(__x) : _S_right(__x);
1589 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1592 template<
typename _Key,
typename _Val,
typename _KoV,
1593 typename _Compare,
typename _Alloc>
1594 template<
typename _NodeGen>
1595 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1596 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1597 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1600 _Link_type __top = _M_clone_node(__x, __node_gen);
1601 __top->_M_parent = __p;
1606 __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen);
1612 _Link_type __y = _M_clone_node(__x, __node_gen);
1614 __y->_M_parent = __p;
1616 __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen);
1624 __throw_exception_again;
1629 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1630 typename _Compare,
typename _Alloc>
1632 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1633 _M_erase(_Link_type __x)
1638 _M_erase(_S_right(__x));
1639 _Link_type __y = _S_left(__x);
1645 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1646 typename _Compare,
typename _Alloc>
1647 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1648 _Compare, _Alloc>::iterator
1649 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1650 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1654 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1655 __y = __x, __x = _S_left(__x);
1657 __x = _S_right(__x);
1658 return iterator(__y);
1661 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1662 typename _Compare,
typename _Alloc>
1663 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1664 _Compare, _Alloc>::const_iterator
1665 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1666 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1667 const _Key& __k)
const 1670 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1671 __y = __x, __x = _S_left(__x);
1673 __x = _S_right(__x);
1674 return const_iterator(__y);
1677 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1678 typename _Compare,
typename _Alloc>
1679 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1680 _Compare, _Alloc>::iterator
1681 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1682 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1686 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1687 __y = __x, __x = _S_left(__x);
1689 __x = _S_right(__x);
1690 return iterator(__y);
1693 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1694 typename _Compare,
typename _Alloc>
1695 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1696 _Compare, _Alloc>::const_iterator
1697 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1698 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1699 const _Key& __k)
const 1702 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1703 __y = __x, __x = _S_left(__x);
1705 __x = _S_right(__x);
1706 return const_iterator(__y);
1709 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1710 typename _Compare,
typename _Alloc>
1711 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1712 _Compare, _Alloc>::iterator,
1713 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1714 _Compare, _Alloc>::iterator>
1715 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1716 equal_range(
const _Key& __k)
1718 _Link_type __x = _M_begin();
1719 _Base_ptr __y = _M_end();
1722 if (_M_impl._M_key_compare(_S_key(__x), __k))
1723 __x = _S_right(__x);
1724 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1725 __y = __x, __x = _S_left(__x);
1728 _Link_type __xu(__x);
1729 _Base_ptr __yu(__y);
1730 __y = __x, __x = _S_left(__x);
1731 __xu = _S_right(__xu);
1732 return pair<iterator,
1733 iterator>(_M_lower_bound(__x, __y, __k),
1734 _M_upper_bound(__xu, __yu, __k));
1737 return pair<iterator, iterator>(iterator(__y),
1741 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1742 typename _Compare,
typename _Alloc>
1743 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1744 _Compare, _Alloc>::const_iterator,
1745 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1746 _Compare, _Alloc>::const_iterator>
1747 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1748 equal_range(
const _Key& __k)
const 1750 _Const_Link_type __x = _M_begin();
1751 _Const_Base_ptr __y = _M_end();
1754 if (_M_impl._M_key_compare(_S_key(__x), __k))
1755 __x = _S_right(__x);
1756 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1757 __y = __x, __x = _S_left(__x);
1760 _Const_Link_type __xu(__x);
1761 _Const_Base_ptr __yu(__y);
1762 __y = __x, __x = _S_left(__x);
1763 __xu = _S_right(__xu);
1764 return pair<const_iterator,
1765 const_iterator>(_M_lower_bound(__x, __y, __k),
1766 _M_upper_bound(__xu, __yu, __k));
1769 return pair<const_iterator, const_iterator>(const_iterator(__y),
1770 const_iterator(__y));
1773 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1774 typename _Compare,
typename _Alloc>
1776 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1778 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
1782 if (__t._M_root() != 0)
1784 _M_root() = __t._M_root();
1785 _M_leftmost() = __t._M_leftmost();
1786 _M_rightmost() = __t._M_rightmost();
1787 _M_root()->_M_parent = _M_end();
1788 _M_impl._M_node_count = __t._M_impl._M_node_count;
1790 __t._M_impl._M_reset();
1793 else if (__t._M_root() == 0)
1795 __t._M_root() = _M_root();
1796 __t._M_leftmost() = _M_leftmost();
1797 __t._M_rightmost() = _M_rightmost();
1798 __t._M_root()->_M_parent = __t._M_end();
1799 __t._M_impl._M_node_count = _M_impl._M_node_count;
1805 std::swap(_M_root(),__t._M_root());
1806 std::swap(_M_leftmost(),__t._M_leftmost());
1807 std::swap(_M_rightmost(),__t._M_rightmost());
1809 _M_root()->_M_parent = _M_end();
1810 __t._M_root()->_M_parent = __t._M_end();
1811 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
1814 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
1816 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
1817 __t._M_get_Node_allocator());
1820 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1821 typename _Compare,
typename _Alloc>
1822 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1823 _Compare, _Alloc>::_Base_ptr,
1824 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1825 _Compare, _Alloc>::_Base_ptr>
1826 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1827 _M_get_insert_unique_pos(
const key_type& __k)
1829 typedef pair<_Base_ptr, _Base_ptr> _Res;
1830 _Link_type __x = _M_begin();
1831 _Base_ptr __y = _M_end();
1836 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
1837 __x = __comp ? _S_left(__x) : _S_right(__x);
1839 iterator __j = iterator(__y);
1843 return _Res(__x, __y);
1847 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
1848 return _Res(__x, __y);
1849 return _Res(__j._M_node, 0);
1852 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1853 typename _Compare,
typename _Alloc>
1854 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1855 _Compare, _Alloc>::_Base_ptr,
1856 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1857 _Compare, _Alloc>::_Base_ptr>
1858 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1859 _M_get_insert_equal_pos(
const key_type& __k)
1861 typedef pair<_Base_ptr, _Base_ptr> _Res;
1862 _Link_type __x = _M_begin();
1863 _Base_ptr __y = _M_end();
1867 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
1868 _S_left(__x) : _S_right(__x);
1870 return _Res(__x, __y);
1873 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1874 typename _Compare,
typename _Alloc>
1875 #if __cplusplus >= 201103L 1876 template<
typename _Arg>
1878 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1879 _Compare, _Alloc>::iterator,
bool>
1880 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1881 #if __cplusplus >= 201103L 1882 _M_insert_unique(_Arg&& __v)
1884 _M_insert_unique(
const _Val& __v)
1887 typedef pair<iterator, bool> _Res;
1888 pair<_Base_ptr, _Base_ptr> __res
1889 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
1893 _Alloc_node __an(*
this);
1894 return _Res(_M_insert_(__res.first, __res.second,
1895 _GLIBCXX_FORWARD(_Arg, __v), __an),
1899 return _Res(iterator(__res.first),
false);
1902 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1903 typename _Compare,
typename _Alloc>
1904 #if __cplusplus >= 201103L 1905 template<
typename _Arg>
1907 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1908 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1909 #if __cplusplus >= 201103L 1910 _M_insert_equal(_Arg&& __v)
1912 _M_insert_equal(
const _Val& __v)
1915 pair<_Base_ptr, _Base_ptr> __res
1916 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
1917 _Alloc_node __an(*
this);
1918 return _M_insert_(__res.first, __res.second,
1919 _GLIBCXX_FORWARD(_Arg, __v), __an);
1922 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1923 typename _Compare,
typename _Alloc>
1924 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1925 _Compare, _Alloc>::_Base_ptr,
1926 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1927 _Compare, _Alloc>::_Base_ptr>
1928 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1929 _M_get_insert_hint_unique_pos(const_iterator __position,
1930 const key_type& __k)
1932 iterator __pos = __position._M_const_cast();
1933 typedef pair<_Base_ptr, _Base_ptr> _Res;
1936 if (__pos._M_node == _M_end())
1939 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
1940 return _Res(0, _M_rightmost());
1942 return _M_get_insert_unique_pos(__k);
1944 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
1947 iterator __before = __pos;
1948 if (__pos._M_node == _M_leftmost())
1949 return _Res(_M_leftmost(), _M_leftmost());
1950 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
1952 if (_S_right(__before._M_node) == 0)
1953 return _Res(0, __before._M_node);
1955 return _Res(__pos._M_node, __pos._M_node);
1958 return _M_get_insert_unique_pos(__k);
1960 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
1963 iterator __after = __pos;
1964 if (__pos._M_node == _M_rightmost())
1965 return _Res(0, _M_rightmost());
1966 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
1968 if (_S_right(__pos._M_node) == 0)
1969 return _Res(0, __pos._M_node);
1971 return _Res(__after._M_node, __after._M_node);
1974 return _M_get_insert_unique_pos(__k);
1978 return _Res(__pos._M_node, 0);
1981 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1982 typename _Compare,
typename _Alloc>
1983 #if __cplusplus >= 201103L 1984 template<
typename _Arg,
typename _NodeGen>
1986 template<
typename _NodeGen>
1988 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1989 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1990 _M_insert_unique_(const_iterator __position,
1991 #
if __cplusplus >= 201103L
1996 _NodeGen& __node_gen)
1998 pair<_Base_ptr, _Base_ptr> __res
1999 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2002 return _M_insert_(__res.first, __res.second,
2003 _GLIBCXX_FORWARD(_Arg, __v),
2005 return iterator(__res.first);
2008 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2009 typename _Compare,
typename _Alloc>
2010 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2011 _Compare, _Alloc>::_Base_ptr,
2012 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2013 _Compare, _Alloc>::_Base_ptr>
2014 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2015 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2017 iterator __pos = __position._M_const_cast();
2018 typedef pair<_Base_ptr, _Base_ptr> _Res;
2021 if (__pos._M_node == _M_end())
2024 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2025 return _Res(0, _M_rightmost());
2027 return _M_get_insert_equal_pos(__k);
2029 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2032 iterator __before = __pos;
2033 if (__pos._M_node == _M_leftmost())
2034 return _Res(_M_leftmost(), _M_leftmost());
2035 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2037 if (_S_right(__before._M_node) == 0)
2038 return _Res(0, __before._M_node);
2040 return _Res(__pos._M_node, __pos._M_node);
2043 return _M_get_insert_equal_pos(__k);
2048 iterator __after = __pos;
2049 if (__pos._M_node == _M_rightmost())
2050 return _Res(0, _M_rightmost());
2051 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2053 if (_S_right(__pos._M_node) == 0)
2054 return _Res(0, __pos._M_node);
2056 return _Res(__after._M_node, __after._M_node);
2063 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2064 typename _Compare,
typename _Alloc>
2065 #if __cplusplus >= 201103L 2066 template<
typename _Arg,
typename _NodeGen>
2068 template<
typename _NodeGen>
2070 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2071 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2072 _M_insert_equal_(const_iterator __position,
2073 #
if __cplusplus >= 201103L
2078 _NodeGen& __node_gen)
2080 pair<_Base_ptr, _Base_ptr> __res
2081 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2084 return _M_insert_(__res.first, __res.second,
2085 _GLIBCXX_FORWARD(_Arg, __v),
2088 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2091 #if __cplusplus >= 201103L 2092 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2093 typename _Compare,
typename _Alloc>
2094 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2095 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2096 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2098 bool __insert_left = (__x != 0 || __p == _M_end()
2099 || _M_impl._M_key_compare(_S_key(__z),
2102 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2103 this->_M_impl._M_header);
2104 ++_M_impl._M_node_count;
2105 return iterator(__z);
2108 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2109 typename _Compare,
typename _Alloc>
2110 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2111 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2112 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2114 bool __insert_left = (__p == _M_end()
2115 || !_M_impl._M_key_compare(_S_key(__p),
2118 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2119 this->_M_impl._M_header);
2120 ++_M_impl._M_node_count;
2121 return iterator(__z);
2124 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2125 typename _Compare,
typename _Alloc>
2126 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2127 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2128 _M_insert_equal_lower_node(_Link_type __z)
2130 _Link_type __x = _M_begin();
2131 _Base_ptr __y = _M_end();
2135 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2136 _S_left(__x) : _S_right(__x);
2138 return _M_insert_lower_node(__y, __z);
2141 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2142 typename _Compare,
typename _Alloc>
2143 template<
typename... _Args>
2144 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2145 _Compare, _Alloc>::iterator,
bool>
2146 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2147 _M_emplace_unique(_Args&&... __args)
2149 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2153 typedef pair<iterator, bool> _Res;
2154 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2156 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2159 return _Res(iterator(__res.first),
false);
2164 __throw_exception_again;
2168 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2169 typename _Compare,
typename _Alloc>
2170 template<
typename... _Args>
2171 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2172 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2173 _M_emplace_equal(_Args&&... __args)
2175 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2179 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2180 return _M_insert_node(__res.first, __res.second, __z);
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_unique(const_iterator __pos, _Args&&... __args)
2196 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2200 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2203 return _M_insert_node(__res.first, __res.second, __z);
2206 return iterator(__res.first);
2211 __throw_exception_again;
2215 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2216 typename _Compare,
typename _Alloc>
2217 template<
typename... _Args>
2218 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2219 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2220 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2222 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2226 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2229 return _M_insert_node(__res.first, __res.second, __z);
2231 return _M_insert_equal_lower_node(__z);
2236 __throw_exception_again;
2241 template<
typename _Key,
typename _Val,
typename _KoV,
2242 typename _Cmp,
typename _Alloc>
2245 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
2246 _M_insert_unique(_II __first, _II __last)
2248 _Alloc_node __an(*
this);
2249 for (; __first != __last; ++__first)
2250 _M_insert_unique_(
end(), *__first, __an);
2253 template<
typename _Key,
typename _Val,
typename _KoV,
2254 typename _Cmp,
typename _Alloc>
2257 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
2258 _M_insert_equal(_II __first, _II __last)
2260 _Alloc_node __an(*
this);
2261 for (; __first != __last; ++__first)
2262 _M_insert_equal_(
end(), *__first, __an);
2265 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2266 typename _Compare,
typename _Alloc>
2268 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2269 _M_erase_aux(const_iterator __position)
2272 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
2273 (const_cast<_Base_ptr>(__position._M_node),
2274 this->_M_impl._M_header));
2276 --_M_impl._M_node_count;
2279 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2280 typename _Compare,
typename _Alloc>
2282 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2283 _M_erase_aux(const_iterator __first, const_iterator __last)
2285 if (__first ==
begin() && __last ==
end())
2288 while (__first != __last)
2292 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2293 typename _Compare,
typename _Alloc>
2294 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2295 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2296 erase(
const _Key& __x)
2298 pair<iterator, iterator> __p = equal_range(__x);
2299 const size_type __old_size =
size();
2300 erase(__p.first, __p.second);
2301 return __old_size -
size();
2304 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2305 typename _Compare,
typename _Alloc>
2307 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2308 erase(
const _Key* __first,
const _Key* __last)
2310 while (__first != __last)
2314 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2315 typename _Compare,
typename _Alloc>
2316 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2317 _Compare, _Alloc>::iterator
2318 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2319 find(
const _Key& __k)
2321 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2322 return (__j ==
end()
2323 || _M_impl._M_key_compare(__k,
2324 _S_key(__j._M_node))) ?
end() : __j;
2327 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2328 typename _Compare,
typename _Alloc>
2329 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2330 _Compare, _Alloc>::const_iterator
2331 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2332 find(
const _Key& __k)
const 2334 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2335 return (__j ==
end()
2336 || _M_impl._M_key_compare(__k,
2337 _S_key(__j._M_node))) ?
end() : __j;
2340 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2341 typename _Compare,
typename _Alloc>
2342 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2343 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2344 count(
const _Key& __k)
const 2346 pair<const_iterator, const_iterator> __p = equal_range(__k);
2351 _GLIBCXX_PURE
unsigned int 2352 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2353 const _Rb_tree_node_base* __root)
throw ();
2355 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2356 typename _Compare,
typename _Alloc>
2358 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const 2360 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2361 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2362 && this->_M_impl._M_header._M_left == _M_end()
2363 && this->_M_impl._M_header._M_right == _M_end();
2365 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2366 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2368 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
2369 _Const_Link_type __L = _S_left(__x);
2370 _Const_Link_type __R = _S_right(__x);
2372 if (__x->_M_color == _S_red)
2373 if ((__L && __L->_M_color == _S_red)
2374 || (__R && __R->_M_color == _S_red))
2377 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2379 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2382 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2386 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2388 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2393 _GLIBCXX_END_NAMESPACE_VERSION
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
Uniform interface to C++98 and C++11 allocators.
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 const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
size_type size() const
As per Table mumble.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
iterator begin()
As per Table mumble.
auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
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.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.