gcc41 removal: Part 1 of 2: makefiles
[dragonfly.git] / contrib / gcc-4.1 / libstdc++-v3 / include / ext / pb_assoc / detail / bin_search_tree_ / rotate_fn_imps.hpp
1 // -*- C++ -*-
2
3 // Copyright (C) 2005 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
31
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
39
40 /**
41  * @file rotate_fn_imps.hpp
42  * Contains imps for rotating nodes.
43  */
44
45 PB_ASSOC_CLASS_T_DEC
46 inline void
47 PB_ASSOC_CLASS_C_DEC::
48 rotate_left(node_pointer p_x)
49 {
50   node_pointer p_y = p_x->m_p_right;
51
52   p_x->m_p_right = p_y->m_p_left;
53
54   if (p_y->m_p_left != NULL)
55     p_y->m_p_left->m_p_parent = p_x;
56
57   p_y->m_p_parent = p_x->m_p_parent;
58
59   if (p_x == m_p_head->m_p_parent)
60     m_p_head->m_p_parent = p_y;
61   else if (p_x == p_x->m_p_parent->m_p_left)
62     p_x->m_p_parent->m_p_left = p_y;
63   else
64     p_x->m_p_parent->m_p_right = p_y;
65
66   p_y->m_p_left = p_x;
67   p_x->m_p_parent = p_y;
68
69   PB_ASSOC_DBG_ONLY(assert_node_consistent(p_x);)
70     PB_ASSOC_DBG_ONLY(assert_node_consistent(p_y);)
71
72     apply_update(p_x, (Node_Updator* )this);
73   apply_update(p_x->m_p_parent, (Node_Updator* )this);
74 }
75
76 PB_ASSOC_CLASS_T_DEC
77 inline void
78 PB_ASSOC_CLASS_C_DEC::
79 rotate_right(node_pointer p_x)
80 {
81   node_pointer p_y = p_x->m_p_left;
82
83   p_x->m_p_left = p_y->m_p_right;
84
85   if (p_y->m_p_right != NULL)
86     p_y->m_p_right->m_p_parent = p_x;
87
88   p_y->m_p_parent = p_x->m_p_parent;
89
90   if (p_x == m_p_head->m_p_parent)
91     m_p_head->m_p_parent = p_y;
92   else if (p_x == p_x->m_p_parent->m_p_right)
93     p_x->m_p_parent->m_p_right = p_y;
94   else
95     p_x->m_p_parent->m_p_left = p_y;
96
97   p_y->m_p_right = p_x;
98   p_x->m_p_parent = p_y;
99
100   PB_ASSOC_DBG_ONLY(assert_node_consistent(p_x);)
101     PB_ASSOC_DBG_ONLY(assert_node_consistent(p_y);)
102
103     apply_update(p_x, (Node_Updator* )this);
104   apply_update(p_x->m_p_parent, (Node_Updator* )this);
105 }
106
107 PB_ASSOC_CLASS_T_DEC
108 inline void
109 PB_ASSOC_CLASS_C_DEC::
110 rotate_parent(node_pointer p_nd)
111 {
112   node_pointer p_parent = p_nd->m_p_parent;
113
114   if (p_nd == p_parent->m_p_left)
115     rotate_right(p_parent);
116   else
117     rotate_left(p_parent);
118
119   PB_ASSOC_DBG_ASSERT(p_parent->m_p_parent = p_nd);
120   PB_ASSOC_DBG_ASSERT(p_nd->m_p_left == p_parent ||
121                       p_nd->m_p_right == p_parent);
122 }
123
124 PB_ASSOC_CLASS_T_DEC
125 inline void
126 PB_ASSOC_CLASS_C_DEC::
127 apply_update(node_pointer /*p_nd*/, pb_assoc::null_node_updator*  /*p_updator*/)
128 { }
129
130 PB_ASSOC_CLASS_T_DEC
131 template<class Node_Updator_>
132 inline void
133 PB_ASSOC_CLASS_C_DEC::
134 apply_update(node_pointer p_nd, Node_Updator_* p_updator)
135 {
136   p_updator->operator()(
137                         &PB_ASSOC_V2F(p_nd->m_value),(p_nd->m_p_left == NULL)?
138                         NULL :
139                         &PB_ASSOC_V2F(p_nd->m_p_left->m_value),(p_nd->m_p_right == NULL)?
140                         NULL :
141                         &PB_ASSOC_V2F(p_nd->m_p_right->m_value));
142 }
143
144 PB_ASSOC_CLASS_T_DEC
145 template<class Node_Updator_>
146 inline void
147 PB_ASSOC_CLASS_C_DEC::
148 update_to_top(node_pointer p_nd, Node_Updator_* p_updator)
149 {
150   while (p_nd != m_p_head)
151     {
152       apply_update(p_nd, p_updator);
153
154       p_nd = p_nd->m_p_parent;
155     }
156 }
157
158 PB_ASSOC_CLASS_T_DEC
159 inline void
160 PB_ASSOC_CLASS_C_DEC::
161 update_to_top(node_pointer /*p_nd*/, pb_assoc::null_node_updator*  /*p_updator*/)
162 { }
163