]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_standard_resize_policy_imp.hpp
inclhack.def (solaris_once_init_2): New fix.
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / pb_ds / detail / resize_policy / hash_standard_resize_policy_imp.hpp
CommitLineData
4569a895
AT
1// -*- C++ -*-
2
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.
10
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.
15
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.
20
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.
30
31// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32
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.
41
42/**
43 * @file hash_standard_resize_policy_imp.hpp
44 * Contains a resize policy implementation.
45 */
46
d7f245b1
BK
47#define PB_DS_STATIC_ASSERT(UNIQUE, E) \
48 typedef detail::static_assert_dumclass<sizeof(detail::static_assert<(bool)(E)>)> UNIQUE##static_assert_type
4569a895
AT
49
50PB_DS_CLASS_T_DEC
51PB_DS_CLASS_C_DEC::
52hash_standard_resize_policy() :
53 m_size(Size_Policy::get_nearest_larger_size(1))
d7f245b1 54{ trigger_policy_base::notify_externally_resized(m_size); }
4569a895
AT
55
56PB_DS_CLASS_T_DEC
57PB_DS_CLASS_C_DEC::
58hash_standard_resize_policy(const Size_Policy& r_size_policy) :
59 Size_Policy(r_size_policy),
60 m_size(Size_Policy::get_nearest_larger_size(1))
d7f245b1 61{ trigger_policy_base::notify_externally_resized(m_size); }
4569a895
AT
62
63PB_DS_CLASS_T_DEC
64PB_DS_CLASS_C_DEC::
d7f245b1
BK
65hash_standard_resize_policy(const Size_Policy& r_size_policy,
66 const Trigger_Policy& r_trigger_policy) :
4569a895
AT
67 Size_Policy(r_size_policy),
68 Trigger_Policy(r_trigger_policy),
69 m_size(Size_Policy::get_nearest_larger_size(1))
d7f245b1 70{ trigger_policy_base::notify_externally_resized(m_size); }
4569a895
AT
71
72PB_DS_CLASS_T_DEC
73PB_DS_CLASS_C_DEC::
74~hash_standard_resize_policy()
75{ }
76
77PB_DS_CLASS_T_DEC
78void
79PB_DS_CLASS_C_DEC::
80swap(PB_DS_CLASS_C_DEC& other)
81{
82 trigger_policy_base::swap(other);
4569a895 83 size_policy_base::swap(other);
4569a895
AT
84 std::swap(m_size, other.m_size);
85}
86
87PB_DS_CLASS_T_DEC
88inline void
89PB_DS_CLASS_C_DEC::
90notify_find_search_start()
d7f245b1 91{ trigger_policy_base::notify_find_search_start(); }
4569a895
AT
92
93PB_DS_CLASS_T_DEC
94inline void
95PB_DS_CLASS_C_DEC::
96notify_find_search_collision()
d7f245b1 97{ trigger_policy_base::notify_find_search_collision(); }
4569a895
AT
98
99PB_DS_CLASS_T_DEC
100inline void
101PB_DS_CLASS_C_DEC::
102notify_find_search_end()
d7f245b1 103{ trigger_policy_base::notify_find_search_end(); }
4569a895
AT
104
105PB_DS_CLASS_T_DEC
106inline void
107PB_DS_CLASS_C_DEC::
108notify_insert_search_start()
d7f245b1 109{ trigger_policy_base::notify_insert_search_start(); }
4569a895
AT
110
111PB_DS_CLASS_T_DEC
112inline void
113PB_DS_CLASS_C_DEC::
114notify_insert_search_collision()
d7f245b1 115{ trigger_policy_base::notify_insert_search_collision(); }
4569a895
AT
116
117PB_DS_CLASS_T_DEC
118inline void
119PB_DS_CLASS_C_DEC::
120notify_insert_search_end()
d7f245b1 121{ trigger_policy_base::notify_insert_search_end(); }
4569a895
AT
122
123PB_DS_CLASS_T_DEC
124inline void
125PB_DS_CLASS_C_DEC::
126notify_erase_search_start()
d7f245b1 127{ trigger_policy_base::notify_erase_search_start(); }
4569a895
AT
128
129PB_DS_CLASS_T_DEC
130inline void
131PB_DS_CLASS_C_DEC::
132notify_erase_search_collision()
d7f245b1 133{ trigger_policy_base::notify_erase_search_collision(); }
4569a895
AT
134
135PB_DS_CLASS_T_DEC
136inline void
137PB_DS_CLASS_C_DEC::
138notify_erase_search_end()
d7f245b1 139{ trigger_policy_base::notify_erase_search_end(); }
4569a895
AT
140
141PB_DS_CLASS_T_DEC
142inline void
143PB_DS_CLASS_C_DEC::
144notify_inserted(size_type num_e)
d7f245b1 145{ trigger_policy_base::notify_inserted(num_e); }
4569a895
AT
146
147PB_DS_CLASS_T_DEC
148inline void
149PB_DS_CLASS_C_DEC::
150notify_erased(size_type num_e)
d7f245b1 151{ trigger_policy_base::notify_erased(num_e); }
4569a895
AT
152
153PB_DS_CLASS_T_DEC
154void
155PB_DS_CLASS_C_DEC::
156notify_cleared()
d7f245b1 157{ trigger_policy_base::notify_cleared(); }
4569a895
AT
158
159PB_DS_CLASS_T_DEC
160inline bool
161PB_DS_CLASS_C_DEC::
162is_resize_needed() const
d7f245b1 163{ return trigger_policy_base::is_resize_needed(); }
4569a895
AT
164
165PB_DS_CLASS_T_DEC
166typename PB_DS_CLASS_C_DEC::size_type
167PB_DS_CLASS_C_DEC::
168get_new_size(size_type size, size_type num_used_e) const
169{
170 if (trigger_policy_base::
171 is_grow_needed(size, num_used_e))
d7f245b1
BK
172 return size_policy_base::get_nearest_larger_size(size);
173 return size_policy_base::get_nearest_smaller_size(size);
4569a895
AT
174}
175
176PB_DS_CLASS_T_DEC
177void
178PB_DS_CLASS_C_DEC::
179notify_resized(size_type new_size)
180{
181 trigger_policy_base::notify_resized(new_size);
4569a895
AT
182 m_size = new_size;
183}
184
185PB_DS_CLASS_T_DEC
186inline typename PB_DS_CLASS_C_DEC::size_type
187PB_DS_CLASS_C_DEC::
188get_actual_size() const
189{
190 PB_DS_STATIC_ASSERT(access, external_size_access);
d7f245b1 191 return m_size;
4569a895
AT
192}
193
194PB_DS_CLASS_T_DEC
195void
196PB_DS_CLASS_C_DEC::
197resize(size_type new_size)
198{
199 PB_DS_STATIC_ASSERT(access, external_size_access);
4569a895
AT
200 size_type actual_new_size = size_policy_base::get_nearest_larger_size(1);
201 while (actual_new_size < new_size)
202 {
203 const size_type pot =
204 size_policy_base::get_nearest_larger_size(actual_new_size);
205
206 if (pot == actual_new_size&& pot < new_size)
207 throw resize_error();
4569a895
AT
208 actual_new_size = pot;
209 }
210
211 if (actual_new_size > 0)
212 --actual_new_size;
213
214 const size_type old_size = m_size;
4569a895
AT
215 try
216 {
217 do_resize(actual_new_size - 1);
218 }
219 catch(insert_error& )
220 {
221 m_size = old_size;
4569a895
AT
222 throw resize_error();
223 }
224 catch(...)
225 {
226 m_size = old_size;
4569a895
AT
227 throw;
228 }
229}
230
231PB_DS_CLASS_T_DEC
232void
233PB_DS_CLASS_C_DEC::
d7f245b1 234do_resize(size_type)
4569a895
AT
235{
236 // Do nothing
237}
238
239PB_DS_CLASS_T_DEC
240Trigger_Policy&
241PB_DS_CLASS_C_DEC::
242get_trigger_policy()
d7f245b1 243{ return *this; }
4569a895
AT
244
245PB_DS_CLASS_T_DEC
246const Trigger_Policy&
247PB_DS_CLASS_C_DEC::
248get_trigger_policy() const
d7f245b1 249{ return *this; }
4569a895
AT
250
251PB_DS_CLASS_T_DEC
252Size_Policy&
253PB_DS_CLASS_C_DEC::
254get_size_policy()
d7f245b1 255{ return *this; }
4569a895
AT
256
257PB_DS_CLASS_T_DEC
258const Size_Policy&
259PB_DS_CLASS_C_DEC::
260get_size_policy() const
d7f245b1 261{ return *this; }
4569a895
AT
262
263#undef PB_DS_STATIC_ASSERT
264