3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
43 * @file erase_fn_imps.hpp
44 * Contains an implementation for thin_heap_.
52 _GLIBCXX_DEBUG_ONLY(assert_valid();)
53 _GLIBCXX_DEBUG_ASSERT(!base_type::empty());
55 _GLIBCXX_DEBUG_ASSERT(m_p_max != NULL);
57 node_pointer p_nd = m_p_max;
61 base_type::actual_erase_node(p_nd);
63 _GLIBCXX_DEBUG_ONLY(assert_valid();)
81 node_pointer p_add = base_type::m_p_root;
83 while (p_add != m_p_max)
85 node_pointer p_next_add = p_add->m_p_next_sibling;
92 p_add = m_p_max->m_p_l_child;
96 node_pointer p_next_add = p_add->m_p_next_sibling;
98 p_add->m_metadata = p_add->m_p_l_child == NULL?
100 p_add->m_p_l_child->m_metadata + 1;
107 p_add = m_p_max->m_p_next_sibling;
109 while (p_add != NULL)
111 node_pointer p_next_add = p_add->m_p_next_sibling;
122 add_to_aux(node_pointer p_nd)
124 size_type r = p_nd->m_metadata;
126 while (m_a_aux[r] != NULL)
128 _GLIBCXX_DEBUG_ASSERT(p_nd->m_metadata < rank_bound());
130 if (Cmp_Fn::operator()(m_a_aux[r]->m_value, p_nd->m_value))
131 make_child_of(m_a_aux[r], p_nd);
134 make_child_of(p_nd, m_a_aux[r]);
144 _GLIBCXX_DEBUG_ASSERT(p_nd->m_metadata < rank_bound());
152 make_child_of(node_pointer p_nd, node_pointer p_new_parent)
154 _GLIBCXX_DEBUG_ASSERT(p_nd->m_metadata == p_new_parent->m_metadata);
155 _GLIBCXX_DEBUG_ASSERT(m_a_aux[p_nd->m_metadata] == p_nd ||
156 m_a_aux[p_nd->m_metadata] == p_new_parent);
158 ++p_new_parent->m_metadata;
160 base_type::make_child_of(p_nd, p_new_parent);
168 base_type::m_p_root = m_p_max = NULL;
170 const size_type rnk_bnd = rank_bound();
176 if (m_a_aux[i] != NULL)
178 make_root_and_link(m_a_aux[i]);
186 _GLIBCXX_DEBUG_ONLY(assert_aux_null();)
192 remove_node(node_pointer p_nd)
194 node_pointer p_parent = p_nd;
195 while (base_type::parent(p_parent) != NULL)
196 p_parent = base_type::parent(p_parent);
198 base_type::bubble_to_top(p_nd);
202 node_pointer p_fix = base_type::m_p_root;
203 while (p_fix != NULL&& p_fix->m_p_next_sibling != p_parent)
204 p_fix = p_fix->m_p_next_sibling;
207 p_fix->m_p_next_sibling = p_nd;
225 erase(point_iterator it)
227 _GLIBCXX_DEBUG_ONLY(assert_valid();)
228 _GLIBCXX_DEBUG_ASSERT(!base_type::empty());
230 node_pointer p_nd = it.m_p_nd;
234 base_type::actual_erase_node(p_nd);
236 _GLIBCXX_DEBUG_ONLY(assert_valid();)
240 template<typename Pred>
241 typename PB_DS_CLASS_C_DEC::size_type
245 _GLIBCXX_DEBUG_ONLY(assert_valid();)
247 if (base_type::empty())
249 _GLIBCXX_DEBUG_ONLY(assert_valid();)
254 base_type::to_linked_list();
256 node_pointer p_out = base_type::prune(pred);
260 while (p_out != NULL)
264 node_pointer p_next = p_out->m_p_next_sibling;
266 base_type::actual_erase_node(p_out);
271 node_pointer p_cur = base_type::m_p_root;
273 m_p_max = base_type::m_p_root = NULL;
275 while (p_cur != NULL)
277 node_pointer p_next = p_cur->m_p_next_sibling;
279 make_root_and_link(p_cur);
284 _GLIBCXX_DEBUG_ONLY(assert_valid();)
290 inline typename PB_DS_CLASS_C_DEC::size_type
294 const std::size_t* const p_upper =
295 std::upper_bound( g_a_rank_bounds, g_a_rank_bounds + num_distinct_rank_bounds, base_type::m_size);
297 if (p_upper == g_a_rank_bounds + num_distinct_rank_bounds)
300 return (p_upper - g_a_rank_bounds);