66 #if __cplusplus >= 201103L
70 namespace std _GLIBCXX_VISIBILITY(default)
72 _GLIBCXX_BEGIN_NAMESPACE_VERSION
90 enum _Rb_tree_color { _S_red =
false, _S_black =
true };
92 struct _Rb_tree_node_base
94 typedef _Rb_tree_node_base* _Base_ptr;
95 typedef const _Rb_tree_node_base* _Const_Base_ptr;
97 _Rb_tree_color _M_color;
103 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
105 while (__x->_M_left != 0) __x = __x->_M_left;
109 static _Const_Base_ptr
110 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
112 while (__x->_M_left != 0) __x = __x->_M_left;
117 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
119 while (__x->_M_right != 0) __x = __x->_M_right;
123 static _Const_Base_ptr
124 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
126 while (__x->_M_right != 0) __x = __x->_M_right;
131 template<
typename _Val>
132 struct _Rb_tree_node :
public _Rb_tree_node_base
134 typedef _Rb_tree_node<_Val>* _Link_type;
136 #if __cplusplus < 201103L
147 __gnu_cxx::__aligned_buffer<_Val> _M_storage;
151 {
return _M_storage._M_ptr(); }
155 {
return _M_storage._M_ptr(); }
159 _GLIBCXX_PURE _Rb_tree_node_base*
160 _Rb_tree_increment(_Rb_tree_node_base* __x)
throw ();
162 _GLIBCXX_PURE
const _Rb_tree_node_base*
163 _Rb_tree_increment(
const _Rb_tree_node_base* __x)
throw ();
165 _GLIBCXX_PURE _Rb_tree_node_base*
166 _Rb_tree_decrement(_Rb_tree_node_base* __x)
throw ();
168 _GLIBCXX_PURE
const _Rb_tree_node_base*
169 _Rb_tree_decrement(
const _Rb_tree_node_base* __x)
throw ();
171 template<
typename _Tp>
172 struct _Rb_tree_iterator
174 typedef _Tp value_type;
175 typedef _Tp& reference;
176 typedef _Tp* pointer;
178 typedef bidirectional_iterator_tag iterator_category;
179 typedef ptrdiff_t difference_type;
181 typedef _Rb_tree_iterator<_Tp> _Self;
182 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
183 typedef _Rb_tree_node<_Tp>* _Link_type;
185 _Rb_tree_iterator() _GLIBCXX_NOEXCEPT
189 _Rb_tree_iterator(_Link_type __x) _GLIBCXX_NOEXCEPT
193 operator*() const _GLIBCXX_NOEXCEPT
194 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
197 operator->() const _GLIBCXX_NOEXCEPT
198 {
return static_cast<_Link_type
> (_M_node)->_M_valptr(); }
201 operator++() _GLIBCXX_NOEXCEPT
203 _M_node = _Rb_tree_increment(_M_node);
208 operator++(
int) _GLIBCXX_NOEXCEPT
211 _M_node = _Rb_tree_increment(_M_node);
216 operator--() _GLIBCXX_NOEXCEPT
218 _M_node = _Rb_tree_decrement(_M_node);
223 operator--(
int) _GLIBCXX_NOEXCEPT
226 _M_node = _Rb_tree_decrement(_M_node);
231 operator==(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
232 {
return _M_node == __x._M_node; }
235 operator!=(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
236 {
return _M_node != __x._M_node; }
241 template<
typename _Tp>
242 struct _Rb_tree_const_iterator
244 typedef _Tp value_type;
245 typedef const _Tp& reference;
246 typedef const _Tp* pointer;
248 typedef _Rb_tree_iterator<_Tp> iterator;
250 typedef bidirectional_iterator_tag iterator_category;
251 typedef ptrdiff_t difference_type;
253 typedef _Rb_tree_const_iterator<_Tp> _Self;
254 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
255 typedef const _Rb_tree_node<_Tp>* _Link_type;
257 _Rb_tree_const_iterator() _GLIBCXX_NOEXCEPT
261 _Rb_tree_const_iterator(_Link_type __x) _GLIBCXX_NOEXCEPT
264 _Rb_tree_const_iterator(
const iterator& __it) _GLIBCXX_NOEXCEPT
265 : _M_node(__it._M_node) { }
268 _M_const_cast() const _GLIBCXX_NOEXCEPT
269 {
return iterator(static_cast<typename iterator::_Link_type>
270 (const_cast<typename iterator::_Base_ptr>(_M_node))); }
273 operator*() const _GLIBCXX_NOEXCEPT
274 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
277 operator->() const _GLIBCXX_NOEXCEPT
278 {
return static_cast<_Link_type
>(_M_node)->_M_valptr(); }
281 operator++() _GLIBCXX_NOEXCEPT
283 _M_node = _Rb_tree_increment(_M_node);
288 operator++(
int) _GLIBCXX_NOEXCEPT
291 _M_node = _Rb_tree_increment(_M_node);
296 operator--() _GLIBCXX_NOEXCEPT
298 _M_node = _Rb_tree_decrement(_M_node);
303 operator--(
int) _GLIBCXX_NOEXCEPT
306 _M_node = _Rb_tree_decrement(_M_node);
311 operator==(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
312 {
return _M_node == __x._M_node; }
315 operator!=(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
316 {
return _M_node != __x._M_node; }
321 template<
typename _Val>
323 operator==(
const _Rb_tree_iterator<_Val>& __x,
324 const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
325 {
return __x._M_node == __y._M_node; }
327 template<
typename _Val>
329 operator!=(
const _Rb_tree_iterator<_Val>& __x,
330 const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
331 {
return __x._M_node != __y._M_node; }
334 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
335 _Rb_tree_node_base* __x,
336 _Rb_tree_node_base* __p,
337 _Rb_tree_node_base& __header)
throw ();
340 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
341 _Rb_tree_node_base& __header)
throw ();
344 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
345 typename _Compare,
typename _Alloc = allocator<_Val> >
349 rebind<_Rb_tree_node<_Val> >::other _Node_allocator;
354 typedef _Rb_tree_node_base* _Base_ptr;
355 typedef const _Rb_tree_node_base* _Const_Base_ptr;
358 typedef _Key key_type;
359 typedef _Val value_type;
360 typedef value_type* pointer;
361 typedef const value_type* const_pointer;
362 typedef value_type& reference;
363 typedef const value_type& const_reference;
364 typedef _Rb_tree_node<_Val>* _Link_type;
365 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
366 typedef size_t size_type;
367 typedef ptrdiff_t difference_type;
368 typedef _Alloc allocator_type;
371 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
372 {
return *
static_cast<_Node_allocator*
>(&this->_M_impl); }
374 const _Node_allocator&
375 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
376 {
return *
static_cast<const _Node_allocator*
>(&this->_M_impl); }
379 get_allocator() const _GLIBCXX_NOEXCEPT
380 {
return allocator_type(_M_get_Node_allocator()); }
388 _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
391 #if __cplusplus < 201103L
393 _M_create_node(
const value_type& __x)
395 _Link_type __tmp = _M_get_node();
397 { get_allocator().construct(__tmp->_M_valptr(), __x); }
401 __throw_exception_again;
407 _M_destroy_node(_Link_type __p)
409 get_allocator().destroy(__p->_M_valptr());
413 template<
typename... _Args>
415 _M_create_node(_Args&&... __args)
417 _Link_type __tmp = _M_get_node();
420 ::new(__tmp) _Rb_tree_node<_Val>;
421 _Alloc_traits::construct(_M_get_Node_allocator(),
428 __throw_exception_again;
434 _M_destroy_node(_Link_type __p) noexcept
436 _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr());
437 __p->~_Rb_tree_node<_Val>();
443 _M_clone_node(_Const_Link_type __x)
445 _Link_type __tmp = _M_create_node(*__x->_M_valptr());
446 __tmp->_M_color = __x->_M_color;
453 template<
typename _Key_compare,
454 bool _Is_pod_comparator = __is_pod(_Key_compare)>
455 struct _Rb_tree_impl :
public _Node_allocator
457 _Key_compare _M_key_compare;
458 _Rb_tree_node_base _M_header;
459 size_type _M_node_count;
462 : _Node_allocator(), _M_key_compare(), _M_header(),
466 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
467 : _Node_allocator(__a), _M_key_compare(__comp), _M_header(),
471 #if __cplusplus >= 201103L
472 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
473 : _Node_allocator(
std::
move(__a)), _M_key_compare(__comp),
474 _M_header(), _M_node_count(0)
482 this->_M_header._M_color = _S_red;
483 this->_M_header._M_parent = 0;
484 this->_M_header._M_left = &this->_M_header;
485 this->_M_header._M_right = &this->_M_header;
489 _Rb_tree_impl<_Compare> _M_impl;
493 _M_root() _GLIBCXX_NOEXCEPT
494 {
return this->_M_impl._M_header._M_parent; }
497 _M_root() const _GLIBCXX_NOEXCEPT
498 {
return this->_M_impl._M_header._M_parent; }
501 _M_leftmost() _GLIBCXX_NOEXCEPT
502 {
return this->_M_impl._M_header._M_left; }
505 _M_leftmost() const _GLIBCXX_NOEXCEPT
506 {
return this->_M_impl._M_header._M_left; }
509 _M_rightmost() _GLIBCXX_NOEXCEPT
510 {
return this->_M_impl._M_header._M_right; }
513 _M_rightmost() const _GLIBCXX_NOEXCEPT
514 {
return this->_M_impl._M_header._M_right; }
517 _M_begin() _GLIBCXX_NOEXCEPT
518 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
521 _M_begin() const _GLIBCXX_NOEXCEPT
523 return static_cast<_Const_Link_type
>
524 (this->_M_impl._M_header._M_parent);
528 _M_end() _GLIBCXX_NOEXCEPT
529 {
return reinterpret_cast<_Link_type
>(&this->_M_impl._M_header); }
532 _M_end() const _GLIBCXX_NOEXCEPT
533 {
return reinterpret_cast<_Const_Link_type
>(&this->_M_impl._M_header); }
535 static const_reference
536 _S_value(_Const_Link_type __x)
537 {
return *__x->_M_valptr(); }
540 _S_key(_Const_Link_type __x)
541 {
return _KeyOfValue()(_S_value(__x)); }
544 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
545 {
return static_cast<_Link_type
>(__x->_M_left); }
547 static _Const_Link_type
548 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
549 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
552 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
553 {
return static_cast<_Link_type
>(__x->_M_right); }
555 static _Const_Link_type
556 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
557 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
559 static const_reference
560 _S_value(_Const_Base_ptr __x)
561 {
return *
static_cast<_Const_Link_type
>(__x)->_M_valptr(); }
564 _S_key(_Const_Base_ptr __x)
565 {
return _KeyOfValue()(_S_value(__x)); }
568 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
569 {
return _Rb_tree_node_base::_S_minimum(__x); }
571 static _Const_Base_ptr
572 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
573 {
return _Rb_tree_node_base::_S_minimum(__x); }
576 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
577 {
return _Rb_tree_node_base::_S_maximum(__x); }
579 static _Const_Base_ptr
580 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
581 {
return _Rb_tree_node_base::_S_maximum(__x); }
584 typedef _Rb_tree_iterator<value_type> iterator;
585 typedef _Rb_tree_const_iterator<value_type> const_iterator;
591 pair<_Base_ptr, _Base_ptr>
592 _M_get_insert_unique_pos(
const key_type& __k);
594 pair<_Base_ptr, _Base_ptr>
595 _M_get_insert_equal_pos(
const key_type& __k);
597 pair<_Base_ptr, _Base_ptr>
598 _M_get_insert_hint_unique_pos(const_iterator __pos,
599 const key_type& __k);
601 pair<_Base_ptr, _Base_ptr>
602 _M_get_insert_hint_equal_pos(const_iterator __pos,
603 const key_type& __k);
605 #if __cplusplus >= 201103L
606 template<
typename _Arg>
608 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v);
611 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
613 template<
typename _Arg>
615 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
617 template<
typename _Arg>
619 _M_insert_equal_lower(_Arg&& __x);
622 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
625 _M_insert_equal_lower_node(_Link_type __z);
628 _M_insert_(_Base_ptr __x, _Base_ptr __y,
629 const value_type& __v);
634 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
637 _M_insert_equal_lower(
const value_type& __x);
641 _M_copy(_Const_Link_type __x, _Link_type __p);
644 _M_erase(_Link_type __x);
647 _M_lower_bound(_Link_type __x, _Link_type __y,
651 _M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
652 const _Key& __k)
const;
655 _M_upper_bound(_Link_type __x, _Link_type __y,
659 _M_upper_bound(_Const_Link_type __x, _Const_Link_type __y,
660 const _Key& __k)
const;
666 _Rb_tree(
const _Compare& __comp,
667 const allocator_type& __a = allocator_type())
668 : _M_impl(__comp, _Node_allocator(__a)) { }
670 _Rb_tree(
const _Rb_tree& __x)
671 : _M_impl(__x._M_impl._M_key_compare,
672 _Alloc_traits::_S_select_on_copy(__x._M_get_Node_allocator()))
674 if (__x._M_root() != 0)
676 _M_root() = _M_copy(__x._M_begin(), _M_end());
677 _M_leftmost() = _S_minimum(_M_root());
678 _M_rightmost() = _S_maximum(_M_root());
679 _M_impl._M_node_count = __x._M_impl._M_node_count;
683 #if __cplusplus >= 201103L
684 _Rb_tree(
const allocator_type& __a)
685 : _M_impl(_Compare(), _Node_allocator(__a))
688 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
689 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
691 if (__x._M_root() != 0)
693 _M_root() = _M_copy(__x._M_begin(), _M_end());
694 _M_leftmost() = _S_minimum(_M_root());
695 _M_rightmost() = _S_maximum(_M_root());
696 _M_impl._M_node_count = __x._M_impl._M_node_count;
700 _Rb_tree(_Rb_tree&& __x)
701 : _M_impl(__x._M_impl._M_key_compare, __x._M_get_Node_allocator())
703 if (__x._M_root() != 0)
704 _M_move_data(__x, std::true_type());
707 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
708 : _Rb_tree(
std::
move(__x), _Node_allocator(__a))
711 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a);
714 ~_Rb_tree() _GLIBCXX_NOEXCEPT
715 { _M_erase(_M_begin()); }
718 operator=(
const _Rb_tree& __x);
723 {
return _M_impl._M_key_compare; }
726 begin() _GLIBCXX_NOEXCEPT
728 return iterator(static_cast<_Link_type>
729 (this->_M_impl._M_header._M_left));
733 begin() const _GLIBCXX_NOEXCEPT
735 return const_iterator(static_cast<_Const_Link_type>
736 (this->_M_impl._M_header._M_left));
740 end() _GLIBCXX_NOEXCEPT
741 {
return iterator(static_cast<_Link_type>(&this->_M_impl._M_header)); }
744 end() const _GLIBCXX_NOEXCEPT
746 return const_iterator(static_cast<_Const_Link_type>
747 (&this->_M_impl._M_header));
751 rbegin() _GLIBCXX_NOEXCEPT
752 {
return reverse_iterator(
end()); }
754 const_reverse_iterator
755 rbegin() const _GLIBCXX_NOEXCEPT
756 {
return const_reverse_iterator(
end()); }
759 rend() _GLIBCXX_NOEXCEPT
760 {
return reverse_iterator(
begin()); }
762 const_reverse_iterator
763 rend() const _GLIBCXX_NOEXCEPT
764 {
return const_reverse_iterator(
begin()); }
767 empty() const _GLIBCXX_NOEXCEPT
768 {
return _M_impl._M_node_count == 0; }
771 size() const _GLIBCXX_NOEXCEPT
772 {
return _M_impl._M_node_count; }
775 max_size() const _GLIBCXX_NOEXCEPT
779 #if __cplusplus >= 201103L
780 swap(_Rb_tree& __t) noexcept(_Alloc_traits::_S_nothrow_swap());
786 #if __cplusplus >= 201103L
787 template<
typename _Arg>
789 _M_insert_unique(_Arg&& __x);
791 template<
typename _Arg>
793 _M_insert_equal(_Arg&& __x);
795 template<
typename _Arg>
797 _M_insert_unique_(const_iterator __position, _Arg&& __x);
799 template<
typename _Arg>
801 _M_insert_equal_(const_iterator __position, _Arg&& __x);
803 template<
typename... _Args>
805 _M_emplace_unique(_Args&&... __args);
807 template<
typename... _Args>
809 _M_emplace_equal(_Args&&... __args);
811 template<
typename... _Args>
813 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
815 template<
typename... _Args>
817 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
820 _M_insert_unique(
const value_type& __x);
823 _M_insert_equal(
const value_type& __x);
826 _M_insert_unique_(const_iterator __position,
const value_type& __x);
829 _M_insert_equal_(const_iterator __position,
const value_type& __x);
832 template<
typename _InputIterator>
834 _M_insert_unique(_InputIterator __first, _InputIterator __last);
836 template<
typename _InputIterator>
838 _M_insert_equal(_InputIterator __first, _InputIterator __last);
842 _M_erase_aux(const_iterator __position);
845 _M_erase_aux(const_iterator __first, const_iterator __last);
848 #if __cplusplus >= 201103L
851 _GLIBCXX_ABI_TAG_CXX11
853 erase(const_iterator __position)
855 const_iterator __result = __position;
857 _M_erase_aux(__position);
858 return __result._M_const_cast();
862 _GLIBCXX_ABI_TAG_CXX11
864 erase(iterator __position)
866 iterator __result = __position;
868 _M_erase_aux(__position);
873 erase(iterator __position)
874 { _M_erase_aux(__position); }
877 erase(const_iterator __position)
878 { _M_erase_aux(__position); }
881 erase(
const key_type& __x);
883 #if __cplusplus >= 201103L
886 _GLIBCXX_ABI_TAG_CXX11
888 erase(const_iterator __first, const_iterator __last)
890 _M_erase_aux(__first, __last);
891 return __last._M_const_cast();
895 erase(iterator __first, iterator __last)
896 { _M_erase_aux(__first, __last); }
899 erase(const_iterator __first, const_iterator __last)
900 { _M_erase_aux(__first, __last); }
903 erase(
const key_type* __first,
const key_type* __last);
906 clear() _GLIBCXX_NOEXCEPT
908 _M_erase(_M_begin());
909 _M_leftmost() = _M_end();
911 _M_rightmost() = _M_end();
912 _M_impl._M_node_count = 0;
917 find(
const key_type& __k);
920 find(
const key_type& __k)
const;
923 count(
const key_type& __k)
const;
926 lower_bound(
const key_type& __k)
927 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
930 lower_bound(
const key_type& __k)
const
931 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
934 upper_bound(
const key_type& __k)
935 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
938 upper_bound(
const key_type& __k)
const
939 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
941 pair<iterator, iterator>
942 equal_range(
const key_type& __k);
944 pair<const_iterator, const_iterator>
945 equal_range(
const key_type& __k)
const;
951 #if __cplusplus >= 201103L
953 _M_move_assign(_Rb_tree&);
958 _M_move_data(_Rb_tree&, std::true_type);
963 _M_move_data(_Rb_tree&, std::false_type);
967 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
968 typename _Compare,
typename _Alloc>
970 operator==(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
971 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
973 return __x.size() == __y.size()
974 &&
std::equal(__x.begin(), __x.end(), __y.begin());
977 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
978 typename _Compare,
typename _Alloc>
980 operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
981 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
984 __y.begin(), __y.end());
987 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
988 typename _Compare,
typename _Alloc>
990 operator!=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
991 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
992 {
return !(__x == __y); }
994 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
995 typename _Compare,
typename _Alloc>
997 operator>(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
998 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
999 {
return __y < __x; }
1001 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1002 typename _Compare,
typename _Alloc>
1004 operator<=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1005 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1006 {
return !(__y < __x); }
1008 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1009 typename _Compare,
typename _Alloc>
1011 operator>=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1012 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1013 {
return !(__x < __y); }
1015 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1016 typename _Compare,
typename _Alloc>
1018 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1019 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1022 #if __cplusplus >= 201103L
1023 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1024 typename _Compare,
typename _Alloc>
1025 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1026 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
1027 : _M_impl(__x._M_impl._M_key_compare,
std::
move(__a))
1029 using __eq = integral_constant<bool, _Alloc_traits::_S_always_equal()>;
1030 if (__x._M_root() != 0)
1031 _M_move_data(__x, __eq());
1034 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1035 typename _Compare,
typename _Alloc>
1037 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1038 _M_move_data(_Rb_tree& __x, std::true_type)
1040 _M_root() = __x._M_root();
1041 _M_leftmost() = __x._M_leftmost();
1042 _M_rightmost() = __x._M_rightmost();
1043 _M_root()->_M_parent = _M_end();
1046 __x._M_leftmost() = __x._M_end();
1047 __x._M_rightmost() = __x._M_end();
1049 this->_M_impl._M_node_count = __x._M_impl._M_node_count;
1050 __x._M_impl._M_node_count = 0;
1053 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1054 typename _Compare,
typename _Alloc>
1056 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1057 _M_move_data(_Rb_tree& __x, std::false_type)
1059 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1060 _M_move_data(__x, std::true_type());
1063 _M_root() = _M_copy(__x._M_begin(), _M_end());
1064 _M_leftmost() = _S_minimum(_M_root());
1065 _M_rightmost() = _S_maximum(_M_root());
1066 _M_impl._M_node_count = __x._M_impl._M_node_count;
1070 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1071 typename _Compare,
typename _Alloc>
1073 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1074 _M_move_assign(_Rb_tree& __x)
1076 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1077 if (_Alloc_traits::_S_propagate_on_move_assign()
1078 || _Alloc_traits::_S_always_equal()
1079 || _M_get_Node_allocator() == __x._M_get_Node_allocator())
1082 if (__x._M_root() != 0)
1083 _M_move_data(__x, std::true_type());
1084 std::__alloc_on_move(_M_get_Node_allocator(),
1085 __x._M_get_Node_allocator());
1092 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1093 typename _Compare,
typename _Alloc>
1094 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1095 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1096 operator=(
const _Rb_tree& __x)
1102 #if __cplusplus >= 201103L
1103 if (_Alloc_traits::_S_propagate_on_copy_assign())
1105 auto& __this_alloc = this->_M_get_Node_allocator();
1106 auto& __that_alloc = __x._M_get_Node_allocator();
1107 if (!_Alloc_traits::_S_always_equal()
1108 && __this_alloc != __that_alloc)
1110 std::__alloc_on_copy(__this_alloc, __that_alloc);
1114 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1115 if (__x._M_root() != 0)
1117 _M_root() = _M_copy(__x._M_begin(), _M_end());
1118 _M_leftmost() = _S_minimum(_M_root());
1119 _M_rightmost() = _S_maximum(_M_root());
1120 _M_impl._M_node_count = __x._M_impl._M_node_count;
1126 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1127 typename _Compare,
typename _Alloc>
1128 #if __cplusplus >= 201103L
1129 template<
typename _Arg>
1131 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1132 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1133 #if __cplusplus >= 201103L
1134 _M_insert_(_Base_ptr __x, _Base_ptr __p, _Arg&& __v)
1136 _M_insert_(_Base_ptr __x, _Base_ptr __p,
const _Val& __v)
1139 bool __insert_left = (__x != 0 || __p == _M_end()
1140 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1143 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1145 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1146 this->_M_impl._M_header);
1147 ++_M_impl._M_node_count;
1148 return iterator(__z);
1151 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1152 typename _Compare,
typename _Alloc>
1153 #if __cplusplus >= 201103L
1154 template<
typename _Arg>
1156 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1157 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1158 #if __cplusplus >= 201103L
1159 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1161 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1164 bool __insert_left = (__p == _M_end()
1165 || !_M_impl._M_key_compare(_S_key(__p),
1166 _KeyOfValue()(__v)));
1168 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1170 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1171 this->_M_impl._M_header);
1172 ++_M_impl._M_node_count;
1173 return iterator(__z);
1176 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1177 typename _Compare,
typename _Alloc>
1178 #if __cplusplus >= 201103L
1179 template<
typename _Arg>
1181 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1182 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1183 #if __cplusplus >= 201103L
1184 _M_insert_equal_lower(_Arg&& __v)
1186 _M_insert_equal_lower(
const _Val& __v)
1189 _Link_type __x = _M_begin();
1190 _Link_type __y = _M_end();
1194 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1195 _S_left(__x) : _S_right(__x);
1197 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1200 template<
typename _Key,
typename _Val,
typename _KoV,
1201 typename _Compare,
typename _Alloc>
1202 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1203 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1204 _M_copy(_Const_Link_type __x, _Link_type __p)
1207 _Link_type __top = _M_clone_node(__x);
1208 __top->_M_parent = __p;
1213 __top->_M_right = _M_copy(_S_right(__x), __top);
1219 _Link_type __y = _M_clone_node(__x);
1221 __y->_M_parent = __p;
1223 __y->_M_right = _M_copy(_S_right(__x), __y);
1231 __throw_exception_again;
1236 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1237 typename _Compare,
typename _Alloc>
1239 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1240 _M_erase(_Link_type __x)
1245 _M_erase(_S_right(__x));
1246 _Link_type __y = _S_left(__x);
1247 _M_destroy_node(__x);
1252 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1253 typename _Compare,
typename _Alloc>
1254 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1255 _Compare, _Alloc>::iterator
1256 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1257 _M_lower_bound(_Link_type __x, _Link_type __y,
1261 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1262 __y = __x, __x = _S_left(__x);
1264 __x = _S_right(__x);
1265 return iterator(__y);
1268 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1269 typename _Compare,
typename _Alloc>
1270 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1271 _Compare, _Alloc>::const_iterator
1272 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1273 _M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
1274 const _Key& __k)
const
1277 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1278 __y = __x, __x = _S_left(__x);
1280 __x = _S_right(__x);
1281 return const_iterator(__y);
1284 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1285 typename _Compare,
typename _Alloc>
1286 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1287 _Compare, _Alloc>::iterator
1288 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1289 _M_upper_bound(_Link_type __x, _Link_type __y,
1293 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1294 __y = __x, __x = _S_left(__x);
1296 __x = _S_right(__x);
1297 return iterator(__y);
1300 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1301 typename _Compare,
typename _Alloc>
1302 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1303 _Compare, _Alloc>::const_iterator
1304 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1305 _M_upper_bound(_Const_Link_type __x, _Const_Link_type __y,
1306 const _Key& __k)
const
1309 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1310 __y = __x, __x = _S_left(__x);
1312 __x = _S_right(__x);
1313 return const_iterator(__y);
1316 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1317 typename _Compare,
typename _Alloc>
1318 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1319 _Compare, _Alloc>::iterator,
1320 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1321 _Compare, _Alloc>::iterator>
1322 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1323 equal_range(
const _Key& __k)
1325 _Link_type __x = _M_begin();
1326 _Link_type __y = _M_end();
1329 if (_M_impl._M_key_compare(_S_key(__x), __k))
1330 __x = _S_right(__x);
1331 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1332 __y = __x, __x = _S_left(__x);
1335 _Link_type __xu(__x), __yu(__y);
1336 __y = __x, __x = _S_left(__x);
1337 __xu = _S_right(__xu);
1338 return pair<iterator,
1339 iterator>(_M_lower_bound(__x, __y, __k),
1340 _M_upper_bound(__xu, __yu, __k));
1343 return pair<iterator, iterator>(iterator(__y),
1347 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1348 typename _Compare,
typename _Alloc>
1349 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1350 _Compare, _Alloc>::const_iterator,
1351 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1352 _Compare, _Alloc>::const_iterator>
1353 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1354 equal_range(
const _Key& __k)
const
1356 _Const_Link_type __x = _M_begin();
1357 _Const_Link_type __y = _M_end();
1360 if (_M_impl._M_key_compare(_S_key(__x), __k))
1361 __x = _S_right(__x);
1362 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1363 __y = __x, __x = _S_left(__x);
1366 _Const_Link_type __xu(__x), __yu(__y);
1367 __y = __x, __x = _S_left(__x);
1368 __xu = _S_right(__xu);
1369 return pair<const_iterator,
1370 const_iterator>(_M_lower_bound(__x, __y, __k),
1371 _M_upper_bound(__xu, __yu, __k));
1374 return pair<const_iterator, const_iterator>(const_iterator(__y),
1375 const_iterator(__y));
1378 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1379 typename _Compare,
typename _Alloc>
1381 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1382 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __t)
1383 #if __cplusplus >= 201103L
1384 noexcept(_Alloc_traits::_S_nothrow_swap())
1389 if (__t._M_root() != 0)
1391 _M_root() = __t._M_root();
1392 _M_leftmost() = __t._M_leftmost();
1393 _M_rightmost() = __t._M_rightmost();
1394 _M_root()->_M_parent = _M_end();
1397 __t._M_leftmost() = __t._M_end();
1398 __t._M_rightmost() = __t._M_end();
1401 else if (__t._M_root() == 0)
1403 __t._M_root() = _M_root();
1404 __t._M_leftmost() = _M_leftmost();
1405 __t._M_rightmost() = _M_rightmost();
1406 __t._M_root()->_M_parent = __t._M_end();
1409 _M_leftmost() = _M_end();
1410 _M_rightmost() = _M_end();
1415 std::swap(_M_leftmost(),__t._M_leftmost());
1416 std::swap(_M_rightmost(),__t._M_rightmost());
1418 _M_root()->_M_parent = _M_end();
1419 __t._M_root()->_M_parent = __t._M_end();
1422 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
1423 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
1425 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
1426 __t._M_get_Node_allocator());
1429 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1430 typename _Compare,
typename _Alloc>
1431 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1432 _Compare, _Alloc>::_Base_ptr,
1433 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1434 _Compare, _Alloc>::_Base_ptr>
1435 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1436 _M_get_insert_unique_pos(
const key_type& __k)
1438 typedef pair<_Base_ptr, _Base_ptr> _Res;
1439 _Link_type __x = _M_begin();
1440 _Link_type __y = _M_end();
1445 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
1446 __x = __comp ? _S_left(__x) : _S_right(__x);
1448 iterator __j = iterator(__y);
1452 return _Res(__x, __y);
1456 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
1457 return _Res(__x, __y);
1458 return _Res(__j._M_node, 0);
1461 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1462 typename _Compare,
typename _Alloc>
1463 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1464 _Compare, _Alloc>::_Base_ptr,
1465 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1466 _Compare, _Alloc>::_Base_ptr>
1467 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1468 _M_get_insert_equal_pos(
const key_type& __k)
1470 typedef pair<_Base_ptr, _Base_ptr> _Res;
1471 _Link_type __x = _M_begin();
1472 _Link_type __y = _M_end();
1476 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
1477 _S_left(__x) : _S_right(__x);
1479 return _Res(__x, __y);
1482 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1483 typename _Compare,
typename _Alloc>
1484 #if __cplusplus >= 201103L
1485 template<
typename _Arg>
1487 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1488 _Compare, _Alloc>::iterator,
bool>
1489 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1490 #if __cplusplus >= 201103L
1491 _M_insert_unique(_Arg&& __v)
1493 _M_insert_unique(
const _Val& __v)
1496 typedef pair<iterator, bool> _Res;
1497 pair<_Base_ptr, _Base_ptr> __res
1498 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
1501 return _Res(_M_insert_(__res.first, __res.second,
1502 _GLIBCXX_FORWARD(_Arg, __v)),
1505 return _Res(iterator(static_cast<_Link_type>(__res.first)),
false);
1508 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1509 typename _Compare,
typename _Alloc>
1510 #if __cplusplus >= 201103L
1511 template<
typename _Arg>
1513 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1514 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1515 #if __cplusplus >= 201103L
1516 _M_insert_equal(_Arg&& __v)
1518 _M_insert_equal(
const _Val& __v)
1521 pair<_Base_ptr, _Base_ptr> __res
1522 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
1523 return _M_insert_(__res.first, __res.second, _GLIBCXX_FORWARD(_Arg, __v));
1526 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1527 typename _Compare,
typename _Alloc>
1528 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1529 _Compare, _Alloc>::_Base_ptr,
1530 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1531 _Compare, _Alloc>::_Base_ptr>
1532 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1533 _M_get_insert_hint_unique_pos(const_iterator __position,
1534 const key_type& __k)
1536 iterator __pos = __position._M_const_cast();
1537 typedef pair<_Base_ptr, _Base_ptr> _Res;
1540 if (__pos._M_node == _M_end())
1543 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
1544 return _Res(0, _M_rightmost());
1546 return _M_get_insert_unique_pos(__k);
1548 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
1551 iterator __before = __pos;
1552 if (__pos._M_node == _M_leftmost())
1553 return _Res(_M_leftmost(), _M_leftmost());
1554 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
1556 if (_S_right(__before._M_node) == 0)
1557 return _Res(0, __before._M_node);
1559 return _Res(__pos._M_node, __pos._M_node);
1562 return _M_get_insert_unique_pos(__k);
1564 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
1567 iterator __after = __pos;
1568 if (__pos._M_node == _M_rightmost())
1569 return _Res(0, _M_rightmost());
1570 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
1572 if (_S_right(__pos._M_node) == 0)
1573 return _Res(0, __pos._M_node);
1575 return _Res(__after._M_node, __after._M_node);
1578 return _M_get_insert_unique_pos(__k);
1582 return _Res(__pos._M_node, 0);
1585 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1586 typename _Compare,
typename _Alloc>
1587 #if __cplusplus >= 201103L
1588 template<
typename _Arg>
1590 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1591 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1592 #if __cplusplus >= 201103L
1593 _M_insert_unique_(const_iterator __position, _Arg&& __v)
1595 _M_insert_unique_(const_iterator __position,
const _Val& __v)
1598 pair<_Base_ptr, _Base_ptr> __res
1599 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
1602 return _M_insert_(__res.first, __res.second,
1603 _GLIBCXX_FORWARD(_Arg, __v));
1604 return iterator(static_cast<_Link_type>(__res.first));
1607 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1608 typename _Compare,
typename _Alloc>
1609 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1610 _Compare, _Alloc>::_Base_ptr,
1611 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1612 _Compare, _Alloc>::_Base_ptr>
1613 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1614 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
1616 iterator __pos = __position._M_const_cast();
1617 typedef pair<_Base_ptr, _Base_ptr> _Res;
1620 if (__pos._M_node == _M_end())
1623 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
1624 return _Res(0, _M_rightmost());
1626 return _M_get_insert_equal_pos(__k);
1628 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
1631 iterator __before = __pos;
1632 if (__pos._M_node == _M_leftmost())
1633 return _Res(_M_leftmost(), _M_leftmost());
1634 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
1636 if (_S_right(__before._M_node) == 0)
1637 return _Res(0, __before._M_node);
1639 return _Res(__pos._M_node, __pos._M_node);
1642 return _M_get_insert_equal_pos(__k);
1647 iterator __after = __pos;
1648 if (__pos._M_node == _M_rightmost())
1649 return _Res(0, _M_rightmost());
1650 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
1652 if (_S_right(__pos._M_node) == 0)
1653 return _Res(0, __pos._M_node);
1655 return _Res(__after._M_node, __after._M_node);
1662 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1663 typename _Compare,
typename _Alloc>
1664 #if __cplusplus >= 201103L
1665 template<
typename _Arg>
1667 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1668 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1669 #if __cplusplus >= 201103L
1670 _M_insert_equal_(const_iterator __position, _Arg&& __v)
1672 _M_insert_equal_(const_iterator __position,
const _Val& __v)
1675 pair<_Base_ptr, _Base_ptr> __res
1676 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
1679 return _M_insert_(__res.first, __res.second,
1680 _GLIBCXX_FORWARD(_Arg, __v));
1682 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
1685 #if __cplusplus >= 201103L
1686 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1687 typename _Compare,
typename _Alloc>
1688 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1689 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1690 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
1692 bool __insert_left = (__x != 0 || __p == _M_end()
1693 || _M_impl._M_key_compare(_S_key(__z),
1696 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1697 this->_M_impl._M_header);
1698 ++_M_impl._M_node_count;
1699 return iterator(__z);
1702 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1703 typename _Compare,
typename _Alloc>
1704 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1705 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1706 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
1708 bool __insert_left = (__p == _M_end()
1709 || !_M_impl._M_key_compare(_S_key(__p),
1712 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1713 this->_M_impl._M_header);
1714 ++_M_impl._M_node_count;
1715 return iterator(__z);
1718 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1719 typename _Compare,
typename _Alloc>
1720 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1721 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1722 _M_insert_equal_lower_node(_Link_type __z)
1724 _Link_type __x = _M_begin();
1725 _Link_type __y = _M_end();
1729 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
1730 _S_left(__x) : _S_right(__x);
1732 return _M_insert_lower_node(__y, __z);
1735 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1736 typename _Compare,
typename _Alloc>
1737 template<
typename... _Args>
1738 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1739 _Compare, _Alloc>::iterator,
bool>
1740 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1741 _M_emplace_unique(_Args&&... __args)
1743 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1747 typedef pair<iterator, bool> _Res;
1748 auto __res = _M_get_insert_unique_pos(_S_key(__z));
1750 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
1752 _M_destroy_node(__z);
1753 return _Res(iterator(static_cast<_Link_type>(__res.first)),
false);
1757 _M_destroy_node(__z);
1758 __throw_exception_again;
1762 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1763 typename _Compare,
typename _Alloc>
1764 template<
typename... _Args>
1765 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1766 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1767 _M_emplace_equal(_Args&&... __args)
1769 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1773 auto __res = _M_get_insert_equal_pos(_S_key(__z));
1774 return _M_insert_node(__res.first, __res.second, __z);
1778 _M_destroy_node(__z);
1779 __throw_exception_again;
1783 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1784 typename _Compare,
typename _Alloc>
1785 template<
typename... _Args>
1786 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1787 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1788 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
1790 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1794 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
1797 return _M_insert_node(__res.first, __res.second, __z);
1799 _M_destroy_node(__z);
1800 return iterator(static_cast<_Link_type>(__res.first));
1804 _M_destroy_node(__z);
1805 __throw_exception_again;
1809 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1810 typename _Compare,
typename _Alloc>
1811 template<
typename... _Args>
1812 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1813 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1814 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
1816 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
1820 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
1823 return _M_insert_node(__res.first, __res.second, __z);
1825 return _M_insert_equal_lower_node(__z);
1829 _M_destroy_node(__z);
1830 __throw_exception_again;
1835 template<
typename _Key,
typename _Val,
typename _KoV,
1836 typename _Cmp,
typename _Alloc>
1839 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
1840 _M_insert_unique(_II __first, _II __last)
1842 for (; __first != __last; ++__first)
1843 _M_insert_unique_(
end(), *__first);
1846 template<
typename _Key,
typename _Val,
typename _KoV,
1847 typename _Cmp,
typename _Alloc>
1850 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
1851 _M_insert_equal(_II __first, _II __last)
1853 for (; __first != __last; ++__first)
1854 _M_insert_equal_(
end(), *__first);
1857 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1858 typename _Compare,
typename _Alloc>
1860 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1861 _M_erase_aux(const_iterator __position)
1864 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
1865 (const_cast<_Base_ptr>(__position._M_node),
1866 this->_M_impl._M_header));
1867 _M_destroy_node(__y);
1868 --_M_impl._M_node_count;
1871 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1872 typename _Compare,
typename _Alloc>
1874 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1875 _M_erase_aux(const_iterator __first, const_iterator __last)
1877 if (__first ==
begin() && __last ==
end())
1880 while (__first != __last)
1884 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1885 typename _Compare,
typename _Alloc>
1886 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
1887 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1888 erase(
const _Key& __x)
1890 pair<iterator, iterator> __p = equal_range(__x);
1891 const size_type __old_size = size();
1892 erase(__p.first, __p.second);
1893 return __old_size - size();
1896 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1897 typename _Compare,
typename _Alloc>
1899 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1900 erase(
const _Key* __first,
const _Key* __last)
1902 while (__first != __last)
1906 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1907 typename _Compare,
typename _Alloc>
1908 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1909 _Compare, _Alloc>::iterator
1910 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1911 find(
const _Key& __k)
1913 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
1914 return (__j ==
end()
1915 || _M_impl._M_key_compare(__k,
1916 _S_key(__j._M_node))) ?
end() : __j;
1919 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1920 typename _Compare,
typename _Alloc>
1921 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1922 _Compare, _Alloc>::const_iterator
1923 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1924 find(
const _Key& __k)
const
1926 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
1927 return (__j ==
end()
1928 || _M_impl._M_key_compare(__k,
1929 _S_key(__j._M_node))) ?
end() : __j;
1932 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1933 typename _Compare,
typename _Alloc>
1934 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
1935 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1936 count(
const _Key& __k)
const
1938 pair<const_iterator, const_iterator> __p = equal_range(__k);
1943 _GLIBCXX_PURE
unsigned int
1944 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
1945 const _Rb_tree_node_base* __root)
throw ();
1947 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1948 typename _Compare,
typename _Alloc>
1950 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const
1952 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
1953 return _M_impl._M_node_count == 0 &&
begin() ==
end()
1954 && this->_M_impl._M_header._M_left == _M_end()
1955 && this->_M_impl._M_header._M_right == _M_end();
1957 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
1958 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
1960 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
1961 _Const_Link_type __L = _S_left(__x);
1962 _Const_Link_type __R = _S_right(__x);
1964 if (__x->_M_color == _S_red)
1965 if ((__L && __L->_M_color == _S_red)
1966 || (__R && __R->_M_color == _S_red))
1969 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
1971 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
1974 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
1978 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
1980 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
1985 _GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Uniform interface to C++98 and C++0x allocators.
auto end(_Container &__cont) -> decltype(__cont.end())
Return an iterator pointing to one past the last element of the container.
auto begin(_Container &__cont) -> decltype(__cont.begin())
Return an iterator pointing to the first element of the container.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
ISO C++ entities toplevel namespace is std.
bool equal(_II1 __first1, _II1 __last1, _II2 __first2)
Tests a range for element-wise equality.
bool operator>=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't precede string.
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
bool operator>(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string follows string.
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
static pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.