1 // unordered_set implementation -*- C++ -*-
3 // Copyright (C) 2010 Free Software Foundation, Inc.
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 3, or (at your option)
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 // 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 /** @file bits/unordered_set.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{unordered_set}
30 #ifndef _UNORDERED_SET_H
31 #define _UNORDERED_SET_H
33 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std
, _GLIBCXX_STD_D
)
35 // XXX When we get typedef templates these class definitions
36 // will be unnecessary.
37 template<class _Value
,
38 class _Hash
= hash
<_Value
>,
39 class _Pred
= std::equal_to
<_Value
>,
40 class _Alloc
= std::allocator
<_Value
>,
41 bool __cache_hash_code
= false>
43 : public _Hashtable
<_Value
, _Value
, _Alloc
,
44 std::_Identity
<_Value
>, _Pred
,
45 _Hash
, __detail::_Mod_range_hashing
,
46 __detail::_Default_ranged_hash
,
47 __detail::_Prime_rehash_policy
,
48 __cache_hash_code
, true, true>
50 typedef _Hashtable
<_Value
, _Value
, _Alloc
,
51 std::_Identity
<_Value
>, _Pred
,
52 _Hash
, __detail::_Mod_range_hashing
,
53 __detail::_Default_ranged_hash
,
54 __detail::_Prime_rehash_policy
,
55 __cache_hash_code
, true, true>
59 typedef typename
_Base::value_type value_type
;
60 typedef typename
_Base::size_type size_type
;
61 typedef typename
_Base::hasher hasher
;
62 typedef typename
_Base::key_equal key_equal
;
63 typedef typename
_Base::allocator_type allocator_type
;
66 __unordered_set(size_type __n
= 10,
67 const hasher
& __hf
= hasher(),
68 const key_equal
& __eql
= key_equal(),
69 const allocator_type
& __a
= allocator_type())
70 : _Base(__n
, __hf
, __detail::_Mod_range_hashing(),
71 __detail::_Default_ranged_hash(), __eql
,
72 std::_Identity
<value_type
>(), __a
)
75 template<typename _InputIterator
>
76 __unordered_set(_InputIterator __f
, _InputIterator __l
,
78 const hasher
& __hf
= hasher(),
79 const key_equal
& __eql
= key_equal(),
80 const allocator_type
& __a
= allocator_type())
81 : _Base(__f
, __l
, __n
, __hf
, __detail::_Mod_range_hashing(),
82 __detail::_Default_ranged_hash(), __eql
,
83 std::_Identity
<value_type
>(), __a
)
86 __unordered_set(initializer_list
<value_type
> __l
,
88 const hasher
& __hf
= hasher(),
89 const key_equal
& __eql
= key_equal(),
90 const allocator_type
& __a
= allocator_type())
91 : _Base(__l
.begin(), __l
.end(), __n
, __hf
,
92 __detail::_Mod_range_hashing(),
93 __detail::_Default_ranged_hash(), __eql
,
94 std::_Identity
<value_type
>(), __a
)
98 operator=(initializer_list
<value_type
> __l
)
101 this->insert(__l
.begin(), __l
.end());
106 template<class _Value
,
107 class _Hash
= hash
<_Value
>,
108 class _Pred
= std::equal_to
<_Value
>,
109 class _Alloc
= std::allocator
<_Value
>,
110 bool __cache_hash_code
= false>
111 class __unordered_multiset
112 : public _Hashtable
<_Value
, _Value
, _Alloc
,
113 std::_Identity
<_Value
>, _Pred
,
114 _Hash
, __detail::_Mod_range_hashing
,
115 __detail::_Default_ranged_hash
,
116 __detail::_Prime_rehash_policy
,
117 __cache_hash_code
, true, false>
119 typedef _Hashtable
<_Value
, _Value
, _Alloc
,
120 std::_Identity
<_Value
>, _Pred
,
121 _Hash
, __detail::_Mod_range_hashing
,
122 __detail::_Default_ranged_hash
,
123 __detail::_Prime_rehash_policy
,
124 __cache_hash_code
, true, false>
128 typedef typename
_Base::value_type value_type
;
129 typedef typename
_Base::size_type size_type
;
130 typedef typename
_Base::hasher hasher
;
131 typedef typename
_Base::key_equal key_equal
;
132 typedef typename
_Base::allocator_type allocator_type
;
135 __unordered_multiset(size_type __n
= 10,
136 const hasher
& __hf
= hasher(),
137 const key_equal
& __eql
= key_equal(),
138 const allocator_type
& __a
= allocator_type())
139 : _Base(__n
, __hf
, __detail::_Mod_range_hashing(),
140 __detail::_Default_ranged_hash(), __eql
,
141 std::_Identity
<value_type
>(), __a
)
145 template<typename _InputIterator
>
146 __unordered_multiset(_InputIterator __f
, _InputIterator __l
,
148 const hasher
& __hf
= hasher(),
149 const key_equal
& __eql
= key_equal(),
150 const allocator_type
& __a
= allocator_type())
151 : _Base(__f
, __l
, __n
, __hf
, __detail::_Mod_range_hashing(),
152 __detail::_Default_ranged_hash(), __eql
,
153 std::_Identity
<value_type
>(), __a
)
156 __unordered_multiset(initializer_list
<value_type
> __l
,
158 const hasher
& __hf
= hasher(),
159 const key_equal
& __eql
= key_equal(),
160 const allocator_type
& __a
= allocator_type())
161 : _Base(__l
.begin(), __l
.end(), __n
, __hf
,
162 __detail::_Mod_range_hashing(),
163 __detail::_Default_ranged_hash(), __eql
,
164 std::_Identity
<value_type
>(), __a
)
167 __unordered_multiset
&
168 operator=(initializer_list
<value_type
> __l
)
171 this->insert(__l
.begin(), __l
.end());
176 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
,
177 bool __cache_hash_code
>
179 swap(__unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
, __cache_hash_code
>& __x
,
180 __unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
, __cache_hash_code
>& __y
)
183 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
,
184 bool __cache_hash_code
>
186 swap(__unordered_multiset
<_Value
, _Hash
, _Pred
,
187 _Alloc
, __cache_hash_code
>& __x
,
188 __unordered_multiset
<_Value
, _Hash
, _Pred
,
189 _Alloc
, __cache_hash_code
>& __y
)
192 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
,
193 bool __cache_hash_code
>
195 operator==(const __unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
,
196 __cache_hash_code
>& __x
,
197 const __unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
,
198 __cache_hash_code
>& __y
)
199 { return __x
._M_equal(__y
); }
201 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
,
202 bool __cache_hash_code
>
204 operator!=(const __unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
,
205 __cache_hash_code
>& __x
,
206 const __unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
,
207 __cache_hash_code
>& __y
)
208 { return !(__x
== __y
); }
210 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
,
211 bool __cache_hash_code
>
213 operator==(const __unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
,
214 __cache_hash_code
>& __x
,
215 const __unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
,
216 __cache_hash_code
>& __y
)
217 { return __x
._M_equal(__y
); }
219 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
,
220 bool __cache_hash_code
>
222 operator!=(const __unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
,
223 __cache_hash_code
>& __x
,
224 const __unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
,
225 __cache_hash_code
>& __y
)
226 { return !(__x
== __y
); }
229 * @brief A standard container composed of unique keys (containing
230 * at most one of each key value) in which the elements' keys are
231 * the elements themselves.
233 * @ingroup unordered_associative_containers
235 * Meets the requirements of a <a href="tables.html#65">container</a>, and
236 * <a href="tables.html#xx">unordered associative container</a>
238 * @param Value Type of key objects.
239 * @param Hash Hashing function object type, defaults to hash<Value>.
240 * @param Pred Predicate function object type, defaults to equal_to<Value>.
241 * @param Alloc Allocator type, defaults to allocator<Key>.
243 template<class _Value
,
244 class _Hash
= hash
<_Value
>,
245 class _Pred
= std::equal_to
<_Value
>,
246 class _Alloc
= std::allocator
<_Value
> >
248 : public __unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
>
250 typedef __unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
> _Base
;
253 typedef typename
_Base::value_type value_type
;
254 typedef typename
_Base::size_type size_type
;
255 typedef typename
_Base::hasher hasher
;
256 typedef typename
_Base::key_equal key_equal
;
257 typedef typename
_Base::allocator_type allocator_type
;
260 unordered_set(size_type __n
= 10,
261 const hasher
& __hf
= hasher(),
262 const key_equal
& __eql
= key_equal(),
263 const allocator_type
& __a
= allocator_type())
264 : _Base(__n
, __hf
, __eql
, __a
)
267 template<typename _InputIterator
>
268 unordered_set(_InputIterator __f
, _InputIterator __l
,
270 const hasher
& __hf
= hasher(),
271 const key_equal
& __eql
= key_equal(),
272 const allocator_type
& __a
= allocator_type())
273 : _Base(__f
, __l
, __n
, __hf
, __eql
, __a
)
276 unordered_set(initializer_list
<value_type
> __l
,
278 const hasher
& __hf
= hasher(),
279 const key_equal
& __eql
= key_equal(),
280 const allocator_type
& __a
= allocator_type())
281 : _Base(__l
.begin(), __l
.end(), __n
, __hf
, __eql
, __a
)
285 operator=(initializer_list
<value_type
> __l
)
288 this->insert(__l
.begin(), __l
.end());
294 * @brief A standard container composed of equivalent keys
295 * (possibly containing multiple of each key value) in which the
296 * elements' keys are the elements themselves.
298 * @ingroup unordered_associative_containers
300 * Meets the requirements of a <a href="tables.html#65">container</a>, and
301 * <a href="tables.html#xx">unordered associative container</a>
303 * @param Value Type of key objects.
304 * @param Hash Hashing function object type, defaults to hash<Value>.
305 * @param Pred Predicate function object type, defaults to equal_to<Value>.
306 * @param Alloc Allocator type, defaults to allocator<Key>.
308 template<class _Value
,
309 class _Hash
= hash
<_Value
>,
310 class _Pred
= std::equal_to
<_Value
>,
311 class _Alloc
= std::allocator
<_Value
> >
312 class unordered_multiset
313 : public __unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
>
315 typedef __unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
> _Base
;
318 typedef typename
_Base::value_type value_type
;
319 typedef typename
_Base::size_type size_type
;
320 typedef typename
_Base::hasher hasher
;
321 typedef typename
_Base::key_equal key_equal
;
322 typedef typename
_Base::allocator_type allocator_type
;
325 unordered_multiset(size_type __n
= 10,
326 const hasher
& __hf
= hasher(),
327 const key_equal
& __eql
= key_equal(),
328 const allocator_type
& __a
= allocator_type())
329 : _Base(__n
, __hf
, __eql
, __a
)
333 template<typename _InputIterator
>
334 unordered_multiset(_InputIterator __f
, _InputIterator __l
,
336 const hasher
& __hf
= hasher(),
337 const key_equal
& __eql
= key_equal(),
338 const allocator_type
& __a
= allocator_type())
339 : _Base(__f
, __l
, __n
, __hf
, __eql
, __a
)
342 unordered_multiset(initializer_list
<value_type
> __l
,
344 const hasher
& __hf
= hasher(),
345 const key_equal
& __eql
= key_equal(),
346 const allocator_type
& __a
= allocator_type())
347 : _Base(__l
.begin(), __l
.end(), __n
, __hf
, __eql
, __a
)
351 operator=(initializer_list
<value_type
> __l
)
354 this->insert(__l
.begin(), __l
.end());
359 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
>
361 swap(unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
>& __x
,
362 unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
>& __y
)
365 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
>
367 swap(unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
>& __x
,
368 unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
>& __y
)
371 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
>
373 operator==(const unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
>& __x
,
374 const unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
>& __y
)
375 { return __x
._M_equal(__y
); }
377 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
>
379 operator!=(const unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
>& __x
,
380 const unordered_set
<_Value
, _Hash
, _Pred
, _Alloc
>& __y
)
381 { return !(__x
== __y
); }
383 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
>
385 operator==(const unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
>& __x
,
386 const unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
>& __y
)
387 { return __x
._M_equal(__y
); }
389 template<class _Value
, class _Hash
, class _Pred
, class _Alloc
>
391 operator!=(const unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
>& __x
,
392 const unordered_multiset
<_Value
, _Hash
, _Pred
, _Alloc
>& __y
)
393 { return !(__x
== __y
); }
395 _GLIBCXX_END_NESTED_NAMESPACE
397 #endif /* _UNORDERED_SET_H */