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