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