Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / ext / pb_ds / detail / ov_tree_map_ / erase_fn_imps.hpp
blob18f9e1ce8456280c60a51e796306bc7ec6d5c03f
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006 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 2, 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 // 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
29 // Public License.
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
40 // warranty.
42 /**
43 * @file erase_fn_imps.hpp
44 * Contains an implementation class for ov_tree_.
47 PB_DS_CLASS_T_DEC
48 void
49 PB_DS_CLASS_C_DEC::
50 clear()
52 _GLIBCXX_DEBUG_ONLY(assert_valid();)
53 if (m_size == 0)
55 _GLIBCXX_DEBUG_ONLY(assert_valid();)
56 return;
58 else
60 reallocate_metadata((node_update* )this, 0);
61 cond_dtor<size_type> cd(m_a_values, m_end_it, m_size);
64 _GLIBCXX_DEBUG_ONLY(debug_base::clear();)
65 m_a_values = NULL;
66 m_size = 0;
67 m_end_it = m_a_values;
68 _GLIBCXX_DEBUG_ONLY(assert_valid();)
71 PB_DS_CLASS_T_DEC
72 template<typename Pred>
73 inline typename PB_DS_CLASS_C_DEC::size_type
74 PB_DS_CLASS_C_DEC::
75 erase_if(Pred pred)
77 _GLIBCXX_DEBUG_ONLY(assert_valid();)
79 #ifdef PB_DS_REGRESSION
80 typename Allocator::group_throw_prob_adjustor adjust(m_size);
81 #endif
83 size_type new_size = 0;
84 size_type num_val_ersd = 0;
85 iterator source_it = m_a_values;
86 for (source_it = begin(); source_it != m_end_it; ++source_it)
87 if (!pred(*source_it))
88 ++new_size;
89 else
90 ++num_val_ersd;
92 if (new_size == 0)
94 clear();
95 return num_val_ersd;
98 value_vector a_new_values = s_value_alloc.allocate(new_size);
99 iterator target_it = a_new_values;
100 cond_dtor<size_type> cd(a_new_values, target_it, new_size);
101 _GLIBCXX_DEBUG_ONLY(debug_base::clear());
102 for (source_it = begin(); source_it != m_end_it; ++source_it)
104 if (!pred(*source_it))
106 new (const_cast<void*>(static_cast<const void* >(target_it)))
107 value_type(*source_it);
109 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(*source_it)));
110 ++target_it;
114 reallocate_metadata((node_update* )this, new_size);
115 cd.set_no_action();
118 cond_dtor<size_type> cd1(m_a_values, m_end_it, m_size);
121 m_a_values = a_new_values;
122 m_size = new_size;
123 m_end_it = target_it;
124 update(node_begin(), (node_update* )this);
125 _GLIBCXX_DEBUG_ONLY(assert_valid();)
126 return num_val_ersd;
129 PB_DS_CLASS_T_DEC
130 template<typename It>
132 PB_DS_CLASS_C_DEC::
133 erase_imp(It it)
135 _GLIBCXX_DEBUG_ONLY(assert_valid();)
136 if (it == end())
137 return end();
139 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::check_key_exists(PB_DS_V2F(*it));)
141 #ifdef PB_DS_REGRESSION
142 typename Allocator::group_throw_prob_adjustor adjust(m_size);
143 #endif
145 _GLIBCXX_DEBUG_ASSERT(m_size > 0);
146 value_vector a_values = s_value_alloc.allocate(m_size - 1);
147 iterator source_it = begin();
148 iterator source_end_it = end();
149 iterator target_it = a_values;
150 iterator ret_it = end();
152 cond_dtor<size_type> cd(a_values, target_it, m_size - 1);
154 _GLIBCXX_DEBUG_ONLY(size_type cnt = 0;)
156 while (source_it != source_end_it)
158 if (source_it != it)
160 _GLIBCXX_DEBUG_ONLY(++cnt;)
161 _GLIBCXX_DEBUG_ASSERT(cnt != m_size);
162 new (const_cast<void* >(static_cast<const void* >(target_it)))
163 value_type(*source_it);
165 ++target_it;
167 else
168 ret_it = target_it;
169 ++source_it;
172 _GLIBCXX_DEBUG_ASSERT(m_size > 0);
173 reallocate_metadata((node_update* )this, m_size - 1);
174 cd.set_no_action();
175 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::erase_existing(PB_DS_V2F(*it));)
177 cond_dtor<size_type> cd1(m_a_values, m_end_it, m_size);
180 m_a_values = a_values;
181 --m_size;
182 m_end_it = m_a_values + m_size;
183 update(node_begin(), (node_update* )this);
184 _GLIBCXX_DEBUG_ONLY(assert_valid();)
185 return It(ret_it);
188 PB_DS_CLASS_T_DEC
189 bool
190 PB_DS_CLASS_C_DEC::
191 erase(const_key_reference r_key)
193 point_iterator it = find(r_key);
194 if (it == end())
195 return false;
196 erase(it);
197 return true;