1 /*=========================================================================
3 Program: KWSys - Kitware System Library
4 Module: $RCSfile: hash_map.hxx.in,v $
6 Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notices for more information.
13 =========================================================================*/
16 * Silicon Graphics Computer Systems, Inc.
18 * Permission to use, copy, modify, distribute and sell this software
19 * and its documentation for any purpose is hereby granted without fee,
20 * provided that the above copyright notice appear in all copies and
21 * that both that copyright notice and this permission notice appear
22 * in supporting documentation. Silicon Graphics makes no
23 * representations about the suitability of this software for any
24 * purpose. It is provided "as is" without express or implied warranty.
28 * Hewlett-Packard Company
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
39 #ifndef @KWSYS_NAMESPACE@_hash_map_hxx
40 #define @KWSYS_NAMESPACE@_hash_map_hxx
42 #include <@KWSYS_NAMESPACE@/hashtable.hxx>
43 #include <@KWSYS_NAMESPACE@/hash_fun.hxx>
44 #include <@KWSYS_NAMESPACE@/stl/functional> // equal_to
47 # pragma warning (push)
48 # pragma warning (disable:4284)
49 # pragma warning (disable:4786)
52 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
53 # pragma set woff 1174
54 # pragma set woff 1375
57 namespace @KWSYS_NAMESPACE@
60 // select1st is an extension: it is not part of the standard.
61 template <class T1
, class T2
>
62 struct hash_select1st
:
63 public @KWSYS_NAMESPACE@
_stl::unary_function
<@KWSYS_NAMESPACE@
_stl::pair
<T1
, T2
>, T1
>
65 const T1
& operator()(const @KWSYS_NAMESPACE@
_stl::pair
<T1
, T2
>& __x
) const
69 // Forward declaration of equality operator; needed for friend declaration.
71 template <class _Key
, class _Tp
,
72 class _HashFcn
= hash
<_Key
>,
73 class _EqualKey
= @KWSYS_NAMESPACE@
_stl::equal_to
<_Key
>,
74 class _Alloc
= @KWSYS_NAMESPACE@
_HASH_DEFAULT_ALLOCATOR(char) >
77 template <class _Key
, class _Tp
, class _HashFn
, class _EqKey
, class _Alloc
>
78 bool operator==(const hash_map
<_Key
, _Tp
, _HashFn
, _EqKey
, _Alloc
>&,
79 const hash_map
<_Key
, _Tp
, _HashFn
, _EqKey
, _Alloc
>&);
81 template <class _Key
, class _Tp
, class _HashFcn
, class _EqualKey
,
86 typedef hashtable
<@KWSYS_NAMESPACE@
_stl::pair
<const _Key
,_Tp
>,_Key
,_HashFcn
,
87 hash_select1st
<const _Key
,_Tp
>,_EqualKey
,_Alloc
> _Ht
;
91 typedef typename
_Ht::key_type key_type
;
92 typedef _Tp data_type
;
93 typedef _Tp mapped_type
;
94 typedef typename
_Ht::value_type value_type
;
95 typedef typename
_Ht::hasher hasher
;
96 typedef typename
_Ht::key_equal key_equal
;
98 typedef typename
_Ht::size_type size_type
;
99 typedef typename
_Ht::difference_type difference_type
;
100 typedef typename
_Ht::pointer pointer
;
101 typedef typename
_Ht::const_pointer const_pointer
;
102 typedef typename
_Ht::reference reference
;
103 typedef typename
_Ht::const_reference const_reference
;
105 typedef typename
_Ht::iterator iterator
;
106 typedef typename
_Ht::const_iterator const_iterator
;
108 typedef typename
_Ht::allocator_type allocator_type
;
110 hasher
hash_funct() const { return _M_ht
.hash_funct(); }
111 key_equal
key_eq() const { return _M_ht
.key_eq(); }
112 allocator_type
get_allocator() const { return _M_ht
.get_allocator(); }
115 hash_map() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
116 explicit hash_map(size_type __n
)
117 : _M_ht(__n
, hasher(), key_equal(), allocator_type()) {}
118 hash_map(size_type __n
, const hasher
& __hf
)
119 : _M_ht(__n
, __hf
, key_equal(), allocator_type()) {}
120 hash_map(size_type __n
, const hasher
& __hf
, const key_equal
& __eql
,
121 const allocator_type
& __a
= allocator_type())
122 : _M_ht(__n
, __hf
, __eql
, __a
) {}
124 #if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
125 template <class _InputIterator
>
126 hash_map(_InputIterator __f
, _InputIterator __l
)
127 : _M_ht(100, hasher(), key_equal(), allocator_type())
128 { _M_ht
.insert_unique(__f
, __l
); }
129 template <class _InputIterator
>
130 hash_map(_InputIterator __f
, _InputIterator __l
, size_type __n
)
131 : _M_ht(__n
, hasher(), key_equal(), allocator_type())
132 { _M_ht
.insert_unique(__f
, __l
); }
133 template <class _InputIterator
>
134 hash_map(_InputIterator __f
, _InputIterator __l
, size_type __n
,
136 : _M_ht(__n
, __hf
, key_equal(), allocator_type())
137 { _M_ht
.insert_unique(__f
, __l
); }
138 template <class _InputIterator
>
139 hash_map(_InputIterator __f
, _InputIterator __l
, size_type __n
,
140 const hasher
& __hf
, const key_equal
& __eql
,
141 const allocator_type
& __a
= allocator_type())
142 : _M_ht(__n
, __hf
, __eql
, __a
)
143 { _M_ht
.insert_unique(__f
, __l
); }
146 hash_map(const value_type
* __f
, const value_type
* __l
)
147 : _M_ht(100, hasher(), key_equal(), allocator_type())
148 { _M_ht
.insert_unique(__f
, __l
); }
149 hash_map(const value_type
* __f
, const value_type
* __l
, size_type __n
)
150 : _M_ht(__n
, hasher(), key_equal(), allocator_type())
151 { _M_ht
.insert_unique(__f
, __l
); }
152 hash_map(const value_type
* __f
, const value_type
* __l
, size_type __n
,
154 : _M_ht(__n
, __hf
, key_equal(), allocator_type())
155 { _M_ht
.insert_unique(__f
, __l
); }
156 hash_map(const value_type
* __f
, const value_type
* __l
, size_type __n
,
157 const hasher
& __hf
, const key_equal
& __eql
,
158 const allocator_type
& __a
= allocator_type())
159 : _M_ht(__n
, __hf
, __eql
, __a
)
160 { _M_ht
.insert_unique(__f
, __l
); }
162 hash_map(const_iterator __f
, const_iterator __l
)
163 : _M_ht(100, hasher(), key_equal(), allocator_type())
164 { _M_ht
.insert_unique(__f
, __l
); }
165 hash_map(const_iterator __f
, const_iterator __l
, size_type __n
)
166 : _M_ht(__n
, hasher(), key_equal(), allocator_type())
167 { _M_ht
.insert_unique(__f
, __l
); }
168 hash_map(const_iterator __f
, const_iterator __l
, size_type __n
,
170 : _M_ht(__n
, __hf
, key_equal(), allocator_type())
171 { _M_ht
.insert_unique(__f
, __l
); }
172 hash_map(const_iterator __f
, const_iterator __l
, size_type __n
,
173 const hasher
& __hf
, const key_equal
& __eql
,
174 const allocator_type
& __a
= allocator_type())
175 : _M_ht(__n
, __hf
, __eql
, __a
)
176 { _M_ht
.insert_unique(__f
, __l
); }
180 size_type
size() const { return _M_ht
.size(); }
181 size_type
max_size() const { return _M_ht
.max_size(); }
182 bool empty() const { return _M_ht
.empty(); }
183 void swap(hash_map
& __hs
) { _M_ht
.swap(__hs
._M_ht
); }
185 friend bool operator==@KWSYS_NAMESPACE@
_CXX_NULL_TEMPLATE_ARGS(const hash_map
&,
188 iterator
begin() { return _M_ht
.begin(); }
189 iterator
end() { return _M_ht
.end(); }
190 const_iterator
begin() const { return _M_ht
.begin(); }
191 const_iterator
end() const { return _M_ht
.end(); }
194 @KWSYS_NAMESPACE@
_stl::pair
<iterator
,bool> insert(const value_type
& __obj
)
195 { return _M_ht
.insert_unique(__obj
); }
196 #if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
197 template <class _InputIterator
>
198 void insert(_InputIterator __f
, _InputIterator __l
)
199 { _M_ht
.insert_unique(__f
,__l
); }
201 void insert(const value_type
* __f
, const value_type
* __l
) {
202 _M_ht
.insert_unique(__f
,__l
);
204 void insert(const_iterator __f
, const_iterator __l
)
205 { _M_ht
.insert_unique(__f
, __l
); }
207 @KWSYS_NAMESPACE@
_stl::pair
<iterator
,bool> insert_noresize(const value_type
& __obj
)
208 { return _M_ht
.insert_unique_noresize(__obj
); }
210 iterator
find(const key_type
& __key
) { return _M_ht
.find(__key
); }
211 const_iterator
find(const key_type
& __key
) const
212 { return _M_ht
.find(__key
); }
214 _Tp
& operator[](const key_type
& __key
) {
215 return _M_ht
.find_or_insert(value_type(__key
, _Tp())).second
;
218 size_type
count(const key_type
& __key
) const { return _M_ht
.count(__key
); }
220 @KWSYS_NAMESPACE@
_stl::pair
<iterator
, iterator
> equal_range(const key_type
& __key
)
221 { return _M_ht
.equal_range(__key
); }
222 @KWSYS_NAMESPACE@
_stl::pair
<const_iterator
, const_iterator
>
223 equal_range(const key_type
& __key
) const
224 { return _M_ht
.equal_range(__key
); }
226 size_type
erase(const key_type
& __key
) {return _M_ht
.erase(__key
); }
227 void erase(iterator __it
) { _M_ht
.erase(__it
); }
228 void erase(iterator __f
, iterator __l
) { _M_ht
.erase(__f
, __l
); }
229 void clear() { _M_ht
.clear(); }
231 void resize(size_type __hint
) { _M_ht
.resize(__hint
); }
232 size_type
bucket_count() const { return _M_ht
.bucket_count(); }
233 size_type
max_bucket_count() const { return _M_ht
.max_bucket_count(); }
234 size_type
elems_in_bucket(size_type __n
) const
235 { return _M_ht
.elems_in_bucket(__n
); }
238 template <class _Key
, class _Tp
, class _HashFcn
, class _EqlKey
, class _Alloc
>
240 operator==(const hash_map
<_Key
,_Tp
,_HashFcn
,_EqlKey
,_Alloc
>& __hm1
,
241 const hash_map
<_Key
,_Tp
,_HashFcn
,_EqlKey
,_Alloc
>& __hm2
)
243 return __hm1
._M_ht
== __hm2
._M_ht
;
246 template <class _Key
, class _Tp
, class _HashFcn
, class _EqlKey
, class _Alloc
>
248 operator!=(const hash_map
<_Key
,_Tp
,_HashFcn
,_EqlKey
,_Alloc
>& __hm1
,
249 const hash_map
<_Key
,_Tp
,_HashFcn
,_EqlKey
,_Alloc
>& __hm2
) {
250 return !(__hm1
== __hm2
);
253 template <class _Key
, class _Tp
, class _HashFcn
, class _EqlKey
, class _Alloc
>
255 swap(hash_map
<_Key
,_Tp
,_HashFcn
,_EqlKey
,_Alloc
>& __hm1
,
256 hash_map
<_Key
,_Tp
,_HashFcn
,_EqlKey
,_Alloc
>& __hm2
)
261 // Forward declaration of equality operator; needed for friend declaration.
263 template <class _Key
, class _Tp
,
264 class _HashFcn
= hash
<_Key
>,
265 class _EqualKey
= @KWSYS_NAMESPACE@
_stl::equal_to
<_Key
>,
266 class _Alloc
= @KWSYS_NAMESPACE@
_HASH_DEFAULT_ALLOCATOR(char) >
269 template <class _Key
, class _Tp
, class _HF
, class _EqKey
, class _Alloc
>
271 operator==(const hash_multimap
<_Key
,_Tp
,_HF
,_EqKey
,_Alloc
>& __hm1
,
272 const hash_multimap
<_Key
,_Tp
,_HF
,_EqKey
,_Alloc
>& __hm2
);
274 template <class _Key
, class _Tp
, class _HashFcn
, class _EqualKey
,
279 typedef hashtable
<@KWSYS_NAMESPACE@
_stl::pair
<const _Key
, _Tp
>, _Key
, _HashFcn
,
280 hash_select1st
<const _Key
, _Tp
>, _EqualKey
, _Alloc
>
285 typedef typename
_Ht::key_type key_type
;
286 typedef _Tp data_type
;
287 typedef _Tp mapped_type
;
288 typedef typename
_Ht::value_type value_type
;
289 typedef typename
_Ht::hasher hasher
;
290 typedef typename
_Ht::key_equal key_equal
;
292 typedef typename
_Ht::size_type size_type
;
293 typedef typename
_Ht::difference_type difference_type
;
294 typedef typename
_Ht::pointer pointer
;
295 typedef typename
_Ht::const_pointer const_pointer
;
296 typedef typename
_Ht::reference reference
;
297 typedef typename
_Ht::const_reference const_reference
;
299 typedef typename
_Ht::iterator iterator
;
300 typedef typename
_Ht::const_iterator const_iterator
;
302 typedef typename
_Ht::allocator_type allocator_type
;
304 hasher
hash_funct() const { return _M_ht
.hash_funct(); }
305 key_equal
key_eq() const { return _M_ht
.key_eq(); }
306 allocator_type
get_allocator() const { return _M_ht
.get_allocator(); }
309 hash_multimap() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
310 explicit hash_multimap(size_type __n
)
311 : _M_ht(__n
, hasher(), key_equal(), allocator_type()) {}
312 hash_multimap(size_type __n
, const hasher
& __hf
)
313 : _M_ht(__n
, __hf
, key_equal(), allocator_type()) {}
314 hash_multimap(size_type __n
, const hasher
& __hf
, const key_equal
& __eql
,
315 const allocator_type
& __a
= allocator_type())
316 : _M_ht(__n
, __hf
, __eql
, __a
) {}
318 #if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
319 template <class _InputIterator
>
320 hash_multimap(_InputIterator __f
, _InputIterator __l
)
321 : _M_ht(100, hasher(), key_equal(), allocator_type())
322 { _M_ht
.insert_equal(__f
, __l
); }
323 template <class _InputIterator
>
324 hash_multimap(_InputIterator __f
, _InputIterator __l
, size_type __n
)
325 : _M_ht(__n
, hasher(), key_equal(), allocator_type())
326 { _M_ht
.insert_equal(__f
, __l
); }
327 template <class _InputIterator
>
328 hash_multimap(_InputIterator __f
, _InputIterator __l
, size_type __n
,
330 : _M_ht(__n
, __hf
, key_equal(), allocator_type())
331 { _M_ht
.insert_equal(__f
, __l
); }
332 template <class _InputIterator
>
333 hash_multimap(_InputIterator __f
, _InputIterator __l
, size_type __n
,
334 const hasher
& __hf
, const key_equal
& __eql
,
335 const allocator_type
& __a
= allocator_type())
336 : _M_ht(__n
, __hf
, __eql
, __a
)
337 { _M_ht
.insert_equal(__f
, __l
); }
340 hash_multimap(const value_type
* __f
, const value_type
* __l
)
341 : _M_ht(100, hasher(), key_equal(), allocator_type())
342 { _M_ht
.insert_equal(__f
, __l
); }
343 hash_multimap(const value_type
* __f
, const value_type
* __l
, size_type __n
)
344 : _M_ht(__n
, hasher(), key_equal(), allocator_type())
345 { _M_ht
.insert_equal(__f
, __l
); }
346 hash_multimap(const value_type
* __f
, const value_type
* __l
, size_type __n
,
348 : _M_ht(__n
, __hf
, key_equal(), allocator_type())
349 { _M_ht
.insert_equal(__f
, __l
); }
350 hash_multimap(const value_type
* __f
, const value_type
* __l
, size_type __n
,
351 const hasher
& __hf
, const key_equal
& __eql
,
352 const allocator_type
& __a
= allocator_type())
353 : _M_ht(__n
, __hf
, __eql
, __a
)
354 { _M_ht
.insert_equal(__f
, __l
); }
356 hash_multimap(const_iterator __f
, const_iterator __l
)
357 : _M_ht(100, hasher(), key_equal(), allocator_type())
358 { _M_ht
.insert_equal(__f
, __l
); }
359 hash_multimap(const_iterator __f
, const_iterator __l
, size_type __n
)
360 : _M_ht(__n
, hasher(), key_equal(), allocator_type())
361 { _M_ht
.insert_equal(__f
, __l
); }
362 hash_multimap(const_iterator __f
, const_iterator __l
, size_type __n
,
364 : _M_ht(__n
, __hf
, key_equal(), allocator_type())
365 { _M_ht
.insert_equal(__f
, __l
); }
366 hash_multimap(const_iterator __f
, const_iterator __l
, size_type __n
,
367 const hasher
& __hf
, const key_equal
& __eql
,
368 const allocator_type
& __a
= allocator_type())
369 : _M_ht(__n
, __hf
, __eql
, __a
)
370 { _M_ht
.insert_equal(__f
, __l
); }
374 size_type
size() const { return _M_ht
.size(); }
375 size_type
max_size() const { return _M_ht
.max_size(); }
376 bool empty() const { return _M_ht
.empty(); }
377 void swap(hash_multimap
& __hs
) { _M_ht
.swap(__hs
._M_ht
); }
379 friend bool operator==@KWSYS_NAMESPACE@
_CXX_NULL_TEMPLATE_ARGS(const hash_multimap
&,
380 const hash_multimap
&);
382 iterator
begin() { return _M_ht
.begin(); }
383 iterator
end() { return _M_ht
.end(); }
384 const_iterator
begin() const { return _M_ht
.begin(); }
385 const_iterator
end() const { return _M_ht
.end(); }
388 iterator
insert(const value_type
& __obj
)
389 { return _M_ht
.insert_equal(__obj
); }
390 #if @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
391 template <class _InputIterator
>
392 void insert(_InputIterator __f
, _InputIterator __l
)
393 { _M_ht
.insert_equal(__f
,__l
); }
395 void insert(const value_type
* __f
, const value_type
* __l
) {
396 _M_ht
.insert_equal(__f
,__l
);
398 void insert(const_iterator __f
, const_iterator __l
)
399 { _M_ht
.insert_equal(__f
, __l
); }
401 iterator
insert_noresize(const value_type
& __obj
)
402 { return _M_ht
.insert_equal_noresize(__obj
); }
404 iterator
find(const key_type
& __key
) { return _M_ht
.find(__key
); }
405 const_iterator
find(const key_type
& __key
) const
406 { return _M_ht
.find(__key
); }
408 size_type
count(const key_type
& __key
) const { return _M_ht
.count(__key
); }
410 @KWSYS_NAMESPACE@
_stl::pair
<iterator
, iterator
> equal_range(const key_type
& __key
)
411 { return _M_ht
.equal_range(__key
); }
412 @KWSYS_NAMESPACE@
_stl::pair
<const_iterator
, const_iterator
>
413 equal_range(const key_type
& __key
) const
414 { return _M_ht
.equal_range(__key
); }
416 size_type
erase(const key_type
& __key
) {return _M_ht
.erase(__key
); }
417 void erase(iterator __it
) { _M_ht
.erase(__it
); }
418 void erase(iterator __f
, iterator __l
) { _M_ht
.erase(__f
, __l
); }
419 void clear() { _M_ht
.clear(); }
422 void resize(size_type __hint
) { _M_ht
.resize(__hint
); }
423 size_type
bucket_count() const { return _M_ht
.bucket_count(); }
424 size_type
max_bucket_count() const { return _M_ht
.max_bucket_count(); }
425 size_type
elems_in_bucket(size_type __n
) const
426 { return _M_ht
.elems_in_bucket(__n
); }
429 template <class _Key
, class _Tp
, class _HF
, class _EqKey
, class _Alloc
>
431 operator==(const hash_multimap
<_Key
,_Tp
,_HF
,_EqKey
,_Alloc
>& __hm1
,
432 const hash_multimap
<_Key
,_Tp
,_HF
,_EqKey
,_Alloc
>& __hm2
)
434 return __hm1
._M_ht
== __hm2
._M_ht
;
437 template <class _Key
, class _Tp
, class _HF
, class _EqKey
, class _Alloc
>
439 operator!=(const hash_multimap
<_Key
,_Tp
,_HF
,_EqKey
,_Alloc
>& __hm1
,
440 const hash_multimap
<_Key
,_Tp
,_HF
,_EqKey
,_Alloc
>& __hm2
) {
441 return !(__hm1
== __hm2
);
444 template <class _Key
, class _Tp
, class _HashFcn
, class _EqlKey
, class _Alloc
>
446 swap(hash_multimap
<_Key
,_Tp
,_HashFcn
,_EqlKey
,_Alloc
>& __hm1
,
447 hash_multimap
<_Key
,_Tp
,_HashFcn
,_EqlKey
,_Alloc
>& __hm2
)
452 } // namespace @KWSYS_NAMESPACE@
454 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
455 # pragma reset woff 1174
456 # pragma reset woff 1375
459 #if defined(_MSC_VER)
460 # pragma warning (pop)