Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / include / ext / pb_assoc / detail / hash_fn / ranged_probe_fn.hpp
blob61643d8d24675518257a7b58d955d8001910b369
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.
40 /**
41 * @file ranged_probe_fn.hpp
42 * Contains a unified ranged probe functor, allowing the probe tables to deal with
43 * a single class for ranged probeing.
46 #ifndef RANGED_PROBE_FN_HPP
47 #define RANGED_PROBE_FN_HPP
49 #include <ext/pb_assoc/hash_policy.hpp>
50 #include <utility>
52 namespace pb_assoc
55 namespace detail
58 #ifdef PB_ASSOC_RANGED_PROBE_FN_DEBUG
59 #define PB_ASSOC_DBG_ASSERT(X) assert(X)
60 #define PB_ASSOC_DBG_VERIFY(X) assert(X)
61 #define PB_ASSOC_DBG_ONLY(X) X
62 #else // #ifdef PB_ASSOC_RANGED_PROBE_FN_DEBUG
63 #define PB_ASSOC_DBG_ASSERT(X)
64 #define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
65 #define PB_ASSOC_DBG_ONLY(X) ;
66 #endif // #ifdef PB_ASSOC_RANGED_PROBE_FN_DEBUG
68 template<typename Key,
69 class Hash_Fn,
70 class Allocator,
71 class Comb_Probe_Fn,
72 class Probe_Fn,
73 bool Store_Hash>
74 class ranged_probe_fn;
76 #define PB_ASSOC_CLASS_T_DEC \
77 template< \
78 typename Key, \
79 class Hash_Fn, \
80 class Allocator, \
81 class Comb_Probe_Fn, \
82 class Probe_Fn>
84 #define PB_ASSOC_CLASS_C_DEC \
85 ranged_probe_fn< \
86 Key, \
87 Hash_Fn, \
88 Allocator, \
89 Comb_Probe_Fn, \
90 Probe_Fn, \
91 false>
93 /**
94 * Specialization 1- The client supplies a probe function and a ranged
95 * probe function, and requests that hash values not be stored.
96 **/
97 template<typename Key,
98 class Hash_Fn,
99 class Allocator,
100 class Comb_Probe_Fn,
101 class Probe_Fn>
102 class ranged_probe_fn<
103 Key,
104 Hash_Fn,
105 Allocator,
106 Comb_Probe_Fn,
107 Probe_Fn,
108 false> : public Hash_Fn,
109 public Comb_Probe_Fn,
110 public Probe_Fn
112 protected:
113 typedef typename Allocator::size_type size_type;
115 typedef Comb_Probe_Fn my_comb_probe_fn_base;
117 typedef Hash_Fn my_hash_fn_base;
119 typedef Probe_Fn my_probe_fn_base;
121 typedef typename Allocator::template rebind< Key>::other key_allocator;
123 typedef typename key_allocator::const_reference const_key_reference;
125 protected:
126 ranged_probe_fn(size_type size);
128 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn);
130 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Probe_Fn& r_comb_probe_fn);
132 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Probe_Fn& r_comb_probe_fn, const Probe_Fn& r_probe_fn);
134 void
135 swap(PB_ASSOC_CLASS_C_DEC& r_other);
137 void
138 notify_resized(size_type size);
140 inline size_type
141 operator()(const_key_reference r_key) const;
143 inline size_type
144 operator()(const_key_reference r_key, size_type hash, size_type i) const;
147 PB_ASSOC_CLASS_T_DEC
148 PB_ASSOC_CLASS_C_DEC::
149 ranged_probe_fn(size_type size)
151 Comb_Probe_Fn::notify_resized(size);
154 PB_ASSOC_CLASS_T_DEC
155 PB_ASSOC_CLASS_C_DEC::
156 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn) :
157 Hash_Fn(r_hash_fn)
159 Comb_Probe_Fn::notify_resized(size);
162 PB_ASSOC_CLASS_T_DEC
163 PB_ASSOC_CLASS_C_DEC::
164 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Probe_Fn& r_comb_probe_fn) :
165 Hash_Fn(r_hash_fn),
166 Comb_Probe_Fn(r_comb_probe_fn)
168 my_comb_probe_fn_base::notify_resized(size);
171 PB_ASSOC_CLASS_T_DEC
172 PB_ASSOC_CLASS_C_DEC::
173 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Probe_Fn& r_comb_probe_fn, const Probe_Fn& r_probe_fn) :
174 Hash_Fn(r_hash_fn),
175 Comb_Probe_Fn(r_comb_probe_fn),
176 Probe_Fn(r_probe_fn)
178 my_comb_probe_fn_base::notify_resized(size);
181 PB_ASSOC_CLASS_T_DEC
182 void
183 PB_ASSOC_CLASS_C_DEC::
184 swap(PB_ASSOC_CLASS_C_DEC& r_other)
186 my_comb_probe_fn_base::swap(r_other);
188 std::swap((Hash_Fn& )(*this), (Hash_Fn& )r_other);
191 PB_ASSOC_CLASS_T_DEC
192 void
193 PB_ASSOC_CLASS_C_DEC::
194 notify_resized(size_type size)
196 my_comb_probe_fn_base::notify_resized(size);
199 PB_ASSOC_CLASS_T_DEC
200 inline typename PB_ASSOC_CLASS_C_DEC::size_type
201 PB_ASSOC_CLASS_C_DEC::
202 operator()(const_key_reference r_key) const
204 return (my_comb_probe_fn_base::operator()(
205 my_hash_fn_base::operator()(r_key)));
208 PB_ASSOC_CLASS_T_DEC
209 inline typename PB_ASSOC_CLASS_C_DEC::size_type
210 PB_ASSOC_CLASS_C_DEC::
211 operator()(const_key_reference r_key, size_type hash, size_type i) const
213 return (my_comb_probe_fn_base::operator()(
214 hash + my_probe_fn_base::operator()(r_key, i)));
217 #undef PB_ASSOC_CLASS_T_DEC
218 #undef PB_ASSOC_CLASS_C_DEC
220 #define PB_ASSOC_CLASS_T_DEC \
221 template< \
222 typename Key, \
223 class Hash_Fn, \
224 class Allocator, \
225 class Comb_Probe_Fn, \
226 class Probe_Fn>
228 #define PB_ASSOC_CLASS_C_DEC \
229 ranged_probe_fn< \
230 Key, \
231 Hash_Fn, \
232 Allocator, \
233 Comb_Probe_Fn, \
234 Probe_Fn, \
235 true>
238 * Specialization 2- The client supplies a probe function and a ranged
239 * probe function, and requests that hash values be stored.
241 template<typename Key,
242 class Hash_Fn,
243 class Allocator,
244 class Comb_Probe_Fn,
245 class Probe_Fn>
246 class ranged_probe_fn<
247 Key,
248 Hash_Fn,
249 Allocator,
250 Comb_Probe_Fn,
251 Probe_Fn,
252 true> :
253 public Hash_Fn,
254 public Comb_Probe_Fn,
255 public Probe_Fn
257 protected:
258 typedef typename Allocator::size_type size_type;
260 typedef std::pair<size_type, size_type> comp_hash;
262 typedef Comb_Probe_Fn my_comb_probe_fn_base;
264 typedef Hash_Fn my_hash_fn_base;
266 typedef Probe_Fn my_probe_fn_base;
268 typedef typename Allocator::template rebind<Key>::other key_allocator;
270 typedef typename key_allocator::const_reference const_key_reference;
272 protected:
273 ranged_probe_fn(size_type size);
275 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn);
277 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Probe_Fn& r_comb_probe_fn);
279 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Probe_Fn& r_comb_probe_fn, const Probe_Fn& r_probe_fn);
281 void
282 swap(PB_ASSOC_CLASS_C_DEC& r_other);
284 void
285 notify_resized(size_type size);
287 inline comp_hash
288 operator()(const_key_reference r_key) const;
290 inline size_type
291 operator()(const_key_reference r_key, size_type hash, size_type i) const;
293 inline size_type
294 operator()(const_key_reference r_key, size_type hash) const;
297 PB_ASSOC_CLASS_T_DEC
298 PB_ASSOC_CLASS_C_DEC::
299 ranged_probe_fn(size_type size)
301 Comb_Probe_Fn::notify_resized(size);
304 PB_ASSOC_CLASS_T_DEC
305 PB_ASSOC_CLASS_C_DEC::
306 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn) :
307 Hash_Fn(r_hash_fn)
309 Comb_Probe_Fn::notify_resized(size);
312 PB_ASSOC_CLASS_T_DEC
313 PB_ASSOC_CLASS_C_DEC::
314 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Probe_Fn& r_comb_probe_fn) :
315 Hash_Fn(r_hash_fn),
316 Comb_Probe_Fn(r_comb_probe_fn)
318 my_comb_probe_fn_base::notify_resized(size);
321 PB_ASSOC_CLASS_T_DEC
322 PB_ASSOC_CLASS_C_DEC::
323 ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Probe_Fn& r_comb_probe_fn, const Probe_Fn& r_probe_fn) :
324 Hash_Fn(r_hash_fn),
325 Comb_Probe_Fn(r_comb_probe_fn),
326 Probe_Fn(r_probe_fn)
328 my_comb_probe_fn_base::notify_resized(size);
331 PB_ASSOC_CLASS_T_DEC
332 void
333 PB_ASSOC_CLASS_C_DEC::
334 swap(PB_ASSOC_CLASS_C_DEC& r_other)
336 my_comb_probe_fn_base::swap(r_other);
338 std::swap((Hash_Fn& )(*this), (Hash_Fn& )r_other);
341 PB_ASSOC_CLASS_T_DEC
342 void
343 PB_ASSOC_CLASS_C_DEC::
344 notify_resized(size_type size)
346 my_comb_probe_fn_base::notify_resized(size);
349 PB_ASSOC_CLASS_T_DEC
350 inline typename PB_ASSOC_CLASS_C_DEC::comp_hash
351 PB_ASSOC_CLASS_C_DEC::
352 operator()(const_key_reference r_key) const
354 const size_type hash = my_hash_fn_base::operator()(r_key);
356 return (std::make_pair(my_comb_probe_fn_base::operator()(hash), hash));
359 PB_ASSOC_CLASS_T_DEC
360 inline typename PB_ASSOC_CLASS_C_DEC::size_type
361 PB_ASSOC_CLASS_C_DEC::
362 operator()(const_key_reference r_key, size_type hash, size_type i) const
364 return (my_comb_probe_fn_base::operator()(
365 hash + my_probe_fn_base::operator()(r_key, i)));
368 PB_ASSOC_CLASS_T_DEC
369 inline typename PB_ASSOC_CLASS_C_DEC::size_type
370 PB_ASSOC_CLASS_C_DEC::
371 operator()
372 #ifdef PB_ASSOC_RANGED_PROBE_FN_DEBUG
373 (const_key_reference r_key, size_type hash) const
374 #else // #ifdef PB_ASSOC_RANGED_PROBE_FN_DEBUG
375 (const_key_reference /*r_key*/, size_type hash) const
376 #endif // #ifdef PB_ASSOC_RANGED_PROBE_FN_DEBUG
378 PB_ASSOC_DBG_ASSERT(hash == my_hash_fn_base::operator()(r_key));
380 return (hash);
383 #undef PB_ASSOC_CLASS_T_DEC
384 #undef PB_ASSOC_CLASS_C_DEC
386 #define PB_ASSOC_CLASS_T_DEC \
387 template<typename Key, class Allocator, class Comb_Probe_Fn>
389 #define PB_ASSOC_CLASS_C_DEC \
390 ranged_probe_fn< \
391 Key, \
392 null_hash_fn, \
393 Allocator, \
394 Comb_Probe_Fn, \
395 null_probe_fn, \
396 false>
399 * Specialization 3 and 4- The client does not supply a hash function or
400 * probe function, and requests that hash values not be stored.
402 template<typename Key, class Allocator, class Comb_Probe_Fn>
403 class ranged_probe_fn<
404 Key,
405 null_hash_fn,
406 Allocator,
407 Comb_Probe_Fn,
408 null_probe_fn,
409 false> :
410 public Comb_Probe_Fn,
411 public null_hash_fn,
412 public null_probe_fn
414 protected:
415 typedef typename Allocator::size_type size_type;
417 typedef Comb_Probe_Fn my_comb_probe_fn_base;
419 typedef typename Allocator::template rebind<Key>::other key_allocator;
421 typedef typename key_allocator::const_reference const_key_reference;
423 protected:
424 ranged_probe_fn(size_type size);
426 ranged_probe_fn(size_type size, const Comb_Probe_Fn& r_comb_probe_fn);
428 ranged_probe_fn(size_type size, const null_hash_fn& r_null_hash_fn, const Comb_Probe_Fn& r_comb_probe_fn, const null_probe_fn& r_null_probe_fn);
430 void
431 swap(PB_ASSOC_CLASS_C_DEC& r_other);
434 PB_ASSOC_CLASS_T_DEC
435 PB_ASSOC_CLASS_C_DEC::
436 ranged_probe_fn(size_type size)
438 Comb_Probe_Fn::notify_resized(size);
441 PB_ASSOC_CLASS_T_DEC
442 PB_ASSOC_CLASS_C_DEC::
443 ranged_probe_fn(size_type size, const Comb_Probe_Fn& r_comb_probe_fn) :
444 Comb_Probe_Fn(r_comb_probe_fn)
447 PB_ASSOC_CLASS_T_DEC
448 PB_ASSOC_CLASS_C_DEC::
449 ranged_probe_fn(size_type size, const null_hash_fn& r_null_hash_fn, const Comb_Probe_Fn& r_comb_probe_fn, const null_probe_fn& r_null_probe_fn) :
450 Comb_Probe_Fn(r_comb_probe_fn)
453 PB_ASSOC_CLASS_T_DEC
454 void
455 PB_ASSOC_CLASS_C_DEC::
456 swap(PB_ASSOC_CLASS_C_DEC& r_other)
458 my_comb_probe_fn_base::swap(r_other);
461 #undef PB_ASSOC_CLASS_T_DEC
462 #undef PB_ASSOC_CLASS_C_DEC
464 #undef PB_ASSOC_DBG_ASSERT
465 #undef PB_ASSOC_DBG_VERIFY
466 #undef PB_ASSOC_DBG_ONLY
468 } // namespace detail
470 } // namespace pb_assoc
472 #endif // #ifndef RANGED_PROBE_FN_HPP