00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _STLP_INTERNAL_HASH_MAP_H
00031 #define _STLP_INTERNAL_HASH_MAP_H
00032
00033 #ifndef _STLP_INTERNAL_HASHTABLE_H
00034 # include <stl/_hashtable.h>
00035 #endif
00036
00037 _STLP_BEGIN_NAMESPACE
00038
00039 # define hash_map __WORKAROUND_RENAME(hash_map)
00040 # define hash_multimap __WORKAROUND_RENAME(hash_multimap)
00041
00042 # define _STLP_KEY_PAIR pair< const _Key, _Tp >
00043 # define _STLP_HASHTABLE hashtable \
00044 < pair < const _Key, _Tp >, _Key, _HashFcn, \
00045 _STLP_SELECT1ST( _STLP_KEY_PAIR, _Key ), _EqualKey, _Alloc >
00046
00047 template <class _Key, class _Tp, __DFL_TMPL_PARAM(_HashFcn,hash<_Key>),
00048 __DFL_TMPL_PARAM(_EqualKey,equal_to<_Key>),
00049 _STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
00050 class hash_map
00051 {
00052 private:
00053 typedef _STLP_HASHTABLE _Ht;
00054 typedef hash_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc> _Self;
00055 public:
00056 typedef typename _Ht::key_type key_type;
00057 typedef _Tp data_type;
00058 typedef _Tp mapped_type;
00059 typedef typename _Ht::value_type _value_type;
00060 typedef typename _Ht::value_type value_type;
00061 typedef typename _Ht::hasher hasher;
00062 typedef typename _Ht::key_equal key_equal;
00063
00064 typedef typename _Ht::size_type size_type;
00065 typedef typename _Ht::difference_type difference_type;
00066 typedef typename _Ht::pointer pointer;
00067 typedef typename _Ht::const_pointer const_pointer;
00068 typedef typename _Ht::reference reference;
00069 typedef typename _Ht::const_reference const_reference;
00070
00071 typedef typename _Ht::iterator iterator;
00072 typedef typename _Ht::const_iterator const_iterator;
00073
00074 typedef typename _Ht::allocator_type allocator_type;
00075
00076 hasher hash_funct() const { return _M_ht.hash_funct(); }
00077 key_equal key_eq() const { return _M_ht.key_eq(); }
00078 allocator_type get_allocator() const { return _M_ht.get_allocator(); }
00079
00080 private:
00081 _Ht _M_ht;
00082 public:
00083 hash_map() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
00084 explicit hash_map(size_type __n)
00085 : _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
00086 hash_map(size_type __n, const hasher& __hf)
00087 : _M_ht(__n, __hf, key_equal(), allocator_type()) {}
00088 hash_map(size_type __n, const hasher& __hf, const key_equal& __eql,
00089 const allocator_type& __a = allocator_type())
00090 : _M_ht(__n, __hf, __eql, __a) {}
00091
00092 #ifdef _STLP_MEMBER_TEMPLATES
00093 template <class _InputIterator>
00094 hash_map(_InputIterator __f, _InputIterator __l)
00095 : _M_ht(100, hasher(), key_equal(), allocator_type())
00096 { _M_ht.insert_unique(__f, __l); }
00097 template <class _InputIterator>
00098 hash_map(_InputIterator __f, _InputIterator __l, size_type __n)
00099 : _M_ht(__n, hasher(), key_equal(), allocator_type())
00100 { _M_ht.insert_unique(__f, __l); }
00101 template <class _InputIterator>
00102 hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
00103 const hasher& __hf)
00104 : _M_ht(__n, __hf, key_equal(), allocator_type())
00105 { _M_ht.insert_unique(__f, __l); }
00106 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
00107 template <class _InputIterator>
00108 hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
00109 const hasher& __hf, const key_equal& __eql)
00110 : _M_ht(__n, __hf, __eql, allocator_type())
00111 { _M_ht.insert_unique(__f, __l); }
00112 # endif
00113 template <class _InputIterator>
00114 hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
00115 const hasher& __hf, const key_equal& __eql,
00116 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00117 : _M_ht(__n, __hf, __eql, __a)
00118 { _M_ht.insert_unique(__f, __l); }
00119
00120 #else
00121 hash_map(const value_type* __f, const value_type* __l)
00122 : _M_ht(100, hasher(), key_equal(), allocator_type())
00123 { _M_ht.insert_unique(__f, __l); }
00124 hash_map(const value_type* __f, const value_type* __l, size_type __n)
00125 : _M_ht(__n, hasher(), key_equal(), allocator_type())
00126 { _M_ht.insert_unique(__f, __l); }
00127 hash_map(const value_type* __f, const value_type* __l, size_type __n,
00128 const hasher& __hf)
00129 : _M_ht(__n, __hf, key_equal(), allocator_type())
00130 { _M_ht.insert_unique(__f, __l); }
00131 hash_map(const value_type* __f, const value_type* __l, size_type __n,
00132 const hasher& __hf, const key_equal& __eql,
00133 const allocator_type& __a = allocator_type())
00134 : _M_ht(__n, __hf, __eql, __a)
00135 { _M_ht.insert_unique(__f, __l); }
00136
00137 hash_map(const_iterator __f, const_iterator __l)
00138 : _M_ht(100, hasher(), key_equal(), allocator_type())
00139 { _M_ht.insert_unique(__f, __l); }
00140 hash_map(const_iterator __f, const_iterator __l, size_type __n)
00141 : _M_ht(__n, hasher(), key_equal(), allocator_type())
00142 { _M_ht.insert_unique(__f, __l); }
00143 hash_map(const_iterator __f, const_iterator __l, size_type __n,
00144 const hasher& __hf)
00145 : _M_ht(__n, __hf, key_equal(), allocator_type())
00146 { _M_ht.insert_unique(__f, __l); }
00147 hash_map(const_iterator __f, const_iterator __l, size_type __n,
00148 const hasher& __hf, const key_equal& __eql,
00149 const allocator_type& __a = allocator_type())
00150 : _M_ht(__n, __hf, __eql, __a)
00151 { _M_ht.insert_unique(__f, __l); }
00152 #endif
00153
00154 public:
00155 size_type size() const { return _M_ht.size(); }
00156 size_type max_size() const { return _M_ht.max_size(); }
00157 bool empty() const { return _M_ht.empty(); }
00158 void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
00159 iterator begin() { return _M_ht.begin(); }
00160 iterator end() { return _M_ht.end(); }
00161 const_iterator begin() const { return _M_ht.begin(); }
00162 const_iterator end() const { return _M_ht.end(); }
00163
00164 public:
00165 pair<iterator,bool> insert(const value_type& __obj)
00166 { return _M_ht.insert_unique(__obj); }
00167 #ifdef _STLP_MEMBER_TEMPLATES
00168 template <class _InputIterator>
00169 void insert(_InputIterator __f, _InputIterator __l)
00170 { _M_ht.insert_unique(__f,__l); }
00171 #else
00172 void insert(const value_type* __f, const value_type* __l) {
00173 _M_ht.insert_unique(__f,__l);
00174 }
00175 void insert(const_iterator __f, const_iterator __l)
00176 { _M_ht.insert_unique(__f, __l); }
00177 #endif
00178 pair<iterator,bool> insert_noresize(const value_type& __obj)
00179 { return _M_ht.insert_unique_noresize(__obj); }
00180
00181 iterator find(const key_type& __key) { return _M_ht.find(__key); }
00182 const_iterator find(const key_type& __key) const { return _M_ht.find(__key); }
00183
00184 _Tp& operator[](const key_type& __key) {
00185 return _M_ht.find_or_insert(_value_type(__key, _Tp())).second;
00186 }
00187
00188 size_type count(const key_type& __key) const { return _M_ht.count(__key); }
00189
00190 pair<iterator, iterator> equal_range(const key_type& __key)
00191 { return _M_ht.equal_range(__key); }
00192 pair<const_iterator, const_iterator>
00193 equal_range(const key_type& __key) const
00194 { return _M_ht.equal_range(__key); }
00195
00196 size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
00197 void erase(iterator __it) { _M_ht.erase(__it); }
00198 void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
00199 void clear() { _M_ht.clear(); }
00200
00201 void resize(size_type __hint) { _M_ht.resize(__hint); }
00202 size_type bucket_count() const { return _M_ht.bucket_count(); }
00203 size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
00204 size_type elems_in_bucket(size_type __n) const
00205 { return _M_ht.elems_in_bucket(__n); }
00206 static bool _STLP_CALL _M_equal (const _Self& __x, const _Self& __y) {
00207 return _Ht::_M_equal(__x._M_ht,__y._M_ht);
00208 }
00209 };
00210
00211
00212 template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
00213 inline bool _STLP_CALL
00214 operator==(const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
00215 const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
00216 {
00217 return hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>::_M_equal(__hm1, __hm2);
00218 }
00219 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
00220
00221 template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
00222 inline bool _STLP_CALL
00223 operator!=(const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
00224 const hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2) {
00225 return !(__hm1 == __hm2);
00226 }
00227
00228 template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
00229 inline void _STLP_CALL
00230 swap(hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
00231 hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
00232 {
00233 __hm1.swap(__hm2);
00234 }
00235
00236 #endif
00237
00238 template <class _Key, class _Tp, __DFL_TMPL_PARAM(_HashFcn,hash<_Key>),
00239 __DFL_TMPL_PARAM(_EqualKey,equal_to<_Key>),
00240 _STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
00241 class hash_multimap
00242 {
00243 private:
00244 typedef _STLP_HASHTABLE _Ht;
00245 typedef hash_multimap<_Key, _Tp, _HashFcn, _EqualKey, _Alloc> _Self;
00246 public:
00247 typedef typename _Ht::key_type key_type;
00248 typedef _Tp data_type;
00249 typedef _Tp mapped_type;
00250 typedef typename _Ht::value_type _value_type;
00251 typedef _value_type value_type;
00252 typedef typename _Ht::hasher hasher;
00253 typedef typename _Ht::key_equal key_equal;
00254
00255 typedef typename _Ht::size_type size_type;
00256 typedef typename _Ht::difference_type difference_type;
00257 typedef typename _Ht::pointer pointer;
00258 typedef typename _Ht::const_pointer const_pointer;
00259 typedef typename _Ht::reference reference;
00260 typedef typename _Ht::const_reference const_reference;
00261
00262 typedef typename _Ht::iterator iterator;
00263 typedef typename _Ht::const_iterator const_iterator;
00264
00265 typedef typename _Ht::allocator_type allocator_type;
00266
00267 hasher hash_funct() const { return _M_ht.hash_funct(); }
00268 key_equal key_eq() const { return _M_ht.key_eq(); }
00269 allocator_type get_allocator() const { return _M_ht.get_allocator(); }
00270
00271 private:
00272 _Ht _M_ht;
00273 public:
00274 hash_multimap() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
00275 explicit hash_multimap(size_type __n)
00276 : _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
00277 hash_multimap(size_type __n, const hasher& __hf)
00278 : _M_ht(__n, __hf, key_equal(), allocator_type()) {}
00279 hash_multimap(size_type __n, const hasher& __hf, const key_equal& __eql,
00280 const allocator_type& __a = allocator_type())
00281 : _M_ht(__n, __hf, __eql, __a) {}
00282
00283 #ifdef _STLP_MEMBER_TEMPLATES
00284 template <class _InputIterator>
00285 hash_multimap(_InputIterator __f, _InputIterator __l)
00286 : _M_ht(100, hasher(), key_equal(), allocator_type())
00287 { _M_ht.insert_equal(__f, __l); }
00288 template <class _InputIterator>
00289 hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n)
00290 : _M_ht(__n, hasher(), key_equal(), allocator_type())
00291 { _M_ht.insert_equal(__f, __l); }
00292 template <class _InputIterator>
00293 hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
00294 const hasher& __hf)
00295 : _M_ht(__n, __hf, key_equal(), allocator_type())
00296 { _M_ht.insert_equal(__f, __l); }
00297 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
00298 template <class _InputIterator>
00299 hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
00300 const hasher& __hf, const key_equal& __eql)
00301 : _M_ht(__n, __hf, __eql, allocator_type())
00302 { _M_ht.insert_equal(__f, __l); }
00303 # endif
00304 template <class _InputIterator>
00305 hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
00306 const hasher& __hf, const key_equal& __eql,
00307 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00308 : _M_ht(__n, __hf, __eql, __a)
00309 { _M_ht.insert_equal(__f, __l); }
00310
00311 #else
00312 hash_multimap(const value_type* __f, const value_type* __l)
00313 : _M_ht(100, hasher(), key_equal(), allocator_type())
00314 { _M_ht.insert_equal(__f, __l); }
00315 hash_multimap(const value_type* __f, const value_type* __l, size_type __n)
00316 : _M_ht(__n, hasher(), key_equal(), allocator_type())
00317 { _M_ht.insert_equal(__f, __l); }
00318 hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
00319 const hasher& __hf)
00320 : _M_ht(__n, __hf, key_equal(), allocator_type())
00321 { _M_ht.insert_equal(__f, __l); }
00322 hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
00323 const hasher& __hf, const key_equal& __eql,
00324 const allocator_type& __a = allocator_type())
00325 : _M_ht(__n, __hf, __eql, __a)
00326 { _M_ht.insert_equal(__f, __l); }
00327
00328 hash_multimap(const_iterator __f, const_iterator __l)
00329 : _M_ht(100, hasher(), key_equal(), allocator_type())
00330 { _M_ht.insert_equal(__f, __l); }
00331 hash_multimap(const_iterator __f, const_iterator __l, size_type __n)
00332 : _M_ht(__n, hasher(), key_equal(), allocator_type())
00333 { _M_ht.insert_equal(__f, __l); }
00334 hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
00335 const hasher& __hf)
00336 : _M_ht(__n, __hf, key_equal(), allocator_type())
00337 { _M_ht.insert_equal(__f, __l); }
00338 hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
00339 const hasher& __hf, const key_equal& __eql,
00340 const allocator_type& __a = allocator_type())
00341 : _M_ht(__n, __hf, __eql, __a)
00342 { _M_ht.insert_equal(__f, __l); }
00343 #endif
00344
00345 public:
00346 size_type size() const { return _M_ht.size(); }
00347 size_type max_size() const { return _M_ht.max_size(); }
00348 bool empty() const { return _M_ht.empty(); }
00349 void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
00350
00351 iterator begin() { return _M_ht.begin(); }
00352 iterator end() { return _M_ht.end(); }
00353 const_iterator begin() const { return _M_ht.begin(); }
00354 const_iterator end() const { return _M_ht.end(); }
00355
00356 public:
00357 iterator insert(const value_type& __obj)
00358 { return _M_ht.insert_equal(__obj); }
00359 #ifdef _STLP_MEMBER_TEMPLATES
00360 template <class _InputIterator>
00361 void insert(_InputIterator __f, _InputIterator __l)
00362 { _M_ht.insert_equal(__f,__l); }
00363 #else
00364 void insert(const value_type* __f, const value_type* __l) {
00365 _M_ht.insert_equal(__f,__l);
00366 }
00367 void insert(const_iterator __f, const_iterator __l)
00368 { _M_ht.insert_equal(__f, __l); }
00369 #endif
00370 iterator insert_noresize(const value_type& __obj)
00371 { return _M_ht.insert_equal_noresize(__obj); }
00372
00373 iterator find(const key_type& __key) { return _M_ht.find(__key); }
00374 const_iterator find(const key_type& __key) const
00375 { return _M_ht.find(__key); }
00376
00377 size_type count(const key_type& __key) const { return _M_ht.count(__key); }
00378
00379 pair<iterator, iterator> equal_range(const key_type& __key)
00380 { return _M_ht.equal_range(__key); }
00381 pair<const_iterator, const_iterator>
00382 equal_range(const key_type& __key) const
00383 { return _M_ht.equal_range(__key); }
00384
00385 size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
00386 void erase(iterator __it) { _M_ht.erase(__it); }
00387 void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
00388 void clear() { _M_ht.clear(); }
00389
00390 public:
00391 void resize(size_type __hint) { _M_ht.resize(__hint); }
00392 size_type bucket_count() const { return _M_ht.bucket_count(); }
00393 size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
00394 size_type elems_in_bucket(size_type __n) const
00395 { return _M_ht.elems_in_bucket(__n); }
00396 static bool _STLP_CALL _M_equal (const _Self& __x, const _Self& __y) {
00397 return _Ht::_M_equal(__x._M_ht,__y._M_ht);
00398 }
00399 };
00400
00401
00402 template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
00403 inline bool _STLP_CALL
00404 operator==(const hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
00405 const hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
00406 {
00407 return hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>::_M_equal(__hm1, __hm2);
00408 }
00409
00410 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
00411
00412 template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
00413 inline bool _STLP_CALL
00414 operator!=(const hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
00415 const hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2) {
00416 return !(__hm1 == __hm2);
00417 }
00418
00419 template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
00420 inline void _STLP_CALL
00421 swap(hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm1,
00422 hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>& __hm2)
00423 {
00424 __hm1.swap(__hm2);
00425 }
00426
00427 #endif
00428
00429
00430
00431
00432
00433 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
00434
00435 template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
00436 class insert_iterator<hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
00437 protected:
00438 typedef hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
00439 _Container* container;
00440 public:
00441 typedef _Container container_type;
00442 typedef output_iterator_tag iterator_category;
00443 typedef void value_type;
00444 typedef void difference_type;
00445 typedef void pointer;
00446 typedef void reference;
00447
00448 insert_iterator(_Container& __x) : container(&__x) {}
00449 insert_iterator(_Container& __x, typename _Container::iterator)
00450 : container(&__x) {}
00451 insert_iterator<_Container>&
00452 operator=(const typename _Container::value_type& __value) {
00453 container->insert(__value);
00454 return *this;
00455 }
00456 insert_iterator<_Container>& operator*() { return *this; }
00457 insert_iterator<_Container>& operator++() { return *this; }
00458 insert_iterator<_Container>& operator++(int) { return *this; }
00459 };
00460
00461 template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
00462 class insert_iterator<hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
00463 protected:
00464 typedef hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
00465 _Container* container;
00466 typename _Container::iterator iter;
00467 public:
00468 typedef _Container container_type;
00469 typedef output_iterator_tag iterator_category;
00470 typedef void value_type;
00471 typedef void difference_type;
00472 typedef void pointer;
00473 typedef void reference;
00474
00475 insert_iterator(_Container& __x) : container(&__x) {}
00476 insert_iterator(_Container& __x, typename _Container::iterator)
00477 : container(&__x) {}
00478 insert_iterator<_Container>&
00479 operator=(const typename _Container::value_type& __value) {
00480 container->insert(__value);
00481 return *this;
00482 }
00483 insert_iterator<_Container>& operator*() { return *this; }
00484 insert_iterator<_Container>& operator++() { return *this; }
00485 insert_iterator<_Container>& operator++(int) { return *this; }
00486 };
00487
00488 #endif
00489
00490
00491 # undef hash_map
00492 # undef hash_multimap
00493
00494 # define __hash_map__ __FULL_NAME(hash_map)
00495 # define __hash_multimap__ __FULL_NAME(hash_multimap)
00496
00497
00498 _STLP_END_NAMESPACE
00499
00500 # if defined (_STLP_USE_WRAPPER_FOR_ALLOC_PARAM)
00501 # include <stl/wrappers/_hash_map.h>
00502 # endif
00503
00504 #endif
00505
00506
00507
00508
00509