]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_standard_resize_policy_imp.hpp
re PR testsuite/39696 (gcc.dg/tree-ssa/ssa-ccp-25.c scan-tree-dump doesn't work on...
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / pb_ds / detail / resize_policy / hash_standard_resize_policy_imp.hpp
CommitLineData
4569a895
AT
1// -*- C++ -*-
2
bc2631e0 3// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4569a895
AT
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
4569a895
AT
47PB_DS_CLASS_T_DEC
48PB_DS_CLASS_C_DEC::
3441f106
BK
49hash_standard_resize_policy()
50: m_size(Size_Policy::get_nearest_larger_size(1))
d7f245b1 51{ trigger_policy_base::notify_externally_resized(m_size); }
4569a895
AT
52
53PB_DS_CLASS_T_DEC
54PB_DS_CLASS_C_DEC::
3441f106
BK
55hash_standard_resize_policy(const Size_Policy& r_size_policy)
56: Size_Policy(r_size_policy), m_size(Size_Policy::get_nearest_larger_size(1))
d7f245b1 57{ trigger_policy_base::notify_externally_resized(m_size); }
4569a895
AT
58
59PB_DS_CLASS_T_DEC
60PB_DS_CLASS_C_DEC::
d7f245b1 61hash_standard_resize_policy(const Size_Policy& r_size_policy,
3441f106
BK
62 const Trigger_Policy& r_trigger_policy)
63: Size_Policy(r_size_policy), Trigger_Policy(r_trigger_policy),
4569a895 64 m_size(Size_Policy::get_nearest_larger_size(1))
d7f245b1 65{ trigger_policy_base::notify_externally_resized(m_size); }
4569a895
AT
66
67PB_DS_CLASS_T_DEC
68PB_DS_CLASS_C_DEC::
69~hash_standard_resize_policy()
70{ }
71
72PB_DS_CLASS_T_DEC
73void
74PB_DS_CLASS_C_DEC::
75swap(PB_DS_CLASS_C_DEC& other)
76{
77 trigger_policy_base::swap(other);
4569a895 78 size_policy_base::swap(other);
4569a895
AT
79 std::swap(m_size, other.m_size);
80}
81
82PB_DS_CLASS_T_DEC
83inline void
84PB_DS_CLASS_C_DEC::
85notify_find_search_start()
d7f245b1 86{ trigger_policy_base::notify_find_search_start(); }
4569a895
AT
87
88PB_DS_CLASS_T_DEC
89inline void
90PB_DS_CLASS_C_DEC::
91notify_find_search_collision()
d7f245b1 92{ trigger_policy_base::notify_find_search_collision(); }
4569a895
AT
93
94PB_DS_CLASS_T_DEC
95inline void
96PB_DS_CLASS_C_DEC::
97notify_find_search_end()
d7f245b1 98{ trigger_policy_base::notify_find_search_end(); }
4569a895
AT
99
100PB_DS_CLASS_T_DEC
101inline void
102PB_DS_CLASS_C_DEC::
103notify_insert_search_start()
d7f245b1 104{ trigger_policy_base::notify_insert_search_start(); }
4569a895
AT
105
106PB_DS_CLASS_T_DEC
107inline void
108PB_DS_CLASS_C_DEC::
109notify_insert_search_collision()
d7f245b1 110{ trigger_policy_base::notify_insert_search_collision(); }
4569a895
AT
111
112PB_DS_CLASS_T_DEC
113inline void
114PB_DS_CLASS_C_DEC::
115notify_insert_search_end()
d7f245b1 116{ trigger_policy_base::notify_insert_search_end(); }
4569a895
AT
117
118PB_DS_CLASS_T_DEC
119inline void
120PB_DS_CLASS_C_DEC::
121notify_erase_search_start()
d7f245b1 122{ trigger_policy_base::notify_erase_search_start(); }
4569a895
AT
123
124PB_DS_CLASS_T_DEC
125inline void
126PB_DS_CLASS_C_DEC::
127notify_erase_search_collision()
d7f245b1 128{ trigger_policy_base::notify_erase_search_collision(); }
4569a895
AT
129
130PB_DS_CLASS_T_DEC
131inline void
132PB_DS_CLASS_C_DEC::
133notify_erase_search_end()
d7f245b1 134{ trigger_policy_base::notify_erase_search_end(); }
4569a895
AT
135
136PB_DS_CLASS_T_DEC
137inline void
138PB_DS_CLASS_C_DEC::
139notify_inserted(size_type num_e)
d7f245b1 140{ trigger_policy_base::notify_inserted(num_e); }
4569a895
AT
141
142PB_DS_CLASS_T_DEC
143inline void
144PB_DS_CLASS_C_DEC::
145notify_erased(size_type num_e)
d7f245b1 146{ trigger_policy_base::notify_erased(num_e); }
4569a895
AT
147
148PB_DS_CLASS_T_DEC
149void
150PB_DS_CLASS_C_DEC::
151notify_cleared()
d7f245b1 152{ trigger_policy_base::notify_cleared(); }
4569a895
AT
153
154PB_DS_CLASS_T_DEC
155inline bool
156PB_DS_CLASS_C_DEC::
157is_resize_needed() const
d7f245b1 158{ return trigger_policy_base::is_resize_needed(); }
4569a895
AT
159
160PB_DS_CLASS_T_DEC
161typename PB_DS_CLASS_C_DEC::size_type
162PB_DS_CLASS_C_DEC::
163get_new_size(size_type size, size_type num_used_e) const
164{
3441f106 165 if (trigger_policy_base::is_grow_needed(size, num_used_e))
d7f245b1
BK
166 return size_policy_base::get_nearest_larger_size(size);
167 return size_policy_base::get_nearest_smaller_size(size);
4569a895
AT
168}
169
170PB_DS_CLASS_T_DEC
171void
172PB_DS_CLASS_C_DEC::
173notify_resized(size_type new_size)
174{
175 trigger_policy_base::notify_resized(new_size);
4569a895
AT
176 m_size = new_size;
177}
178
179PB_DS_CLASS_T_DEC
180inline typename PB_DS_CLASS_C_DEC::size_type
181PB_DS_CLASS_C_DEC::
182get_actual_size() const
183{
184 PB_DS_STATIC_ASSERT(access, external_size_access);
d7f245b1 185 return m_size;
4569a895
AT
186}
187
188PB_DS_CLASS_T_DEC
189void
190PB_DS_CLASS_C_DEC::
191resize(size_type new_size)
192{
193 PB_DS_STATIC_ASSERT(access, external_size_access);
3441f106
BK
194 size_type actual_size = size_policy_base::get_nearest_larger_size(1);
195 while (actual_size < new_size)
4569a895 196 {
3441f106 197 const size_type pot = size_policy_base::get_nearest_larger_size(actual_size);
4569a895 198
3441f106 199 if (pot == actual_size && pot < new_size)
8fafc2d3 200 __throw_resize_error();
3441f106 201 actual_size = pot;
4569a895
AT
202 }
203
3441f106
BK
204 if (actual_size > 0)
205 --actual_size;
4569a895
AT
206
207 const size_type old_size = m_size;
bc2631e0 208 __try
4569a895 209 {
3441f106 210 do_resize(actual_size - 1);
4569a895 211 }
bc2631e0 212 __catch(insert_error& )
4569a895
AT
213 {
214 m_size = old_size;
8fafc2d3 215 __throw_resize_error();
4569a895 216 }
bc2631e0 217 __catch(...)
4569a895
AT
218 {
219 m_size = old_size;
8fafc2d3 220 __throw_exception_again;
4569a895
AT
221 }
222}
223
224PB_DS_CLASS_T_DEC
225void
226PB_DS_CLASS_C_DEC::
d7f245b1 227do_resize(size_type)
4569a895
AT
228{
229 // Do nothing
230}
231
232PB_DS_CLASS_T_DEC
233Trigger_Policy&
234PB_DS_CLASS_C_DEC::
235get_trigger_policy()
d7f245b1 236{ return *this; }
4569a895
AT
237
238PB_DS_CLASS_T_DEC
239const Trigger_Policy&
240PB_DS_CLASS_C_DEC::
241get_trigger_policy() const
d7f245b1 242{ return *this; }
4569a895
AT
243
244PB_DS_CLASS_T_DEC
245Size_Policy&
246PB_DS_CLASS_C_DEC::
247get_size_policy()
d7f245b1 248{ return *this; }
4569a895
AT
249
250PB_DS_CLASS_T_DEC
251const Size_Policy&
252PB_DS_CLASS_C_DEC::
253get_size_policy() const
d7f245b1 254{ return *this; }
4569a895 255