OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [include/] [ext/] [pb_assoc/] [detail/] [resize_policy/] [hash_standard_resize_policy_imp.hpp] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 jlechner
// -*- C++ -*-
2
 
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.
10
 
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.
15
 
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.
20
 
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.
29
 
30
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
31
 
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.
39
 
40
/*
41
 * @file hash_standard_resize_policy_imp.hpp
42
 * Contains an implementation of hash_standard_resize_policy.
43
 */
44
 
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
54
 
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;
58
 
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))
63
{
64
  my_trigger_policy_base::notify_externally_resized(
65
                                                    Size_Policy::get_init_size(suggested_size));
66
}
67
 
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
{ }
74
 
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
{ }
82
 
83
PB_ASSOC_CLASS_T_DEC
84
PB_ASSOC_CLASS_C_DEC::
85
~hash_standard_resize_policy()
86
{ }
87
 
88
PB_ASSOC_CLASS_T_DEC
89
void
90
PB_ASSOC_CLASS_C_DEC::
91
swap(PB_ASSOC_CLASS_C_DEC& r_other)
92
{
93
  my_trigger_policy_base::swap(r_other);
94
 
95
  my_size_policy_base::swap(r_other);
96
 
97
  std::swap(m_size, r_other.m_size);
98
}
99
 
100
PB_ASSOC_CLASS_T_DEC
101
inline void
102
PB_ASSOC_CLASS_C_DEC::
103
notify_find_search_start()
104
{
105
  my_trigger_policy_base::notify_find_search_start();
106
}
107
 
108
PB_ASSOC_CLASS_T_DEC
109
inline void
110
PB_ASSOC_CLASS_C_DEC::
111
notify_find_search_collision()
112
{
113
  my_trigger_policy_base::notify_find_search_collision();
114
}
115
 
116
PB_ASSOC_CLASS_T_DEC
117
inline void
118
PB_ASSOC_CLASS_C_DEC::
119
notify_find_search_end()
120
{
121
  my_trigger_policy_base::notify_find_search_end();
122
}
123
 
124
PB_ASSOC_CLASS_T_DEC
125
inline void
126
PB_ASSOC_CLASS_C_DEC::
127
notify_insert_search_start()
128
{
129
  my_trigger_policy_base::notify_insert_search_start();
130
}
131
 
132
PB_ASSOC_CLASS_T_DEC
133
inline void
134
PB_ASSOC_CLASS_C_DEC::
135
notify_insert_search_collision()
136
{
137
  my_trigger_policy_base::notify_insert_search_collision();
138
}
139
 
140
PB_ASSOC_CLASS_T_DEC
141
inline void
142
PB_ASSOC_CLASS_C_DEC::
143
notify_insert_search_end()
144
{
145
  my_trigger_policy_base::notify_insert_search_end();
146
}
147
 
148
PB_ASSOC_CLASS_T_DEC
149
inline void
150
PB_ASSOC_CLASS_C_DEC::
151
notify_erase_search_start()
152
{
153
  my_trigger_policy_base::notify_erase_search_start();
154
}
155
 
156
PB_ASSOC_CLASS_T_DEC
157
inline void
158
PB_ASSOC_CLASS_C_DEC::
159
notify_erase_search_collision()
160
{
161
  my_trigger_policy_base::notify_erase_search_collision();
162
}
163
 
164
PB_ASSOC_CLASS_T_DEC
165
inline void
166
PB_ASSOC_CLASS_C_DEC::
167
notify_erase_search_end()
168
{
169
  my_trigger_policy_base::notify_erase_search_end();
170
}
171
 
172
PB_ASSOC_CLASS_T_DEC
173
inline void
174
PB_ASSOC_CLASS_C_DEC::
175
notify_inserted(size_type num_e)
176
{
177
  my_trigger_policy_base::notify_inserted(num_e);
178
}
179
 
180
PB_ASSOC_CLASS_T_DEC
181
inline void
182
PB_ASSOC_CLASS_C_DEC::
183
notify_erased(size_type num_e)
184
{
185
  my_trigger_policy_base::notify_inserted(num_e);
186
}
187
 
