41#ifdef PB_DS_CLASS_C_DEC
46splay(node_pointer p_nd)
48 while (p_nd->m_p_parent != base_type::m_p_head)
52 node_pointer p_head = base_type::m_p_head;
53 assert_special_imp(p_head, __FILE__, __LINE__);
57 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_nd)
59 if (p_nd->m_p_parent->m_p_parent == base_type::m_p_head)
61 base_type::rotate_parent(p_nd);
62 _GLIBCXX_DEBUG_ASSERT(p_nd == this->m_p_head->m_p_parent);
66 const node_pointer p_parent = p_nd->m_p_parent;
67 const node_pointer p_grandparent = p_parent->m_p_parent;
70 const size_type total =
71 base_type::recursive_count(p_grandparent);
72 _GLIBCXX_DEBUG_ASSERT(total >= 3);
75 if (p_parent->m_p_left == p_nd &&
76 p_grandparent->m_p_right == p_parent)
77 splay_zig_zag_left(p_nd, p_parent, p_grandparent);
78 else if (p_parent->m_p_right == p_nd &&
79 p_grandparent->m_p_left == p_parent)
80 splay_zig_zag_right(p_nd, p_parent, p_grandparent);
81 else if (p_parent->m_p_left == p_nd &&
82 p_grandparent->m_p_left == p_parent)
83 splay_zig_zig_left(p_nd, p_parent, p_grandparent);
85 splay_zig_zig_right(p_nd, p_parent, p_grandparent);
86 _GLIBCXX_DEBUG_ASSERT(total ==this->recursive_count(p_nd));
89 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_nd)
96splay_zig_zag_left(node_pointer p_nd, node_pointer p_parent,
97 node_pointer p_grandparent)
99 _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent);
100 _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent);
102 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent)
104 _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_left == p_nd &&
105 p_grandparent->m_p_right == p_parent);
107 splay_zz_start(p_nd, p_parent, p_grandparent);
109 node_pointer p_b = p_nd->m_p_right;
110 node_pointer p_c = p_nd->m_p_left;
112 p_nd->m_p_right = p_parent;
113 p_parent->m_p_parent = p_nd;
115 p_nd->m_p_left = p_grandparent;
116 p_grandparent->m_p_parent = p_nd;
118 p_parent->m_p_left = p_b;
120 p_b->m_p_parent = p_parent;
122 p_grandparent->m_p_right = p_c;
124 p_c->m_p_parent = p_grandparent;
126 splay_zz_end(p_nd, p_parent, p_grandparent);
132splay_zig_zag_right(node_pointer p_nd, node_pointer p_parent,
133 node_pointer p_grandparent)
135 _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent);
136 _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent);
138 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent)
140 _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_right == p_nd &&
141 p_grandparent->m_p_left == p_parent);
143 splay_zz_start(p_nd, p_parent, p_grandparent);
145 node_pointer p_b = p_nd->m_p_left;
146 node_pointer p_c = p_nd->m_p_right;
148 p_nd->m_p_left = p_parent;
149 p_parent->m_p_parent = p_nd;
151 p_nd->m_p_right = p_grandparent;
152 p_grandparent->m_p_parent = p_nd;
154 p_parent->m_p_right = p_b;
156 p_b->m_p_parent = p_parent;
158 p_grandparent->m_p_left = p_c;
160 p_c->m_p_parent = p_grandparent;
162 splay_zz_end(p_nd, p_parent, p_grandparent);
168splay_zig_zig_left(node_pointer p_nd, node_pointer p_parent,
169 node_pointer p_grandparent)
171 _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent);
172 _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent);
174 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent)
176 _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_left == p_nd &&
177 p_nd->m_p_parent->m_p_parent->m_p_left == p_nd->m_p_parent);
179 splay_zz_start(p_nd, p_parent, p_grandparent);
181 node_pointer p_b = p_nd->m_p_right;
182 node_pointer p_c = p_parent->m_p_right;
184 p_nd->m_p_right = p_parent;
185 p_parent->m_p_parent = p_nd;
187 p_parent->m_p_right = p_grandparent;
188 p_grandparent->m_p_parent = p_parent;
190 p_parent->m_p_left = p_b;
192 p_b->m_p_parent = p_parent;
194 p_grandparent->m_p_left = p_c;
196 p_c->m_p_parent = p_grandparent;
198 splay_zz_end(p_nd, p_parent, p_grandparent);
204splay_zig_zig_right(node_pointer p_nd, node_pointer p_parent,
205 node_pointer p_grandparent)
207 _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent);
208 _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent);
209 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent)
210 _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_right == p_nd &&
211 p_nd->m_p_parent->m_p_parent->m_p_right == p_nd->m_p_parent);
213 splay_zz_start(p_nd, p_parent, p_grandparent);
215 node_pointer p_b = p_nd->m_p_left;
216 node_pointer p_c = p_parent->m_p_left;
218 p_nd->m_p_left = p_parent;
219 p_parent->m_p_parent = p_nd;
221 p_parent->m_p_left = p_grandparent;
222 p_grandparent->m_p_parent = p_parent;
224 p_parent->m_p_right = p_b;
226 p_b->m_p_parent = p_parent;
228 p_grandparent->m_p_right = p_c;
230 p_c->m_p_parent = p_grandparent;
232 base_type::update_to_top(p_grandparent, (node_update*)
this);
233 splay_zz_end(p_nd, p_parent, p_grandparent);
239splay_zz_start(node_pointer p_nd,
241 node_pointer p_parent,
245 node_pointer p_grandparent)
247 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
248 _GLIBCXX_DEBUG_ASSERT(p_parent != 0);
249 _GLIBCXX_DEBUG_ASSERT(p_grandparent != 0);
251 const bool grandparent_head = p_grandparent->m_p_parent == base_type::m_p_head;
253 if (grandparent_head)
255 base_type::m_p_head->m_p_parent = base_type::m_p_head->m_p_parent;
256 p_nd->m_p_parent = base_type::m_p_head;
260 node_pointer p_greatgrandparent = p_grandparent->m_p_parent;
262 p_nd->m_p_parent = p_greatgrandparent;
264 if (p_grandparent == p_greatgrandparent->m_p_left)
265 p_greatgrandparent->m_p_left = p_nd;
267 p_greatgrandparent->m_p_right = p_nd;
273splay_zz_end(node_pointer p_nd, node_pointer p_parent,
274 node_pointer p_grandparent)
276 if (p_nd->m_p_parent == base_type::m_p_head)
277 base_type::m_p_head->m_p_parent = p_nd;
279 this->apply_update(p_grandparent, (node_update*)
this);
280 this->apply_update(p_parent, (node_update*)
this);
281 this->apply_update(p_nd, (node_update*)
this);
282 PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_nd)