_Rb_tree_node_base* _Rb_tree<_Key,_Compare,_Value,_KeyOfValue,_Traits,_Alloc> ::_M_copy(_Rb_tree_node_base* __x, _Rb_tree_node_base* __p) { // structural copy. __x and __p must be non-null. _Base_ptr __top = _M_clone_node(__x); _S_parent(__top) = __p; _STLP_TRY { if (_S_right(__x)) _S_right(__top) = _M_copy(_S_right(__x), __top); __p = __top; __x = _S_left(__x); while (__x != 0) { _Base_ptr __y = _M_clone_node(__x); _S_left(__p) = __y; _S_parent(__y) = __p; if (_S_right(__x)) _S_right(__y) = _M_copy(_S_right(__x), __y); __p = __y; __x = _S_left(__x); } } _STLP_UNWIND(_M_erase(__top)) return __top; }
__iterator__ _Rb_tree<_Key,_Compare,_Value,_KeyOfValue,_Traits,_Alloc> ::_M_insert(_Rb_tree_node_base * __parent, const _Value& __val, _Rb_tree_node_base * __on_left, _Rb_tree_node_base * __on_right) { // We do not create the node here as, depending on tests, we might call // _M_key_compare that can throw an exception. _Base_ptr __new_node; if ( __parent == &this->_M_header._M_data ) { __new_node = _M_create_node(__val); _S_left(__parent) = __new_node; // also makes _M_leftmost() = __new_node _M_root() = __new_node; _M_rightmost() = __new_node; } else if ( __on_right == 0 && // If __on_right != 0, the remainder fails to false ( __on_left != 0 || // If __on_left != 0, the remainder succeeds to true _M_key_compare( _KeyOfValue()(__val), _S_key(__parent) ) ) ) { __new_node = _M_create_node(__val); _S_left(__parent) = __new_node; if (__parent == _M_leftmost()) _M_leftmost() = __new_node; // maintain _M_leftmost() pointing to min node } else { __new_node = _M_create_node(__val); _S_right(__parent) = __new_node; if (__parent == _M_rightmost()) _M_rightmost() = __new_node; // maintain _M_rightmost() pointing to max node } _S_parent(__new_node) = __parent; _Rb_global_inst::_Rebalance(__new_node, this->_M_header._M_data._M_parent); ++_M_node_count; return iterator(__new_node); }
class _Compare, class _Alloc> __iterator__ _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc> ::_M_insert(_Rb_tree_node_base* __x_, _Rb_tree_node_base* __y_, const _Value& __v, _Rb_tree_node_base* __w_) { _Link_type __w = (_Link_type) __w_; _Link_type __x = (_Link_type) __x_; _Link_type __y = (_Link_type) __y_; _Link_type __z; if ( __y == this->_M_header._M_data || ( __w == 0 && // If w != 0, the remainder fails to false ( __x != 0 || // If x != 0, the remainder succeeds to true _M_key_compare( _KeyOfValue()(__v), _S_key(__y) ) ) ) ) { __z = _M_create_node(__v); _S_left(__y) = __z; // also makes _M_leftmost() = __z // when __y == _M_header if (__y == this->_M_header._M_data) { _M_root() = __z; _M_rightmost() = __z; } else if (__y == _M_leftmost()) _M_leftmost() = __z; // maintain _M_leftmost() pointing to min node } else { __z = _M_create_node(__v); _S_right(__y) = __z; if (__y == _M_rightmost()) _M_rightmost() = __z; // maintain _M_rightmost() pointing to max node } _S_parent(__z) = __y; _S_left(__z) = 0; _S_right(__z) = 0; _Rb_global_inst::_Rebalance(__z, this->_M_header._M_data->_M_parent); ++_M_node_count; return iterator(__z); }