1*38fd1498Szrj // TR1 unordered_map 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_map.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_map}
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 _Key, class _Tp,
39*38fd1498Szrj class _Hash = hash<_Key>,
40*38fd1498Szrj class _Pred = std::equal_to<_Key>,
41*38fd1498Szrj class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
42*38fd1498Szrj bool __cache_hash_code = false>
43*38fd1498Szrj class __unordered_map
44*38fd1498Szrj : public _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
45*38fd1498Szrj std::_Select1st<std::pair<const _Key, _Tp> >, _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, false, true>
50*38fd1498Szrj {
51*38fd1498Szrj typedef _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
52*38fd1498Szrj std::_Select1st<std::pair<const _Key, _Tp> >, _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, false, 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_map(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(),
72*38fd1498Szrj __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
73*38fd1498Szrj { }
74*38fd1498Szrj
75*38fd1498Szrj template<typename _InputIterator>
76*38fd1498Szrj __unordered_map(_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(),
83*38fd1498Szrj __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
84*38fd1498Szrj { }
85*38fd1498Szrj };
86*38fd1498Szrj
87*38fd1498Szrj template<class _Key, class _Tp,
88*38fd1498Szrj class _Hash = hash<_Key>,
89*38fd1498Szrj class _Pred = std::equal_to<_Key>,
90*38fd1498Szrj class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
91*38fd1498Szrj bool __cache_hash_code = false>
92*38fd1498Szrj class __unordered_multimap
93*38fd1498Szrj : public _Hashtable<_Key, std::pair<const _Key, _Tp>,
94*38fd1498Szrj _Alloc,
95*38fd1498Szrj std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
96*38fd1498Szrj _Hash, __detail::_Mod_range_hashing,
97*38fd1498Szrj __detail::_Default_ranged_hash,
98*38fd1498Szrj __detail::_Prime_rehash_policy,
99*38fd1498Szrj __cache_hash_code, false, false>
100*38fd1498Szrj {
101*38fd1498Szrj typedef _Hashtable<_Key, std::pair<const _Key, _Tp>,
102*38fd1498Szrj _Alloc,
103*38fd1498Szrj std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
104*38fd1498Szrj _Hash, __detail::_Mod_range_hashing,
105*38fd1498Szrj __detail::_Default_ranged_hash,
106*38fd1498Szrj __detail::_Prime_rehash_policy,
107*38fd1498Szrj __cache_hash_code, false, false>
108*38fd1498Szrj _Base;
109*38fd1498Szrj
110*38fd1498Szrj public:
111*38fd1498Szrj typedef typename _Base::size_type size_type;
112*38fd1498Szrj typedef typename _Base::hasher hasher;
113*38fd1498Szrj typedef typename _Base::key_equal key_equal;
114*38fd1498Szrj typedef typename _Base::allocator_type allocator_type;
115*38fd1498Szrj
116*38fd1498Szrj explicit
117*38fd1498Szrj __unordered_multimap(size_type __n = 10,
118*38fd1498Szrj const hasher& __hf = hasher(),
119*38fd1498Szrj const key_equal& __eql = key_equal(),
120*38fd1498Szrj const allocator_type& __a = allocator_type())
121*38fd1498Szrj : _Base(__n, __hf, __detail::_Mod_range_hashing(),
122*38fd1498Szrj __detail::_Default_ranged_hash(),
123*38fd1498Szrj __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
124*38fd1498Szrj { }
125*38fd1498Szrj
126*38fd1498Szrj
127*38fd1498Szrj template<typename _InputIterator>
128*38fd1498Szrj __unordered_multimap(_InputIterator __f, _InputIterator __l,
129*38fd1498Szrj typename _Base::size_type __n = 0,
130*38fd1498Szrj const hasher& __hf = hasher(),
131*38fd1498Szrj const key_equal& __eql = key_equal(),
132*38fd1498Szrj const allocator_type& __a = allocator_type())
133*38fd1498Szrj : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
134*38fd1498Szrj __detail::_Default_ranged_hash(),
135*38fd1498Szrj __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
136*38fd1498Szrj { }
137*38fd1498Szrj };
138*38fd1498Szrj
139*38fd1498Szrj template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
140*38fd1498Szrj bool __cache_hash_code>
141*38fd1498Szrj inline void
142*38fd1498Szrj swap(__unordered_map<_Key, _Tp, _Hash, _Pred,
143*38fd1498Szrj _Alloc, __cache_hash_code>& __x,
144*38fd1498Szrj __unordered_map<_Key, _Tp, _Hash, _Pred,
145*38fd1498Szrj _Alloc, __cache_hash_code>& __y)
146*38fd1498Szrj { __x.swap(__y); }
147*38fd1498Szrj
148*38fd1498Szrj template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
149*38fd1498Szrj bool __cache_hash_code>
150*38fd1498Szrj inline void
151*38fd1498Szrj swap(__unordered_multimap<_Key, _Tp, _Hash, _Pred,
152*38fd1498Szrj _Alloc, __cache_hash_code>& __x,
153*38fd1498Szrj __unordered_multimap<_Key, _Tp, _Hash, _Pred,
154*38fd1498Szrj _Alloc, __cache_hash_code>& __y)
155*38fd1498Szrj { __x.swap(__y); }
156*38fd1498Szrj
157*38fd1498Szrj
158*38fd1498Szrj /**
159*38fd1498Szrj * @brief A standard container composed of unique keys (containing
160*38fd1498Szrj * at most one of each key value) that associates values of another type
161*38fd1498Szrj * with the keys.
162*38fd1498Szrj *
163*38fd1498Szrj * @ingroup unordered_associative_containers
164*38fd1498Szrj *
165*38fd1498Szrj * Meets the requirements of a <a href="tables.html#65">container</a>, and
166*38fd1498Szrj * <a href="tables.html#xx">unordered associative container</a>
167*38fd1498Szrj *
168*38fd1498Szrj * @param Key Type of key objects.
169*38fd1498Szrj * @param Tp Type of mapped objects.
170*38fd1498Szrj * @param Hash Hashing function object type, defaults to hash<Value>.
171*38fd1498Szrj * @param Pred Predicate function object type, defaults to equal_to<Value>.
172*38fd1498Szrj * @param Alloc Allocator type, defaults to allocator<Key>.
173*38fd1498Szrj *
174*38fd1498Szrj * The resulting value type of the container is std::pair<const Key, Tp>.
175*38fd1498Szrj */
176*38fd1498Szrj template<class _Key, class _Tp,
177*38fd1498Szrj class _Hash = hash<_Key>,
178*38fd1498Szrj class _Pred = std::equal_to<_Key>,
179*38fd1498Szrj class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
180*38fd1498Szrj class unordered_map
181*38fd1498Szrj : public __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
182*38fd1498Szrj {
183*38fd1498Szrj typedef __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc> _Base;
184*38fd1498Szrj
185*38fd1498Szrj public:
186*38fd1498Szrj typedef typename _Base::value_type value_type;
187*38fd1498Szrj typedef typename _Base::size_type size_type;
188*38fd1498Szrj typedef typename _Base::hasher hasher;
189*38fd1498Szrj typedef typename _Base::key_equal key_equal;
190*38fd1498Szrj typedef typename _Base::allocator_type allocator_type;
191*38fd1498Szrj
192*38fd1498Szrj explicit
193*38fd1498Szrj unordered_map(size_type __n = 10,
194*38fd1498Szrj const hasher& __hf = hasher(),
195*38fd1498Szrj const key_equal& __eql = key_equal(),
196*38fd1498Szrj const allocator_type& __a = allocator_type())
197*38fd1498Szrj : _Base(__n, __hf, __eql, __a)
198*38fd1498Szrj { }
199*38fd1498Szrj
200*38fd1498Szrj template<typename _InputIterator>
201*38fd1498Szrj unordered_map(_InputIterator __f, _InputIterator __l,
202*38fd1498Szrj size_type __n = 10,
203*38fd1498Szrj const hasher& __hf = hasher(),
204*38fd1498Szrj const key_equal& __eql = key_equal(),
205*38fd1498Szrj const allocator_type& __a = allocator_type())
206*38fd1498Szrj : _Base(__f, __l, __n, __hf, __eql, __a)
207*38fd1498Szrj { }
208*38fd1498Szrj };
209*38fd1498Szrj
210*38fd1498Szrj /**
211*38fd1498Szrj * @brief A standard container composed of equivalent keys
212*38fd1498Szrj * (possibly containing multiple of each key value) that associates
213*38fd1498Szrj * values of another type with the keys.
214*38fd1498Szrj *
215*38fd1498Szrj * @ingroup unordered_associative_containers
216*38fd1498Szrj *
217*38fd1498Szrj * Meets the requirements of a <a href="tables.html#65">container</a>, and
218*38fd1498Szrj * <a href="tables.html#xx">unordered associative container</a>
219*38fd1498Szrj *
220*38fd1498Szrj * @param Key Type of key objects.
221*38fd1498Szrj * @param Tp Type of mapped objects.
222*38fd1498Szrj * @param Hash Hashing function object type, defaults to hash<Value>.
223*38fd1498Szrj * @param Pred Predicate function object type, defaults to equal_to<Value>.
224*38fd1498Szrj * @param Alloc Allocator type, defaults to allocator<Key>.
225*38fd1498Szrj *
226*38fd1498Szrj * The resulting value type of the container is std::pair<const Key, Tp>.
227*38fd1498Szrj */
228*38fd1498Szrj template<class _Key, class _Tp,
229*38fd1498Szrj class _Hash = hash<_Key>,
230*38fd1498Szrj class _Pred = std::equal_to<_Key>,
231*38fd1498Szrj class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
232*38fd1498Szrj class unordered_multimap
233*38fd1498Szrj : public __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
234*38fd1498Szrj {
235*38fd1498Szrj typedef __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> _Base;
236*38fd1498Szrj
237*38fd1498Szrj public:
238*38fd1498Szrj typedef typename _Base::value_type value_type;
239*38fd1498Szrj typedef typename _Base::size_type size_type;
240*38fd1498Szrj typedef typename _Base::hasher hasher;
241*38fd1498Szrj typedef typename _Base::key_equal key_equal;
242*38fd1498Szrj typedef typename _Base::allocator_type allocator_type;
243*38fd1498Szrj
244*38fd1498Szrj explicit
245*38fd1498Szrj unordered_multimap(size_type __n = 10,
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(__n, __hf, __eql, __a)
250*38fd1498Szrj { }
251*38fd1498Szrj
252*38fd1498Szrj
253*38fd1498Szrj template<typename _InputIterator>
254*38fd1498Szrj unordered_multimap(_InputIterator __f, _InputIterator __l,
255*38fd1498Szrj typename _Base::size_type __n = 0,
256*38fd1498Szrj const hasher& __hf = hasher(),
257*38fd1498Szrj const key_equal& __eql = key_equal(),
258*38fd1498Szrj const allocator_type& __a = allocator_type())
259*38fd1498Szrj : _Base(__f, __l, __n, __hf, __eql, __a)
260*38fd1498Szrj { }
261*38fd1498Szrj
262*38fd1498Szrj };
263*38fd1498Szrj
264*38fd1498Szrj template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
265*38fd1498Szrj inline void
266*38fd1498Szrj swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
267*38fd1498Szrj unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
268*38fd1498Szrj { __x.swap(__y); }
269*38fd1498Szrj
270*38fd1498Szrj template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
271*38fd1498Szrj inline void
272*38fd1498Szrj swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
273*38fd1498Szrj unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
274*38fd1498Szrj { __x.swap(__y); }
275*38fd1498Szrj }
276*38fd1498Szrj
277*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
278*38fd1498Szrj }
279