Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / include / ext / pb_assoc / detail / resize_policy / hash_standard_resize_policy_imp.hpp
blob3a6a2fd454601b16d38957e678d0b374c0ec0e77
1 // -*- C++ -*-
3 // Copyright (C) 2005 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
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
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,
19 // USA.
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 hash_standard_resize_policy_imp.hpp
42 * Contains an implementation of hash_standard_resize_policy.
45 #ifdef PB_ASSOC_HT_STANDARD_RESIZE_POLICY_DEBUG
46 #define PB_ASSOC_DBG_ASSERT(X) assert(X)
47 #define PB_ASSOC_DBG_VERIFY(X) assert(X)
48 #define PB_ASSOC_DBG_ONLY(X) X
49 #else // #ifdef PB_ASSOC_HT_STANDARD_RESIZE_POLICY_DEBUG
50 #define PB_ASSOC_DBG_ASSERT(X)
51 #define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
52 #define PB_ASSOC_DBG_ONLY(X) ;
53 #endif // #ifdef PB_ASSOC_HT_STANDARD_RESIZE_POLICY_DEBUG
55 PB_ASSOC_CLASS_T_DEC
56 pb_assoc::detail::int_to_type<External_Size_Access>
57 PB_ASSOC_CLASS_C_DEC::s_external_size_access_indicator;
59 PB_ASSOC_CLASS_T_DEC
60 PB_ASSOC_CLASS_C_DEC::
61 hash_standard_resize_policy(size_type suggested_size /*= 8*/) :
62 m_size(Size_Policy::get_init_size(suggested_size))
64 my_trigger_policy_base::notify_externally_resized(
65 Size_Policy::get_init_size(suggested_size));
68 PB_ASSOC_CLASS_T_DEC
69 PB_ASSOC_CLASS_C_DEC::
70 hash_standard_resize_policy(const Size_Policy& r_size_policy, size_type suggested_size /*= 8*/) :
71 Size_Policy(r_size_policy),
72 m_size(Size_Policy::get_init_size(suggested_size))
73 { }
75 PB_ASSOC_CLASS_T_DEC
76 PB_ASSOC_CLASS_C_DEC::
77 hash_standard_resize_policy(const Size_Policy& r_size_policy, const Trigger_Policy& r_trigger_policy, size_type suggested_size /*= 8*/) :
78 Size_Policy(r_size_policy),
79 Trigger_Policy(r_trigger_policy),
80 m_size(Size_Policy::get_init_size(suggested_size))
81 { }
83 PB_ASSOC_CLASS_T_DEC
84 PB_ASSOC_CLASS_C_DEC::
85 ~hash_standard_resize_policy()
86 { }
88 PB_ASSOC_CLASS_T_DEC
89 void
90 PB_ASSOC_CLASS_C_DEC::
91 swap(PB_ASSOC_CLASS_C_DEC& r_other)
93 my_trigger_policy_base::swap(r_other);
95 my_size_policy_base::swap(r_other);
97 std::swap(m_size, r_other.m_size);
100 PB_ASSOC_CLASS_T_DEC
101 inline void
102 PB_ASSOC_CLASS_C_DEC::
103 notify_find_search_start()
105 my_trigger_policy_base::notify_find_search_start();
108 PB_ASSOC_CLASS_T_DEC
109 inline void
110 PB_ASSOC_CLASS_C_DEC::
111 notify_find_search_collision()
113 my_trigger_policy_base::notify_find_search_collision();
116 PB_ASSOC_CLASS_T_DEC
117 inline void
118 PB_ASSOC_CLASS_C_DEC::
119 notify_find_search_end()
121 my_trigger_policy_base::notify_find_search_end();
124 PB_ASSOC_CLASS_T_DEC
125 inline void
126 PB_ASSOC_CLASS_C_DEC::
127 notify_insert_search_start()
129 my_trigger_policy_base::notify_insert_search_start();
132 PB_ASSOC_CLASS_T_DEC
133 inline void
134 PB_ASSOC_CLASS_C_DEC::
135 notify_insert_search_collision()
137 my_trigger_policy_base::notify_insert_search_collision();
140 PB_ASSOC_CLASS_T_DEC
141 inline void
142 PB_ASSOC_CLASS_C_DEC::
143 notify_insert_search_end()
145 my_trigger_policy_base::notify_insert_search_end();
148 PB_ASSOC_CLASS_T_DEC
149 inline void
150 PB_ASSOC_CLASS_C_DEC::
151 notify_erase_search_start()
153 my_trigger_policy_base::notify_erase_search_start();
156 PB_ASSOC_CLASS_T_DEC
157 inline void
158 PB_ASSOC_CLASS_C_DEC::
159 notify_erase_search_collision()
161 my_trigger_policy_base::notify_erase_search_collision();
164 PB_ASSOC_CLASS_T_DEC
165 inline void
166 PB_ASSOC_CLASS_C_DEC::
167 notify_erase_search_end()
169 my_trigger_policy_base::notify_erase_search_end();
172 PB_ASSOC_CLASS_T_DEC
173 inline void
174 PB_ASSOC_CLASS_C_DEC::
175 notify_inserted(size_type num_e)
177 my_trigger_policy_base::notify_inserted(num_e);
180 PB_ASSOC_CLASS_T_DEC
181 inline void
182 PB_ASSOC_CLASS_C_DEC::
183 notify_erased(size_type num_e)
185 my_trigger_policy_base::notify_inserted(num_e);
188 PB_ASSOC_CLASS_T_DEC
189 void
190 PB_ASSOC_CLASS_C_DEC::
191 notify_cleared()
193 my_trigger_policy_base::notify_cleared();
196 PB_ASSOC_CLASS_T_DEC
197 inline bool
198 PB_ASSOC_CLASS_C_DEC::
199 is_resize_needed() const
201 return (my_trigger_policy_base::is_resize_needed());
204 PB_ASSOC_CLASS_T_DEC
205 typename PB_ASSOC_CLASS_C_DEC::size_type
206 PB_ASSOC_CLASS_C_DEC::
207 get_new_size(size_type size, size_type num_used_e) const
209 PB_ASSOC_DBG_ASSERT(m_size == size);
211 if (my_trigger_policy_base::
212 is_grow_needed(size, num_used_e))
213 return (my_size_policy_base::get_nearest_larger_size(m_size));
215 PB_ASSOC_DBG_ASSERT(my_trigger_policy_base::
216 is_shrink_needed(size, num_used_e));
218 return (my_size_policy_base::get_nearest_smaller_size(m_size));
221 PB_ASSOC_CLASS_T_DEC
222 typename PB_ASSOC_CLASS_C_DEC::size_type
223 PB_ASSOC_CLASS_C_DEC::
224 get_init_size() const
226 PB_ASSOC_DBG_ASSERT(m_size ==
227 my_trigger_policy_base::get_init_size());
229 return (m_size);
232 PB_ASSOC_CLASS_T_DEC
233 void
234 PB_ASSOC_CLASS_C_DEC::
235 notify_resized(size_type new_size)
237 my_trigger_policy_base::notify_resized(new_size);
239 m_size = new_size;
242 PB_ASSOC_CLASS_T_DEC
243 inline typename PB_ASSOC_CLASS_C_DEC::size_type
244 PB_ASSOC_CLASS_C_DEC::
245 get_actual_size() const
247 return (get_actual_size(s_external_size_access_indicator));
250 PB_ASSOC_CLASS_T_DEC
251 inline typename PB_ASSOC_CLASS_C_DEC::size_type
252 PB_ASSOC_CLASS_C_DEC::
253 get_actual_size(external_resize_true_indicator) const
255 return (m_size);
258 PB_ASSOC_CLASS_T_DEC
259 void
260 PB_ASSOC_CLASS_C_DEC::
261 resize(size_type new_size)
263 resize(new_size, s_external_size_access_indicator);
266 PB_ASSOC_CLASS_T_DEC
267 void
268 PB_ASSOC_CLASS_C_DEC::
269 resize(size_type new_size, external_resize_true_indicator)
271 size_type actual_new_size = my_size_policy_base::get_init_size(1);
272 while (actual_new_size < new_size)
274 const size_type pot =
275 my_size_policy_base::get_nearest_larger_size(actual_new_size);
277 if (pot == actual_new_size&& pot < new_size)
278 throw cannot_resize();
280 actual_new_size = pot;
283 const size_type old_size = m_size;
287 do_resize(actual_new_size);
289 catch(cannot_insert& )
291 m_size = old_size;
293 throw cannot_resize();
295 catch(...)
297 m_size = old_size;
299 throw;
303 PB_ASSOC_CLASS_T_DEC
304 void
305 PB_ASSOC_CLASS_C_DEC::
306 do_resize(size_type /*new_size*/)
308 // Tmp Ami
309 abort();
312 PB_ASSOC_CLASS_T_DEC
313 Trigger_Policy&
314 PB_ASSOC_CLASS_C_DEC::
315 get_trigger_policy()
317 return (*this);
320 PB_ASSOC_CLASS_T_DEC
321 const Trigger_Policy&
322 PB_ASSOC_CLASS_C_DEC::
323 get_trigger_policy() const
325 return (*this);
328 PB_ASSOC_CLASS_T_DEC
329 Size_Policy&
330 PB_ASSOC_CLASS_C_DEC::
331 get_size_policy()
333 return (*this);
336 PB_ASSOC_CLASS_T_DEC
337 const Size_Policy&
338 PB_ASSOC_CLASS_C_DEC::
339 get_size_policy() const
341 return (*this);