188
PB_ASSOC_CLASS_T_DEC
189
void
190
PB_ASSOC_CLASS_C_DEC::
191
notify_cleared()
192
{
193
  my_trigger_policy_base::notify_cleared();
194
}
195
 
196
PB_ASSOC_CLASS_T_DEC
197
inline bool
198
PB_ASSOC_CLASS_C_DEC::
199
is_resize_needed() const
200
{
201
  return (my_trigger_policy_base::is_resize_needed());
202
}
203
 
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
208
{
209
  PB_ASSOC_DBG_ASSERT(m_size == size);
210
 
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));
214
 
215
  PB_ASSOC_DBG_ASSERT(my_trigger_policy_base::
216
                      is_shrink_needed(size, num_used_e));
217
 
218
  return (my_size_policy_base::get_nearest_smaller_size(m_size));
219
}
220
 
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
225
{
226
  PB_ASSOC_DBG_ASSERT(m_size ==
227
                      my_trigger_policy_base::get_init_size());
228
 
229
  return (m_size);
230
}
231
 
232
PB_ASSOC_CLASS_T_DEC
233
void
234
PB_ASSOC_CLASS_C_DEC::
235
notify_resized(size_type new_size)
236
{
237
  my_trigger_policy_base::notify_resized(new_size);
238
 
239
  m_size = new_size;
240
}
241
 
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
246
{
247
  return (get_actual_size(s_external_size_access_indicator));
248
}
249
 
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
254
{
255
  return (m_size);
256
}
257
 
258
PB_ASSOC_CLASS_T_DEC
259
void
260
PB_ASSOC_CLASS_C_DEC::
261
resize(size_type new_size)
262
{
263
  resize(new_size, s_external_size_access_indicator);
264
}
265
 
266
PB_ASSOC_CLASS_T_DEC
267
void
268
PB_ASSOC_CLASS_C_DEC::
269
resize(size_type new_size, external_resize_true_indicator)
270
{
271
  size_type actual_new_size = my_size_policy_base::get_init_size(1);
272
  while (actual_new_size < new_size)
273
    {
274
      const size_type pot =
275
        my_size_policy_base::get_nearest_larger_size(actual_new_size);
276
 
277
      if (pot == actual_new_size&&  pot < new_size)
278
        throw cannot_resize();
279
 
280
      actual_new_size = pot;
281
    }
282
 
283
  const size_type old_size = m_size;
284
 
285
  try
286
    {
287
      do_resize(actual_new_size);
288
    }
289
  catch(cannot_insert& )
290
    {
291
      m_size = old_size;
292
 
293
      throw cannot_resize();
294
    }
295
  catch(...)
296
    {
297
      m_size = old_size;
298
 
299
      throw;
300
    }
301
}
302
 
303
PB_ASSOC_CLASS_T_DEC
304
void
305
PB_ASSOC_CLASS_C_DEC::
306
do_resize(size_type /*new_size*/)
307
{
308
  // Tmp Ami
309
  abort();
310
}
311
 
312
PB_ASSOC_CLASS_T_DEC
313
Trigger_Policy&
314
PB_ASSOC_CLASS_C_DEC::
315
get_trigger_policy()
316
{
317
  return (*this);
318
}
319
 
320
PB_ASSOC_CLASS_T_DEC
321
const Trigger_Policy&
322
PB_ASSOC_CLASS_C_DEC::
323
get_trigger_policy() const
324
{
325
  return (*this);
326
}
327
 
328
PB_ASSOC_CLASS_T_DEC
329
Size_Policy&
330
PB_ASSOC_CLASS_C_DEC::
331
get_size_policy()
332
{
333
  return (*this);
334
}
335
 
336
PB_ASSOC_CLASS_T_DEC
337
const Size_Policy&
338
PB_ASSOC_CLASS_C_DEC::
339
get_size_policy() const
340
{
341
  return (*this);
342
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.