_hashtable.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_DBG_HASHTABLE_H
00031 #define _STLP_INTERNAL_DBG_HASHTABLE_H
00032 
00033 // Hashtable class, used to implement the hashed associative containers
00034 // hash_set, hash_map, hash_multiset, and hash_multimap.
00035 
00036 # include <stl/debug/_iterator.h>
00037 
00038 #  undef  hashtable
00039 #  undef  _DBG_hashtable
00040 #  define _DBG_hashtable  hashtable
00041 
00042 #  define _STLP_DBG_HT_SUPER \
00043 __WORKAROUND_DBG_RENAME(hashtable) <_Val, _Key, _HF, _ExK, _EqK, _All>
00044 
00045 _STLP_BEGIN_NAMESPACE
00046 
00047 # ifdef _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS
00048 template <class _Val, class _Key, class _HF,
00049           class _ExK, class _EqK, class _All>
00050 inline _Val*
00051 value_type(const  _DBG_iter_base< _STLP_DBG_HT_SUPER >&) {
00052   return (_Val*)0;
00053 }
00054 
00055 template <class _Val, class _Key, class _HF,
00056           class _ExK, class _EqK, class _All>
00057 inline forward_iterator_tag
00058 iterator_category(const  _DBG_iter_base< _STLP_DBG_HT_SUPER >&) {
00059   return forward_iterator_tag();
00060 }
00061 # endif
00062 
00063 template <class _Val, class _Key, class _HF,
00064           class _ExK, class _EqK, class _All>
00065 class _DBG_hashtable : public _STLP_DBG_HT_SUPER {
00066   typedef _DBG_hashtable<_Val, _Key, _HF, _ExK, _EqK, _All> _Self;
00067   typedef _STLP_DBG_HT_SUPER _Base;
00068 public:
00069   typedef _Key key_type;
00070   typedef _HF hasher;
00071   typedef _EqK key_equal;
00072 
00073   __IMPORT_CONTAINER_TYPEDEFS(_Base)
00074 
00075 public:
00076   typedef _DBG_iter<_Base, _Nonconst_traits<value_type> >  iterator;
00077   typedef _DBG_iter<_Base, _Const_traits<value_type> > const_iterator;
00078   typedef typename _Base::iterator _Base_iterator;
00079   typedef typename _Base::const_iterator _Base_const_iterator;
00080 
00081 public:
00082   _DBG_hashtable(size_type __n,
00083                  const _HF&  __hf,
00084                  const _EqK& __eql,
00085                  const _ExK& __ext,
00086                  const allocator_type& __a = allocator_type()):
00087     _STLP_DBG_HT_SUPER(__n, __hf, __eql, __ext, __a),
00088     _M_iter_list((_Base*)this) {}
00089   
00090   _DBG_hashtable(size_type __n,
00091                  const _HF&    __hf,
00092                  const _EqK&   __eql,
00093                  const allocator_type& __a = allocator_type()):
00094     
00095     _STLP_DBG_HT_SUPER(__n, __hf, __eql, __a),
00096     _M_iter_list((_Base*)this) {}
00097   
00098   _DBG_hashtable(const _Self& __ht):
00099     _STLP_DBG_HT_SUPER(__ht),
00100     _M_iter_list((_Base*)this) {}
00101   
00102   _Self& operator= (const _Self& __ht) {
00103     _M_iter_list._Invalidate_all();
00104     _Base::operator=(__ht);
00105     return *this;
00106   }
00107   
00108   void swap(_Self& __ht)
00109   {
00110    _M_iter_list._Swap_owners(__ht._M_iter_list);
00111    _Base::swap(__ht);
00112   }
00113 
00114   iterator begin() { return iterator(&_M_iter_list, _Base::begin()); }
00115   iterator end()   { return iterator(&_M_iter_list, _Base::end()); }
00116 
00117   const_iterator begin() const { return const_iterator(&_M_iter_list, _Base::begin()); }
00118   const_iterator end() const { return const_iterator(&_M_iter_list, _Base::end()); }
00119 
00120   pair<iterator, bool> insert_unique(const value_type& __obj)
00121   {
00122     pair < _Base_iterator, bool> __res =
00123       _Base::insert_unique(__obj);
00124     return pair<iterator, bool> ( iterator(&_M_iter_list, __res.first), __res.second);
00125   }
00126 
00127   iterator insert_equal(const value_type& __obj) {
00128     return iterator(&_M_iter_list, _Base::insert_equal(__obj));
00129   }
00130   
00131   pair<iterator, bool> insert_unique_noresize(const value_type& __obj) {
00132     pair < _Base_iterator, bool> __res =
00133       _Base::insert_unique_noresize(__obj);
00134     return pair<iterator, bool> ( iterator(&_M_iter_list, __res.first), __res.second);
00135   }
00136   
00137   iterator insert_equal_noresize(const value_type& __obj) {
00138     return iterator(&_M_iter_list, _Base::insert_equal_noresize(__obj));
00139   }
00140   
00141 #ifdef _STLP_MEMBER_TEMPLATES
00142   template <class _InputIterator>
00143   void insert_unique(_InputIterator __f, _InputIterator __l) {
00144     _Base::insert_unique(__f, __l);
00145   }
00146 
00147   template <class _InputIterator>
00148   void insert_equal(_InputIterator __f, _InputIterator __l){
00149     _Base::insert_equal(__f, __l);
00150   }
00151 
00152 #else /* _STLP_MEMBER_TEMPLATES */
00153 
00154   void insert_unique(const value_type* __f, const value_type* __l) {
00155     _Base::insert_unique(__f, __l);
00156   }
00157   
00158   void insert_equal(const value_type* __f, const value_type* __l) {
00159     _Base::insert_equal(__f, __l);
00160   }
00161   
00162   void insert_unique(const_iterator __f, const_iterator __l) {
00163     _Base::insert_unique(__f._M_iterator, __l._M_iterator);
00164   }
00165   
00166   void insert_equal(const_iterator __f, const_iterator __l) {
00167     _Base::insert_equal(__f._M_iterator, __l._M_iterator);
00168   }
00169 #endif /*_STLP_MEMBER_TEMPLATES */
00170   
00171   iterator find(const key_type& __key) {
00172     return iterator(&_M_iter_list, _Base::find(__key));
00173   } 
00174 
00175   const_iterator find(const key_type& __key) const {
00176     return const_iterator(&_M_iter_list, _Base::find(__key));
00177   } 
00178 
00179   pair<iterator, iterator> 
00180   equal_range(const key_type& __key) {
00181     pair < _Base_iterator, _Base_iterator > __res =
00182       _Base::equal_range(__key);
00183     return pair<iterator,iterator> (iterator(&_M_iter_list,__res.first),
00184                                     iterator(&_M_iter_list,__res.second));
00185   }
00186 
00187   pair<const_iterator, const_iterator> 
00188   equal_range(const key_type& __key) const {
00189     pair <  _Base_const_iterator, _Base_const_iterator > __res =
00190       _Base::equal_range(__key);
00191     return pair<const_iterator,const_iterator> (const_iterator(&_M_iter_list,__res.first),
00192                                     const_iterator(&_M_iter_list,__res.second));
00193   }
00194 
00195   size_type erase(const key_type& __key) {
00196     return _Base::erase(__key);
00197   }
00198 
00199   void erase(const const_iterator& __it) {
00200     _STLP_VERBOSE_ASSERT(__it._Owner()==&_M_iter_list, _StlMsg_NOT_OWNER)
00201     _Base::erase(__it._M_iterator);
00202   }
00203   void erase(const_iterator __first, const_iterator __last) {
00204     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __first)&&
00205                       __check_if_owner(&_M_iter_list, __last))
00206     _Base::erase(__first._M_iterator, __last._M_iterator);
00207   }
00208   void resize(size_type __num_elements_hint) {
00209     _Base::resize(__num_elements_hint);
00210   }
00211   
00212   void clear() {
00213     _M_iter_list._Invalidate_all();
00214     _Base::clear();
00215   }
00216 
00217 private:
00218   __owned_list _M_iter_list;
00219 
00220 };
00221 
00222 #ifdef _STLP_EXTRA_OPERATORS_FOR_DEBUG
00223 template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
00224 inline bool operator==(const  _DBG_hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>& __ht1,
00225                        const  _DBG_hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>& __ht2)
00226 {
00227   return hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::_M_equal( __ht1, __ht2 );
00228 }
00229 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
00230 template <class _Val, class _Key, class _HF, class _Ex, class _Eq, class _All>
00231 inline bool operator!=(const  _DBG_hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>& __ht1,
00232                        const  _DBG_hashtable<_Val,_Key,_HF,_Ex,_Eq,_All>& __ht2) {
00233   return !(__ht1 == __ht2);
00234 }
00235 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
00236 
00237 #endif /* _STLP_EXTRA_OPERATORS_FOR_DEBUG */
00238 
00239 #ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
00240 template <class _Val, class _Key, class _HF, class _ExK, class _EqK, 
00241           class _All>
00242 inline void swap( _DBG_hashtable<_Val, _Key, _HF, _ExK, _EqK, _All>& __ht1,
00243                   _DBG_hashtable<_Val, _Key, _HF, _ExK, _EqK, _All>& __ht2) {
00244   __ht1.swap(__ht2);
00245 }
00246 #endif
00247 _STLP_END_NAMESPACE
00248 #  undef  hashtable
00249 
00250 #endif /* _STLP_INTERNAL_HASHTABLE_H */
00251 
00252 // Local Variables:
00253 // mode:C++
00254 // End:
00255 
00256 

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