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