GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / toolchains / hndtools-arm-linux-2.6.36-uclibc-4.5.3 / arm-brcm-linux-uclibcgnueabi / include / c++ / 4.5.3 / ext / pb_ds / detail / hash_fn / ranged_hash_fn.hpp
blob24899272f8fd5aa3b8d627f96cb17ff594769488
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2009 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 3, or (at your option) any later
9 // version.
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.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
34 // warranty.
36 /**
37 * @file ranged_hash_fn.hpp
38 * Contains a unified ranged hash functor, allowing the hash tables
39 * to deal with a single class for ranged hashing.
42 #ifndef PB_DS_RANGED_HASH_FN_HPP
43 #define PB_DS_RANGED_HASH_FN_HPP
45 #include <ext/pb_ds/detail/basic_types.hpp>
46 #include <utility>
47 #include <debug/debug.h>
49 namespace __gnu_pbds
51 namespace detail
53 template<typename Key, typename Hash_Fn, typename Allocator,
54 typename Comb_Hash_Fn, bool Store_Hash>
55 class ranged_hash_fn;
57 #define PB_DS_CLASS_T_DEC \
58 template<typename Key, typename Hash_Fn, typename Allocator, \
59 typename Comb_Hash_Fn>
61 #define PB_DS_CLASS_C_DEC \
62 ranged_hash_fn<Key, Hash_Fn, Allocator, Comb_Hash_Fn, false>
64 /**
65 * Specialization 1
66 * The client supplies a hash function and a ranged hash function,
67 * and requests that hash values not be stored.
68 **/
69 template<typename Key, typename Hash_Fn, typename Allocator,
70 typename Comb_Hash_Fn>
71 class ranged_hash_fn< Key, Hash_Fn, Allocator, Comb_Hash_Fn, false>
72 : public Hash_Fn, public Comb_Hash_Fn
74 protected:
75 typedef typename Allocator::size_type size_type;
76 typedef Hash_Fn hash_fn_base;
77 typedef Comb_Hash_Fn comb_hash_fn_base;
78 typedef typename Allocator::template rebind< Key>::other key_allocator;
79 typedef typename key_allocator::const_reference const_key_reference;
81 ranged_hash_fn(size_type);
83 ranged_hash_fn(size_type, const Hash_Fn&);
85 ranged_hash_fn(size_type, const Hash_Fn&, const Comb_Hash_Fn&);
87 void
88 swap(PB_DS_CLASS_C_DEC&);
90 void
91 notify_resized(size_type);
93 inline size_type
94 operator()(const_key_reference) const;
97 PB_DS_CLASS_T_DEC
98 PB_DS_CLASS_C_DEC::
99 ranged_hash_fn(size_type size)
100 { Comb_Hash_Fn::notify_resized(size); }
102 PB_DS_CLASS_T_DEC
103 PB_DS_CLASS_C_DEC::
104 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn)
105 : Hash_Fn(r_hash_fn)
106 { Comb_Hash_Fn::notify_resized(size); }
108 PB_DS_CLASS_T_DEC
109 PB_DS_CLASS_C_DEC::
110 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn,
111 const Comb_Hash_Fn& r_comb_hash_fn)
112 : Hash_Fn(r_hash_fn), Comb_Hash_Fn(r_comb_hash_fn)
113 { comb_hash_fn_base::notify_resized(size); }
115 PB_DS_CLASS_T_DEC
116 void
117 PB_DS_CLASS_C_DEC::
118 swap(PB_DS_CLASS_C_DEC& other)
120 comb_hash_fn_base::swap(other);
121 std::swap((Hash_Fn& )(*this), (Hash_Fn& )other);
124 PB_DS_CLASS_T_DEC
125 void
126 PB_DS_CLASS_C_DEC::
127 notify_resized(size_type size)
128 { comb_hash_fn_base::notify_resized(size); }
130 PB_DS_CLASS_T_DEC
131 inline typename PB_DS_CLASS_C_DEC::size_type
132 PB_DS_CLASS_C_DEC::
133 operator()(const_key_reference r_key) const
134 { return (comb_hash_fn_base::operator()(hash_fn_base::operator()(r_key)));}
136 #undef PB_DS_CLASS_T_DEC
137 #undef PB_DS_CLASS_C_DEC
139 #define PB_DS_CLASS_T_DEC \
140 template<typename Key, typename Hash_Fn, typename Allocator, \
141 typename Comb_Hash_Fn>
143 #define PB_DS_CLASS_C_DEC \
144 ranged_hash_fn<Key,Hash_Fn, Allocator, Comb_Hash_Fn, true>
147 * Specialization 2
148 * The client supplies a hash function and a ranged hash function,
149 * and requests that hash values be stored.
151 template<typename Key, typename Hash_Fn, typename Allocator,
152 typename Comb_Hash_Fn>
153 class ranged_hash_fn<Key, Hash_Fn, Allocator, Comb_Hash_Fn, true>
154 : public Hash_Fn, public Comb_Hash_Fn
156 protected:
157 typedef typename Allocator::size_type size_type;
158 typedef std::pair<size_type, size_type> comp_hash;
159 typedef Hash_Fn hash_fn_base;
160 typedef Comb_Hash_Fn comb_hash_fn_base;
161 typedef typename Allocator::template rebind<Key>::other key_allocator;
162 typedef typename key_allocator::const_reference const_key_reference;
164 ranged_hash_fn(size_type);
166 ranged_hash_fn(size_type, const Hash_Fn&);
168 ranged_hash_fn(size_type, const Hash_Fn&, const Comb_Hash_Fn&);
170 void
171 swap(PB_DS_CLASS_C_DEC&);
173 void
174 notify_resized(size_type);
176 inline comp_hash
177 operator()(const_key_reference) const;
179 inline comp_hash
180 operator()(const_key_reference, size_type) const;
183 PB_DS_CLASS_T_DEC
184 PB_DS_CLASS_C_DEC::
185 ranged_hash_fn(size_type size)
186 { Comb_Hash_Fn::notify_resized(size); }
188 PB_DS_CLASS_T_DEC
189 PB_DS_CLASS_C_DEC::
190 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn) :
191 Hash_Fn(r_hash_fn)
192 { Comb_Hash_Fn::notify_resized(size); }
194 PB_DS_CLASS_T_DEC
195 PB_DS_CLASS_C_DEC::
196 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn,
197 const Comb_Hash_Fn& r_comb_hash_fn)
198 : Hash_Fn(r_hash_fn), Comb_Hash_Fn(r_comb_hash_fn)
199 { comb_hash_fn_base::notify_resized(size); }
201 PB_DS_CLASS_T_DEC
202 void
203 PB_DS_CLASS_C_DEC::
204 swap(PB_DS_CLASS_C_DEC& other)
206 comb_hash_fn_base::swap(other);
207 std::swap((Hash_Fn& )(*this), (Hash_Fn& )other);
210 PB_DS_CLASS_T_DEC
211 void
212 PB_DS_CLASS_C_DEC::
213 notify_resized(size_type size)
214 { comb_hash_fn_base::notify_resized(size); }
216 PB_DS_CLASS_T_DEC
217 inline typename PB_DS_CLASS_C_DEC::comp_hash
218 PB_DS_CLASS_C_DEC::
219 operator()(const_key_reference r_key) const
221 const size_type hash = hash_fn_base::operator()(r_key);
222 return std::make_pair(comb_hash_fn_base::operator()(hash), hash);
225 PB_DS_CLASS_T_DEC
226 inline typename PB_DS_CLASS_C_DEC::comp_hash
227 PB_DS_CLASS_C_DEC::
228 operator()
229 #ifdef _GLIBCXX_DEBUG
230 (const_key_reference r_key, size_type hash) const
231 #else
232 (const_key_reference /*r_key*/, size_type hash) const
233 #endif
235 _GLIBCXX_DEBUG_ASSERT(hash == hash_fn_base::operator()(r_key));
236 return std::make_pair(comb_hash_fn_base::operator()(hash), hash);
239 #undef PB_DS_CLASS_T_DEC
240 #undef PB_DS_CLASS_C_DEC
242 #define PB_DS_CLASS_T_DEC \
243 template<typename Key, typename Allocator, typename Comb_Hash_Fn>
245 #define PB_DS_CLASS_C_DEC \
246 ranged_hash_fn<Key, null_hash_fn, Allocator, Comb_Hash_Fn, false>
249 * Specialization 3
250 * The client does not supply a hash function (by specifying
251 * null_hash_fn as the Hash_Fn parameter), and requests that hash
252 * values not be stored.
254 template<typename Key, typename Allocator, typename Comb_Hash_Fn>
255 class ranged_hash_fn<Key, null_hash_fn, Allocator, Comb_Hash_Fn, false>
256 : public null_hash_fn, public Comb_Hash_Fn
258 protected:
259 typedef typename Allocator::size_type size_type;
260 typedef Comb_Hash_Fn comb_hash_fn_base;
262 ranged_hash_fn(size_type);
264 ranged_hash_fn(size_type, const Comb_Hash_Fn&);
266 ranged_hash_fn(size_type, const null_hash_fn&, const Comb_Hash_Fn&);
268 void
269 swap(PB_DS_CLASS_C_DEC&);
272 PB_DS_CLASS_T_DEC
273 PB_DS_CLASS_C_DEC::
274 ranged_hash_fn(size_type size)
275 { Comb_Hash_Fn::notify_resized(size); }
277 PB_DS_CLASS_T_DEC
278 PB_DS_CLASS_C_DEC::
279 ranged_hash_fn(size_type size, const Comb_Hash_Fn& r_comb_hash_fn) :
280 Comb_Hash_Fn(r_comb_hash_fn)
283 PB_DS_CLASS_T_DEC
284 PB_DS_CLASS_C_DEC::
285 ranged_hash_fn(size_type size, const null_hash_fn& r_null_hash_fn,
286 const Comb_Hash_Fn& r_comb_hash_fn)
287 : Comb_Hash_Fn(r_comb_hash_fn)
290 PB_DS_CLASS_T_DEC
291 void
292 PB_DS_CLASS_C_DEC::
293 swap(PB_DS_CLASS_C_DEC& other)
294 { comb_hash_fn_base::swap(other); }
296 #undef PB_DS_CLASS_T_DEC
297 #undef PB_DS_CLASS_C_DEC
299 #define PB_DS_CLASS_T_DEC \
300 template<typename Key, typename Allocator, typename Comb_Hash_Fn>
302 #define PB_DS_CLASS_C_DEC \
303 ranged_hash_fn<Key, null_hash_fn, Allocator, Comb_Hash_Fn, true>
306 * Specialization 4
307 * The client does not supply a hash function (by specifying
308 * null_hash_fn as the Hash_Fn parameter), and requests that hash
309 * values be stored.
311 template<typename Key, typename Allocator, typename Comb_Hash_Fn>
312 class ranged_hash_fn<Key, null_hash_fn, Allocator, Comb_Hash_Fn, true>
313 : public null_hash_fn, public Comb_Hash_Fn
315 protected:
316 typedef typename Allocator::size_type size_type;
317 typedef Comb_Hash_Fn comb_hash_fn_base;
319 ranged_hash_fn(size_type);
321 ranged_hash_fn(size_type, const Comb_Hash_Fn&);
323 ranged_hash_fn(size_type, const null_hash_fn&, const Comb_Hash_Fn&);
325 void
326 swap(PB_DS_CLASS_C_DEC&);
329 PB_DS_CLASS_T_DEC
330 PB_DS_CLASS_C_DEC::
331 ranged_hash_fn(size_type size)
332 { Comb_Hash_Fn::notify_resized(size); }
334 PB_DS_CLASS_T_DEC
335 PB_DS_CLASS_C_DEC::
336 ranged_hash_fn(size_type size, const Comb_Hash_Fn& r_comb_hash_fn)
337 : Comb_Hash_Fn(r_comb_hash_fn)
340 PB_DS_CLASS_T_DEC
341 PB_DS_CLASS_C_DEC::
342 ranged_hash_fn(size_type size, const null_hash_fn& r_null_hash_fn,
343 const Comb_Hash_Fn& r_comb_hash_fn)
344 : Comb_Hash_Fn(r_comb_hash_fn)
347 PB_DS_CLASS_T_DEC
348 void
349 PB_DS_CLASS_C_DEC::
350 swap(PB_DS_CLASS_C_DEC& other)
351 { comb_hash_fn_base::swap(other); }
353 #undef PB_DS_CLASS_T_DEC
354 #undef PB_DS_CLASS_C_DEC
356 } // namespace detail
357 } // namespace __gnu_pbds
359 #endif