_set.h

00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Copyright (c) 1996,1997
00007  * Silicon Graphics Computer Systems, Inc.
00008  *
00009  * Copyright (c) 1997
00010  * Moscow Center for SPARC Technology
00011  *
00012  * Copyright (c) 1999 
00013  * Boris Fomitchev
00014  *
00015  * This material is provided "as is", with absolutely no warranty expressed
00016  * or implied. Any use is at your own risk.
00017  *
00018  * Permission to use or copy this software for any purpose is hereby granted 
00019  * without fee, provided the above notices are retained on all copies.
00020  * Permission to modify the code and to distribute modified code is granted,
00021  * provided the above notices are retained, and a notice that the code was
00022  * modified is included with the above copyright notice.
00023  *
00024  */
00025 
00026 /* NOTE: This is an internal header file, included by other STL headers.
00027  *   You should not attempt to use it directly.
00028  */
00029 
00030 #ifndef _STLP_INTERNAL_SET_H
00031 #define _STLP_INTERNAL_SET_H
00032 
00033 #ifndef _STLP_INTERNAL_TREE_H
00034 #include <stl/_tree.h>
00035 #endif
00036 
00037 #define set __WORKAROUND_RENAME(set)
00038 #define multiset __WORKAROUND_RENAME(multiset)
00039 
00040 _STLP_BEGIN_NAMESPACE
00041 
00042 template <class _Key, __DFL_TMPL_PARAM(_Compare,less<_Key>), 
00043                      _STLP_DEFAULT_ALLOCATOR_SELECT(_Key) >
00044 class set {
00045 public:
00046 // typedefs:
00047   typedef _Key     key_type;
00048   typedef _Key     value_type;
00049   typedef _Compare key_compare;
00050   typedef _Compare value_compare;
00051 private:
00052   typedef _Rb_tree<key_type, value_type, 
00053     _Identity<value_type>, key_compare, _Alloc> _Rep_type;
00054 public:
00055   typedef typename _Rep_type::pointer pointer;
00056   typedef typename _Rep_type::const_pointer const_pointer;
00057   typedef typename _Rep_type::reference reference;
00058   typedef typename _Rep_type::const_reference const_reference;
00059   typedef typename _Rep_type::const_iterator const_iterator;
00060   typedef const_iterator iterator;
00061   typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
00062   typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00063   typedef typename _Rep_type::size_type size_type;
00064   typedef typename _Rep_type::difference_type difference_type;
00065   typedef typename _Rep_type::allocator_type allocator_type;
00066 
00067 private:
00068   _Rep_type _M_t;  // red-black tree representing set
00069 public:
00070 
00071   // allocation/deallocation
00072 
00073   set() : _M_t(_Compare(), allocator_type()) {}
00074   explicit set(const _Compare& __comp,
00075                const allocator_type& __a = allocator_type())
00076     : _M_t(__comp, __a) {}
00077 
00078 #ifdef _STLP_MEMBER_TEMPLATES
00079   template <class _InputIterator>
00080   set(_InputIterator __first, _InputIterator __last)
00081     : _M_t(_Compare(), allocator_type())
00082     { _M_t.insert_unique(__first, __last); }
00083 
00084 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
00085   template <class _InputIterator>
00086   set(_InputIterator __first, _InputIterator __last, const _Compare& __comp)
00087     : _M_t(__comp, allocator_type()) { _M_t.insert_unique(__first, __last); }
00088 # endif
00089   template <class _InputIterator>
00090   set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
00091       const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00092     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00093 #else
00094   set(const value_type* __first, const value_type* __last) 
00095     : _M_t(_Compare(), allocator_type()) 
00096     { _M_t.insert_unique(__first, __last); }
00097 
00098   set(const value_type* __first, 
00099       const value_type* __last, const _Compare& __comp,
00100       const allocator_type& __a = allocator_type())
00101     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00102 
00103   set(const_iterator __first, const_iterator __last)
00104     : _M_t(_Compare(), allocator_type()) 
00105     { _M_t.insert_unique(__first, __last); }
00106 
00107   set(const_iterator __first, const_iterator __last, const _Compare& __comp,
00108       const allocator_type& __a = allocator_type())
00109     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00110 #endif /* _STLP_MEMBER_TEMPLATES */
00111 
00112   set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
00113   set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
00114   { 
00115     _M_t = __x._M_t; 
00116     return *this;
00117   }
00118 
00119   // accessors:
00120 
00121   key_compare key_comp() const { return _M_t.key_comp(); }
00122   value_compare value_comp() const { return _M_t.key_comp(); }
00123   allocator_type get_allocator() const { return _M_t.get_allocator(); }
00124 
00125   iterator begin() const { return _M_t.begin(); }
00126   iterator end() const { return _M_t.end(); }
00127   reverse_iterator rbegin() const { return _M_t.rbegin(); } 
00128   reverse_iterator rend() const { return _M_t.rend(); }
00129   bool empty() const { return _M_t.empty(); }
00130   size_type size() const { return _M_t.size(); }
00131   size_type max_size() const { return _M_t.max_size(); }
00132   void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
00133 
00134   // insert/erase
00135   pair<iterator,bool> insert(const value_type& __x) { 
00136     typedef typename _Rep_type::iterator _Rep_iterator;
00137     pair<_Rep_iterator, bool> __p = _M_t.insert_unique(__x); 
00138     return pair<iterator, bool>(__REINTERPRET_CAST(const iterator&,__p.first), __p.second);
00139   }
00140   iterator insert(iterator __position, const value_type& __x) {
00141     typedef typename _Rep_type::iterator _Rep_iterator;
00142     return _M_t.insert_unique((_Rep_iterator&)__position, __x);
00143   }
00144 #ifdef _STLP_MEMBER_TEMPLATES
00145   template <class _InputIterator>
00146   void insert(_InputIterator __first, _InputIterator __last) {
00147     _M_t.insert_unique(__first, __last);
00148   }
00149 #else
00150   void insert(const_iterator __first, const_iterator __last) {
00151     _M_t.insert_unique(__first, __last);
00152   }
00153   void insert(const value_type* __first, const value_type* __last) {
00154     _M_t.insert_unique(__first, __last);
00155   }
00156 #endif /* _STLP_MEMBER_TEMPLATES */
00157   void erase(iterator __position) { 
00158     typedef typename _Rep_type::iterator _Rep_iterator;
00159     _M_t.erase((_Rep_iterator&)__position); 
00160   }
00161   size_type erase(const key_type& __x) { 
00162     return _M_t.erase(__x); 
00163   }
00164   void erase(iterator __first, iterator __last) { 
00165     typedef typename _Rep_type::iterator _Rep_iterator;
00166     _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); 
00167   }
00168   void clear() { _M_t.clear(); }
00169 
00170   // set operations:
00171 # if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS )
00172   template <class _KT>
00173   iterator find(const _KT& __x) const { return _M_t.find(__x); }
00174 # else
00175   iterator find(const key_type& __x) const { return _M_t.find(__x); }
00176 # endif
00177   size_type count(const key_type& __x) const { 
00178     return _M_t.find(__x) == _M_t.end() ? 0 : 1 ; 
00179   }
00180   iterator lower_bound(const key_type& __x) const {
00181     return _M_t.lower_bound(__x);
00182   }
00183   iterator upper_bound(const key_type& __x) const {
00184     return _M_t.upper_bound(__x); 
00185   }
00186   pair<iterator,iterator> equal_range(const key_type& __x) const {
00187     return _M_t.equal_range(__x);
00188   }
00189 };
00190 
00191 template <class _Key, __DFL_TMPL_PARAM(_Compare,less<_Key>), 
00192                      _STLP_DEFAULT_ALLOCATOR_SELECT(_Key) >
00193 class multiset {
00194 public:
00195   // typedefs:
00196 
00197   typedef _Key     key_type;
00198   typedef _Key     value_type;
00199   typedef _Compare key_compare;
00200   typedef _Compare value_compare;
00201 private:
00202   typedef _Rb_tree<key_type, value_type, 
00203                   _Identity<value_type>, key_compare, _Alloc> _Rep_type;
00204 public:
00205   typedef typename _Rep_type::pointer pointer;
00206   typedef typename _Rep_type::const_pointer const_pointer;
00207   typedef typename _Rep_type::reference reference;
00208   typedef typename _Rep_type::const_reference const_reference;
00209   typedef typename _Rep_type::const_iterator const_iterator;
00210   typedef const_iterator iterator;
00211   typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
00212   typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00213   typedef typename _Rep_type::size_type size_type;
00214   typedef typename _Rep_type::difference_type difference_type;
00215   typedef typename _Rep_type::allocator_type allocator_type;
00216 
00217 private:
00218   _Rep_type _M_t;  // red-black tree representing multiset
00219 public:
00220   // allocation/deallocation
00221 
00222   multiset() : _M_t(_Compare(), allocator_type()) {}
00223   explicit multiset(const _Compare& __comp,
00224                     const allocator_type& __a = allocator_type())
00225     : _M_t(__comp, __a) {}
00226 
00227 #ifdef _STLP_MEMBER_TEMPLATES
00228 
00229   template <class _InputIterator>
00230   multiset(_InputIterator __first, _InputIterator __last)
00231     : _M_t(_Compare(), allocator_type())
00232     { _M_t.insert_equal(__first, __last); }
00233 
00234 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
00235   template <class _InputIterator>
00236   multiset(_InputIterator __first, _InputIterator __last,
00237            const _Compare& __comp)
00238     : _M_t(__comp, allocator_type()) { _M_t.insert_equal(__first, __last); }
00239 # endif
00240   template <class _InputIterator>
00241   multiset(_InputIterator __first, _InputIterator __last,
00242            const _Compare& __comp,
00243            const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00244     : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
00245 
00246 #else
00247 
00248   multiset(const value_type* __first, const value_type* __last)
00249     : _M_t(_Compare(), allocator_type())
00250     { _M_t.insert_equal(__first, __last); }
00251 
00252   multiset(const value_type* __first, const value_type* __last,
00253            const _Compare& __comp,
00254            const allocator_type& __a = allocator_type())
00255     : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
00256 
00257   multiset(const_iterator __first, const_iterator __last)
00258     : _M_t(_Compare(), allocator_type())
00259     { _M_t.insert_equal(__first, __last); }
00260 
00261   multiset(const_iterator __first, const_iterator __last,
00262            const _Compare& __comp,
00263            const allocator_type& __a = allocator_type())
00264     : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
00265    
00266 #endif /* _STLP_MEMBER_TEMPLATES */
00267 
00268   multiset(const multiset<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
00269   multiset<_Key,_Compare,_Alloc>&
00270   operator=(const multiset<_Key,_Compare,_Alloc>& __x) {
00271     _M_t = __x._M_t; 
00272     return *this;
00273   }
00274 
00275   // accessors:
00276 
00277   key_compare key_comp() const { return _M_t.key_comp(); }
00278   value_compare value_comp() const { return _M_t.key_comp(); }
00279   allocator_type get_allocator() const { return _M_t.get_allocator(); }
00280 
00281   iterator begin() const { return _M_t.begin(); }
00282   iterator end() const { return _M_t.end(); }
00283   reverse_iterator rbegin() const { return _M_t.rbegin(); } 
00284   reverse_iterator rend() const { return _M_t.rend(); }
00285   bool empty() const { return _M_t.empty(); }
00286   size_type size() const { return _M_t.size(); }
00287   size_type max_size() const { return _M_t.max_size(); }
00288   void swap(multiset<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
00289 
00290   // insert/erase
00291   iterator insert(const value_type& __x) { 
00292     return _M_t.insert_equal(__x);
00293   }
00294   iterator insert(iterator __position, const value_type& __x) {
00295     typedef typename _Rep_type::iterator _Rep_iterator;
00296     return _M_t.insert_equal((_Rep_iterator&)__position, __x);
00297   }
00298 
00299 #ifdef _STLP_MEMBER_TEMPLATES  
00300   template <class _InputIterator>
00301   void insert(_InputIterator __first, _InputIterator __last) {
00302     _M_t.insert_equal(__first, __last);
00303   }
00304 #else
00305   void insert(const value_type* __first, const value_type* __last) {
00306     _M_t.insert_equal(__first, __last);
00307   }
00308   void insert(const_iterator __first, const_iterator __last) {
00309     _M_t.insert_equal(__first, __last);
00310   }
00311 #endif /* _STLP_MEMBER_TEMPLATES */
00312   void erase(iterator __position) { 
00313     typedef typename _Rep_type::iterator _Rep_iterator;
00314     _M_t.erase((_Rep_iterator&)__position); 
00315   }
00316   size_type erase(const key_type& __x) { 
00317     return _M_t.erase(__x); 
00318   }
00319   void erase(iterator __first, iterator __last) { 
00320     typedef typename _Rep_type::iterator _Rep_iterator;
00321     _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); 
00322   }
00323   void clear() { _M_t.clear(); }
00324 
00325   // multiset operations:
00326 
00327 # if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS )
00328   template <class _KT>
00329   iterator find(const _KT& __x) const { return _M_t.find(__x); }
00330 # else
00331   iterator find(const key_type& __x) const { return _M_t.find(__x); }
00332 # endif
00333   size_type count(const key_type& __x) const { return _M_t.count(__x); }
00334   iterator lower_bound(const key_type& __x) const {
00335     return _M_t.lower_bound(__x);
00336   }
00337   iterator upper_bound(const key_type& __x) const {
00338     return _M_t.upper_bound(__x); 
00339   }
00340   pair<iterator,iterator> equal_range(const key_type& __x) const {
00341     return _M_t.equal_range(__x);
00342   }
00343 };
00344 
00345 # define _STLP_TEMPLATE_HEADER template <class _Key, class _Compare, class _Alloc>
00346 # define _STLP_TEMPLATE_CONTAINER set<_Key,_Compare,_Alloc>
00347 # include <stl/_relops_cont.h>
00348 # undef  _STLP_TEMPLATE_CONTAINER
00349 # define _STLP_TEMPLATE_CONTAINER multiset<_Key,_Compare,_Alloc>
00350 # include <stl/_relops_cont.h>
00351 # undef  _STLP_TEMPLATE_CONTAINER
00352 # undef  _STLP_TEMPLATE_HEADER
00353 
00354 _STLP_END_NAMESPACE
00355 
00356 // do a cleanup
00357 # undef set
00358 # undef multiset
00359 // provide a way to access full funclionality 
00360 # define __set__  __FULL_NAME(set)
00361 # define __multiset__  __FULL_NAME(multiset)
00362 
00363 # ifdef _STLP_USE_WRAPPER_FOR_ALLOC_PARAM
00364 # include <stl/wrappers/_set.h>
00365 # endif
00366 
00367 #endif /* _STLP_INTERNAL_SET_H */
00368 
00369 // Local Variables:
00370 // mode:C++
00371 // End:
00372 

Generated on Mon Jun 5 10:20:47 2006 for Intelligence.kdevelop by  doxygen 1.4.6