44 splay(node_pointer p_nd)
46 while (p_nd->m_p_parent != base_type::m_p_head)
50 node_pointer p_head = base_type::m_p_head;
51 assert_special_imp(p_head, __FILE__, __LINE__);
55 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_nd)
57 if (p_nd->m_p_parent->m_p_parent == base_type::m_p_head)
59 base_type::rotate_parent(p_nd);
60 _GLIBCXX_DEBUG_ASSERT(p_nd == this->m_p_head->m_p_parent);
64 const node_pointer p_parent = p_nd->m_p_parent;
65 const node_pointer p_grandparent = p_parent->m_p_parent;
68 const size_type total =
69 base_type::recursive_count(p_grandparent);
70 _GLIBCXX_DEBUG_ASSERT(total >= 3);
73 if (p_parent->m_p_left == p_nd &&
74 p_grandparent->m_p_right == p_parent)
75 splay_zig_zag_left(p_nd, p_parent, p_grandparent);
76 else if (p_parent->m_p_right == p_nd &&
77 p_grandparent->m_p_left == p_parent)
78 splay_zig_zag_right(p_nd, p_parent, p_grandparent);
79 else if (p_parent->m_p_left == p_nd &&
80 p_grandparent->m_p_left == p_parent)
81 splay_zig_zig_left(p_nd, p_parent, p_grandparent);
83 splay_zig_zig_right(p_nd, p_parent, p_grandparent);
84 _GLIBCXX_DEBUG_ASSERT(total ==this->recursive_count(p_nd));
87 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_nd)
94 splay_zig_zag_left(node_pointer p_nd, node_pointer p_parent,
95 node_pointer p_grandparent)
97 _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent);
98 _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent);
100 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent)
102 _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_left == p_nd &&
103 p_grandparent->m_p_right == p_parent);
105 splay_zz_start(p_nd, p_parent, p_grandparent);
107 node_pointer p_b = p_nd->m_p_right;
108 node_pointer p_c = p_nd->m_p_left;
110 p_nd->m_p_right = p_parent;
111 p_parent->m_p_parent = p_nd;
113 p_nd->m_p_left = p_grandparent;
114 p_grandparent->m_p_parent = p_nd;
116 p_parent->m_p_left = p_b;
118 p_b->m_p_parent = p_parent;
120 p_grandparent->m_p_right = p_c;
122 p_c->m_p_parent = p_grandparent;
124 splay_zz_end(p_nd, p_parent, p_grandparent);
130 splay_zig_zag_right(node_pointer p_nd, node_pointer p_parent,
131 node_pointer p_grandparent)
133 _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent);
134 _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent);
136 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent)
138 _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_right == p_nd &&
139 p_grandparent->m_p_left == p_parent);
141 splay_zz_start(p_nd, p_parent, p_grandparent);
143 node_pointer p_b = p_nd->m_p_left;
144 node_pointer p_c = p_nd->m_p_right;
146 p_nd->m_p_left = p_parent;
147 p_parent->m_p_parent = p_nd;
149 p_nd->m_p_right = p_grandparent;
150 p_grandparent->m_p_parent = p_nd;
152 p_parent->m_p_right = p_b;
154 p_b->m_p_parent = p_parent;
156 p_grandparent->m_p_left = p_c;
158 p_c->m_p_parent = p_grandparent;
160 splay_zz_end(p_nd, p_parent, p_grandparent);
166 splay_zig_zig_left(node_pointer p_nd, node_pointer p_parent,
167 node_pointer p_grandparent)
169 _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent);
170 _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent);
172 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent)
174 _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_left == p_nd &&
175 p_nd->m_p_parent->m_p_parent->m_p_left == p_nd->m_p_parent);
177 splay_zz_start(p_nd, p_parent, p_grandparent);
179 node_pointer p_b = p_nd->m_p_right;
180 node_pointer p_c = p_parent->m_p_right;
182 p_nd->m_p_right = p_parent;
183 p_parent->m_p_parent = p_nd;
185 p_parent->m_p_right = p_grandparent;
186 p_grandparent->m_p_parent = p_parent;
188 p_parent->m_p_left = p_b;
190 p_b->m_p_parent = p_parent;
192 p_grandparent->m_p_left = p_c;
194 p_c->m_p_parent = p_grandparent;
196 splay_zz_end(p_nd, p_parent, p_grandparent);
202 splay_zig_zig_right(node_pointer p_nd, node_pointer p_parent,
203 node_pointer p_grandparent)
205 _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent);
206 _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent);
207 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent)
208 _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_right == p_nd &&
209 p_nd->m_p_parent->m_p_parent->m_p_right == p_nd->m_p_parent);
211 splay_zz_start(p_nd, p_parent, p_grandparent);
213 node_pointer p_b = p_nd->m_p_left;
214 node_pointer p_c = p_parent->m_p_left;
216 p_nd->m_p_left = p_parent;
217 p_parent->m_p_parent = p_nd;
219 p_parent->m_p_left = p_grandparent;
220 p_grandparent->m_p_parent = p_parent;
222 p_parent->m_p_right = p_b;
224 p_b->m_p_parent = p_parent;
226 p_grandparent->m_p_right = p_c;
228 p_c->m_p_parent = p_grandparent;
230 base_type::update_to_top(p_grandparent, (node_update*)this);
231 splay_zz_end(p_nd, p_parent, p_grandparent);
237 splay_zz_start(node_pointer p_nd,
238 #ifdef _GLIBCXX_DEBUG
239 node_pointer p_parent,
243 node_pointer p_grandparent)
245 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
246 _GLIBCXX_DEBUG_ASSERT(p_parent != 0);
247 _GLIBCXX_DEBUG_ASSERT(p_grandparent != 0);
249 const bool grandparent_head = p_grandparent->m_p_parent == base_type::m_p_head;
251 if (grandparent_head)
253 base_type::m_p_head->m_p_parent = base_type::m_p_head->m_p_parent;
254 p_nd->m_p_parent = base_type::m_p_head;
258 node_pointer p_greatgrandparent = p_grandparent->m_p_parent;
260 p_nd->m_p_parent = p_greatgrandparent;
262 if (p_grandparent == p_greatgrandparent->m_p_left)
263 p_greatgrandparent->m_p_left = p_nd;
265 p_greatgrandparent->m_p_right = p_nd;
271 splay_zz_end(node_pointer p_nd, node_pointer p_parent,
272 node_pointer p_grandparent)
274 if (p_nd->m_p_parent == base_type::m_p_head)
275 base_type::m_p_head->m_p_parent = p_nd;
277 this->apply_update(p_grandparent, (node_update*)
this);
278 this->apply_update(p_parent, (node_update*)
this);
279 this->apply_update(p_nd, (node_update*)
this);
280 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_nd)