44 erase(key_const_reference r_key)
46 node_pointer p_nd = find_imp(r_key);
47 if (p_nd == 0 || p_nd->m_type == i_node)
49 PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
53 _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == leaf_node);
54 if (!synth_access_traits::equal_keys(PB_DS_V2F(reinterpret_cast<leaf_pointer>(p_nd)->value()), r_key))
56 PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
60 PB_DS_CHECK_KEY_EXISTS(r_key)
61 erase_leaf(static_cast<leaf_pointer>(p_nd));
62 PB_DS_ASSERT_VALID((*this))
69 erase_fixup(inode_pointer p_nd)
71 _GLIBCXX_DEBUG_ASSERT(
std::distance(p_nd->begin(), p_nd->end()) >= 1);
74 node_pointer p_parent = p_nd->m_p_parent;
75 if (p_parent == m_p_head)
76 m_p_head->m_p_parent = *p_nd->begin();
79 _GLIBCXX_DEBUG_ASSERT(p_parent->m_type == i_node);
80 node_pointer p_new_child = *p_nd->begin();
82 typedef inode_pointer inode_ptr;
83 inode_ptr p_internal =
static_cast<inode_ptr
>(p_parent);
84 p_internal->replace_child(p_new_child, pref_begin(p_new_child),
85 pref_end(p_new_child),
this);
87 (*p_nd->begin())->m_p_parent = p_nd->m_p_parent;
89 s_inode_allocator.deallocate(p_nd, 1);
91 if (p_parent == m_p_head)
94 _GLIBCXX_DEBUG_ASSERT(p_parent->m_type == i_node);
95 p_nd =
static_cast<inode_pointer
>(p_parent);
100 _GLIBCXX_DEBUG_ASSERT(
std::distance(p_nd->begin(), p_nd->end()) > 1);
101 p_nd->update_prefixes(
this);
102 apply_update(p_nd, (node_update*)
this);
103 PB_DS_ASSERT_NODE_VALID(p_nd)
104 if (p_nd->m_p_parent->m_type == head_node)
107 _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_parent->m_type == i_node);
109 p_nd = static_cast<inode_pointer>(p_nd->m_p_parent);
116 actual_erase_leaf(leaf_pointer p_l)
118 _GLIBCXX_DEBUG_ASSERT(m_size > 0);
120 _GLIBCXX_DEBUG_ONLY(debug_base::erase_existing(PB_DS_V2F(p_l->value())));
122 s_leaf_allocator.deallocate(p_l, 1);
132 clear_imp(m_p_head->m_p_parent);
135 _GLIBCXX_DEBUG_ONLY(debug_base::clear();)
136 PB_DS_ASSERT_VALID((*
this))
143 clear_imp(node_pointer p_nd)
145 if (p_nd->m_type == i_node)
147 _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == i_node);
148 for (
typename inode::iterator it =
149 static_cast<inode_pointer>(p_nd)->
begin();
150 it !=
static_cast<inode_pointer
>(p_nd)->
end();
153 node_pointer p_child =* it;
156 s_inode_allocator.deallocate(static_cast<inode_pointer>(p_nd), 1);
160 _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == leaf_node);
161 static_cast<leaf_pointer
>(p_nd)->~leaf();
162 s_leaf_allocator.deallocate(static_cast<leaf_pointer>(p_nd), 1);
166 inline typename PB_DS_CLASS_C_DEC::const_iterator
168 erase(const_iterator it)
170 PB_DS_ASSERT_VALID((*
this))
175 const_iterator ret_it = it;
177 _GLIBCXX_DEBUG_ASSERT(it.m_p_nd->m_type == leaf_node);
178 erase_leaf(static_cast<leaf_pointer>(it.m_p_nd));
179 PB_DS_ASSERT_VALID((*this))
183 #ifdef PB_DS_DATA_TRUE_INDICATOR
185 inline typename PB_DS_CLASS_C_DEC::iterator
189 PB_DS_ASSERT_VALID((*
this))
193 iterator ret_it = it;
195 _GLIBCXX_DEBUG_ASSERT(it.m_p_nd->m_type == leaf_node);
196 erase_leaf(static_cast<leaf_pointer>(it.m_p_nd));
197 PB_DS_ASSERT_VALID((*this))
200 #endif // #ifdef PB_DS_DATA_TRUE_INDICATOR
203 inline typename PB_DS_CLASS_C_DEC::const_reverse_iterator
205 erase(const_reverse_iterator it)
207 PB_DS_ASSERT_VALID((*
this))
209 if (it.m_p_nd == m_p_head)
211 const_reverse_iterator ret_it = it;
214 _GLIBCXX_DEBUG_ASSERT(it.m_p_nd->m_type == leaf_node);
215 erase_leaf(static_cast<leaf_pointer>(it.m_p_nd));
216 PB_DS_ASSERT_VALID((*this))
220 #ifdef PB_DS_DATA_TRUE_INDICATOR
222 inline typename PB_DS_CLASS_C_DEC::reverse_iterator
224 erase(reverse_iterator it)
226 PB_DS_ASSERT_VALID((*
this))
228 if (it.m_p_nd == m_p_head)
230 reverse_iterator ret_it = it;
233 _GLIBCXX_DEBUG_ASSERT(it.m_p_nd->m_type == leaf_node);
234 erase_leaf(static_cast<leaf_pointer>(it.m_p_nd));
235 PB_DS_ASSERT_VALID((*this))
238 #endif // #ifdef PB_DS_DATA_TRUE_INDICATOR
241 template<
typename Pred>
242 inline typename PB_DS_CLASS_C_DEC::size_type
246 size_type num_ersd = 0;
247 PB_DS_ASSERT_VALID((*
this))
249 iterator it =
begin();
252 PB_DS_ASSERT_VALID((*
this))
262 PB_DS_ASSERT_VALID((*
this))
269 erase_leaf(leaf_pointer p_l)
271 update_min_max_for_erased_leaf(p_l);
272 if (p_l->m_p_parent->m_type == head_node)
274 _GLIBCXX_DEBUG_ASSERT(size() == 1);
279 _GLIBCXX_DEBUG_ASSERT(size() > 1);
280 _GLIBCXX_DEBUG_ASSERT(p_l->m_p_parent->m_type == i_node);
282 inode_pointer p_parent =
static_cast<inode_pointer
>(p_l->m_p_parent);
284 p_parent->remove_child(p_l);
285 erase_fixup(p_parent);
286 actual_erase_leaf(p_l);
292 update_min_max_for_erased_leaf(leaf_pointer p_l)
296 m_p_head->m_p_min = m_p_head;
297 m_p_head->m_p_max = m_p_head;
301 if (p_l == static_cast<leaf_const_pointer>(m_p_head->m_p_min))
305 m_p_head->m_p_min = it.m_p_nd;
309 if (p_l == static_cast<leaf_const_pointer>(m_p_head->m_p_max))
313 m_p_head->m_p_max = it.m_p_nd;
auto end(_Container &__cont) -> decltype(__cont.end())
Return an iterator pointing to one past the last element of the container.
auto begin(_Container &__cont) -> decltype(__cont.begin())
Return an iterator pointing to the first element of the container.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.