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