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_hash_fn.hpp
blobc260ccabfe88b7c0094899d439f04ac432c216f6
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_hash_fn.hpp
42 * Contains a unified ranged hash functor, allowing the hash tables to deal with
43 * a single class for ranged hashing.
46 #ifndef RANGED_HASH_FN_HPP
47 #define RANGED_HASH_FN_HPP
49 #include <utility>
51 namespace pb_assoc
54 namespace detail
57 #ifdef PB_ASSOC_RANGED_HASH_FN_DEBUG
58 #define PB_ASSOC_DBG_ASSERT(X) assert(X)
59 #define PB_ASSOC_DBG_VERIFY(X) assert(X)
60 #define PB_ASSOC_DBG_ONLY(X) X
61 #else // #ifdef PB_ASSOC_RANGED_HASH_FN_DEBUG
62 #define PB_ASSOC_DBG_ASSERT(X)
63 #define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
64 #define PB_ASSOC_DBG_ONLY(X) ;
65 #endif // #ifdef PB_ASSOC_RANGED_HASH_FN_DEBUG
67 template<typename Key,
68 class Hash_Fn,
69 class Allocator,
70 class Comb_Hash_Fn,
71 bool Store_Hash>
72 class ranged_hash_fn;
74 #define PB_ASSOC_CLASS_T_DEC \
75 template< \
76 typename Key, \
77 class Hash_Fn, \
78 class Allocator, \
79 class Comb_Hash_Fn>
81 #define PB_ASSOC_CLASS_C_DEC \
82 ranged_hash_fn< \
83 Key, \
84 Hash_Fn, \
85 Allocator, \
86 Comb_Hash_Fn, \
87 false>
89 /**
90 * Specialization 1- The client supplies a hash function and a ranged
91 * hash function, and requests that hash values not be stored.
92 **/
93 template<typename Key,
94 class Hash_Fn,
95 class Allocator,
96 class Comb_Hash_Fn>
97 class ranged_hash_fn<Key, Hash_Fn, Allocator, Comb_Hash_Fn, false> : public Hash_Fn,
98 public Comb_Hash_Fn
100 protected:
101 typedef typename Allocator::size_type size_type;
103 typedef Hash_Fn my_hash_fn_base;
105 typedef Comb_Hash_Fn my_comb_hash_fn_base;
107 typedef typename Allocator::template rebind<Key>::other key_allocator;
109 typedef typename key_allocator::const_reference const_key_reference;
111 protected:
112 ranged_hash_fn(size_type size);
114 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn);
116 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Hash_Fn& r_comb_hash_fn);
118 void
119 swap(PB_ASSOC_CLASS_C_DEC& r_other);
121 void
122 notify_resized(size_type size);
124 inline size_type
125 operator()(const_key_reference r_key) const;
128 PB_ASSOC_CLASS_T_DEC
129 PB_ASSOC_CLASS_C_DEC::
130 ranged_hash_fn(size_type size)
132 Comb_Hash_Fn::notify_resized(size);
135 PB_ASSOC_CLASS_T_DEC
136 PB_ASSOC_CLASS_C_DEC::
137 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn) :
138 Hash_Fn(r_hash_fn)
140 Comb_Hash_Fn::notify_resized(size);
143 PB_ASSOC_CLASS_T_DEC
144 PB_ASSOC_CLASS_C_DEC::
145 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Hash_Fn& r_comb_hash_fn) :
146 Hash_Fn(r_hash_fn),
147 Comb_Hash_Fn(r_comb_hash_fn)
149 my_comb_hash_fn_base::notify_resized(size);
152 PB_ASSOC_CLASS_T_DEC
153 void
154 PB_ASSOC_CLASS_C_DEC::
155 swap(PB_ASSOC_CLASS_C_DEC& r_other)
157 my_comb_hash_fn_base::swap(r_other);
159 std::swap((Hash_Fn& )(*this), (Hash_Fn& )r_other);
162 PB_ASSOC_CLASS_T_DEC
163 void
164 PB_ASSOC_CLASS_C_DEC::
165 notify_resized(size_type size)
167 my_comb_hash_fn_base::notify_resized(size);
170 PB_ASSOC_CLASS_T_DEC
171 inline typename PB_ASSOC_CLASS_C_DEC::size_type
172 PB_ASSOC_CLASS_C_DEC::
173 operator()(const_key_reference r_key) const
175 return (my_comb_hash_fn_base::operator()(
176 my_hash_fn_base::operator()(r_key)));
179 #undef PB_ASSOC_CLASS_T_DEC
180 #undef PB_ASSOC_CLASS_C_DEC
182 #define PB_ASSOC_CLASS_T_DEC \
183 template< \
184 typename Key, \
185 class Hash_Fn, \
186 class Allocator, \
187 class Comb_Hash_Fn>
189 #define PB_ASSOC_CLASS_C_DEC \
190 ranged_hash_fn< \
191 Key, \
192 Hash_Fn, \
193 Allocator, \
194 Comb_Hash_Fn, \
195 true>
198 * Specialization 2- The client supplies a hash function and a ranged
199 * hash function, and requests that hash values be stored.
201 template<typename Key,
202 class Hash_Fn,
203 class Allocator,
204 class Comb_Hash_Fn>
205 class ranged_hash_fn<Key, Hash_Fn, Allocator, Comb_Hash_Fn, true> :
206 public Hash_Fn,
207 public Comb_Hash_Fn
209 protected:
210 typedef typename Allocator::size_type size_type;
212 typedef std::pair<size_type, size_type> comp_hash;
214 typedef Hash_Fn my_hash_fn_base;
216 typedef Comb_Hash_Fn my_comb_hash_fn_base;
218 typedef typename Allocator::template rebind<Key>::other key_allocator;
220 typedef typename key_allocator::const_reference const_key_reference;
222 protected:
223 ranged_hash_fn(size_type size);
225 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn);
227 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Hash_Fn& r_comb_hash_fn);
229 void
230 swap(PB_ASSOC_CLASS_C_DEC& r_other);
232 void
233 notify_resized(size_type size);
235 inline comp_hash
236 operator()(const_key_reference r_key) const;
238 inline comp_hash
239 operator()(const_key_reference r_key, size_type hash) const;
242 PB_ASSOC_CLASS_T_DEC
243 PB_ASSOC_CLASS_C_DEC::
244 ranged_hash_fn(size_type size)
246 Comb_Hash_Fn::notify_resized(size);
249 PB_ASSOC_CLASS_T_DEC
250 PB_ASSOC_CLASS_C_DEC::
251 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn) :
252 Hash_Fn(r_hash_fn)
254 Comb_Hash_Fn::notify_resized(size);
257 PB_ASSOC_CLASS_T_DEC
258 PB_ASSOC_CLASS_C_DEC::
259 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn, const Comb_Hash_Fn& r_comb_hash_fn) :
260 Hash_Fn(r_hash_fn),
261 Comb_Hash_Fn(r_comb_hash_fn)
263 my_comb_hash_fn_base::notify_resized(size);
266 PB_ASSOC_CLASS_T_DEC
267 void
268 PB_ASSOC_CLASS_C_DEC::
269 swap(PB_ASSOC_CLASS_C_DEC& r_other)
271 my_comb_hash_fn_base::swap(r_other);
273 std::swap((Hash_Fn& )(*this), (Hash_Fn& )r_other);
276 PB_ASSOC_CLASS_T_DEC
277 void
278 PB_ASSOC_CLASS_C_DEC::
279 notify_resized(size_type size)
281 my_comb_hash_fn_base::notify_resized(size);
284 PB_ASSOC_CLASS_T_DEC
285 inline typename PB_ASSOC_CLASS_C_DEC::comp_hash
286 PB_ASSOC_CLASS_C_DEC::
287 operator()(const_key_reference r_key) const
289 const size_type hash = my_hash_fn_base::operator()(r_key);
291 return (std::make_pair(my_comb_hash_fn_base::operator()(hash), hash));
294 PB_ASSOC_CLASS_T_DEC
295 inline typename PB_ASSOC_CLASS_C_DEC::comp_hash
296 PB_ASSOC_CLASS_C_DEC::
297 operator()
298 #ifdef PB_ASSOC_RANGED_HASH_FN_DEBUG
299 (const_key_reference r_key, size_type hash) const
300 #else // #ifdef PB_ASSOC_RANGED_HASH_FN_DEBUG
301 (const_key_reference /*r_key*/, size_type hash) const
302 #endif // #ifdef PB_ASSOC_RANGED_HASH_FN_DEBUG
304 PB_ASSOC_DBG_ASSERT(hash == my_hash_fn_base::operator()(r_key));
306 return (std::make_pair(my_comb_hash_fn_base::operator()(hash), hash));
309 #undef PB_ASSOC_CLASS_T_DEC
310 #undef PB_ASSOC_CLASS_C_DEC
312 #define PB_ASSOC_CLASS_T_DEC \
313 template<typename Key, class Allocator, class Comb_Hash_Fn>
315 #define PB_ASSOC_CLASS_C_DEC \
316 ranged_hash_fn< \
317 Key, \
318 null_hash_fn, \
319 Allocator, \
320 Comb_Hash_Fn, \
321 false>
324 * Specialization 3- The client does not supply a hash function
325 * (by specifying null_hash_fn as the Hash_Fn parameter),
326 * and requests that hash values not be stored.
329 template<typename Key, class Allocator, class Comb_Hash_Fn>
330 class ranged_hash_fn<Key, null_hash_fn, Allocator,
331 Comb_Hash_Fn, false> :
332 public null_hash_fn,
333 public Comb_Hash_Fn
335 protected:
337 typedef typename Allocator::size_type size_type;
339 typedef Comb_Hash_Fn my_comb_hash_fn_base;
341 protected:
342 ranged_hash_fn(size_type size);
344 ranged_hash_fn(size_type size, const Comb_Hash_Fn& r_comb_hash_fn);
346 ranged_hash_fn(size_type size, const null_hash_fn&r_null_hash_fn, const Comb_Hash_Fn& r_comb_hash_fn);
348 void
349 swap(PB_ASSOC_CLASS_C_DEC& r_other);
352 PB_ASSOC_CLASS_T_DEC
353 PB_ASSOC_CLASS_C_DEC::
354 ranged_hash_fn(size_type size)
356 Comb_Hash_Fn::notify_resized(size);
359 PB_ASSOC_CLASS_T_DEC
360 PB_ASSOC_CLASS_C_DEC::
361 ranged_hash_fn(size_type size, const Comb_Hash_Fn& r_comb_hash_fn) :
362 Comb_Hash_Fn(r_comb_hash_fn)
365 PB_ASSOC_CLASS_T_DEC
366 PB_ASSOC_CLASS_C_DEC::
367 ranged_hash_fn(size_type size, const null_hash_fn& r_null_hash_fn, const Comb_Hash_Fn& r_comb_hash_fn) :
368 Comb_Hash_Fn(r_comb_hash_fn)
371 PB_ASSOC_CLASS_T_DEC
372 void
373 PB_ASSOC_CLASS_C_DEC::
374 swap(PB_ASSOC_CLASS_C_DEC& r_other)
376 my_comb_hash_fn_base::swap(r_other);
379 #undef PB_ASSOC_CLASS_T_DEC
380 #undef PB_ASSOC_CLASS_C_DEC
382 #define PB_ASSOC_CLASS_T_DEC \
383 template<typename Key, class Allocator, class Comb_Hash_Fn>
385 #define PB_ASSOC_CLASS_C_DEC \
386 ranged_hash_fn< \
387 Key, \
388 null_hash_fn, \
389 Allocator, \
390 Comb_Hash_Fn, \
391 true>
394 * Specialization 4- The client does not supply a hash function
395 * (by specifying null_hash_fn as the Hash_Fn parameter),
396 * and requests that hash values be stored.
399 template<typename Key, class Allocator, class Comb_Hash_Fn>
400 class ranged_hash_fn<Key, null_hash_fn, Allocator,
401 Comb_Hash_Fn, true> :
402 public null_hash_fn,
403 public Comb_Hash_Fn
405 protected:
406 typedef typename Allocator::size_type size_type;
408 typedef Comb_Hash_Fn my_comb_hash_fn_base;
410 protected:
411 ranged_hash_fn(size_type size);
413 ranged_hash_fn(size_type size, const Comb_Hash_Fn& r_comb_hash_fn);
415 ranged_hash_fn(size_type size, const null_hash_fn&r_null_hash_fn, const Comb_Hash_Fn& r_comb_hash_fn);
417 void
418 swap(PB_ASSOC_CLASS_C_DEC& r_other);
421 PB_ASSOC_CLASS_T_DEC
422 PB_ASSOC_CLASS_C_DEC::
423 ranged_hash_fn(size_type size)
425 Comb_Hash_Fn::notify_resized(size);
428 PB_ASSOC_CLASS_T_DEC
429 PB_ASSOC_CLASS_C_DEC::
430 ranged_hash_fn(size_type size, const Comb_Hash_Fn& r_comb_hash_fn) :
431 Comb_Hash_Fn(r_comb_hash_fn)
434 PB_ASSOC_CLASS_T_DEC
435 PB_ASSOC_CLASS_C_DEC::
436 ranged_hash_fn(size_type size, const null_hash_fn&r_null_hash_fn, const Comb_Hash_Fn& r_comb_hash_fn) :
437 Comb_Hash_Fn(r_comb_hash_fn)
440 PB_ASSOC_CLASS_T_DEC
441 void
442 PB_ASSOC_CLASS_C_DEC::
443 swap(PB_ASSOC_CLASS_C_DEC& r_other)
445 my_comb_hash_fn_base::swap(r_other);
448 #undef PB_ASSOC_CLASS_T_DEC
449 #undef PB_ASSOC_CLASS_C_DEC
451 #undef PB_ASSOC_DBG_ASSERT
452 #undef PB_ASSOC_DBG_VERIFY
453 #undef PB_ASSOC_DBG_ONLY
455 } // namespace detail
457 } // namespace pb_assoc
459 #endif // #ifndef RANGED_HASH_FN_HPP