RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / toolchains / hndtools-arm-linux-2.6.36-uclibc-4.5.3 / arm-brcm-linux-uclibcgnueabi / include / c++ / 4.5.3 / ext / pb_ds / detail / ov_tree_map_ / erase_fn_imps.hpp
blob05e7d1a11075ce1ed323b132a41a3090069a5a8d
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
4 //
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 3, or (at your option) any later
9 // version.
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 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
34 // warranty.
36 /**
37 * @file erase_fn_imps.hpp
38 * Contains an implementation class for ov_tree_.
41 PB_DS_CLASS_T_DEC
42 void
43 PB_DS_CLASS_C_DEC::
44 clear()
46 _GLIBCXX_DEBUG_ONLY(assert_valid();)
47 if (m_size == 0)
49 _GLIBCXX_DEBUG_ONLY(assert_valid();)
50 return;
52 else
54 reallocate_metadata((node_update* )this, 0);
55 cond_dtor<size_type> cd(m_a_values, m_end_it, m_size);
58 _GLIBCXX_DEBUG_ONLY(debug_base::clear();)
59 m_a_values = NULL;
60 m_size = 0;
61 m_end_it = m_a_values;
62 _GLIBCXX_DEBUG_ONLY(assert_valid();)
65 PB_DS_CLASS_T_DEC
66 template<typename Pred>
67 inline typename PB_DS_CLASS_C_DEC::size_type
68 PB_DS_CLASS_C_DEC::
69 erase_if(Pred pred)
71 _GLIBCXX_DEBUG_ONLY(assert_valid();)
73 #ifdef PB_DS_REGRESSION
74 typename Allocator::group_adjustor adjust(m_size);
75 #endif
77 size_type new_size = 0;
78 size_type num_val_ersd = 0;
79 iterator source_it = m_a_values;
80 for (source_it = begin(); source_it != m_end_it; ++source_it)
81 if (!pred(*source_it))
82 ++new_size;
83 else
84 ++num_val_ersd;
86 if (new_size == 0)
88 clear();
89 return num_val_ersd;
92 value_vector a_new_values = s_value_alloc.allocate(new_size);
93 iterator target_it = a_new_values;
94 cond_dtor<size_type> cd(a_new_values, target_it, new_size);
95 _GLIBCXX_DEBUG_ONLY(debug_base::clear());
96 for (source_it = begin(); source_it != m_end_it; ++source_it)
98 if (!pred(*source_it))
100 new (const_cast<void*>(static_cast<const void* >(target_it)))
101 value_type(*source_it);
103 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(*source_it)));
104 ++target_it;
108 reallocate_metadata((node_update* )this, new_size);
109 cd.set_no_action();
112 cond_dtor<size_type> cd1(m_a_values, m_end_it, m_size);
115 m_a_values = a_new_values;
116 m_size = new_size;
117 m_end_it = target_it;
118 update(node_begin(), (node_update* )this);
119 _GLIBCXX_DEBUG_ONLY(assert_valid();)
120 return num_val_ersd;
123 PB_DS_CLASS_T_DEC
124 template<typename It>
126 PB_DS_CLASS_C_DEC::
127 erase_imp(It it)
129 _GLIBCXX_DEBUG_ONLY(assert_valid();)
130 if (it == end())
131 return end();
133 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::check_key_exists(PB_DS_V2F(*it));)
135 #ifdef PB_DS_REGRESSION
136 typename Allocator::group_adjustor adjust(m_size);
137 #endif
139 _GLIBCXX_DEBUG_ASSERT(m_size > 0);
140 value_vector a_values = s_value_alloc.allocate(m_size - 1);
141 iterator source_it = begin();
142 iterator source_end_it = end();
143 iterator target_it = a_values;
144 iterator ret_it = end();
146 cond_dtor<size_type> cd(a_values, target_it, m_size - 1);
148 _GLIBCXX_DEBUG_ONLY(size_type cnt = 0;)
150 while (source_it != source_end_it)
152 if (source_it != it)
154 _GLIBCXX_DEBUG_ONLY(++cnt;)
155 _GLIBCXX_DEBUG_ASSERT(cnt != m_size);
156 new (const_cast<void* >(static_cast<const void* >(target_it)))
157 value_type(*source_it);
159 ++target_it;
161 else
162 ret_it = target_it;
163 ++source_it;
166 _GLIBCXX_DEBUG_ASSERT(m_size > 0);
167 reallocate_metadata((node_update* )this, m_size - 1);
168 cd.set_no_action();
169 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::erase_existing(PB_DS_V2F(*it));)
171 cond_dtor<size_type> cd1(m_a_values, m_end_it, m_size);
174 m_a_values = a_values;
175 --m_size;
176 m_end_it = m_a_values + m_size;
177 update(node_begin(), (node_update* )this);
178 _GLIBCXX_DEBUG_ONLY(assert_valid();)
179 return It(ret_it);
182 PB_DS_CLASS_T_DEC
183 bool
184 PB_DS_CLASS_C_DEC::
185 erase(const_key_reference r_key)
187 point_iterator it = find(r_key);
188 if (it == end())
189 return false;
190 erase(it);
191 return true;