3 // Copyright (C) 2005 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
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
41 * @file erase_fn_imps.hpp
42 * Contains an implementation class for splay_tree_.
46 inline typename PB_ASSOC_CLASS_C_DEC::size_type
47 PB_ASSOC_CLASS_C_DEC::
48 erase(const_key_reference r_key)
50 iterator it = find(r_key);
52 if (it == PB_ASSOC_BASE_C_DEC::find_end())
61 inline typename PB_ASSOC_CLASS_C_DEC::const_iterator
62 PB_ASSOC_CLASS_C_DEC::
63 erase(const_iterator it)
65 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid());
67 if (it == PB_ASSOC_BASE_C_DEC::find_end())
70 const_iterator ret_it = it;
74 erase_node(it.m_p_nd);
79 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
81 inline typename PB_ASSOC_CLASS_C_DEC::iterator
82 PB_ASSOC_CLASS_C_DEC::
85 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid());
86 PB_ASSOC_DBG_ONLY(PB_ASSOC_BASE_C_DEC::assert_iterators();)
88 if (it == PB_ASSOC_BASE_C_DEC::find_end())
95 erase_node(it.m_p_nd);
97 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid());
98 PB_ASSOC_DBG_ONLY(PB_ASSOC_BASE_C_DEC::assert_iterators();)
102 #endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
105 inline typename PB_ASSOC_CLASS_C_DEC::const_reverse_iterator
106 PB_ASSOC_CLASS_C_DEC::
107 erase(const_reverse_iterator it)
109 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid());
111 if (it == PB_ASSOC_BASE_C_DEC::find_rend())
114 const_reverse_iterator ret_it = it;
118 erase_node(it.m_p_nd);
120 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid());
125 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
127 inline typename PB_ASSOC_CLASS_C_DEC::reverse_iterator
128 PB_ASSOC_CLASS_C_DEC::
129 erase(reverse_iterator it)
131 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid());
133 if (it == PB_ASSOC_BASE_C_DEC::find_rend())
136 reverse_iterator ret_it = it;
140 erase_node(it.m_p_nd);
142 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid());
146 #endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
150 inline typename PB_ASSOC_CLASS_C_DEC::size_type
151 PB_ASSOC_CLASS_C_DEC::
154 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
156 size_type num_ersd = 0;
158 iterator it = PB_ASSOC_BASE_C_DEC::begin();
160 while (it != PB_ASSOC_BASE_C_DEC::end())
170 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
177 PB_ASSOC_CLASS_C_DEC::
178 erase_node(node_pointer p_nd)
180 PB_ASSOC_DBG_ASSERT(p_nd != NULL);
184 PB_ASSOC_DBG_ONLY(assert_valid();)
185 PB_ASSOC_DBG_ASSERT(p_nd == PB_ASSOC_BASE_C_DEC::m_p_head->m_p_parent);
187 node_pointer p_l = p_nd->m_p_left;
188 node_pointer p_r = p_nd->m_p_right;
190 PB_ASSOC_BASE_C_DEC::update_min_max_for_erased_node(p_nd);
192 PB_ASSOC_BASE_C_DEC::actual_erase_node(p_nd);
196 PB_ASSOC_BASE_C_DEC::m_p_head->m_p_parent = p_l;
199 p_l->m_p_parent = PB_ASSOC_BASE_C_DEC::m_p_head;
201 PB_ASSOC_DBG_ONLY(assert_valid();)
206 node_pointer p_target_r = leftmost(p_r);
208 PB_ASSOC_DBG_ASSERT(p_target_r != NULL);
210 p_r->m_p_parent = PB_ASSOC_BASE_C_DEC::m_p_head;
212 PB_ASSOC_BASE_C_DEC::m_p_head->m_p_parent = p_r;
216 PB_ASSOC_DBG_ONLY(p_target_r->m_p_left = NULL);
218 PB_ASSOC_DBG_ASSERT(p_target_r->m_p_parent ==
219 PB_ASSOC_BASE_C_DEC::m_p_head);
221 PB_ASSOC_DBG_ASSERT(PB_ASSOC_BASE_C_DEC::m_p_head->m_p_parent ==
224 p_target_r->m_p_left = p_l;
227 p_l->m_p_parent = p_target_r;
229 PB_ASSOC_DBG_ONLY(assert_valid();)
231 apply_update(p_target_r, (Node_Updator* )this);
235 inline typename PB_ASSOC_CLASS_C_DEC::node_pointer
236 PB_ASSOC_CLASS_C_DEC::
237 leftmost(node_pointer p_nd)
239 PB_ASSOC_DBG_ASSERT(p_nd != NULL);
241 while (p_nd->m_p_left != NULL)
242 p_nd = p_nd->m_p_left;