34#ifndef _STLP_INTERNAL_TREE_H
38#if defined (_STLP_DEBUG)
39# define _Rb_tree _STLP_NON_DBG_NAME(Rb_tree)
44#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
45# define __iterator__ _Rb_tree_iterator<_Value, _STLP_HEADER_TYPENAME _Traits::_NonConstTraits>
46# define __size_type__ size_t
47# define iterator __iterator__
49# define __iterator__ _STLP_TYPENAME_ON_RETURN_TYPE _Rb_tree<_Key, _Compare, _Value, _KeyOfValue, _Traits, _Alloc>::iterator
50# define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE _Rb_tree<_Key, _Compare, _Value, _KeyOfValue, _Traits, _Alloc>::size_type
57#if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
113 _Rotate_left(__x, __root);
131 _Rotate_right(__x, __root);
197 if (__leftmost == __z) {
204 if (__rightmost == __z) {
215 if (__x == __x_parent->
_M_left) {
220 _Rotate_left(__x_parent, __root);
234 _Rotate_right(__w, __root);
240 _Rotate_left(__x_parent, __root);
248 _Rotate_right(__x_parent, __root);
262 _Rotate_left(__w, __root);
268 _Rotate_right(__x_parent, __root);
281 else if (_M_node->
_M_left != 0) {
286 while (_M_node == __y->_M_left) {
302 while (_M_node == __y->_M_right) {
318template <
class _Key,
class _Compare,
319 class _Value,
class _KeyOfValue,
class _Traits,
class _Alloc>
330 _M_leftmost() = &this->_M_header._M_data;
331 _M_rightmost() = &this->_M_header._M_data;
334 _M_root() = _M_copy(__x.
_M_root(), &this->_M_header._M_data);
335 _M_leftmost() = _S_minimum(_M_root());
336 _M_rightmost() = _S_maximum(_M_root());
347template <
class _Key,
class _Compare,
348 class _Value,
class _KeyOfValue,
class _Traits,
class _Alloc>
358 if ( __parent == &this->_M_header._M_data ) {
359 __new_node = _M_create_node(
__val);
360 _S_left(__parent) = __new_node;
361 _M_root() = __new_node;
362 _M_rightmost() = __new_node;
366 _M_key_compare( _KeyOfValue()(
__val), _S_key(__parent) ) ) ) {
367 __new_node = _M_create_node(
__val);
368 _S_left(__parent) = __new_node;
369 if (__parent == _M_leftmost())
370 _M_leftmost() = __new_node;
373 __new_node = _M_create_node(
__val);
374 _S_right(__parent) = __new_node;
375 if (__parent == _M_rightmost())
376 _M_rightmost() = __new_node;
378 _S_parent(__new_node) = __parent;
384template <
class _Key,
class _Compare,
385 class _Value,
class _KeyOfValue,
class _Traits,
class _Alloc>
388 _Base_ptr __y = &this->_M_header._M_data;
392 if (_M_key_compare(_KeyOfValue()(
__val), _S_key(__x))) {
398 return _M_insert(__y,
__val, __x);
402template <
class _Key,
class _Compare,
403 class _Value,
class _KeyOfValue,
class _Traits,
class _Alloc>
406 _Base_ptr __y = &this->_M_header._M_data;
411 __comp = _M_key_compare(_KeyOfValue()(
__val), _S_key(__x));
412 __x = __comp ? _S_left(__x) : _S_right(__x);
421 if (_M_key_compare(_S_key(__j.
_M_node), _KeyOfValue()(
__val))) {
429template <
class _Key,
class _Compare,
430 class _Value,
class _KeyOfValue,
class _Traits,
class _Alloc>
438 return insert_unique(
__val).first;
440 if (_M_key_compare(_KeyOfValue()(
__val), _S_key(__position.
_M_node))) {
445 bool __comp_pos_v = _M_key_compare( _S_key(__position.
_M_node), _KeyOfValue()(
__val) );
447 if (__comp_pos_v ==
false)
458 if (__after.
_M_node == &this->_M_header._M_data)
468 if (_M_key_compare( _KeyOfValue()(
__val), _S_key(__after.
_M_node) )) {
469 if (_S_right(__position.
_M_node) == 0)
475 return insert_unique(
__val).first;
479 else if (__position.
_M_node == &this->_M_header._M_data) {
480 if (_M_key_compare(_S_key(_M_rightmost()), _KeyOfValue()(
__val))) {
483 return _M_insert(_M_rightmost(),
__val, 0, __position.
_M_node);
486 return insert_unique(
__val).first;
492 bool __comp_v_pos = _M_key_compare(_KeyOfValue()(
__val), _S_key(__position.
_M_node));
495 && _M_key_compare( _S_key(__before._M_node), _KeyOfValue()(
__val) )) {
497 if (_S_right(__before._M_node) == 0)
498 return _M_insert(__before._M_node,
__val, 0, __before._M_node);
508 bool __comp_pos_v = !__comp_v_pos;
514 __comp_pos_v = _M_key_compare(_S_key(__position.
_M_node), _KeyOfValue()(
__val));
519 && (__after._M_node == &this->_M_header._M_data ||
520 _M_key_compare( _KeyOfValue()(
__val), _S_key(__after._M_node) ))) {
521 if (_S_right(__position.
_M_node) == 0)
524 return _M_insert(__after._M_node,
__val, __after._M_node);
527 if (__comp_v_pos == __comp_pos_v)
530 return insert_unique(
__val).first;
536template <
class _Key,
class _Compare,
537 class _Value,
class _KeyOfValue,
class _Traits,
class _Alloc>
545 return insert_equal(
__val);
547 if (!_M_key_compare(_S_key(__position.
_M_node), _KeyOfValue()(
__val)))
565 if ( __after.
_M_node == &this->_M_header._M_data ||
566 !_M_key_compare( _S_key(__after.
_M_node), _KeyOfValue()(
__val) ) ) {
567 if (_S_right(__position.
_M_node) == 0)
573 return insert_equal(
__val);
577 else if (__position.
_M_node == &this->_M_header._M_data) {
578 if (!_M_key_compare(_KeyOfValue()(
__val), _S_key(_M_rightmost())))
579 return _M_insert(_M_rightmost(),
__val, 0, __position.
_M_node);
581 return insert_equal(
__val);
592 bool __comp_pos_v = _M_key_compare(_S_key(__position.
_M_node), _KeyOfValue()(
__val));
594 !_M_key_compare(_KeyOfValue()(
__val), _S_key(__before.
_M_node))) {
595 if (_S_right(__before.
_M_node) == 0)
607 ( __after.
_M_node == &this->_M_header._M_data ||
608 !_M_key_compare( _S_key(__after.
_M_node), _KeyOfValue()(
__val) ) ) ) {
609 if (_S_right(__position.
_M_node) == 0)
615 return insert_equal(
__val);
621template <
class _Key,
class _Compare,
622 class _Value,
class _KeyOfValue,
class _Traits,
class _Alloc>
628 _S_parent(__top) = __p;
632 _S_right(__top) = _M_copy(_S_right(__x), __top);
639 _S_parent(__y) = __p;
641 _S_right(__y) = _M_copy(_S_right(__x), __y);
652template <
class _Key,
class _Compare,
653 class _Value,
class _KeyOfValue,
class _Traits,
class _Alloc>
658 _M_erase(_S_right(__x));
660 _STLP_STD::_Destroy(&_S_value(__x));
666#if defined (_STLP_DEBUG)
673 if (__node == __root)
676 return __bc + __black_count(__node->
_M_parent, __root);
680template <
class _Key,
class _Compare,
681 class _Value,
class _KeyOfValue,
class _Traits,
class _Alloc>
683 if (_M_node_count == 0 ||
begin() ==
end())
684 return ((_M_node_count == 0) &&
686 (this->_M_header._M_data._M_left == &this->_M_header._M_data) &&
687 (this->_M_header._M_data._M_right == &this->_M_header._M_data));
689 int __len = __black_count(_M_leftmost(), _M_root());
691 _Base_ptr __x =
__it._M_node;
692 _Base_ptr
__L = _S_left(__x);
693 _Base_ptr __R = _S_right(__x);
700 if (
__L && _M_key_compare(_S_key(__x), _S_key(
__L)))
702 if (__R && _M_key_compare(_S_key(__R), _S_key(__x)))
705 if (!
__L && !__R && __black_count(__x, _M_root()) != __len)
_STLP_INLINE_LOOP _InputIter const _Tp & __val
_STLP_MOVE_TO_PRIV_NAMESPACE const _InputIterator const input_iterator_tag &_InputIterator __it(__first)
static _Base_ptr _STLP_CALL _Rebalance_for_erase(_Base_ptr __z, _Base_ptr &__root, _Base_ptr &__leftmost, _Base_ptr &__rightmost)
static void _STLP_CALL _Rotate_left(_Base_ptr __x, _Base_ptr &__root)
static _Base_ptr _STLP_CALL _M_decrement(_Base_ptr)
static void _STLP_CALL _Rebalance(_Base_ptr __x, _Base_ptr &__root)
static _Base_ptr _STLP_CALL _M_increment(_Base_ptr)
static void _STLP_CALL _Rotate_right(_Base_ptr __x, _Base_ptr &__root)
void _M_erase(_Base_ptr __x)
_Base_ptr _M_root() const
static const WCHAR empty[]
#define _STLP_UNWIND(action)
#define _STLP_MOVE_TO_STD_NAMESPACE
#define __STATIC_CAST(__x, __y)
#define _STLP_BEGIN_NAMESPACE
#define _STLP_END_NAMESPACE
#define _STLP_MOVE_TO_PRIV_NAMESPACE
static _Base_ptr _STLP_CALL _S_maximum(_Base_ptr __x)
static _Base_ptr _STLP_CALL _S_minimum(_Base_ptr __x)