1 // RB tree implementation -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
33 * Copyright (c) 1996,1997
34 * Silicon Graphics Computer Systems, Inc.
36 * Permission to use, copy, modify, distribute and sell this software
37 * and its documentation for any purpose is hereby granted without fee,
38 * provided that the above copyright notice appear in all copies and
39 * that both that copyright notice and this permission notice appear
40 * in supporting documentation. Silicon Graphics makes no
41 * representations about the suitability of this software for any
42 * purpose. It is provided "as is" without express or implied warranty.
46 * Hewlett-Packard Company
48 * Permission to use, copy, modify, distribute and sell this software
49 * and its documentation for any purpose is hereby granted without fee,
50 * provided that the above copyright notice appear in all copies and
51 * that both that copyright notice and this permission notice appear
52 * in supporting documentation. Hewlett-Packard Company makes no
53 * representations about the suitability of this software for any
54 * purpose. It is provided "as is" without express or implied warranty.
60 * This is an internal header file, included by other library headers.
61 * You should not attempt to use it directly.
67 #include <bits/stl_algobase.h>
68 #include <bits/allocator.h>
69 #include <bits/stl_construct.h>
70 #include <bits/stl_function.h>
71 #include <bits/cpp_type_traits.h>
73 _GLIBCXX_BEGIN_NAMESPACE(std
)
75 // Red-black tree class, designed for use in implementing STL
76 // associative containers (set, multiset, map, and multimap). The
77 // insertion and deletion algorithms are based on those in Cormen,
78 // Leiserson, and Rivest, Introduction to Algorithms (MIT Press,
81 // (1) the header cell is maintained with links not only to the root
82 // but also to the leftmost node of the tree, to enable constant
83 // time begin(), and to the rightmost node of the tree, to enable
84 // linear time performance when used with the generic set algorithms
87 // (2) when a node being deleted has two children its successor node
88 // is relinked into its place, rather than copied, so that the only
89 // iterators invalidated are those referring to the deleted node.
91 enum _Rb_tree_color
{ _S_red
= false, _S_black
= true };
93 struct _Rb_tree_node_base
95 typedef _Rb_tree_node_base
* _Base_ptr
;
96 typedef const _Rb_tree_node_base
* _Const_Base_ptr
;
98 _Rb_tree_color _M_color
;
104 _S_minimum(_Base_ptr __x
)
106 while (__x
->_M_left
!= 0) __x
= __x
->_M_left
;
110 static _Const_Base_ptr
111 _S_minimum(_Const_Base_ptr __x
)
113 while (__x
->_M_left
!= 0) __x
= __x
->_M_left
;
118 _S_maximum(_Base_ptr __x
)
120 while (__x
->_M_right
!= 0) __x
= __x
->_M_right
;
124 static _Const_Base_ptr
125 _S_maximum(_Const_Base_ptr __x
)
127 while (__x
->_M_right
!= 0) __x
= __x
->_M_right
;
132 template<typename _Val
>
133 struct _Rb_tree_node
: public _Rb_tree_node_base
135 typedef _Rb_tree_node
<_Val
>* _Link_type
;
140 _Rb_tree_increment(_Rb_tree_node_base
* __x
);
142 const _Rb_tree_node_base
*
143 _Rb_tree_increment(const _Rb_tree_node_base
* __x
);
146 _Rb_tree_decrement(_Rb_tree_node_base
* __x
);
148 const _Rb_tree_node_base
*
149 _Rb_tree_decrement(const _Rb_tree_node_base
* __x
);
151 template<typename _Tp
>
152 struct _Rb_tree_iterator
154 typedef _Tp value_type
;
155 typedef _Tp
& reference
;
156 typedef _Tp
* pointer
;
158 typedef bidirectional_iterator_tag iterator_category
;
159 typedef ptrdiff_t difference_type
;
161 typedef _Rb_tree_iterator
<_Tp
> _Self
;
162 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr
;
163 typedef _Rb_tree_node
<_Tp
>* _Link_type
;
169 _Rb_tree_iterator(_Link_type __x
)
174 { return static_cast<_Link_type
>(_M_node
)->_M_value_field
; }
178 { return &static_cast<_Link_type
>(_M_node
)->_M_value_field
; }
183 _M_node
= _Rb_tree_increment(_M_node
);
191 _M_node
= _Rb_tree_increment(_M_node
);
198 _M_node
= _Rb_tree_decrement(_M_node
);
206 _M_node
= _Rb_tree_decrement(_M_node
);
211 operator==(const _Self
& __x
) const
212 { return _M_node
== __x
._M_node
; }
215 operator!=(const _Self
& __x
) const
216 { return _M_node
!= __x
._M_node
; }
221 template<typename _Tp
>
222 struct _Rb_tree_const_iterator
224 typedef _Tp value_type
;
225 typedef const _Tp
& reference
;
226 typedef const _Tp
* pointer
;
228 typedef _Rb_tree_iterator
<_Tp
> iterator
;
230 typedef bidirectional_iterator_tag iterator_category
;
231 typedef ptrdiff_t difference_type
;
233 typedef _Rb_tree_const_iterator
<_Tp
> _Self
;
234 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr
;
235 typedef const _Rb_tree_node
<_Tp
>* _Link_type
;
237 _Rb_tree_const_iterator()
241 _Rb_tree_const_iterator(_Link_type __x
)
244 _Rb_tree_const_iterator(const iterator
& __it
)
245 : _M_node(__it
._M_node
) { }
249 { return static_cast<_Link_type
>(_M_node
)->_M_value_field
; }
253 { return &static_cast<_Link_type
>(_M_node
)->_M_value_field
; }
258 _M_node
= _Rb_tree_increment(_M_node
);
266 _M_node
= _Rb_tree_increment(_M_node
);
273 _M_node
= _Rb_tree_decrement(_M_node
);
281 _M_node
= _Rb_tree_decrement(_M_node
);
286 operator==(const _Self
& __x
) const
287 { return _M_node
== __x
._M_node
; }
290 operator!=(const _Self
& __x
) const
291 { return _M_node
!= __x
._M_node
; }
296 template<typename _Val
>
298 operator==(const _Rb_tree_iterator
<_Val
>& __x
,
299 const _Rb_tree_const_iterator
<_Val
>& __y
)
300 { return __x
._M_node
== __y
._M_node
; }
302 template<typename _Val
>
304 operator!=(const _Rb_tree_iterator
<_Val
>& __x
,
305 const _Rb_tree_const_iterator
<_Val
>& __y
)
306 { return __x
._M_node
!= __y
._M_node
; }
309 _Rb_tree_rotate_left(_Rb_tree_node_base
* const __x
,
310 _Rb_tree_node_base
*& __root
);
313 _Rb_tree_rotate_right(_Rb_tree_node_base
* const __x
,
314 _Rb_tree_node_base
*& __root
);
317 _Rb_tree_insert_and_rebalance(const bool __insert_left
,
318 _Rb_tree_node_base
* __x
,
319 _Rb_tree_node_base
* __p
,
320 _Rb_tree_node_base
& __header
);
323 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base
* const __z
,
324 _Rb_tree_node_base
& __header
);
327 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
328 typename _Compare
, typename _Alloc
= allocator
<_Val
> >
331 typedef typename
_Alloc::template rebind
<_Rb_tree_node
<_Val
> >::other
335 typedef _Rb_tree_node_base
* _Base_ptr
;
336 typedef const _Rb_tree_node_base
* _Const_Base_ptr
;
337 typedef _Rb_tree_node
<_Val
> _Rb_tree_node
;
340 typedef _Key key_type
;
341 typedef _Val value_type
;
342 typedef value_type
* pointer
;
343 typedef const value_type
* const_pointer
;
344 typedef value_type
& reference
;
345 typedef const value_type
& const_reference
;
346 typedef _Rb_tree_node
* _Link_type
;
347 typedef const _Rb_tree_node
* _Const_Link_type
;
348 typedef size_t size_type
;
349 typedef ptrdiff_t difference_type
;
350 typedef _Alloc allocator_type
;
353 _M_get_Node_allocator()
354 { return *static_cast<_Node_allocator
*>(&this->_M_impl
); }
356 const _Node_allocator
&
357 _M_get_Node_allocator() const
358 { return *static_cast<const _Node_allocator
*>(&this->_M_impl
); }
361 get_allocator() const
362 { return allocator_type(_M_get_Node_allocator()); }
367 { return _M_impl
._Node_allocator::allocate(1); }
370 _M_put_node(_Rb_tree_node
* __p
)
371 { _M_impl
._Node_allocator::deallocate(__p
, 1); }
374 _M_create_node(const value_type
& __x
)
376 _Link_type __tmp
= _M_get_node();
378 { get_allocator().construct(&__tmp
->_M_value_field
, __x
); }
382 __throw_exception_again
;
388 _M_clone_node(_Const_Link_type __x
)
390 _Link_type __tmp
= _M_create_node(__x
->_M_value_field
);
391 __tmp
->_M_color
= __x
->_M_color
;
398 destroy_node(_Link_type __p
)
400 get_allocator().destroy(&__p
->_M_value_field
);
405 template<typename _Key_compare
,
406 bool _Is_pod_comparator
= std::__is_pod
<_Key_compare
>::__value
>
407 struct _Rb_tree_impl
: public _Node_allocator
409 _Key_compare _M_key_compare
;
410 _Rb_tree_node_base _M_header
;
411 size_type _M_node_count
; // Keeps track of size of tree.
413 _Rb_tree_impl(const _Node_allocator
& __a
= _Node_allocator(),
414 const _Key_compare
& __comp
= _Key_compare())
415 : _Node_allocator(__a
), _M_key_compare(__comp
), _M_header(),
418 this->_M_header
._M_color
= _S_red
;
419 this->_M_header
._M_parent
= 0;
420 this->_M_header
._M_left
= &this->_M_header
;
421 this->_M_header
._M_right
= &this->_M_header
;
425 // Specialization for _Comparison types that are not capable of
426 // being base classes / super classes.
427 template<typename _Key_compare
>
428 struct _Rb_tree_impl
<_Key_compare
, true> : public _Node_allocator
430 _Key_compare _M_key_compare
;
431 _Rb_tree_node_base _M_header
;
432 size_type _M_node_count
; // Keeps track of size of tree.
434 _Rb_tree_impl(const _Node_allocator
& __a
= _Node_allocator(),
435 const _Key_compare
& __comp
= _Key_compare())
436 : _Node_allocator(__a
), _M_key_compare(__comp
), _M_header(),
439 this->_M_header
._M_color
= _S_red
;
440 this->_M_header
._M_parent
= 0;
441 this->_M_header
._M_left
= &this->_M_header
;
442 this->_M_header
._M_right
= &this->_M_header
;
446 _Rb_tree_impl
<_Compare
> _M_impl
;
451 { return this->_M_impl
._M_header
._M_parent
; }
455 { return this->_M_impl
._M_header
._M_parent
; }
459 { return this->_M_impl
._M_header
._M_left
; }
463 { return this->_M_impl
._M_header
._M_left
; }
467 { return this->_M_impl
._M_header
._M_right
; }
471 { return this->_M_impl
._M_header
._M_right
; }
475 { return static_cast<_Link_type
>(this->_M_impl
._M_header
._M_parent
); }
480 return static_cast<_Const_Link_type
>
481 (this->_M_impl
._M_header
._M_parent
);
486 { return static_cast<_Link_type
>(&this->_M_impl
._M_header
); }
490 { return static_cast<_Const_Link_type
>(&this->_M_impl
._M_header
); }
492 static const_reference
493 _S_value(_Const_Link_type __x
)
494 { return __x
->_M_value_field
; }
497 _S_key(_Const_Link_type __x
)
498 { return _KeyOfValue()(_S_value(__x
)); }
501 _S_left(_Base_ptr __x
)
502 { return static_cast<_Link_type
>(__x
->_M_left
); }
504 static _Const_Link_type
505 _S_left(_Const_Base_ptr __x
)
506 { return static_cast<_Const_Link_type
>(__x
->_M_left
); }
509 _S_right(_Base_ptr __x
)
510 { return static_cast<_Link_type
>(__x
->_M_right
); }
512 static _Const_Link_type
513 _S_right(_Const_Base_ptr __x
)
514 { return static_cast<_Const_Link_type
>(__x
->_M_right
); }
516 static const_reference
517 _S_value(_Const_Base_ptr __x
)
518 { return static_cast<_Const_Link_type
>(__x
)->_M_value_field
; }
521 _S_key(_Const_Base_ptr __x
)
522 { return _KeyOfValue()(_S_value(__x
)); }
525 _S_minimum(_Base_ptr __x
)
526 { return _Rb_tree_node_base::_S_minimum(__x
); }
528 static _Const_Base_ptr
529 _S_minimum(_Const_Base_ptr __x
)
530 { return _Rb_tree_node_base::_S_minimum(__x
); }
533 _S_maximum(_Base_ptr __x
)
534 { return _Rb_tree_node_base::_S_maximum(__x
); }
536 static _Const_Base_ptr
537 _S_maximum(_Const_Base_ptr __x
)
538 { return _Rb_tree_node_base::_S_maximum(__x
); }
541 typedef _Rb_tree_iterator
<value_type
> iterator
;
542 typedef _Rb_tree_const_iterator
<value_type
> const_iterator
;
544 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
545 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
549 _M_insert(_Base_ptr __x
, _Base_ptr __y
, const value_type
& __v
);
552 _M_insert(_Const_Base_ptr __x
, _Const_Base_ptr __y
,
553 const value_type
& __v
);
556 _M_copy(_Const_Link_type __x
, _Link_type __p
);
559 _M_erase(_Link_type __x
);
562 // allocation/deallocation
566 _Rb_tree(const _Compare
& __comp
)
567 : _M_impl(allocator_type(), __comp
)
570 _Rb_tree(const _Compare
& __comp
, const allocator_type
& __a
)
571 : _M_impl(__a
, __comp
)
574 _Rb_tree(const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __x
)
575 : _M_impl(__x
._M_get_Node_allocator(), __x
._M_impl
._M_key_compare
)
577 if (__x
._M_root() != 0)
579 _M_root() = _M_copy(__x
._M_begin(), _M_end());
580 _M_leftmost() = _S_minimum(_M_root());
581 _M_rightmost() = _S_maximum(_M_root());
582 _M_impl
._M_node_count
= __x
._M_impl
._M_node_count
;
587 { _M_erase(_M_begin()); }
589 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>&
590 operator=(const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __x
);
595 { return _M_impl
._M_key_compare
; }
600 return iterator(static_cast<_Link_type
>
601 (this->_M_impl
._M_header
._M_left
));
607 return const_iterator(static_cast<_Const_Link_type
>
608 (this->_M_impl
._M_header
._M_left
));
613 { return iterator(static_cast<_Link_type
>(&this->_M_impl
._M_header
)); }
618 return const_iterator(static_cast<_Const_Link_type
>
619 (&this->_M_impl
._M_header
));
624 { return reverse_iterator(end()); }
626 const_reverse_iterator
628 { return const_reverse_iterator(end()); }
632 { return reverse_iterator(begin()); }
634 const_reverse_iterator
636 { return const_reverse_iterator(begin()); }
640 { return _M_impl
._M_node_count
== 0; }
644 { return _M_impl
._M_node_count
; }
648 { return size_type(-1); }
651 swap(_Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __t
);
655 insert_unique(const value_type
& __x
);
658 insert_equal(const value_type
& __x
);
661 insert_unique(iterator __position
, const value_type
& __x
);
664 insert_unique(const_iterator __position
, const value_type
& __x
);
667 insert_equal(iterator __position
, const value_type
& __x
);
670 insert_equal(const_iterator __position
, const value_type
& __x
);
672 template<typename _InputIterator
>
674 insert_unique(_InputIterator __first
, _InputIterator __last
);
676 template<typename _InputIterator
>
678 insert_equal(_InputIterator __first
, _InputIterator __last
);
681 erase(iterator __position
);
684 erase(const_iterator __position
);
687 erase(const key_type
& __x
);
690 erase(iterator __first
, iterator __last
);
693 erase(const_iterator __first
, const_iterator __last
);
696 erase(const key_type
* __first
, const key_type
* __last
);
701 _M_erase(_M_begin());
702 _M_leftmost() = _M_end();
704 _M_rightmost() = _M_end();
705 _M_impl
._M_node_count
= 0;
710 find(const key_type
& __x
);
713 find(const key_type
& __x
) const;
716 count(const key_type
& __x
) const;
719 lower_bound(const key_type
& __x
);
722 lower_bound(const key_type
& __x
) const;
725 upper_bound(const key_type
& __x
);
728 upper_bound(const key_type
& __x
) const;
730 pair
<iterator
,iterator
>
731 equal_range(const key_type
& __x
);
733 pair
<const_iterator
, const_iterator
>
734 equal_range(const key_type
& __x
) const;
741 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
742 typename _Compare
, typename _Alloc
>
744 operator==(const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __x
,
745 const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __y
)
747 return __x
.size() == __y
.size()
748 && std::equal(__x
.begin(), __x
.end(), __y
.begin());
751 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
752 typename _Compare
, typename _Alloc
>
754 operator<(const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __x
,
755 const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __y
)
757 return std::lexicographical_compare(__x
.begin(), __x
.end(),
758 __y
.begin(), __y
.end());
761 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
762 typename _Compare
, typename _Alloc
>
764 operator!=(const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __x
,
765 const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __y
)
766 { return !(__x
== __y
); }
768 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
769 typename _Compare
, typename _Alloc
>
771 operator>(const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __x
,
772 const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __y
)
773 { return __y
< __x
; }
775 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
776 typename _Compare
, typename _Alloc
>
778 operator<=(const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __x
,
779 const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __y
)
780 { return !(__y
< __x
); }
782 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
783 typename _Compare
, typename _Alloc
>
785 operator>=(const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __x
,
786 const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __y
)
787 { return !(__x
< __y
); }
789 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
790 typename _Compare
, typename _Alloc
>
792 swap(_Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __x
,
793 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __y
)
796 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
797 typename _Compare
, typename _Alloc
>
798 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>&
799 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
800 operator=(const _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __x
)
804 // Note that _Key may be a constant type.
806 _M_impl
._M_key_compare
= __x
._M_impl
._M_key_compare
;
807 if (__x
._M_root() != 0)
809 _M_root() = _M_copy(__x
._M_begin(), _M_end());
810 _M_leftmost() = _S_minimum(_M_root());
811 _M_rightmost() = _S_maximum(_M_root());
812 _M_impl
._M_node_count
= __x
._M_impl
._M_node_count
;
818 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
819 typename _Compare
, typename _Alloc
>
820 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::iterator
821 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
822 _M_insert(_Base_ptr __x
, _Base_ptr __p
, const _Val
& __v
)
824 bool __insert_left
= (__x
!= 0 || __p
== _M_end()
825 || _M_impl
._M_key_compare(_KeyOfValue()(__v
),
828 _Link_type __z
= _M_create_node(__v
);
830 _Rb_tree_insert_and_rebalance(__insert_left
, __z
, __p
,
831 this->_M_impl
._M_header
);
832 ++_M_impl
._M_node_count
;
833 return iterator(__z
);
836 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
837 typename _Compare
, typename _Alloc
>
838 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::const_iterator
839 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
840 _M_insert(_Const_Base_ptr __x
, _Const_Base_ptr __p
, const _Val
& __v
)
842 bool __insert_left
= (__x
!= 0 || __p
== _M_end()
843 || _M_impl
._M_key_compare(_KeyOfValue()(__v
),
846 _Link_type __z
= _M_create_node(__v
);
848 _Rb_tree_insert_and_rebalance(__insert_left
, __z
,
849 const_cast<_Base_ptr
>(__p
),
850 this->_M_impl
._M_header
);
851 ++_M_impl
._M_node_count
;
852 return const_iterator(__z
);
855 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
856 typename _Compare
, typename _Alloc
>
857 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::iterator
858 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
859 insert_equal(const _Val
& __v
)
861 _Link_type __x
= _M_begin();
862 _Link_type __y
= _M_end();
866 __x
= _M_impl
._M_key_compare(_KeyOfValue()(__v
), _S_key(__x
)) ?
867 _S_left(__x
) : _S_right(__x
);
869 return _M_insert(__x
, __y
, __v
);
872 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
873 typename _Compare
, typename _Alloc
>
875 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
876 swap(_Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>& __t
)
880 if (__t
._M_root() != 0)
882 _M_root() = __t
._M_root();
883 _M_leftmost() = __t
._M_leftmost();
884 _M_rightmost() = __t
._M_rightmost();
885 _M_root()->_M_parent
= _M_end();
888 __t
._M_leftmost() = __t
._M_end();
889 __t
._M_rightmost() = __t
._M_end();
892 else if (__t
._M_root() == 0)
894 __t
._M_root() = _M_root();
895 __t
._M_leftmost() = _M_leftmost();
896 __t
._M_rightmost() = _M_rightmost();
897 __t
._M_root()->_M_parent
= __t
._M_end();
900 _M_leftmost() = _M_end();
901 _M_rightmost() = _M_end();
905 std::swap(_M_root(),__t
._M_root());
906 std::swap(_M_leftmost(),__t
._M_leftmost());
907 std::swap(_M_rightmost(),__t
._M_rightmost());
909 _M_root()->_M_parent
= _M_end();
910 __t
._M_root()->_M_parent
= __t
._M_end();
912 // No need to swap header's color as it does not change.
913 std::swap(this->_M_impl
._M_node_count
, __t
._M_impl
._M_node_count
);
914 std::swap(this->_M_impl
._M_key_compare
, __t
._M_impl
._M_key_compare
);
917 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
918 typename _Compare
, typename _Alloc
>
919 pair
<typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
,
920 _Compare
, _Alloc
>::iterator
, bool>
921 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
922 insert_unique(const _Val
& __v
)
924 _Link_type __x
= _M_begin();
925 _Link_type __y
= _M_end();
930 __comp
= _M_impl
._M_key_compare(_KeyOfValue()(__v
), _S_key(__x
));
931 __x
= __comp
? _S_left(__x
) : _S_right(__x
);
933 iterator __j
= iterator(__y
);
936 return pair
<iterator
,bool>(_M_insert(__x
, __y
, __v
), true);
939 if (_M_impl
._M_key_compare(_S_key(__j
._M_node
), _KeyOfValue()(__v
)))
940 return pair
<iterator
, bool>(_M_insert(__x
, __y
, __v
), true);
941 return pair
<iterator
, bool>(__j
, false);
944 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
945 typename _Compare
, typename _Alloc
>
946 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::iterator
947 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
948 insert_unique(iterator __position
, const _Val
& __v
)
951 if (__position
._M_node
== _M_end())
954 && _M_impl
._M_key_compare(_S_key(_M_rightmost()),
956 return _M_insert(0, _M_rightmost(), __v
);
958 return insert_unique(__v
).first
;
960 else if (_M_impl
._M_key_compare(_KeyOfValue()(__v
),
961 _S_key(__position
._M_node
)))
963 // First, try before...
964 iterator __before
= __position
;
965 if (__position
._M_node
== _M_leftmost()) // begin()
966 return _M_insert(_M_leftmost(), _M_leftmost(), __v
);
967 else if (_M_impl
._M_key_compare(_S_key((--__before
)._M_node
),
970 if (_S_right(__before
._M_node
) == 0)
971 return _M_insert(0, __before
._M_node
, __v
);
973 return _M_insert(__position
._M_node
,
974 __position
._M_node
, __v
);
977 return insert_unique(__v
).first
;
979 else if (_M_impl
._M_key_compare(_S_key(__position
._M_node
),
982 // ... then try after.
983 iterator __after
= __position
;
984 if (__position
._M_node
== _M_rightmost())
985 return _M_insert(0, _M_rightmost(), __v
);
986 else if (_M_impl
._M_key_compare(_KeyOfValue()(__v
),
987 _S_key((++__after
)._M_node
)))
989 if (_S_right(__position
._M_node
) == 0)
990 return _M_insert(0, __position
._M_node
, __v
);
992 return _M_insert(__after
._M_node
, __after
._M_node
, __v
);
995 return insert_unique(__v
).first
;
998 return __position
; // Equivalent keys.
1001 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1002 typename _Compare
, typename _Alloc
>
1003 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::const_iterator
1004 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1005 insert_unique(const_iterator __position
, const _Val
& __v
)
1008 if (__position
._M_node
== _M_end())
1011 && _M_impl
._M_key_compare(_S_key(_M_rightmost()),
1012 _KeyOfValue()(__v
)))
1013 return _M_insert(0, _M_rightmost(), __v
);
1015 return const_iterator(insert_unique(__v
).first
);
1017 else if (_M_impl
._M_key_compare(_KeyOfValue()(__v
),
1018 _S_key(__position
._M_node
)))
1020 // First, try before...
1021 const_iterator __before
= __position
;
1022 if (__position
._M_node
== _M_leftmost()) // begin()
1023 return _M_insert(_M_leftmost(), _M_leftmost(), __v
);
1024 else if (_M_impl
._M_key_compare(_S_key((--__before
)._M_node
),
1025 _KeyOfValue()(__v
)))
1027 if (_S_right(__before
._M_node
) == 0)
1028 return _M_insert(0, __before
._M_node
, __v
);
1030 return _M_insert(__position
._M_node
,
1031 __position
._M_node
, __v
);
1034 return const_iterator(insert_unique(__v
).first
);
1036 else if (_M_impl
._M_key_compare(_S_key(__position
._M_node
),
1037 _KeyOfValue()(__v
)))
1039 // ... then try after.
1040 const_iterator __after
= __position
;
1041 if (__position
._M_node
== _M_rightmost())
1042 return _M_insert(0, _M_rightmost(), __v
);
1043 else if (_M_impl
._M_key_compare(_KeyOfValue()(__v
),
1044 _S_key((++__after
)._M_node
)))
1046 if (_S_right(__position
._M_node
) == 0)
1047 return _M_insert(0, __position
._M_node
, __v
);
1049 return _M_insert(__after
._M_node
, __after
._M_node
, __v
);
1052 return const_iterator(insert_unique(__v
).first
);
1055 return __position
; // Equivalent keys.
1058 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1059 typename _Compare
, typename _Alloc
>
1060 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::iterator
1061 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1062 insert_equal(iterator __position
, const _Val
& __v
)
1065 if (__position
._M_node
== _M_end())
1068 && !_M_impl
._M_key_compare(_KeyOfValue()(__v
),
1069 _S_key(_M_rightmost())))
1070 return _M_insert(0, _M_rightmost(), __v
);
1072 return insert_equal(__v
);
1074 else if (!_M_impl
._M_key_compare(_S_key(__position
._M_node
),
1075 _KeyOfValue()(__v
)))
1077 // First, try before...
1078 iterator __before
= __position
;
1079 if (__position
._M_node
== _M_leftmost()) // begin()
1080 return _M_insert(_M_leftmost(), _M_leftmost(), __v
);
1081 else if (!_M_impl
._M_key_compare(_KeyOfValue()(__v
),
1082 _S_key((--__before
)._M_node
)))
1084 if (_S_right(__before
._M_node
) == 0)
1085 return _M_insert(0, __before
._M_node
, __v
);
1087 return _M_insert(__position
._M_node
,
1088 __position
._M_node
, __v
);
1091 return insert_equal(__v
);
1095 // ... then try after.
1096 iterator __after
= __position
;
1097 if (__position
._M_node
== _M_rightmost())
1098 return _M_insert(0, _M_rightmost(), __v
);
1099 else if (!_M_impl
._M_key_compare(_S_key((++__after
)._M_node
),
1100 _KeyOfValue()(__v
)))
1102 if (_S_right(__position
._M_node
) == 0)
1103 return _M_insert(0, __position
._M_node
, __v
);
1105 return _M_insert(__after
._M_node
, __after
._M_node
, __v
);
1108 return insert_equal(__v
);
1112 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1113 typename _Compare
, typename _Alloc
>
1114 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::const_iterator
1115 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1116 insert_equal(const_iterator __position
, const _Val
& __v
)
1119 if (__position
._M_node
== _M_end())
1122 && !_M_impl
._M_key_compare(_KeyOfValue()(__v
),
1123 _S_key(_M_rightmost())))
1124 return _M_insert(0, _M_rightmost(), __v
);
1126 return const_iterator(insert_equal(__v
));
1128 else if (!_M_impl
._M_key_compare(_S_key(__position
._M_node
),
1129 _KeyOfValue()(__v
)))
1131 // First, try before...
1132 const_iterator __before
= __position
;
1133 if (__position
._M_node
== _M_leftmost()) // begin()
1134 return _M_insert(_M_leftmost(), _M_leftmost(), __v
);
1135 else if (!_M_impl
._M_key_compare(_KeyOfValue()(__v
),
1136 _S_key((--__before
)._M_node
)))
1138 if (_S_right(__before
._M_node
) == 0)
1139 return _M_insert(0, __before
._M_node
, __v
);
1141 return _M_insert(__position
._M_node
,
1142 __position
._M_node
, __v
);
1145 return const_iterator(insert_equal(__v
));
1149 // ... then try after.
1150 const_iterator __after
= __position
;
1151 if (__position
._M_node
== _M_rightmost())
1152 return _M_insert(0, _M_rightmost(), __v
);
1153 else if (!_M_impl
._M_key_compare(_S_key((++__after
)._M_node
),
1154 _KeyOfValue()(__v
)))
1156 if (_S_right(__position
._M_node
) == 0)
1157 return _M_insert(0, __position
._M_node
, __v
);
1159 return _M_insert(__after
._M_node
, __after
._M_node
, __v
);
1162 return const_iterator(insert_equal(__v
));
1166 template<typename _Key
, typename _Val
, typename _KoV
,
1167 typename _Cmp
, typename _Alloc
>
1170 _Rb_tree
<_Key
, _Val
, _KoV
, _Cmp
, _Alloc
>::
1171 insert_equal(_II __first
, _II __last
)
1173 for (; __first
!= __last
; ++__first
)
1174 insert_equal(end(), *__first
);
1177 template<typename _Key
, typename _Val
, typename _KoV
,
1178 typename _Cmp
, typename _Alloc
>
1181 _Rb_tree
<_Key
, _Val
, _KoV
, _Cmp
, _Alloc
>::
1182 insert_unique(_II __first
, _II __last
)
1184 for (; __first
!= __last
; ++__first
)
1185 insert_unique(end(), *__first
);
1188 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1189 typename _Compare
, typename _Alloc
>
1191 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1192 erase(iterator __position
)
1195 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
1196 (__position
._M_node
,
1197 this->_M_impl
._M_header
));
1199 --_M_impl
._M_node_count
;
1202 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1203 typename _Compare
, typename _Alloc
>
1205 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1206 erase(const_iterator __position
)
1209 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
1210 (const_cast<_Base_ptr
>(__position
._M_node
),
1211 this->_M_impl
._M_header
));
1213 --_M_impl
._M_node_count
;
1216 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1217 typename _Compare
, typename _Alloc
>
1218 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::size_type
1219 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1220 erase(const _Key
& __x
)
1222 pair
<iterator
,iterator
> __p
= equal_range(__x
);
1223 size_type __n
= std::distance(__p
.first
, __p
.second
);
1224 erase(__p
.first
, __p
.second
);
1228 template<typename _Key
, typename _Val
, typename _KoV
,
1229 typename _Compare
, typename _Alloc
>
1230 typename _Rb_tree
<_Key
, _Val
, _KoV
, _Compare
, _Alloc
>::_Link_type
1231 _Rb_tree
<_Key
, _Val
, _KoV
, _Compare
, _Alloc
>::
1232 _M_copy(_Const_Link_type __x
, _Link_type __p
)
1234 // Structural copy. __x and __p must be non-null.
1235 _Link_type __top
= _M_clone_node(__x
);
1236 __top
->_M_parent
= __p
;
1241 __top
->_M_right
= _M_copy(_S_right(__x
), __top
);
1247 _Link_type __y
= _M_clone_node(__x
);
1249 __y
->_M_parent
= __p
;
1251 __y
->_M_right
= _M_copy(_S_right(__x
), __y
);
1259 __throw_exception_again
;
1264 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1265 typename _Compare
, typename _Alloc
>
1267 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1268 _M_erase(_Link_type __x
)
1270 // Erase without rebalancing.
1273 _M_erase(_S_right(__x
));
1274 _Link_type __y
= _S_left(__x
);
1280 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1281 typename _Compare
, typename _Alloc
>
1283 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1284 erase(iterator __first
, iterator __last
)
1286 if (__first
== begin() && __last
== end())
1289 while (__first
!= __last
)
1293 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1294 typename _Compare
, typename _Alloc
>
1296 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1297 erase(const_iterator __first
, const_iterator __last
)
1299 if (__first
== begin() && __last
== end())
1302 while (__first
!= __last
)
1306 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1307 typename _Compare
, typename _Alloc
>
1309 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1310 erase(const _Key
* __first
, const _Key
* __last
)
1312 while (__first
!= __last
)
1316 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1317 typename _Compare
, typename _Alloc
>
1318 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::iterator
1319 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1320 find(const _Key
& __k
)
1322 _Link_type __x
= _M_begin(); // Current node.
1323 _Link_type __y
= _M_end(); // Last node which is not less than __k.
1326 if (!_M_impl
._M_key_compare(_S_key(__x
), __k
))
1327 __y
= __x
, __x
= _S_left(__x
);
1329 __x
= _S_right(__x
);
1331 iterator __j
= iterator(__y
);
1332 return (__j
== end()
1333 || _M_impl
._M_key_compare(__k
,
1334 _S_key(__j
._M_node
))) ? end() : __j
;
1337 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1338 typename _Compare
, typename _Alloc
>
1339 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::const_iterator
1340 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1341 find(const _Key
& __k
) const
1343 _Const_Link_type __x
= _M_begin(); // Current node.
1344 _Const_Link_type __y
= _M_end(); // Last node which is not less than __k.
1348 if (!_M_impl
._M_key_compare(_S_key(__x
), __k
))
1349 __y
= __x
, __x
= _S_left(__x
);
1351 __x
= _S_right(__x
);
1353 const_iterator __j
= const_iterator(__y
);
1354 return (__j
== end()
1355 || _M_impl
._M_key_compare(__k
,
1356 _S_key(__j
._M_node
))) ? end() : __j
;
1359 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1360 typename _Compare
, typename _Alloc
>
1361 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::size_type
1362 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1363 count(const _Key
& __k
) const
1365 pair
<const_iterator
, const_iterator
> __p
= equal_range(__k
);
1366 const size_type __n
= std::distance(__p
.first
, __p
.second
);
1370 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1371 typename _Compare
, typename _Alloc
>
1372 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::iterator
1373 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1374 lower_bound(const _Key
& __k
)
1376 _Link_type __x
= _M_begin(); // Current node.
1377 _Link_type __y
= _M_end(); // Last node which is not less than __k.
1380 if (!_M_impl
._M_key_compare(_S_key(__x
), __k
))
1381 __y
= __x
, __x
= _S_left(__x
);
1383 __x
= _S_right(__x
);
1385 return iterator(__y
);
1388 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1389 typename _Compare
, typename _Alloc
>
1390 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::const_iterator
1391 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1392 lower_bound(const _Key
& __k
) const
1394 _Const_Link_type __x
= _M_begin(); // Current node.
1395 _Const_Link_type __y
= _M_end(); // Last node which is not less than __k.
1398 if (!_M_impl
._M_key_compare(_S_key(__x
), __k
))
1399 __y
= __x
, __x
= _S_left(__x
);
1401 __x
= _S_right(__x
);
1403 return const_iterator(__y
);
1406 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1407 typename _Compare
, typename _Alloc
>
1408 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::iterator
1409 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1410 upper_bound(const _Key
& __k
)
1412 _Link_type __x
= _M_begin(); // Current node.
1413 _Link_type __y
= _M_end(); // Last node which is greater than __k.
1416 if (_M_impl
._M_key_compare(__k
, _S_key(__x
)))
1417 __y
= __x
, __x
= _S_left(__x
);
1419 __x
= _S_right(__x
);
1421 return iterator(__y
);
1424 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1425 typename _Compare
, typename _Alloc
>
1426 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::const_iterator
1427 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1428 upper_bound(const _Key
& __k
) const
1430 _Const_Link_type __x
= _M_begin(); // Current node.
1431 _Const_Link_type __y
= _M_end(); // Last node which is greater than __k.
1434 if (_M_impl
._M_key_compare(__k
, _S_key(__x
)))
1435 __y
= __x
, __x
= _S_left(__x
);
1437 __x
= _S_right(__x
);
1439 return const_iterator(__y
);
1442 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1443 typename _Compare
, typename _Alloc
>
1445 pair
<typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
,
1446 _Compare
, _Alloc
>::iterator
,
1447 typename _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::iterator
>
1448 _Rb_tree
<_Key
, _Val
, _KeyOfValue
, _Compare
, _Alloc
>::
1449 equal_range(const _Key
& __k
)
1450 { return pair
<iterator
, iterator
>(lower_bound(__k
), upper_bound(__k
)); }
1452 template<typename _Key
, typename _Val
, typename _KoV
,
1453 typename _Compare
, typename _Alloc
>
1455 pair
<typename _Rb_tree
<_Key
, _Val
, _KoV
,
1456 _Compare
, _Alloc
>::const_iterator
,
1457 typename _Rb_tree
<_Key
, _Val
, _KoV
, _Compare
, _Alloc
>::const_iterator
>
1458 _Rb_tree
<_Key
, _Val
, _KoV
, _Compare
, _Alloc
>::
1459 equal_range(const _Key
& __k
) const
1460 { return pair
<const_iterator
, const_iterator
>(lower_bound(__k
),
1461 upper_bound(__k
)); }
1464 _Rb_tree_black_count(const _Rb_tree_node_base
* __node
,
1465 const _Rb_tree_node_base
* __root
);
1467 template<typename _Key
, typename _Val
, typename _KeyOfValue
,
1468 typename _Compare
, typename _Alloc
>
1470 _Rb_tree
<_Key
,_Val
,_KeyOfValue
,_Compare
,_Alloc
>::__rb_verify() const
1472 if (_M_impl
._M_node_count
== 0 || begin() == end())
1473 return _M_impl
._M_node_count
== 0 && begin() == end()
1474 && this->_M_impl
._M_header
._M_left
== _M_end()
1475 && this->_M_impl
._M_header
._M_right
== _M_end();
1477 unsigned int __len
= _Rb_tree_black_count(_M_leftmost(), _M_root());
1478 for (const_iterator __it
= begin(); __it
!= end(); ++__it
)
1480 _Const_Link_type __x
= static_cast<_Const_Link_type
>(__it
._M_node
);
1481 _Const_Link_type __L
= _S_left(__x
);
1482 _Const_Link_type __R
= _S_right(__x
);
1484 if (__x
->_M_color
== _S_red
)
1485 if ((__L
&& __L
->_M_color
== _S_red
)
1486 || (__R
&& __R
->_M_color
== _S_red
))
1489 if (__L
&& _M_impl
._M_key_compare(_S_key(__x
), _S_key(__L
)))
1491 if (__R
&& _M_impl
._M_key_compare(_S_key(__R
), _S_key(__x
)))
1494 if (!__L
&& !__R
&& _Rb_tree_black_count(__x
, _M_root()) != __len
)
1498 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
1500 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
1505 _GLIBCXX_END_NAMESPACE