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 / resize_policy / hash_standard_resize_policy_imp.hpp
bloba37ccc0be9ed67d5a0fe4edafcc7bf4332a69ae9
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2007 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 hash_standard_resize_policy_imp.hpp
44 * Contains a resize policy implementation.
47 PB_DS_CLASS_T_DEC
48 PB_DS_CLASS_C_DEC::
49 hash_standard_resize_policy()
50 : m_size(Size_Policy::get_nearest_larger_size(1))
51 { trigger_policy_base::notify_externally_resized(m_size); }
53 PB_DS_CLASS_T_DEC
54 PB_DS_CLASS_C_DEC::
55 hash_standard_resize_policy(const Size_Policy& r_size_policy)
56 : Size_Policy(r_size_policy), m_size(Size_Policy::get_nearest_larger_size(1))
57 { trigger_policy_base::notify_externally_resized(m_size); }
59 PB_DS_CLASS_T_DEC
60 PB_DS_CLASS_C_DEC::
61 hash_standard_resize_policy(const Size_Policy& r_size_policy,
62 const Trigger_Policy& r_trigger_policy)
63 : Size_Policy(r_size_policy), Trigger_Policy(r_trigger_policy),
64 m_size(Size_Policy::get_nearest_larger_size(1))
65 { trigger_policy_base::notify_externally_resized(m_size); }
67 PB_DS_CLASS_T_DEC
68 PB_DS_CLASS_C_DEC::
69 ~hash_standard_resize_policy()
70 { }
72 PB_DS_CLASS_T_DEC
73 void
74 PB_DS_CLASS_C_DEC::
75 swap(PB_DS_CLASS_C_DEC& other)
77 trigger_policy_base::swap(other);
78 size_policy_base::swap(other);
79 std::swap(m_size, other.m_size);
82 PB_DS_CLASS_T_DEC
83 inline void
84 PB_DS_CLASS_C_DEC::
85 notify_find_search_start()
86 { trigger_policy_base::notify_find_search_start(); }
88 PB_DS_CLASS_T_DEC
89 inline void
90 PB_DS_CLASS_C_DEC::
91 notify_find_search_collision()
92 { trigger_policy_base::notify_find_search_collision(); }
94 PB_DS_CLASS_T_DEC
95 inline void
96 PB_DS_CLASS_C_DEC::
97 notify_find_search_end()
98 { trigger_policy_base::notify_find_search_end(); }
100 PB_DS_CLASS_T_DEC
101 inline void
102 PB_DS_CLASS_C_DEC::
103 notify_insert_search_start()
104 { trigger_policy_base::notify_insert_search_start(); }
106 PB_DS_CLASS_T_DEC
107 inline void
108 PB_DS_CLASS_C_DEC::
109 notify_insert_search_collision()
110 { trigger_policy_base::notify_insert_search_collision(); }
112 PB_DS_CLASS_T_DEC
113 inline void
114 PB_DS_CLASS_C_DEC::
115 notify_insert_search_end()
116 { trigger_policy_base::notify_insert_search_end(); }
118 PB_DS_CLASS_T_DEC
119 inline void
120 PB_DS_CLASS_C_DEC::
121 notify_erase_search_start()
122 { trigger_policy_base::notify_erase_search_start(); }
124 PB_DS_CLASS_T_DEC
125 inline void
126 PB_DS_CLASS_C_DEC::
127 notify_erase_search_collision()
128 { trigger_policy_base::notify_erase_search_collision(); }
130 PB_DS_CLASS_T_DEC
131 inline void
132 PB_DS_CLASS_C_DEC::
133 notify_erase_search_end()
134 { trigger_policy_base::notify_erase_search_end(); }
136 PB_DS_CLASS_T_DEC
137 inline void
138 PB_DS_CLASS_C_DEC::
139 notify_inserted(size_type num_e)
140 { trigger_policy_base::notify_inserted(num_e); }
142 PB_DS_CLASS_T_DEC
143 inline void
144 PB_DS_CLASS_C_DEC::
145 notify_erased(size_type num_e)
146 { trigger_policy_base::notify_erased(num_e); }
148 PB_DS_CLASS_T_DEC
149 void
150 PB_DS_CLASS_C_DEC::
151 notify_cleared()
152 { trigger_policy_base::notify_cleared(); }
154 PB_DS_CLASS_T_DEC
155 inline bool
156 PB_DS_CLASS_C_DEC::
157 is_resize_needed() const
158 { return trigger_policy_base::is_resize_needed(); }
160 PB_DS_CLASS_T_DEC
161 typename PB_DS_CLASS_C_DEC::size_type
162 PB_DS_CLASS_C_DEC::
163 get_new_size(size_type size, size_type num_used_e) const
165 if (trigger_policy_base::is_grow_needed(size, num_used_e))
166 return size_policy_base::get_nearest_larger_size(size);
167 return size_policy_base::get_nearest_smaller_size(size);
170 PB_DS_CLASS_T_DEC
171 void
172 PB_DS_CLASS_C_DEC::
173 notify_resized(size_type new_size)
175 trigger_policy_base::notify_resized(new_size);
176 m_size = new_size;
179 PB_DS_CLASS_T_DEC
180 inline typename PB_DS_CLASS_C_DEC::size_type
181 PB_DS_CLASS_C_DEC::
182 get_actual_size() const
184 PB_DS_STATIC_ASSERT(access, external_size_access);
185 return m_size;
188 PB_DS_CLASS_T_DEC
189 void
190 PB_DS_CLASS_C_DEC::
191 resize(size_type new_size)
193 PB_DS_STATIC_ASSERT(access, external_size_access);
194 size_type actual_size = size_policy_base::get_nearest_larger_size(1);
195 while (actual_size < new_size)
197 const size_type pot = size_policy_base::get_nearest_larger_size(actual_size);
199 if (pot == actual_size && pot < new_size)
200 __throw_resize_error();
201 actual_size = pot;
204 if (actual_size > 0)
205 --actual_size;
207 const size_type old_size = m_size;
210 do_resize(actual_size - 1);
212 catch(insert_error& )
214 m_size = old_size;
215 __throw_resize_error();
217 catch(...)
219 m_size = old_size;
220 __throw_exception_again;
224 PB_DS_CLASS_T_DEC
225 void
226 PB_DS_CLASS_C_DEC::
227 do_resize(size_type)
229 // Do nothing
232 PB_DS_CLASS_T_DEC
233 Trigger_Policy&
234 PB_DS_CLASS_C_DEC::
235 get_trigger_policy()
236 { return *this; }
238 PB_DS_CLASS_T_DEC
239 const Trigger_Policy&
240 PB_DS_CLASS_C_DEC::
241 get_trigger_policy() const
242 { return *this; }
244 PB_DS_CLASS_T_DEC
245 Size_Policy&
246 PB_DS_CLASS_C_DEC::
247 get_size_policy()
248 { return *this; }
250 PB_DS_CLASS_T_DEC
251 const Size_Policy&
252 PB_DS_CLASS_C_DEC::
253 get_size_policy() const
254 { return *this; }