3 * Silicon Graphics Computer Systems, Inc.
5 * Permission to use, copy, modify, distribute and sell this software
6 * and its documentation for any purpose is hereby granted without fee,
7 * provided that the above copyright notice appear in all copies and
8 * that both that copyright notice and this permission notice appear
9 * in supporting documentation. Silicon Graphics makes no
10 * representations about the suitability of this software for any
11 * purpose. It is provided "as is" without express or implied warranty.
15 * Hewlett-Packard Company
17 * Permission to use, copy, modify, distribute and sell this software
18 * and its documentation for any purpose is hereby granted without fee,
19 * provided that the above copyright notice appear in all copies and
20 * that both that copyright notice and this permission notice appear
21 * in supporting documentation. Hewlett-Packard Company makes no
22 * representations about the suitability of this software for any
23 * purpose. It is provided "as is" without express or implied warranty.
27 /* NOTE: This is an internal header file, included by other STL headers.
28 * You should not attempt to use it directly.
31 #ifndef __SGI_STL_INTERNAL_HASH_MAP_H
32 #define __SGI_STL_INTERNAL_HASH_MAP_H
34 #include <ext/stl_hashtable.h>
38 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
43 // Forward declaration of equality operator; needed for friend declaration.
45 template <class _Key, class _Tp,
46 class _HashFcn = hash<_Key>,
47 class _EqualKey = equal_to<_Key>,
48 class _Alloc = allocator<_Tp> >
51 template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
52 inline bool operator==(const hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>&,
53 const hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>&);
55 template <class _Key, class _Tp, class _HashFcn, class _EqualKey,
60 typedef hashtable<pair<const _Key,_Tp>,_Key,_HashFcn,
61 _Select1st<pair<const _Key,_Tp> >,_EqualKey,_Alloc> _Ht;
65 typedef typename _Ht::key_type key_type;
66 typedef _Tp data_type;
67 typedef _Tp mapped_type;
68 typedef typename _Ht::value_type value_type;
69 typedef typename _Ht::hasher hasher;
70 typedef typename _Ht::key_equal key_equal;
72 typedef typename _Ht::size_type size_type;
73 typedef typename _Ht::difference_type difference_type;
74 typedef typename _Ht::pointer pointer;
75 typedef typename _Ht::const_pointer const_pointer;
76 typedef typename _Ht::reference reference;
77 typedef typename _Ht::const_reference const_reference;
79 typedef typename _Ht::iterator iterator;
80 typedef typename _Ht::const_iterator const_iterator;
82 typedef typename _Ht::allocator_type allocator_type;
84 hasher hash_funct() const { return _M_ht.hash_funct(); }
85 key_equal key_eq() const { return _M_ht.key_eq(); }
86 allocator_type get_allocator() const { return _M_ht.get_allocator(); }
89 hash_map() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
90 explicit hash_map(size_type __n)
91 : _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
92 hash_map(size_type __n, const hasher& __hf)
93 : _M_ht(__n, __hf, key_equal(), allocator_type()) {}
94 hash_map(size_type __n, const hasher& __hf, const key_equal& __eql,
95 const allocator_type& __a = allocator_type())
96 : _M_ht(__n, __hf, __eql, __a) {}
98 #ifdef __STL_MEMBER_TEMPLATES
99 template <class _InputIterator>
100 hash_map(_InputIterator __f, _InputIterator __l)
101 : _M_ht(100, hasher(), key_equal(), allocator_type())
102 { _M_ht.insert_unique(__f, __l); }
103 template <class _InputIterator>
104 hash_map(_InputIterator __f, _InputIterator __l, size_type __n)
105 : _M_ht(__n, hasher(), key_equal(), allocator_type())
106 { _M_ht.insert_unique(__f, __l); }
107 template <class _InputIterator>
108 hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
110 : _M_ht(__n, __hf, key_equal(), allocator_type())
111 { _M_ht.insert_unique(__f, __l); }
112 template <class _InputIterator>
113 hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
114 const hasher& __hf, const key_equal& __eql,
115 const allocator_type& __a = allocator_type())
116 : _M_ht(__n, __hf, __eql, __a)
117 { _M_ht.insert_unique(__f, __l); }
120 hash_map(const value_type* __f, const value_type* __l)
121 : _M_ht(100, hasher(), key_equal(), allocator_type())
122 { _M_ht.insert_unique(__f, __l); }
123 hash_map(const value_type* __f, const value_type* __l, size_type __n)
124 : _M_ht(__n, hasher(), key_equal(), allocator_type())
125 { _M_ht.insert_unique(__f, __l); }
126 hash_map(const value_type* __f, const value_type* __l, size_type __n,
128 : _M_ht(__n, __hf, key_equal(), allocator_type())
129 { _M_ht.insert_unique(__f, __l); }
130 hash_map(const value_type* __f, const value_type* __l, size_type __n,
131 const hasher& __hf, const key_equal& __eql,
132 const allocator_type& __a = allocator_type())
133 : _M_ht(__n, __hf, __eql, __a)
134 { _M_ht.insert_unique(__f, __l); }
136 hash_map(const_iterator __f, const_iterator __l)
137 : _M_ht(100, hasher(), key_equal(), allocator_type())
138 { _M_ht.insert_unique(__f, __l); }
139 hash_map(const_iterator __f, const_iterator __l, size_type __n)
140 : _M_ht(__n, hasher(), key_equal(), allocator_type())
141 { _M_ht.insert_unique(__f, __l); }
142 hash_map(const_iterator __f, const_iterator __l, size_type __n,
144 : _M_ht(__n, __hf, key_equal(), allocator_type())
145 { _M_ht.insert_unique(__f, __l); }
146 hash_map(const_iterator __f, const_iterator __l, size_type __n,
147 const hasher& __hf, const key_equal& __eql,
148 const allocator_type& __a = allocator_type())
149 : _M_ht(__n, __hf, __eql, __a)
150 { _M_ht.insert_unique(__f, __l); }
151 #endif /*__STL_MEMBER_TEMPLATES */
154 size_type size() const { return _M_ht.size(); }
155 size_type max_size() const { return _M_ht.max_size(); }
156 bool empty() const { return _M_ht.empty(); }
157 void swap(hash_map& __hs) { _M_ht.swap(__hs._M_ht); }
159 #ifdef __STL_MEMBER_TEMPLATES
160 template <class _K1, class _T1, class _HF, class _EqK, class _Al>
161 friend bool operator== (const hash_map<_K1, _T1, _HF, _EqK, _Al>&,
162 const hash_map<_K1, _T1, _HF, _EqK, _Al>&);
163 #else /* __STL_MEMBER_TEMPLATES */
164 friend bool __STD_QUALIFIER
165 operator== __STL_NULL_TMPL_ARGS (const hash_map&, const hash_map&);
166 #endif /* __STL_MEMBER_TEMPLATES */
169 iterator begin() { return _M_ht.begin(); }
170 iterator end() { return _M_ht.end(); }
171 const_iterator begin() const { return _M_ht.begin(); }
172 const_iterator end() const { return _M_ht.end(); }
175 pair<iterator,bool> insert(const value_type& __obj)
176 { return _M_ht.insert_unique(__obj); }
177 #ifdef __STL_MEMBER_TEMPLATES
178 template <class _InputIterator>
179 void insert(_InputIterator __f, _InputIterator __l)
180 { _M_ht.insert_unique(__f,__l); }
182 void insert(const value_type* __f, const value_type* __l) {
183 _M_ht.insert_unique(__f,__l);
185 void insert(const_iterator __f, const_iterator __l)
186 { _M_ht.insert_unique(__f, __l); }
187 #endif /*__STL_MEMBER_TEMPLATES */
188 pair<iterator,bool> insert_noresize(const value_type& __obj)
189 { return _M_ht.insert_unique_noresize(__obj); }
191 iterator find(const key_type& __key) { return _M_ht.find(__key); }
192 const_iterator find(const key_type& __key) const
193 { return _M_ht.find(__key); }
195 _Tp& operator[](const key_type& __key) {
196 return _M_ht.find_or_insert(value_type(__key, _Tp())).second;
199 size_type count(const key_type& __key) const { return _M_ht.count(__key); }
201 pair<iterator, iterator> equal_range(const key_type& __key)
202 { return _M_ht.equal_range(__key); }
203 pair<const_iterator, const_iterator>
204 equal_range(const key_type& __key) const
205 { return _M_ht.equal_range(__key); }
207 size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
208 void erase(iterator __it) { _M_ht.erase(__it); }
209 void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
210 void clear() { _M_ht.clear(); }
212 void resize(size_type __hint) { _M_ht.resize(__hint); }
213 size_type bucket_count() const { return _M_ht.bucket_count(); }
214 size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
215 size_type elems_in_bucket(size_type __n) const
216 { return _M_ht.elems_in_bucket(__n); }
219 template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
221 operator==(const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
222 const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
224 return __hm1._M_ht == __hm2._M_ht;
227 #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
229 template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
231 operator!=(const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
232 const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2) {
233 return !(__hm1 == __hm2);
236 template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
238 swap(hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
239 hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
244 #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
246 // Forward declaration of equality operator; needed for friend declaration.
248 template <class _Key, class _Tp,
249 class _HashFcn = hash<_Key>,
250 class _EqualKey = equal_to<_Key>,
251 class _Alloc = allocator<_Tp> >
254 template <class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
256 operator==(const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm1,
257 const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm2);
259 template <class _Key, class _Tp, class _HashFcn, class _EqualKey,
264 typedef hashtable<pair<const _Key, _Tp>, _Key, _HashFcn,
265 _Select1st<pair<const _Key, _Tp> >, _EqualKey, _Alloc>
270 typedef typename _Ht::key_type key_type;
271 typedef _Tp data_type;
272 typedef _Tp mapped_type;
273 typedef typename _Ht::value_type value_type;
274 typedef typename _Ht::hasher hasher;
275 typedef typename _Ht::key_equal key_equal;
277 typedef typename _Ht::size_type size_type;
278 typedef typename _Ht::difference_type difference_type;
279 typedef typename _Ht::pointer pointer;
280 typedef typename _Ht::const_pointer const_pointer;
281 typedef typename _Ht::reference reference;
282 typedef typename _Ht::const_reference const_reference;
284 typedef typename _Ht::iterator iterator;
285 typedef typename _Ht::const_iterator const_iterator;
287 typedef typename _Ht::allocator_type allocator_type;
289 hasher hash_funct() const { return _M_ht.hash_funct(); }
290 key_equal key_eq() const { return _M_ht.key_eq(); }
291 allocator_type get_allocator() const { return _M_ht.get_allocator(); }
294 hash_multimap() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
295 explicit hash_multimap(size_type __n)
296 : _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
297 hash_multimap(size_type __n, const hasher& __hf)
298 : _M_ht(__n, __hf, key_equal(), allocator_type()) {}
299 hash_multimap(size_type __n, const hasher& __hf, const key_equal& __eql,
300 const allocator_type& __a = allocator_type())
301 : _M_ht(__n, __hf, __eql, __a) {}
303 #ifdef __STL_MEMBER_TEMPLATES
304 template <class _InputIterator>
305 hash_multimap(_InputIterator __f, _InputIterator __l)
306 : _M_ht(100, hasher(), key_equal(), allocator_type())
307 { _M_ht.insert_equal(__f, __l); }
308 template <class _InputIterator>
309 hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n)
310 : _M_ht(__n, hasher(), key_equal(), allocator_type())
311 { _M_ht.insert_equal(__f, __l); }
312 template <class _InputIterator>
313 hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
315 : _M_ht(__n, __hf, key_equal(), allocator_type())
316 { _M_ht.insert_equal(__f, __l); }
317 template <class _InputIterator>
318 hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
319 const hasher& __hf, const key_equal& __eql,
320 const allocator_type& __a = allocator_type())
321 : _M_ht(__n, __hf, __eql, __a)
322 { _M_ht.insert_equal(__f, __l); }
325 hash_multimap(const value_type* __f, const value_type* __l)
326 : _M_ht(100, hasher(), key_equal(), allocator_type())
327 { _M_ht.insert_equal(__f, __l); }
328 hash_multimap(const value_type* __f, const value_type* __l, size_type __n)
329 : _M_ht(__n, hasher(), key_equal(), allocator_type())
330 { _M_ht.insert_equal(__f, __l); }
331 hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
333 : _M_ht(__n, __hf, key_equal(), allocator_type())
334 { _M_ht.insert_equal(__f, __l); }
335 hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
336 const hasher& __hf, const key_equal& __eql,
337 const allocator_type& __a = allocator_type())
338 : _M_ht(__n, __hf, __eql, __a)
339 { _M_ht.insert_equal(__f, __l); }
341 hash_multimap(const_iterator __f, const_iterator __l)
342 : _M_ht(100, hasher(), key_equal(), allocator_type())
343 { _M_ht.insert_equal(__f, __l); }
344 hash_multimap(const_iterator __f, const_iterator __l, size_type __n)
345 : _M_ht(__n, hasher(), key_equal(), allocator_type())
346 { _M_ht.insert_equal(__f, __l); }
347 hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
349 : _M_ht(__n, __hf, key_equal(), allocator_type())
350 { _M_ht.insert_equal(__f, __l); }
351 hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
352 const hasher& __hf, const key_equal& __eql,
353 const allocator_type& __a = allocator_type())
354 : _M_ht(__n, __hf, __eql, __a)
355 { _M_ht.insert_equal(__f, __l); }
356 #endif /*__STL_MEMBER_TEMPLATES */
359 size_type size() const { return _M_ht.size(); }
360 size_type max_size() const { return _M_ht.max_size(); }
361 bool empty() const { return _M_ht.empty(); }
362 void swap(hash_multimap& __hs) { _M_ht.swap(__hs._M_ht); }
364 #ifdef __STL_MEMBER_TEMPLATES
365 template <class _K1, class _T1, class _HF, class _EqK, class _Al>
366 friend bool operator== (const hash_multimap<_K1, _T1, _HF, _EqK, _Al>&,
367 const hash_multimap<_K1, _T1, _HF, _EqK, _Al>&);
368 #else /* __STL_MEMBER_TEMPLATES */
369 friend bool __STD_QUALIFIER
370 operator== __STL_NULL_TMPL_ARGS (const hash_multimap&,const hash_multimap&);
371 #endif /* __STL_MEMBER_TEMPLATES */
373 iterator begin() { return _M_ht.begin(); }
374 iterator end() { return _M_ht.end(); }
375 const_iterator begin() const { return _M_ht.begin(); }
376 const_iterator end() const { return _M_ht.end(); }
379 iterator insert(const value_type& __obj)
380 { return _M_ht.insert_equal(__obj); }
381 #ifdef __STL_MEMBER_TEMPLATES
382 template <class _InputIterator>
383 void insert(_InputIterator __f, _InputIterator __l)
384 { _M_ht.insert_equal(__f,__l); }
386 void insert(const value_type* __f, const value_type* __l) {
387 _M_ht.insert_equal(__f,__l);
389 void insert(const_iterator __f, const_iterator __l)
390 { _M_ht.insert_equal(__f, __l); }
391 #endif /*__STL_MEMBER_TEMPLATES */
392 iterator insert_noresize(const value_type& __obj)
393 { return _M_ht.insert_equal_noresize(__obj); }
395 iterator find(const key_type& __key) { return _M_ht.find(__key); }
396 const_iterator find(const key_type& __key) const
397 { return _M_ht.find(__key); }
399 size_type count(const key_type& __key) const { return _M_ht.count(__key); }
401 pair<iterator, iterator> equal_range(const key_type& __key)
402 { return _M_ht.equal_range(__key); }
403 pair<const_iterator, const_iterator>
404 equal_range(const key_type& __key) const
405 { return _M_ht.equal_range(__key); }
407 size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
408 void erase(iterator __it) { _M_ht.erase(__it); }
409 void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
410 void clear() { _M_ht.clear(); }
413 void resize(size_type __hint) { _M_ht.resize(__hint); }
414 size_type bucket_count() const { return _M_ht.bucket_count(); }
415 size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
416 size_type elems_in_bucket(size_type __n) const
417 { return _M_ht.elems_in_bucket(__n); }
420 template <class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
422 operator==(const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm1,
423 const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm2)
425 return __hm1._M_ht == __hm2._M_ht;
428 #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
430 template <class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
432 operator!=(const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm1,
433 const hash_multimap<_Key,_Tp,_HF,_EqKey,_Alloc>& __hm2) {
434 return !(__hm1 == __hm2);
437 template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
439 swap(hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
440 hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
445 #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
447 // Specialization of insert_iterator so that it will work for hash_map
448 // and hash_multimap.
450 #ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
452 template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
453 class insert_iterator<hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
455 typedef hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
456 _Container* container;
458 typedef _Container container_type;
459 typedef output_iterator_tag iterator_category;
460 typedef void value_type;
461 typedef void difference_type;
462 typedef void pointer;
463 typedef void reference;
465 insert_iterator(_Container& __x) : container(&__x) {}
466 insert_iterator(_Container& __x, typename _Container::iterator)
468 insert_iterator<_Container>&
469 operator=(const typename _Container::value_type& __value) {
470 container->insert(__value);
473 insert_iterator<_Container>& operator*() { return *this; }
474 insert_iterator<_Container>& operator++() { return *this; }
475 insert_iterator<_Container>& operator++(int) { return *this; }
478 template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
479 class insert_iterator<hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
481 typedef hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
482 _Container* container;
483 typename _Container::iterator iter;
485 typedef _Container container_type;
486 typedef output_iterator_tag iterator_category;
487 typedef void value_type;
488 typedef void difference_type;
489 typedef void pointer;
490 typedef void reference;
492 insert_iterator(_Container& __x) : container(&__x) {}
493 insert_iterator(_Container& __x, typename _Container::iterator)
495 insert_iterator<_Container>&
496 operator=(const typename _Container::value_type& __value) {
497 container->insert(__value);
500 insert_iterator<_Container>& operator*() { return *this; }
501 insert_iterator<_Container>& operator++() { return *this; }
502 insert_iterator<_Container>& operator++(int) { return *this; }
505 #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
507 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
508 #pragma reset woff 1174
509 #pragma reset woff 1375
514 #endif /* __SGI_STL_INTERNAL_HASH_MAP_H */