41 #ifdef PB_DS_CLASS_C_DEC
48 PB_DS_ASSERT_VALID((*
this))
49 _GLIBCXX_DEBUG_ASSERT(!base_type::empty());
51 node_pointer p_new_root = join_node_children(base_type::m_p_root);
52 PB_DS_ASSERT_NODE_CONSISTENT(p_new_root, false)
54 p_new_root->m_p_prev_or_parent = 0;
56 base_type::actual_erase_node(base_type::m_p_root);
57 base_type::m_p_root = p_new_root;
58 PB_DS_ASSERT_VALID((*this))
64 erase(point_iterator it)
66 PB_DS_ASSERT_VALID((*
this))
67 _GLIBCXX_DEBUG_ASSERT(!base_type::empty());
68 remove_node(it.m_p_nd);
69 base_type::actual_erase_node(it.m_p_nd);
70 PB_DS_ASSERT_VALID((*this))
76 remove_node(node_pointer p_nd)
78 PB_DS_ASSERT_VALID((*
this))
79 _GLIBCXX_DEBUG_ASSERT(!base_type::empty());
80 node_pointer p_new_child = join_node_children(p_nd);
82 PB_DS_ASSERT_NODE_CONSISTENT(p_new_child, false)
84 if (p_nd == base_type::m_p_root)
87 p_new_child->m_p_prev_or_parent = 0;
88 base_type::m_p_root = p_new_child;
89 PB_DS_ASSERT_NODE_CONSISTENT(base_type::m_p_root,
false)
93 _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_prev_or_parent != 0);
94 if (p_nd->m_p_prev_or_parent->m_p_l_child == p_nd)
98 p_new_child->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
99 p_new_child->m_p_next_sibling = p_nd->m_p_next_sibling;
100 if (p_new_child->m_p_next_sibling != 0)
101 p_new_child->m_p_next_sibling->m_p_prev_or_parent = p_new_child;
102 p_nd->m_p_prev_or_parent->m_p_l_child = p_new_child;
103 PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent,
false)
107 p_nd->m_p_prev_or_parent->m_p_l_child = p_nd->m_p_next_sibling;
108 if (p_nd->m_p_next_sibling != 0)
109 p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
110 PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent, false)
114 if (p_new_child != 0)
116 p_new_child->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
117 p_new_child->m_p_next_sibling = p_nd->m_p_next_sibling;
118 if (p_new_child->m_p_next_sibling != 0)
119 p_new_child->m_p_next_sibling->m_p_prev_or_parent = p_new_child;
120 p_new_child->m_p_prev_or_parent->m_p_next_sibling = p_new_child;
121 PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent,
false)
125 p_nd->m_p_prev_or_parent->m_p_next_sibling = p_nd->m_p_next_sibling;
126 if (p_nd->m_p_next_sibling != 0)
127 p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
128 PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent, false)
132 typename PB_DS_CLASS_C_DEC::node_pointer
134 join_node_children(node_pointer p_nd)
136 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
137 node_pointer p_ret = p_nd->m_p_l_child;
140 while (p_ret->m_p_next_sibling != 0)
141 p_ret = forward_join(p_ret, p_ret->m_p_next_sibling);
142 while (p_ret->m_p_prev_or_parent != p_nd)
143 p_ret = back_join(p_ret->m_p_prev_or_parent, p_ret);
144 PB_DS_ASSERT_NODE_CONSISTENT(p_ret,
false)
149 typename PB_DS_CLASS_C_DEC::node_pointer
151 forward_join(node_pointer p_nd, node_pointer p_next)
153 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
154 _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_next_sibling == p_next);
155 if (Cmp_Fn::operator()(p_nd->m_value, p_next->m_value))
157 p_next->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
158 base_type::make_child_of(p_nd, p_next);
159 return p_next->m_p_next_sibling == 0
160 ? p_next : p_next->m_p_next_sibling;
163 if (p_next->m_p_next_sibling != 0)
165 p_next->m_p_next_sibling->m_p_prev_or_parent = p_nd;
166 p_nd->m_p_next_sibling = p_next->m_p_next_sibling;
167 base_type::make_child_of(p_next, p_nd);
168 return p_nd->m_p_next_sibling;
171 p_nd->m_p_next_sibling = 0;
172 base_type::make_child_of(p_next, p_nd);
173 PB_DS_ASSERT_NODE_CONSISTENT(p_nd,
false)
178 typename PB_DS_CLASS_C_DEC::node_pointer
180 back_join(node_pointer p_nd, node_pointer p_next)
182 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
183 _GLIBCXX_DEBUG_ASSERT(p_next->m_p_next_sibling == 0);
185 if (Cmp_Fn::operator()(p_nd->m_value, p_next->m_value))
187 p_next->m_p_prev_or_parent = p_nd->m_p_prev_or_parent;
188 base_type::make_child_of(p_nd, p_next);
189 PB_DS_ASSERT_NODE_CONSISTENT(p_next,
false)
193 p_nd->m_p_next_sibling = 0;
194 base_type::make_child_of(p_next, p_nd);
195 PB_DS_ASSERT_NODE_CONSISTENT(p_nd, false)
200 template<typename Pred>
201 typename PB_DS_CLASS_C_DEC::size_type
205 PB_DS_ASSERT_VALID((*
this))
206 if (base_type::empty())
208 PB_DS_ASSERT_VALID((*
this))
211 base_type::to_linked_list();
212 node_pointer p_out = base_type::prune(pred);
217 node_pointer p_next = p_out->m_p_next_sibling;
218 base_type::actual_erase_node(p_out);
222 node_pointer p_cur = base_type::m_p_root;
223 base_type::m_p_root = 0;
226 node_pointer p_next = p_cur->m_p_next_sibling;
227 p_cur->m_p_l_child = p_cur->m_p_next_sibling = p_cur->m_p_prev_or_parent = 0;
232 PB_DS_ASSERT_VALID((*
this))