xref: /dflybsd-src/contrib/gcc-4.7/libstdc++-v3/include/tr1/unordered_set.h (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino // TR1 unordered_set implementation -*- C++ -*-
2*e4b17023SJohn Marino 
3*e4b17023SJohn Marino // Copyright (C) 2010 Free Software Foundation, Inc.
4*e4b17023SJohn Marino //
5*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library.  This library is free
6*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the
7*e4b17023SJohn Marino // terms of the GNU General Public License as published by the
8*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option)
9*e4b17023SJohn Marino // any later version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful,
12*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*e4b17023SJohn Marino // GNU General Public License for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional
17*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version
18*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation.
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and
21*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program;
22*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>.
24*e4b17023SJohn Marino 
25*e4b17023SJohn Marino /** @file tr1/unordered_set.h
26*e4b17023SJohn Marino  *  This is an internal header file, included by other library headers.
27*e4b17023SJohn Marino  *  Do not attempt to use it directly. @headername{tr1/unordered_set}
28*e4b17023SJohn Marino  */
29*e4b17023SJohn Marino 
_GLIBCXX_VISIBILITY(default)30*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default)
31*e4b17023SJohn Marino {
32*e4b17023SJohn Marino namespace tr1
33*e4b17023SJohn Marino {
34*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION
35*e4b17023SJohn Marino 
36*e4b17023SJohn Marino   // NB: When we get typedef templates these class definitions
37*e4b17023SJohn Marino   // will be unnecessary.
38*e4b17023SJohn Marino   template<class _Value,
39*e4b17023SJohn Marino 	   class _Hash = hash<_Value>,
40*e4b17023SJohn Marino 	   class _Pred = std::equal_to<_Value>,
41*e4b17023SJohn Marino 	   class _Alloc = std::allocator<_Value>,
42*e4b17023SJohn Marino 	   bool __cache_hash_code = false>
43*e4b17023SJohn Marino     class __unordered_set
44*e4b17023SJohn Marino     : public _Hashtable<_Value, _Value, _Alloc,
45*e4b17023SJohn Marino 			std::_Identity<_Value>, _Pred,
46*e4b17023SJohn Marino 			_Hash, __detail::_Mod_range_hashing,
47*e4b17023SJohn Marino 			__detail::_Default_ranged_hash,
48*e4b17023SJohn Marino 			__detail::_Prime_rehash_policy,
49*e4b17023SJohn Marino 			__cache_hash_code, true, true>
50*e4b17023SJohn Marino     {
51*e4b17023SJohn Marino       typedef _Hashtable<_Value, _Value, _Alloc,
52*e4b17023SJohn Marino 			 std::_Identity<_Value>, _Pred,
53*e4b17023SJohn Marino 			 _Hash, __detail::_Mod_range_hashing,
54*e4b17023SJohn Marino 			 __detail::_Default_ranged_hash,
55*e4b17023SJohn Marino 			 __detail::_Prime_rehash_policy,
56*e4b17023SJohn Marino 			 __cache_hash_code, true, true>
57*e4b17023SJohn Marino 	_Base;
58*e4b17023SJohn Marino 
59*e4b17023SJohn Marino     public:
60*e4b17023SJohn Marino       typedef typename _Base::size_type       size_type;
61*e4b17023SJohn Marino       typedef typename _Base::hasher          hasher;
62*e4b17023SJohn Marino       typedef typename _Base::key_equal       key_equal;
63*e4b17023SJohn Marino       typedef typename _Base::allocator_type  allocator_type;
64*e4b17023SJohn Marino 
65*e4b17023SJohn Marino       explicit
66*e4b17023SJohn Marino       __unordered_set(size_type __n = 10,
67*e4b17023SJohn Marino 		      const hasher& __hf = hasher(),
68*e4b17023SJohn Marino 		      const key_equal& __eql = key_equal(),
69*e4b17023SJohn Marino 		      const allocator_type& __a = allocator_type())
70*e4b17023SJohn Marino       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
71*e4b17023SJohn Marino 	      __detail::_Default_ranged_hash(), __eql,
72*e4b17023SJohn Marino 	      std::_Identity<_Value>(), __a)
73*e4b17023SJohn Marino       { }
74*e4b17023SJohn Marino 
75*e4b17023SJohn Marino       template<typename _InputIterator>
76*e4b17023SJohn Marino 	__unordered_set(_InputIterator __f, _InputIterator __l,
77*e4b17023SJohn Marino 			size_type __n = 10,
78*e4b17023SJohn Marino 			const hasher& __hf = hasher(),
79*e4b17023SJohn Marino 			const key_equal& __eql = key_equal(),
80*e4b17023SJohn Marino 			const allocator_type& __a = allocator_type())
81*e4b17023SJohn Marino 	: _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
82*e4b17023SJohn Marino 		__detail::_Default_ranged_hash(), __eql,
83*e4b17023SJohn Marino 		std::_Identity<_Value>(), __a)
84*e4b17023SJohn Marino 	{ }
85*e4b17023SJohn Marino     };
86*e4b17023SJohn Marino 
87*e4b17023SJohn Marino   template<class _Value,
88*e4b17023SJohn Marino 	   class _Hash = hash<_Value>,
89*e4b17023SJohn Marino 	   class _Pred = std::equal_to<_Value>,
90*e4b17023SJohn Marino 	   class _Alloc = std::allocator<_Value>,
91*e4b17023SJohn Marino 	   bool __cache_hash_code = false>
92*e4b17023SJohn Marino     class __unordered_multiset
93*e4b17023SJohn Marino     : public _Hashtable<_Value, _Value, _Alloc,
94*e4b17023SJohn Marino 			std::_Identity<_Value>, _Pred,
95*e4b17023SJohn Marino 			_Hash, __detail::_Mod_range_hashing,
96*e4b17023SJohn Marino 			__detail::_Default_ranged_hash,
97*e4b17023SJohn Marino 			__detail::_Prime_rehash_policy,
98*e4b17023SJohn Marino 			__cache_hash_code, true, false>
99*e4b17023SJohn Marino     {
100*e4b17023SJohn Marino       typedef _Hashtable<_Value, _Value, _Alloc,
101*e4b17023SJohn Marino 			 std::_Identity<_Value>, _Pred,
102*e4b17023SJohn Marino 			 _Hash, __detail::_Mod_range_hashing,
103*e4b17023SJohn Marino 			 __detail::_Default_ranged_hash,
104*e4b17023SJohn Marino 			 __detail::_Prime_rehash_policy,
105*e4b17023SJohn Marino 			 __cache_hash_code, true, false>
106*e4b17023SJohn Marino 	_Base;
107*e4b17023SJohn Marino 
108*e4b17023SJohn Marino     public:
109*e4b17023SJohn Marino       typedef typename _Base::size_type       size_type;
110*e4b17023SJohn Marino       typedef typename _Base::hasher          hasher;
111*e4b17023SJohn Marino       typedef typename _Base::key_equal       key_equal;
112*e4b17023SJohn Marino       typedef typename _Base::allocator_type  allocator_type;
113*e4b17023SJohn Marino 
114*e4b17023SJohn Marino       explicit
115*e4b17023SJohn Marino       __unordered_multiset(size_type __n = 10,
116*e4b17023SJohn Marino 			   const hasher& __hf = hasher(),
117*e4b17023SJohn Marino 			   const key_equal& __eql = key_equal(),
118*e4b17023SJohn Marino 			   const allocator_type& __a = allocator_type())
119*e4b17023SJohn Marino       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
120*e4b17023SJohn Marino 	      __detail::_Default_ranged_hash(), __eql,
121*e4b17023SJohn Marino 	      std::_Identity<_Value>(), __a)
122*e4b17023SJohn Marino       { }
123*e4b17023SJohn Marino 
124*e4b17023SJohn Marino 
125*e4b17023SJohn Marino       template<typename _InputIterator>
126*e4b17023SJohn Marino 	__unordered_multiset(_InputIterator __f, _InputIterator __l,
127*e4b17023SJohn Marino 			     typename _Base::size_type __n = 0,
128*e4b17023SJohn Marino 			     const hasher& __hf = hasher(),
129*e4b17023SJohn Marino 			     const key_equal& __eql = key_equal(),
130*e4b17023SJohn Marino 			     const allocator_type& __a = allocator_type())
131*e4b17023SJohn Marino 	: _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
132*e4b17023SJohn Marino 		__detail::_Default_ranged_hash(), __eql,
133*e4b17023SJohn Marino 		std::_Identity<_Value>(), __a)
134*e4b17023SJohn Marino 	{ }
135*e4b17023SJohn Marino     };
136*e4b17023SJohn Marino 
137*e4b17023SJohn Marino   template<class _Value, class _Hash, class _Pred, class _Alloc,
138*e4b17023SJohn Marino 	   bool __cache_hash_code>
139*e4b17023SJohn Marino     inline void
140*e4b17023SJohn Marino     swap(__unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __x,
141*e4b17023SJohn Marino 	 __unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __y)
142*e4b17023SJohn Marino     { __x.swap(__y); }
143*e4b17023SJohn Marino 
144*e4b17023SJohn Marino   template<class _Value, class _Hash, class _Pred, class _Alloc,
145*e4b17023SJohn Marino 	   bool __cache_hash_code>
146*e4b17023SJohn Marino     inline void
147*e4b17023SJohn Marino     swap(__unordered_multiset<_Value, _Hash, _Pred,
148*e4b17023SJohn Marino 	 _Alloc, __cache_hash_code>& __x,
149*e4b17023SJohn Marino 	 __unordered_multiset<_Value, _Hash, _Pred,
150*e4b17023SJohn Marino 	 _Alloc, __cache_hash_code>& __y)
151*e4b17023SJohn Marino     { __x.swap(__y); }
152*e4b17023SJohn Marino 
153*e4b17023SJohn Marino 
154*e4b17023SJohn Marino   /**
155*e4b17023SJohn Marino    *  @brief A standard container composed of unique keys (containing
156*e4b17023SJohn Marino    *  at most one of each key value) in which the elements' keys are
157*e4b17023SJohn Marino    *  the elements themselves.
158*e4b17023SJohn Marino    *
159*e4b17023SJohn Marino    *  @ingroup unordered_associative_containers
160*e4b17023SJohn Marino    *
161*e4b17023SJohn Marino    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
162*e4b17023SJohn Marino    *  <a href="tables.html#xx">unordered associative container</a>
163*e4b17023SJohn Marino    *
164*e4b17023SJohn Marino    *  @param  Value  Type of key objects.
165*e4b17023SJohn Marino    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
166*e4b17023SJohn Marino    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
167*e4b17023SJohn Marino    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
168*e4b17023SJohn Marino    */
169*e4b17023SJohn Marino   template<class _Value,
170*e4b17023SJohn Marino 	   class _Hash = hash<_Value>,
171*e4b17023SJohn Marino 	   class _Pred = std::equal_to<_Value>,
172*e4b17023SJohn Marino 	   class _Alloc = std::allocator<_Value> >
173*e4b17023SJohn Marino     class unordered_set
174*e4b17023SJohn Marino     : public __unordered_set<_Value, _Hash, _Pred, _Alloc>
175*e4b17023SJohn Marino     {
176*e4b17023SJohn Marino       typedef __unordered_set<_Value, _Hash, _Pred, _Alloc>  _Base;
177*e4b17023SJohn Marino 
178*e4b17023SJohn Marino     public:
179*e4b17023SJohn Marino       typedef typename _Base::value_type      value_type;
180*e4b17023SJohn Marino       typedef typename _Base::size_type       size_type;
181*e4b17023SJohn Marino       typedef typename _Base::hasher          hasher;
182*e4b17023SJohn Marino       typedef typename _Base::key_equal       key_equal;
183*e4b17023SJohn Marino       typedef typename _Base::allocator_type  allocator_type;
184*e4b17023SJohn Marino 
185*e4b17023SJohn Marino       explicit
186*e4b17023SJohn Marino       unordered_set(size_type __n = 10,
187*e4b17023SJohn Marino 		    const hasher& __hf = hasher(),
188*e4b17023SJohn Marino 		    const key_equal& __eql = key_equal(),
189*e4b17023SJohn Marino 		    const allocator_type& __a = allocator_type())
190*e4b17023SJohn Marino       : _Base(__n, __hf, __eql, __a)
191*e4b17023SJohn Marino       { }
192*e4b17023SJohn Marino 
193*e4b17023SJohn Marino       template<typename _InputIterator>
194*e4b17023SJohn Marino 	unordered_set(_InputIterator __f, _InputIterator __l,
195*e4b17023SJohn Marino 		      size_type __n = 10,
196*e4b17023SJohn Marino 		      const hasher& __hf = hasher(),
197*e4b17023SJohn Marino 		      const key_equal& __eql = key_equal(),
198*e4b17023SJohn Marino 		      const allocator_type& __a = allocator_type())
199*e4b17023SJohn Marino 	: _Base(__f, __l, __n, __hf, __eql, __a)
200*e4b17023SJohn Marino 	{ }
201*e4b17023SJohn Marino     };
202*e4b17023SJohn Marino 
203*e4b17023SJohn Marino   /**
204*e4b17023SJohn Marino    *  @brief A standard container composed of equivalent keys
205*e4b17023SJohn Marino    *  (possibly containing multiple of each key value) in which the
206*e4b17023SJohn Marino    *  elements' keys are the elements themselves.
207*e4b17023SJohn Marino    *
208*e4b17023SJohn Marino    *  @ingroup unordered_associative_containers
209*e4b17023SJohn Marino    *
210*e4b17023SJohn Marino    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
211*e4b17023SJohn Marino    *  <a href="tables.html#xx">unordered associative container</a>
212*e4b17023SJohn Marino    *
213*e4b17023SJohn Marino    *  @param  Value  Type of key objects.
214*e4b17023SJohn Marino    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
215*e4b17023SJohn Marino    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
216*e4b17023SJohn Marino    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
217*e4b17023SJohn Marino    */
218*e4b17023SJohn Marino   template<class _Value,
219*e4b17023SJohn Marino 	   class _Hash = hash<_Value>,
220*e4b17023SJohn Marino 	   class _Pred = std::equal_to<_Value>,
221*e4b17023SJohn Marino 	   class _Alloc = std::allocator<_Value> >
222*e4b17023SJohn Marino     class unordered_multiset
223*e4b17023SJohn Marino     : public __unordered_multiset<_Value, _Hash, _Pred, _Alloc>
224*e4b17023SJohn Marino     {
225*e4b17023SJohn Marino       typedef __unordered_multiset<_Value, _Hash, _Pred, _Alloc>  _Base;
226*e4b17023SJohn Marino 
227*e4b17023SJohn Marino     public:
228*e4b17023SJohn Marino       typedef typename _Base::value_type      value_type;
229*e4b17023SJohn Marino       typedef typename _Base::size_type       size_type;
230*e4b17023SJohn Marino       typedef typename _Base::hasher          hasher;
231*e4b17023SJohn Marino       typedef typename _Base::key_equal       key_equal;
232*e4b17023SJohn Marino       typedef typename _Base::allocator_type  allocator_type;
233*e4b17023SJohn Marino 
234*e4b17023SJohn Marino       explicit
235*e4b17023SJohn Marino       unordered_multiset(size_type __n = 10,
236*e4b17023SJohn Marino 			 const hasher& __hf = hasher(),
237*e4b17023SJohn Marino 			 const key_equal& __eql = key_equal(),
238*e4b17023SJohn Marino 			 const allocator_type& __a = allocator_type())
239*e4b17023SJohn Marino       : _Base(__n, __hf, __eql, __a)
240*e4b17023SJohn Marino       { }
241*e4b17023SJohn Marino 
242*e4b17023SJohn Marino 
243*e4b17023SJohn Marino       template<typename _InputIterator>
244*e4b17023SJohn Marino 	unordered_multiset(_InputIterator __f, _InputIterator __l,
245*e4b17023SJohn Marino 			   typename _Base::size_type __n = 0,
246*e4b17023SJohn Marino 			   const hasher& __hf = hasher(),
247*e4b17023SJohn Marino 			   const key_equal& __eql = key_equal(),
248*e4b17023SJohn Marino 			   const allocator_type& __a = allocator_type())
249*e4b17023SJohn Marino 	: _Base(__f, __l, __n, __hf, __eql, __a)
250*e4b17023SJohn Marino 	{ }
251*e4b17023SJohn Marino     };
252*e4b17023SJohn Marino 
253*e4b17023SJohn Marino   template<class _Value, class _Hash, class _Pred, class _Alloc>
254*e4b17023SJohn Marino     inline void
255*e4b17023SJohn Marino     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
256*e4b17023SJohn Marino 	 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
257*e4b17023SJohn Marino     { __x.swap(__y); }
258*e4b17023SJohn Marino 
259*e4b17023SJohn Marino   template<class _Value, class _Hash, class _Pred, class _Alloc>
260*e4b17023SJohn Marino     inline void
261*e4b17023SJohn Marino     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
262*e4b17023SJohn Marino 	 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
263*e4b17023SJohn Marino     { __x.swap(__y); }
264*e4b17023SJohn Marino 
265*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION
266*e4b17023SJohn Marino }
267*e4b17023SJohn Marino }
268