williamr@2
|
1 |
/*
|
williamr@2
|
2 |
*
|
williamr@2
|
3 |
* Copyright (c) 1994
|
williamr@2
|
4 |
* Hewlett-Packard Company
|
williamr@2
|
5 |
*
|
williamr@2
|
6 |
* Copyright (c) 1996,1997
|
williamr@2
|
7 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Copyright (c) 1997
|
williamr@2
|
10 |
* Moscow Center for SPARC Technology
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Copyright (c) 1999
|
williamr@2
|
13 |
* Boris Fomitchev
|
williamr@2
|
14 |
*
|
williamr@2
|
15 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
16 |
* or implied. Any use is at your own risk.
|
williamr@2
|
17 |
*
|
williamr@2
|
18 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
19 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
20 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
21 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
22 |
* modified is included with the above copyright notice.
|
williamr@2
|
23 |
*
|
williamr@2
|
24 |
*/
|
williamr@2
|
25 |
|
williamr@2
|
26 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@2
|
27 |
* You should not attempt to use it directly.
|
williamr@2
|
28 |
*/
|
williamr@2
|
29 |
|
williamr@2
|
30 |
#ifndef _STLP_INTERNAL_HASH_MAP_H
|
williamr@2
|
31 |
#define _STLP_INTERNAL_HASH_MAP_H
|
williamr@2
|
32 |
|
williamr@2
|
33 |
#ifndef _STLP_INTERNAL_HASHTABLE_H
|
williamr@2
|
34 |
# include <stl/_hashtable.h>
|
williamr@2
|
35 |
#endif
|
williamr@2
|
36 |
|
williamr@2
|
37 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
38 |
|
williamr@2
|
39 |
# define hash_map __WORKAROUND_RENAME(hash_map)
|
williamr@2
|
40 |
# define hash_multimap __WORKAROUND_RENAME(hash_multimap)
|
williamr@2
|
41 |
|
williamr@2
|
42 |
# define _STLP_KEY_PAIR pair< const _Key, _Tp >
|
williamr@2
|
43 |
# define _STLP_HASHTABLE hashtable \
|
williamr@2
|
44 |
< pair < const _Key, _Tp >, _Key, _HashFcn, \
|
williamr@2
|
45 |
_STLP_SELECT1ST( _STLP_KEY_PAIR, _Key ), _EqualKey, _Alloc >
|
williamr@2
|
46 |
|
williamr@2
|
47 |
template <class _Key, class _Tp, __DFL_TMPL_PARAM(_HashFcn,hash<_Key>),
|
williamr@2
|
48 |
__DFL_TMPL_PARAM(_EqualKey,equal_to<_Key>),
|
williamr@2
|
49 |
_STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
|
williamr@2
|
50 |
class hash_map
|
williamr@2
|
51 |
{
|
williamr@2
|
52 |
private:
|
williamr@2
|
53 |
typedef _STLP_HASHTABLE _Ht;
|
williamr@2
|
54 |
typedef hash_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc> _Self;
|
williamr@2
|
55 |
public:
|
williamr@2
|
56 |
typedef typename _Ht::key_type key_type;
|
williamr@2
|
57 |
typedef _Tp data_type;
|
williamr@2
|
58 |
typedef _Tp mapped_type;
|
williamr@2
|
59 |
typedef typename _Ht::value_type _value_type;
|
williamr@2
|
60 |
typedef typename _Ht::value_type value_type;
|
williamr@2
|
61 |
typedef typename _Ht::hasher hasher;
|
williamr@2
|
62 |
typedef typename _Ht::key_equal key_equal;
|
williamr@2
|
63 |
|
williamr@2
|
64 |
typedef typename _Ht::size_type size_type;
|
williamr@2
|
65 |
typedef typename _Ht::difference_type difference_type;
|
williamr@2
|
66 |
typedef typename _Ht::pointer pointer;
|
williamr@2
|
67 |
typedef typename _Ht::const_pointer const_pointer;
|
williamr@2
|
68 |
typedef typename _Ht::reference reference;
|
williamr@2
|
69 |
typedef typename _Ht::const_reference const_reference;
|
williamr@2
|
70 |
|
williamr@2
|
71 |
typedef typename _Ht::iterator iterator;
|
williamr@2
|
72 |
typedef typename _Ht::const_iterator const_iterator;
|
williamr@2
|
73 |
|
williamr@2
|
74 |
typedef typename _Ht::allocator_type allocator_type;
|
williamr@2
|
75 |
|
williamr@2
|
76 |
hasher hash_funct() const { return _M_ht.hash_funct(); }
|
williamr@2
|
77 |
key_equal key_eq() const { return _M_ht.key_eq(); }
|
williamr@2
|
78 |
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
|
williamr@2
|
79 |
|
williamr@2
|
80 |
private:
|
williamr@2
|
81 |
_Ht _M_ht;
|
williamr@2
|
82 |
public:
|
williamr@2
|
83 |
hash_map() : _M_ht(100, hasher(), key_equal(), allocator_type()) {
|
williamr@2
|
84 |
_STLP_POP_IF_CHECK
|
williamr@2
|
85 |
}
|
williamr@2
|
86 |
explicit hash_map(size_type __n)
|
williamr@2
|
87 |
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {
|
williamr@2
|
88 |
_STLP_POP_IF_CHECK
|
williamr@2
|
89 |
}
|
williamr@2
|
90 |
|
williamr@2
|
91 |
|
williamr@2
|
92 |
# ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
93 |
hash_map(const _Self& __o) :
|
williamr@2
|
94 |
_M_ht(__o.size())
|
williamr@2
|
95 |
{
|
williamr@2
|
96 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
97 |
_M_ht = __o._M_ht;
|
williamr@2
|
98 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
99 |
}
|
williamr@2
|
100 |
# else
|
williamr@2
|
101 |
hash_map(const _Self& __o)
|
williamr@2
|
102 |
: _M_ht(__o._M_ht) {
|
williamr@2
|
103 |
}
|
williamr@2
|
104 |
# endif
|
williamr@2
|
105 |
|
williamr@2
|
106 |
hash_map(size_type __n, const hasher& __hf)
|
williamr@2
|
107 |
: _M_ht(__n, __hf, key_equal(), allocator_type()) {
|
williamr@2
|
108 |
_STLP_POP_IF_CHECK
|
williamr@2
|
109 |
}
|
williamr@2
|
110 |
hash_map(size_type __n, const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
111 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
112 |
: _M_ht(__n, __hf, __eql, __a) {
|
williamr@2
|
113 |
_STLP_POP_IF_CHECK
|
williamr@2
|
114 |
}
|
williamr@2
|
115 |
|
williamr@2
|
116 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
117 |
template <class _InputIterator>
|
williamr@2
|
118 |
hash_map(_InputIterator __f, _InputIterator __l)
|
williamr@2
|
119 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
120 |
{
|
williamr@2
|
121 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
122 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
123 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
124 |
}
|
williamr@2
|
125 |
template <class _InputIterator>
|
williamr@2
|
126 |
hash_map(_InputIterator __f, _InputIterator __l, size_type __n)
|
williamr@2
|
127 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
128 |
{
|
williamr@2
|
129 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
130 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
131 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
132 |
}
|
williamr@2
|
133 |
template <class _InputIterator>
|
williamr@2
|
134 |
hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
135 |
const hasher& __hf)
|
williamr@2
|
136 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
137 |
{
|
williamr@2
|
138 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
139 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
140 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
141 |
}
|
williamr@2
|
142 |
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
|
williamr@2
|
143 |
template <class _InputIterator>
|
williamr@2
|
144 |
hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
145 |
const hasher& __hf, const key_equal& __eql)
|
williamr@2
|
146 |
: _M_ht(__n, __hf, __eql, allocator_type())
|
williamr@2
|
147 |
{
|
williamr@2
|
148 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
149 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
150 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
151 |
}
|
williamr@2
|
152 |
# endif
|
williamr@2
|
153 |
template <class _InputIterator>
|
williamr@2
|
154 |
hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
155 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
156 |
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
|
williamr@2
|
157 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
158 |
{
|
williamr@2
|
159 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
160 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
161 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
162 |
}
|
williamr@2
|
163 |
|
williamr@2
|
164 |
#else
|
williamr@2
|
165 |
hash_map(const value_type* __f, const value_type* __l)
|
williamr@2
|
166 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
167 |
{
|
williamr@2
|
168 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
169 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
170 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
171 |
}
|
williamr@2
|
172 |
hash_map(const value_type* __f, const value_type* __l, size_type __n)
|
williamr@2
|
173 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
174 |
{
|
williamr@2
|
175 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
176 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
177 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
178 |
}
|
williamr@2
|
179 |
hash_map(const value_type* __f, const value_type* __l, size_type __n,
|
williamr@2
|
180 |
const hasher& __hf)
|
williamr@2
|
181 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
182 |
{
|
williamr@2
|
183 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
184 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
185 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
186 |
}
|
williamr@2
|
187 |
hash_map(const value_type* __f, const value_type* __l, size_type __n,
|
williamr@2
|
188 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
189 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
190 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
191 |
{
|
williamr@2
|
192 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
193 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
194 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
195 |
}
|
williamr@2
|
196 |
|
williamr@2
|
197 |
hash_map(const_iterator __f, const_iterator __l)
|
williamr@2
|
198 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
199 |
{
|
williamr@2
|
200 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
201 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
202 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
203 |
}
|
williamr@2
|
204 |
hash_map(const_iterator __f, const_iterator __l, size_type __n)
|
williamr@2
|
205 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
206 |
{
|
williamr@2
|
207 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
208 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
209 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
210 |
}
|
williamr@2
|
211 |
hash_map(const_iterator __f, const_iterator __l, size_type __n,
|
williamr@2
|
212 |
const hasher& __hf)
|
williamr@2
|
213 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
214 |
{
|
williamr@2
|
215 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
216 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
217 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
218 |
}
|
williamr@2
|
219 |
hash_map(const_iterator __f, const_iterator __l, size_type __n,
|
williamr@2
|
220 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
221 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
222 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
223 |
{
|
williamr@2
|
224 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
225 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
226 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
227 |
}
|
williamr@2
|
228 |
#endif /*_STLP_MEMBER_TEMPLATES */
|
williamr@2
|
229 |
|
williamr@2
|
230 |
#ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
231 |
public:
|
williamr@2
|
232 |
static void* operator new (size_t __n, TLeave) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
233 |
static void* operator new (size_t __n) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
234 |
#endif
|
williamr@2
|
235 |
|
williamr@2
|
236 |
public:
|
williamr@2
|
237 |
size_type size() const { return _M_ht.size(); }
|
williamr@2
|
238 |
size_type max_size() const { return _M_ht.max_size(); }
|
williamr@2
|
239 |
bool empty() const { return _M_ht.empty(); }
|
williamr@2
|
240 |
void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
|
williamr@2
|
241 |
iterator begin() { return _M_ht.begin(); }
|
williamr@2
|
242 |
iterator end() { return _M_ht.end(); }
|
williamr@2
|
243 |
const_iterator begin() const { return _M_ht.begin(); }
|
williamr@2
|
244 |
const_iterator end() const { return _M_ht.end(); }
|
williamr@2
|
245 |
|
williamr@2
|
246 |
public:
|
williamr@2
|
247 |
pair<iterator,bool> insert(const value_type& __obj)
|
williamr@2
|
248 |
{ return _M_ht.insert_unique(__obj); }
|
williamr@2
|
249 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
250 |
template <class _InputIterator>
|
williamr@2
|
251 |
void insert(_InputIterator __f, _InputIterator __l)
|
williamr@2
|
252 |
{ _M_ht.insert_unique(__f,__l); }
|
williamr@2
|
253 |
#else
|
williamr@2
|
254 |
void insert(const value_type* __f, const value_type* __l) {
|
williamr@2
|
255 |
_M_ht.insert_unique(__f,__l);
|
williamr@2
|
256 |
}
|
williamr@2
|
257 |
void insert(const_iterator __f, const_iterator __l)
|
williamr@2
|
258 |
{ _M_ht.insert_unique(__f, __l); }
|
williamr@2
|
259 |
#endif /*_STLP_MEMBER_TEMPLATES */
|
williamr@2
|
260 |
pair<iterator,bool> insert_noresize(const value_type& __obj)
|
williamr@2
|
261 |
{ return _M_ht.insert_unique_noresize(__obj); }
|
williamr@2
|
262 |
|
williamr@2
|
263 |
iterator find(const key_type& __key) { return _M_ht.find(__key); }
|
williamr@2
|
264 |
const_iterator find(const key_type& __key) const { return _M_ht.find(__key); }
|
williamr@2
|
265 |
|
williamr@2
|
266 |
_Tp& operator[](const key_type& __key) {
|
williamr@2
|
267 |
iterator __it = _M_ht.find(__key);
|
williamr@2
|
268 |
if (__it != _M_ht.end()) {
|
williamr@2
|
269 |
return (*__it).second ;
|
williamr@2
|
270 |
} else {
|
williamr@2
|
271 |
value_type __tmp(__key, __false_type());
|
williamr@2
|
272 |
_STLP_PUSH_STACK_ITEM(value_type, &__tmp)
|
williamr@2
|
273 |
return _M_ht._M_insert(__tmp).second;
|
williamr@2
|
274 |
}
|
williamr@2
|
275 |
}
|
williamr@2
|
276 |
|
williamr@2
|
277 |
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
|
williamr@2
|
278 |
|
williamr@2
|
279 |
pair<iterator, iterator> equal_range(const key_type& __key)
|
williamr@2
|
280 |
{ return _M_ht.equal_range(__key); }
|
williamr@2
|
281 |
pair<const_iterator, const_iterator>
|
williamr@2
|
282 |
equal_range(const key_type& __key) const
|
williamr@2
|
283 |
{ return _M_ht.equal_range(__key); }
|
williamr@2
|
284 |
|
williamr@2
|
285 |
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
|
williamr@2
|
286 |
void erase(iterator __it) { _M_ht.erase(__it); }
|
williamr@2
|
287 |
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
|
williamr@2
|
288 |
void clear() { _M_ht.clear(); }
|
williamr@2
|
289 |
|
williamr@2
|
290 |
void resize(size_type __hint) { _M_ht.resize(__hint); }
|
williamr@2
|
291 |
size_type bucket_count() const { return _M_ht.bucket_count(); }
|
williamr@2
|
292 |
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
|
williamr@2
|
293 |
size_type elems_in_bucket(size_type __n) const
|
williamr@2
|
294 |
{ return _M_ht.elems_in_bucket(__n); }
|
williamr@2
|
295 |
static bool _STLP_CALL _M_equal (const _Self& __x, const _Self& __y) {
|
williamr@2
|
296 |
return _Ht::_M_equal(__x._M_ht,__y._M_ht);
|
williamr@2
|
297 |
}
|
williamr@2
|
298 |
};
|
williamr@2
|
299 |
|
williamr@2
|
300 |
template <class _Key, class _Tp, __DFL_TMPL_PARAM(_HashFcn,hash<_Key>),
|
williamr@2
|
301 |
__DFL_TMPL_PARAM(_EqualKey,equal_to<_Key>),
|
williamr@2
|
302 |
_STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
|
williamr@2
|
303 |
class hash_multimap
|
williamr@2
|
304 |
{
|
williamr@2
|
305 |
private:
|
williamr@2
|
306 |
typedef _STLP_HASHTABLE _Ht;
|
williamr@2
|
307 |
typedef hash_multimap<_Key, _Tp, _HashFcn, _EqualKey, _Alloc> _Self;
|
williamr@2
|
308 |
public:
|
williamr@2
|
309 |
typedef typename _Ht::key_type key_type;
|
williamr@2
|
310 |
typedef _Tp data_type;
|
williamr@2
|
311 |
typedef _Tp mapped_type;
|
williamr@2
|
312 |
typedef typename _Ht::value_type _value_type;
|
williamr@2
|
313 |
typedef _value_type value_type;
|
williamr@2
|
314 |
typedef typename _Ht::hasher hasher;
|
williamr@2
|
315 |
typedef typename _Ht::key_equal key_equal;
|
williamr@2
|
316 |
|
williamr@2
|
317 |
typedef typename _Ht::size_type size_type;
|
williamr@2
|
318 |
typedef typename _Ht::difference_type difference_type;
|
williamr@2
|
319 |
typedef typename _Ht::pointer pointer;
|
williamr@2
|
320 |
typedef typename _Ht::const_pointer const_pointer;
|
williamr@2
|
321 |
typedef typename _Ht::reference reference;
|
williamr@2
|
322 |
typedef typename _Ht::const_reference const_reference;
|
williamr@2
|
323 |
|
williamr@2
|
324 |
typedef typename _Ht::iterator iterator;
|
williamr@2
|
325 |
typedef typename _Ht::const_iterator const_iterator;
|
williamr@2
|
326 |
|
williamr@2
|
327 |
typedef typename _Ht::allocator_type allocator_type;
|
williamr@2
|
328 |
|
williamr@2
|
329 |
hasher hash_funct() const { return _M_ht.hash_funct(); }
|
williamr@2
|
330 |
key_equal key_eq() const { return _M_ht.key_eq(); }
|
williamr@2
|
331 |
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
|
williamr@2
|
332 |
|
williamr@2
|
333 |
private:
|
williamr@2
|
334 |
_Ht _M_ht;
|
williamr@2
|
335 |
public:
|
williamr@2
|
336 |
hash_multimap() : _M_ht(100, hasher(), key_equal(), allocator_type()) {
|
williamr@2
|
337 |
_STLP_POP_IF_CHECK
|
williamr@2
|
338 |
}
|
williamr@2
|
339 |
|
williamr@2
|
340 |
# ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
341 |
hash_multimap(const _Self& __o) :
|
williamr@2
|
342 |
_M_ht(__o.size())
|
williamr@2
|
343 |
{
|
williamr@2
|
344 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
345 |
_M_ht = __o._M_ht;
|
williamr@2
|
346 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
347 |
}
|
williamr@2
|
348 |
# else
|
williamr@2
|
349 |
hash_multimap(const _Self& __o)
|
williamr@2
|
350 |
: _M_ht(__o._M_ht) {
|
williamr@2
|
351 |
}
|
williamr@2
|
352 |
# endif
|
williamr@2
|
353 |
|
williamr@2
|
354 |
explicit hash_multimap(size_type __n)
|
williamr@2
|
355 |
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {
|
williamr@2
|
356 |
_STLP_POP_IF_CHECK
|
williamr@2
|
357 |
}
|
williamr@2
|
358 |
hash_multimap(size_type __n, const hasher& __hf)
|
williamr@2
|
359 |
: _M_ht(__n, __hf, key_equal(), allocator_type()) {
|
williamr@2
|
360 |
_STLP_POP_IF_CHECK
|
williamr@2
|
361 |
}
|
williamr@2
|
362 |
hash_multimap(size_type __n, const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
363 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
364 |
: _M_ht(__n, __hf, __eql, __a) {
|
williamr@2
|
365 |
_STLP_POP_IF_CHECK
|
williamr@2
|
366 |
}
|
williamr@2
|
367 |
|
williamr@2
|
368 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
369 |
template <class _InputIterator>
|
williamr@2
|
370 |
hash_multimap(_InputIterator __f, _InputIterator __l)
|
williamr@2
|
371 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
372 |
{
|
williamr@2
|
373 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
374 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
375 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
376 |
}
|
williamr@2
|
377 |
template <class _InputIterator>
|
williamr@2
|
378 |
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n)
|
williamr@2
|
379 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
380 |
{
|
williamr@2
|
381 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
382 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
383 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
384 |
}
|
williamr@2
|
385 |
template <class _InputIterator>
|
williamr@2
|
386 |
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
387 |
const hasher& __hf)
|
williamr@2
|
388 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
389 |
{
|
williamr@2
|
390 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
391 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
392 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
393 |
}
|
williamr@2
|
394 |
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
|
williamr@2
|
395 |
template <class _InputIterator>
|
williamr@2
|
396 |
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
397 |
const hasher& __hf, const key_equal& __eql)
|
williamr@2
|
398 |
: _M_ht(__n, __hf, __eql, allocator_type())
|
williamr@2
|
399 |
{
|
williamr@2
|
400 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
401 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
402 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
403 |
}
|
williamr@2
|
404 |
# endif
|
williamr@2
|
405 |
template <class _InputIterator>
|
williamr@2
|
406 |
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
407 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
408 |
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
|
williamr@2
|
409 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
410 |
{
|
williamr@2
|
411 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
412 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
413 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
414 |
}
|
williamr@2
|
415 |
|
williamr@2
|
416 |
#else
|
williamr@2
|
417 |
hash_multimap(const value_type* __f, const value_type* __l)
|
williamr@2
|
418 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
419 |
{
|
williamr@2
|
420 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
421 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
422 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
423 |
}
|
williamr@2
|
424 |
hash_multimap(const value_type* __f, const value_type* __l, size_type __n)
|
williamr@2
|
425 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
426 |
{
|
williamr@2
|
427 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
428 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
429 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
430 |
}
|
williamr@2
|
431 |
hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
|
williamr@2
|
432 |
const hasher& __hf)
|
williamr@2
|
433 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
434 |
{
|
williamr@2
|
435 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
436 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
437 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
438 |
}
|
williamr@2
|
439 |
hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
|
williamr@2
|
440 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
441 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
442 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
443 |
{
|
williamr@2
|
444 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
445 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
446 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
447 |
}
|
williamr@2
|
448 |
|
williamr@2
|
449 |
hash_multimap(const_iterator __f, const_iterator __l)
|
williamr@2
|
450 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
451 |
{
|
williamr@2
|
452 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
453 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
454 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
455 |
}
|
williamr@2
|
456 |
hash_multimap(const_iterator __f, const_iterator __l, size_type __n)
|
williamr@2
|
457 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
458 |
{
|
williamr@2
|
459 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
460 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
461 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
462 |
}
|
williamr@2
|
463 |
hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
|
williamr@2
|
464 |
const hasher& __hf)
|
williamr@2
|
465 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
466 |
{
|
williamr@2
|
467 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
468 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
469 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
470 |
}
|
williamr@2
|
471 |
hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
|
williamr@2
|
472 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
473 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
474 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
475 |
{
|
williamr@2
|
476 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
477 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
478 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
479 |
}
|
williamr@2
|
480 |
#endif /*_STLP_MEMBER_TEMPLATES */
|
williamr@2
|
481 |
|
williamr@2
|
482 |
#ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
483 |
public:
|
williamr@2
|
484 |
static void* operator new (size_t __n, TLeave) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
485 |
static void* operator new (size_t __n) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
486 |
#endif
|
williamr@2
|
487 |
|
williamr@2
|
488 |
public:
|
williamr@2
|
489 |
size_type size() const { return _M_ht.size(); }
|
williamr@2
|
490 |
size_type max_size() const { return _M_ht.max_size(); }
|
williamr@2
|
491 |
bool empty() const { return _M_ht.empty(); }
|
williamr@2
|
492 |
void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
|
williamr@2
|
493 |
|
williamr@2
|
494 |
iterator begin() { return _M_ht.begin(); }
|
williamr@2
|
495 |
iterator end() { return _M_ht.end(); }
|
williamr@2
|
496 |
const_iterator begin() const { return _M_ht.begin(); }
|
williamr@2
|
497 |
const_iterator end() const { return _M_ht.end(); }
|
williamr@2
|
498 |
|
williamr@2
|
499 |
public:
|
williamr@2
|
500 |
iterator insert(const value_type& __obj)
|
williamr@2
|
501 |
{ return _M_ht.insert_equal(__obj); }
|
williamr@2
|
502 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
503 |
template <class _InputIterator>
|
williamr@2
|
504 |
void insert(_InputIterator __f, _InputIterator __l)
|
williamr@2
|
505 |
{ _M_ht.insert_equal(__f,__l); }
|
williamr@2
|
506 |
#else
|
williamr@2
|
507 |
void insert(const value_type* __f, const value_type* __l) {
|
williamr@2
|
508 |
_M_ht.insert_equal(__f,__l);
|
williamr@2
|
509 |
}
|
williamr@2
|
510 |
void insert(const_iterator __f, const_iterator __l)
|
williamr@2
|
511 |
{ _M_ht.insert_equal(__f, __l); }
|
williamr@2
|
512 |
#endif /*_STLP_MEMBER_TEMPLATES */
|
williamr@2
|
513 |
iterator insert_noresize(const value_type& __obj)
|
williamr@2
|
514 |
{ return _M_ht.insert_equal_noresize(__obj); }
|
williamr@2
|
515 |
|
williamr@2
|
516 |
iterator find(const key_type& __key) { return _M_ht.find(__key); }
|
williamr@2
|
517 |
const_iterator find(const key_type& __key) const
|
williamr@2
|
518 |
{ return _M_ht.find(__key); }
|
williamr@2
|
519 |
|
williamr@2
|
520 |
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
|
williamr@2
|
521 |
|
williamr@2
|
522 |
pair<iterator, iterator> equal_range(const key_type& __key)
|
williamr@2
|
523 |
{ return _M_ht.equal_range(__key); }
|
williamr@2
|
524 |
pair<const_iterator, const_iterator>
|
williamr@2
|
525 |
equal_range(const key_type& __key) const
|
williamr@2
|
526 |
{ return _M_ht.equal_range(__key); }
|
williamr@2
|
527 |
|
williamr@2
|
528 |
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
|
williamr@2
|
529 |
void erase(iterator __it) { _M_ht.erase(__it); }
|
williamr@2
|
530 |
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
|
williamr@2
|
531 |
void clear() { _M_ht.clear(); }
|
williamr@2
|
532 |
|
williamr@2
|
533 |
public:
|
williamr@2
|
534 |
void resize(size_type __hint) { _M_ht.resize(__hint); }
|
williamr@2
|
535 |
size_type bucket_count() const { return _M_ht.bucket_count(); }
|
williamr@2
|
536 |
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
|
williamr@2
|
537 |
size_type elems_in_bucket(size_type __n) const
|
williamr@2
|
538 |
{ return _M_ht.elems_in_bucket(__n); }
|
williamr@2
|
539 |
static bool _STLP_CALL _M_equal (const _Self& __x, const _Self& __y) {
|
williamr@2
|
540 |
return _Ht::_M_equal(__x._M_ht,__y._M_ht);
|
williamr@2
|
541 |
}
|
williamr@2
|
542 |
};
|
williamr@2
|
543 |
|
williamr@2
|
544 |
#define _STLP_TEMPLATE_HEADER template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
|
williamr@2
|
545 |
#define _STLP_TEMPLATE_CONTAINER hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>
|
williamr@2
|
546 |
|
williamr@2
|
547 |
#include <stl/_relops_hash_cont.h>
|
williamr@2
|
548 |
|
williamr@2
|
549 |
#undef _STLP_TEMPLATE_CONTAINER
|
williamr@2
|
550 |
#define _STLP_TEMPLATE_CONTAINER hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>
|
williamr@2
|
551 |
#include <stl/_relops_hash_cont.h>
|
williamr@2
|
552 |
|
williamr@2
|
553 |
#undef _STLP_TEMPLATE_CONTAINER
|
williamr@2
|
554 |
#undef _STLP_TEMPLATE_HEADER
|
williamr@2
|
555 |
|
williamr@2
|
556 |
// Specialization of insert_iterator so that it will work for hash_map
|
williamr@2
|
557 |
// and hash_multimap.
|
williamr@2
|
558 |
|
williamr@2
|
559 |
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
|
williamr@2
|
560 |
|
williamr@2
|
561 |
template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
|
williamr@2
|
562 |
class insert_iterator<hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
|
williamr@2
|
563 |
protected:
|
williamr@2
|
564 |
typedef hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
|
williamr@2
|
565 |
_Container* container;
|
williamr@2
|
566 |
public:
|
williamr@2
|
567 |
typedef _Container container_type;
|
williamr@2
|
568 |
typedef output_iterator_tag iterator_category;
|
williamr@2
|
569 |
typedef void value_type;
|
williamr@2
|
570 |
typedef void difference_type;
|
williamr@2
|
571 |
typedef void pointer;
|
williamr@2
|
572 |
typedef void reference;
|
williamr@2
|
573 |
|
williamr@2
|
574 |
insert_iterator(_Container& __x) : container(&__x) {}
|
williamr@2
|
575 |
insert_iterator(_Container& __x, typename _Container::iterator)
|
williamr@2
|
576 |
: container(&__x) {}
|
williamr@2
|
577 |
insert_iterator<_Container>&
|
williamr@2
|
578 |
operator=(const typename _Container::value_type& __val) {
|
williamr@2
|
579 |
container->insert(__val);
|
williamr@2
|
580 |
return *this;
|
williamr@2
|
581 |
}
|
williamr@2
|
582 |
insert_iterator<_Container>& operator*() { return *this; }
|
williamr@2
|
583 |
insert_iterator<_Container>& operator++() { return *this; }
|
williamr@2
|
584 |
insert_iterator<_Container>& operator++(int) { return *this; }
|
williamr@2
|
585 |
};
|
williamr@2
|
586 |
|
williamr@2
|
587 |
template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
|
williamr@2
|
588 |
class insert_iterator<hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
|
williamr@2
|
589 |
protected:
|
williamr@2
|
590 |
typedef hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
|
williamr@2
|
591 |
_Container* container;
|
williamr@2
|
592 |
typename _Container::iterator iter;
|
williamr@2
|
593 |
public:
|
williamr@2
|
594 |
typedef _Container container_type;
|
williamr@2
|
595 |
typedef output_iterator_tag iterator_category;
|
williamr@2
|
596 |
typedef void value_type;
|
williamr@2
|
597 |
typedef void difference_type;
|
williamr@2
|
598 |
typedef void pointer;
|
williamr@2
|
599 |
typedef void reference;
|
williamr@2
|
600 |
|
williamr@2
|
601 |
insert_iterator(_Container& __x) : container(&__x) {}
|
williamr@2
|
602 |
insert_iterator(_Container& __x, typename _Container::iterator)
|
williamr@2
|
603 |
: container(&__x) {}
|
williamr@2
|
604 |
insert_iterator<_Container>&
|
williamr@2
|
605 |
operator=(const typename _Container::value_type& __val) {
|
williamr@2
|
606 |
container->insert(__val);
|
williamr@2
|
607 |
return *this;
|
williamr@2
|
608 |
}
|
williamr@2
|
609 |
insert_iterator<_Container>& operator*() { return *this; }
|
williamr@2
|
610 |
insert_iterator<_Container>& operator++() { return *this; }
|
williamr@2
|
611 |
insert_iterator<_Container>& operator++(int) { return *this; }
|
williamr@2
|
612 |
};
|
williamr@2
|
613 |
|
williamr@2
|
614 |
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
|
williamr@2
|
615 |
|
williamr@2
|
616 |
// do a cleanup
|
williamr@2
|
617 |
# undef hash_map
|
williamr@2
|
618 |
# undef hash_multimap
|
williamr@2
|
619 |
|
williamr@2
|
620 |
# define __hash_map__ __FULL_NAME(hash_map)
|
williamr@2
|
621 |
# define __hash_multimap__ __FULL_NAME(hash_multimap)
|
williamr@2
|
622 |
|
williamr@2
|
623 |
|
williamr@2
|
624 |
_STLP_END_NAMESPACE
|
williamr@2
|
625 |
|
williamr@2
|
626 |
# if defined (_STLP_USE_WRAPPER_FOR_ALLOC_PARAM)
|
williamr@2
|
627 |
# include <stl/wrappers/_hash_map.h>
|
williamr@2
|
628 |
# endif /* WRAPPER */
|
williamr@2
|
629 |
|
williamr@2
|
630 |
#endif /* _STLP_INTERNAL_HASH_MAP_H */
|
williamr@2
|
631 |
|
williamr@2
|
632 |
// Local Variables:
|
williamr@2
|
633 |
// mode:C++
|
williamr@2
|
634 |
// End:
|
williamr@2
|
635 |
|