summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-09 20:58:32 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-09 20:58:32 +0000
commit4aa64ee6963597b30760d188245e20d81ef070af (patch)
tree2563a91854f242ee20cb5e919aa383edf7350c59 /libstdc++-v3/include
parent65cf86d5744ddf09aa0bac75f1d38438a5a75102 (diff)
downloadgcc-4aa64ee6963597b30760d188245e20d81ef070af.tar.gz
2003-07-09 Gawain Bolton <gp.bolton@computer.org>
* include/bits/stl_tree.h: Move larger member functions in _Rb_tree_base_iterator and _Rb_tree_node to... * src/stl_tree.cc: Here. * src/Makefile.in: Add stl_tree.cc. * src/Makefile.in: Regenerated. * config/linker-map.gnu: Add symbols here. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@69150 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/bits/stl_tree.h302
1 files changed, 11 insertions, 291 deletions
diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h
index eb124de11e1..9ce52f336e0 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -132,51 +132,10 @@ namespace std
_Base_ptr _M_node;
void
- _M_increment()
- {
- if (_M_node->_M_right != 0)
- {
- _M_node = _M_node->_M_right;
- while (_M_node->_M_left != 0)
- _M_node = _M_node->_M_left;
- }
- else
- {
- _Base_ptr __y = _M_node->_M_parent;
- while (_M_node == __y->_M_right)
- {
- _M_node = __y;
- __y = __y->_M_parent;
- }
- if (_M_node->_M_right != __y)
- _M_node = __y;
- }
- }
+ _M_increment();
void
- _M_decrement()
- {
- if (_M_node->_M_color == _S_red
- && _M_node->_M_parent->_M_parent == _M_node)
- _M_node = _M_node->_M_right;
- else if (_M_node->_M_left != 0)
- {
- _Base_ptr __y = _M_node->_M_left;
- while (__y->_M_right != 0)
- __y = __y->_M_right;
- _M_node = __y;
- }
- else
- {
- _Base_ptr __y = _M_node->_M_parent;
- while (_M_node == __y->_M_left)
- {
- _M_node = __y;
- __y = __y->_M_parent;
- }
- _M_node = __y;
- }
- }
+ _M_decrement();
};
template<typename _Val, typename _Ref, typename _Ptr>
@@ -264,255 +223,18 @@ namespace std
const _Rb_tree_iterator<_Val, const _Val&, const _Val*>& __y)
{ return __x._M_node != __y._M_node; }
- inline void
- _Rb_tree_rotate_left(_Rb_tree_node_base* const __x, _Rb_tree_node_base*& __root)
- {
- _Rb_tree_node_base* const __y = __x->_M_right;
- __x->_M_right = __y->_M_left;
- if (__y->_M_left !=0)
- __y->_M_left->_M_parent = __x;
- __y->_M_parent = __x->_M_parent;
-
- if (__x == __root)
- __root = __y;
- else if (__x == __x->_M_parent->_M_left)
- __x->_M_parent->_M_left = __y;
- else
- __x->_M_parent->_M_right = __y;
- __y->_M_left = __x;
- __x->_M_parent = __y;
- }
+ void
+ _Rb_tree_rotate_left(_Rb_tree_node_base* const __x, _Rb_tree_node_base*& __root);
- inline void
- _Rb_tree_rotate_right(_Rb_tree_node_base* const __x, _Rb_tree_node_base*& __root)
- {
- _Rb_tree_node_base* const __y = __x->_M_left;
- __x->_M_left = __y->_M_right;
- if (__y->_M_right != 0)
- __y->_M_right->_M_parent = __x;
- __y->_M_parent = __x->_M_parent;
-
- if (__x == __root)
- __root = __y;
- else if (__x == __x->_M_parent->_M_right)
- __x->_M_parent->_M_right = __y;
- else
- __x->_M_parent->_M_left = __y;
- __y->_M_right = __x;
- __x->_M_parent = __y;
- }
-
- inline void
- _Rb_tree_rebalance(_Rb_tree_node_base* __x, _Rb_tree_node_base*& __root)
- {
- __x->_M_color = _S_red;
- while (__x != __root
- && __x->_M_parent->_M_color == _S_red)
- {
- _Rb_tree_node_base* const __xpp = __x->_M_parent->_M_parent;
+ void
+ _Rb_tree_rotate_right(_Rb_tree_node_base* const __x, _Rb_tree_node_base*& __root);
- if (__x->_M_parent == __xpp->_M_left)
- {
- _Rb_tree_node_base* const __y = __xpp->_M_right;
- if (__y && __y->_M_color == _S_red)
- {
- __x->_M_parent->_M_color = _S_black;
- __y->_M_color = _S_black;
- __xpp->_M_color = _S_red;
- __x = __xpp;
- }
- else
- {
- if (__x == __x->_M_parent->_M_right)
- {
- __x = __x->_M_parent;
- _Rb_tree_rotate_left(__x, __root);
- }
- __x->_M_parent->_M_color = _S_black;
- __xpp->_M_color = _S_red;
- _Rb_tree_rotate_right(__xpp, __root);
- }
- }
- else
- {
- _Rb_tree_node_base* const __y = __xpp->_M_left;
- if (__y && __y->_M_color == _S_red)
- {
- __x->_M_parent->_M_color = _S_black;
- __y->_M_color = _S_black;
- __xpp->_M_color = _S_red;
- __x = __xpp;
- }
- else
- {
- if (__x == __x->_M_parent->_M_left)
- {
- __x = __x->_M_parent;
- _Rb_tree_rotate_right(__x, __root);
- }
- __x->_M_parent->_M_color = _S_black;
- __xpp->_M_color = _S_red;
- _Rb_tree_rotate_left(__xpp, __root);
- }
- }
- }
- __root->_M_color = _S_black;
- }
+ void
+ _Rb_tree_rebalance(_Rb_tree_node_base* __x, _Rb_tree_node_base*& __root);
- inline _Rb_tree_node_base*
+ _Rb_tree_node_base*
_Rb_tree_rebalance_for_erase(_Rb_tree_node_base* const __z,
- _Rb_tree_node_base*& __root,
- _Rb_tree_node_base*& __leftmost,
- _Rb_tree_node_base*& __rightmost)
- {
- _Rb_tree_node_base* __y = __z;
- _Rb_tree_node_base* __x = 0;
- _Rb_tree_node_base* __x_parent = 0;
- if (__y->_M_left == 0) // __z has at most one non-null child. y == z.
- __x = __y->_M_right; // __x might be null.
- else
- if (__y->_M_right == 0) // __z has exactly one non-null child. y == z.
- __x = __y->_M_left; // __x is not null.
- else
- {
- // __z has two non-null children. Set __y to
- __y = __y->_M_right; // __z's successor. __x might be null.
- while (__y->_M_left != 0)
- __y = __y->_M_left;
- __x = __y->_M_right;
- }
- if (__y != __z)
- {
- // relink y in place of z. y is z's successor
- __z->_M_left->_M_parent = __y;
- __y->_M_left = __z->_M_left;
- if (__y != __z->_M_right)
- {
- __x_parent = __y->_M_parent;
- if (__x) __x->_M_parent = __y->_M_parent;
- __y->_M_parent->_M_left = __x; // __y must be a child of _M_left
- __y->_M_right = __z->_M_right;
- __z->_M_right->_M_parent = __y;
- }
- else
- __x_parent = __y;
- if (__root == __z)
- __root = __y;
- else if (__z->_M_parent->_M_left == __z)
- __z->_M_parent->_M_left = __y;
- else
- __z->_M_parent->_M_right = __y;
- __y->_M_parent = __z->_M_parent;
- std::swap(__y->_M_color, __z->_M_color);
- __y = __z;
- // __y now points to node to be actually deleted
- }
- else
- { // __y == __z
- __x_parent = __y->_M_parent;
- if (__x)
- __x->_M_parent = __y->_M_parent;
- if (__root == __z)
- __root = __x;
- else
- if (__z->_M_parent->_M_left == __z)
- __z->_M_parent->_M_left = __x;
- else
- __z->_M_parent->_M_right = __x;
- if (__leftmost == __z)
- if (__z->_M_right == 0) // __z->_M_left must be null also
- __leftmost = __z->_M_parent;
- // makes __leftmost == _M_header if __z == __root
- else
- __leftmost = _Rb_tree_node_base::_S_minimum(__x);
- if (__rightmost == __z)
- if (__z->_M_left == 0) // __z->_M_right must be null also
- __rightmost = __z->_M_parent;
- // makes __rightmost == _M_header if __z == __root
- else // __x == __z->_M_left
- __rightmost = _Rb_tree_node_base::_S_maximum(__x);
- }
- if (__y->_M_color != _S_red)
- {
- while (__x != __root && (__x == 0 || __x->_M_color == _S_black))
- if (__x == __x_parent->_M_left)
- {
- _Rb_tree_node_base* __w = __x_parent->_M_right;
- if (__w->_M_color == _S_red)
- {
- __w->_M_color = _S_black;
- __x_parent->_M_color = _S_red;
- _Rb_tree_rotate_left(__x_parent, __root);
- __w = __x_parent->_M_right;
- }
- if ((__w->_M_left == 0 ||
- __w->_M_left->_M_color == _S_black) &&
- (__w->_M_right == 0 ||
- __w->_M_right->_M_color == _S_black))
- {
- __w->_M_color = _S_red;
- __x = __x_parent;
- __x_parent = __x_parent->_M_parent;
- }
- else
- {
- if (__w->_M_right == 0
- || __w->_M_right->_M_color == _S_black)
- {
- __w->_M_left->_M_color = _S_black;
- __w->_M_color = _S_red;
- _Rb_tree_rotate_right(__w, __root);
- __w = __x_parent->_M_right;
- }
- __w->_M_color = __x_parent->_M_color;
- __x_parent->_M_color = _S_black;
- if (__w->_M_right)
- __w->_M_right->_M_color = _S_black;
- _Rb_tree_rotate_left(__x_parent, __root);
- break;
- }
- }
- else
- {
- // same as above, with _M_right <-> _M_left.
- _Rb_tree_node_base* __w = __x_parent->_M_left;
- if (__w->_M_color == _S_red)
- {
- __w->_M_color = _S_black;
- __x_parent->_M_color = _S_red;
- _Rb_tree_rotate_right(__x_parent, __root);
- __w = __x_parent->_M_left;
- }
- if ((__w->_M_right == 0 ||
- __w->_M_right->_M_color == _S_black) &&
- (__w->_M_left == 0 ||
- __w->_M_left->_M_color == _S_black))
- {
- __w->_M_color = _S_red;
- __x = __x_parent;
- __x_parent = __x_parent->_M_parent;
- }
- else
- {
- if (__w->_M_left == 0 || __w->_M_left->_M_color == _S_black)
- {
- __w->_M_right->_M_color = _S_black;
- __w->_M_color = _S_red;
- _Rb_tree_rotate_left(__w, __root);
- __w = __x_parent->_M_left;
- }
- __w->_M_color = __x_parent->_M_color;
- __x_parent->_M_color = _S_black;
- if (__w->_M_left)
- __w->_M_left->_M_color = _S_black;
- _Rb_tree_rotate_right(__x_parent, __root);
- break;
- }
- }
- if (__x) __x->_M_color = _S_black;
- }
- return __y;
- }
+ _Rb_tree_node_base& __header);
// Base class to encapsulate the differences between old SGI-style
// allocators and standard-conforming allocators. In order to avoid
@@ -1209,9 +931,7 @@ namespace std
{
_Link_type __y =
(_Link_type) _Rb_tree_rebalance_for_erase(__position._M_node,
- this->_M_header._M_parent,
- this->_M_header._M_left,
- this->_M_header._M_right);
+ this->_M_header);
destroy_node(__y);
--_M_node_count;
}