46 PB_DS_ASSERT_VALID((*
this))
47 _GLIBCXX_DEBUG_ASSERT(!base_type::empty());
49 node_pointer p_new_root = join_node_children(base_type::m_p_root);
50 PB_DS_ASSERT_NODE_CONSISTENT(p_new_root, false)
52 p_new_root->m_p_prev_or_parent = 0;
54 base_type::actual_erase_node(base_type::m_p_root);
55 base_type::m_p_root = p_new_root;
56 PB_DS_ASSERT_VALID((*this))
62 erase(point_iterator it)
64 PB_DS_ASSERT_VALID((*
this))
65 _GLIBCXX_DEBUG_ASSERT(!base_type::empty());
66 remove_node(it.m_p_nd);
67 base_type::actual_erase_node(it.m_p_nd);
68 PB_DS_ASSERT_VALID((*this))
74 remove_node(node_pointer p_nd)
76 PB_DS_ASSERT_VALID((*
this))
77 _GLIBCXX_DEBUG_ASSERT(!base_type::empty());
78 node_pointer p_new_child = join_node_children(p_nd);
80 PB_DS_ASSERT_NODE_CONSISTENT(p_new_child, false)
82 if (p_nd == base_type::m_p_root)
85 p_new_child->m_p_prev_or_parent = 0;
86 base_type::m_p_root = p_new_child;
87 PB_DS_ASSERT_NODE_CONSISTENT(base_type::m_p_root,
false)
91 _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_prev_or_parent != 0);
92 if (p_nd->m_p_prev_or_parent->m_p_l_child == p_nd)
96 p_new_child->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
97 p_new_child->m_p_next_sibling = p_nd->m_p_next_sibling;
98 if (p_new_child->m_p_next_sibling != 0)
99 p_new_child->m_p_next_sibling->m_p_prev_or_parent = p_new_child;
100 p_nd->m_p_prev_or_parent->m_p_l_child = p_new_child;
101 PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent,
false)
105 p_nd->m_p_prev_or_parent->m_p_l_child = p_nd->m_p_next_sibling;
106 if (p_nd->m_p_next_sibling != 0)
107 p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
108 PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent, false)
112 if (p_new_child != 0)
114 p_new_child->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
115 p_new_child->m_p_next_sibling = p_nd->m_p_next_sibling;
116 if (p_new_child->m_p_next_sibling != 0)
117 p_new_child->m_p_next_sibling->m_p_prev_or_parent = p_new_child;
118 p_new_child->m_p_prev_or_parent->m_p_next_sibling = p_new_child;
119 PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent,
false)
123 p_nd->m_p_prev_or_parent->m_p_next_sibling = p_nd->m_p_next_sibling;
124 if (p_nd->m_p_next_sibling != 0)
125 p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
126 PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent, false)
130 typename PB_DS_CLASS_C_DEC::node_pointer
132 join_node_children(node_pointer p_nd)
134 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
135 node_pointer p_ret = p_nd->m_p_l_child;
138 while (p_ret->m_p_next_sibling != 0)
139 p_ret = forward_join(p_ret, p_ret->m_p_next_sibling);
140 while (p_ret->m_p_prev_or_parent != p_nd)
141 p_ret = back_join(p_ret->m_p_prev_or_parent, p_ret);
142 PB_DS_ASSERT_NODE_CONSISTENT(p_ret,
false)
147 typename PB_DS_CLASS_C_DEC::node_pointer
149 forward_join(node_pointer p_nd, node_pointer p_next)
151 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
152 _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_next_sibling == p_next);
153 if (Cmp_Fn::operator()(p_nd->m_value, p_next->m_value))
155 p_next->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
156 base_type::make_child_of(p_nd, p_next);
157 return p_next->m_p_next_sibling == 0
158 ? p_next : p_next->m_p_next_sibling;
161 if (p_next->m_p_next_sibling != 0)
163 p_next->m_p_next_sibling->m_p_prev_or_parent = p_nd;
164 p_nd->m_p_next_sibling = p_next->m_p_next_sibling;
165 base_type::make_child_of(p_next, p_nd);
166 return p_nd->m_p_next_sibling;
169 p_nd->m_p_next_sibling = 0;
170 base_type::make_child_of(p_next, p_nd);
171 PB_DS_ASSERT_NODE_CONSISTENT(p_nd,
false)
176 typename PB_DS_CLASS_C_DEC::node_pointer
178 back_join(node_pointer p_nd, node_pointer p_next)
180 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
181 _GLIBCXX_DEBUG_ASSERT(p_next->m_p_next_sibling == 0);
183 if (Cmp_Fn::operator()(p_nd->m_value, p_next->m_value))
185 p_next->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
186 base_type::make_child_of(p_nd, p_next);
187 PB_DS_ASSERT_NODE_CONSISTENT(p_next,
false)
191 p_nd->m_p_next_sibling = 0;
192 base_type::make_child_of(p_next, p_nd);
193 PB_DS_ASSERT_NODE_CONSISTENT(p_nd, false)
198 template<typename Pred>
199 typename PB_DS_CLASS_C_DEC::size_type
203 PB_DS_ASSERT_VALID((*
this))
204 if (base_type::empty())
206 PB_DS_ASSERT_VALID((*
this))
209 base_type::to_linked_list();
210 node_pointer p_out = base_type::prune(pred);
215 node_pointer p_next = p_out->m_p_next_sibling;
216 base_type::actual_erase_node(p_out);
220 node_pointer p_cur = base_type::m_p_root;
221 base_type::m_p_root = 0;
224 node_pointer p_next = p_cur->m_p_next_sibling;
225 p_cur->m_p_l_child = p_cur->m_p_next_sibling = p_cur->m_p_prev_or_parent = 0;
230 PB_DS_ASSERT_VALID((*
this))