ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_hashtable.h
Go to the documentation of this file.
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 // unordered_set, unordered_map, unordered_multiset, unordered_multimap
00036 
00037 #ifndef _STLP_DBG_ITERATOR_H
00038 #  include <stl/debug/_iterator.h>
00039 #endif
00040 
00041 _STLP_BEGIN_NAMESPACE
00042 
00043 _STLP_MOVE_TO_PRIV_NAMESPACE
00044 
00045 template <class _Key, class _Equal>
00046 class _DbgEqual {
00047 public:
00048   _DbgEqual() {}
00049   _DbgEqual(const _Equal& __eq) : _M_non_dbg_eq(__eq) {}
00050   _DbgEqual(const _DbgEqual& __eq) : _M_non_dbg_eq(__eq._M_non_dbg_eq) {}
00051 
00052 #if !defined (_STLP_USE_CONTAINERS_EXTENSION)
00053   bool operator () (const _Key& __lhs, const _Key& __rhs) const
00054 #else
00055   template <class _Kp1, class _Kp2>
00056   bool operator () (const _Kp1& __lhs, const _Kp2& __rhs) const
00057 #endif
00058       {
00059 #if !defined (_STLP_USE_CONTAINERS_EXTENSION)
00060         _STLP_VERBOSE_ASSERT(_M_non_dbg_eq(__rhs, __lhs) == _M_non_dbg_eq(__lhs, __rhs), _StlMsg_INVALID_EQUIVALENT_PREDICATE)
00061 #endif
00062         return _M_non_dbg_eq(__lhs, __rhs) ? true : false;
00063       }
00064 
00065   _Equal non_dbg_key_eq() const { return _M_non_dbg_eq; }
00066 private:
00067   _Equal _M_non_dbg_eq;
00068 };
00069 
00070 _STLP_MOVE_TO_STD_NAMESPACE
00071 
00072 #define _STLP_NON_DBG_HT \
00073 _STLP_PRIV _STLP_NON_DBG_NAME(hashtable) <_Val, _Key, _HF, _Traits, _ExK, _STLP_PRIV _DbgEqual<_Key, _EqK>, _All>
00074 
00075 #if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
00076 template <class _Val, class _Key, class _HF,
00077           class _ExK, class _EqK, class _All>
00078 inline _Val*
00079 value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_HT >&)
00080 { return (_Val*)0; }
00081 
00082 template <class _Val, class _Key, class _HF,
00083           class _ExK, class _EqK, class _All>
00084 inline forward_iterator_tag
00085 iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_HT >&)
00086 { return forward_iterator_tag(); }
00087 #endif
00088 
00089 template <class _Val, class _Key, class _HF,
00090           class _Traits, class _ExK, class _EqK, class _All>
00091 class hashtable {
00092   typedef hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All> _Self;
00093   typedef _STLP_NON_DBG_HT _Base;
00094 
00095   typedef typename _Traits::_NonConstTraits _NonConstTraits;
00096   typedef typename _Traits::_ConstTraits _ConstTraits;
00097   typedef typename _Traits::_NonConstLocalTraits _NonConstLocalTraits;
00098   typedef typename _Traits::_ConstLocalTraits _ConstLocalTraits;
00099 
00100   _Base _M_non_dbg_impl;
00101   _STLP_PRIV __owned_list _M_iter_list;
00102 
00103 public:
00104   typedef _Key key_type;
00105   typedef _HF hasher;
00106   typedef _EqK key_equal;
00107 
00108   __IMPORT_CONTAINER_TYPEDEFS(_Base)
00109 
00110   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_NonConstTraits> > iterator;
00111   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_ConstTraits> >    const_iterator;
00112   //typedef _STLP_PRIV _DBG_iter<_Base, _DbgTraits<_NonConstLocalTraits> > local_iterator;
00113   typedef iterator local_iterator;
00114   //typedef _STLP_PRIV _DBG_iter<_Base, _DbgTraits<_ConstLocalTraits> >    const_local_iterator;
00115   typedef const_iterator const_local_iterator;
00116 
00117   typedef typename _Base::iterator _Base_iterator;
00118   typedef typename _Base::const_iterator _Base_const_iterator;
00119 
00120   hasher hash_funct() const { return _M_non_dbg_impl.hash_funct(); }
00121   key_equal key_eq() const { return _M_non_dbg_impl.key_eq().non_dbg_key_eq(); }
00122 
00123 private:
00124   void _Invalidate_iterator(const const_iterator& __it)
00125   { _STLP_PRIV __invalidate_iterator(&_M_iter_list, __it); }
00126   void _Invalidate_iterators(const const_iterator& __first, const const_iterator& __last)
00127   { _STLP_PRIV __invalidate_range(&_M_iter_list, __first, __last); }
00128 
00129   _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
00130 
00131 public:
00132   allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
00133 
00134   hashtable(size_type __n,
00135             const _HF&  __hf,
00136             const _EqK& __eql,
00137             const _ExK& __ext,
00138             const allocator_type& __a = allocator_type())
00139     : _M_non_dbg_impl(__n, __hf, __eql, __ext, __a),
00140       _M_iter_list(&_M_non_dbg_impl) {}
00141 
00142   hashtable(size_type __n,
00143             const _HF&    __hf,
00144             const _EqK&   __eql,
00145             const allocator_type& __a = allocator_type())
00146     : _M_non_dbg_impl(__n, __hf, __eql, __a),
00147       _M_iter_list(&_M_non_dbg_impl) {}
00148 
00149   hashtable(const _Self& __ht)
00150     : _M_non_dbg_impl(__ht._M_non_dbg_impl),
00151       _M_iter_list(&_M_non_dbg_impl) {}
00152 
00153 #if !defined (_STLP_NO_MOVE_SEMANTIC)
00154   hashtable(__move_source<_Self> src)
00155     : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
00156       _M_iter_list(&_M_non_dbg_impl) {
00157 #  if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
00158     src.get()._M_iter_list._Invalidate_all();
00159 #  else
00160     src.get()._M_iter_list._Set_owner(_M_iter_list);
00161 #  endif
00162   }
00163 #endif
00164 
00165   size_type size() const { return _M_non_dbg_impl.size(); }
00166   size_type max_size() const { return _M_non_dbg_impl.max_size(); }
00167   bool empty() const { return _M_non_dbg_impl.empty(); }
00168 
00169   _Self& operator=(const _Self& __ht) {
00170     if (this != &__ht) {
00171       //Should not invalidate end iterator
00172       _Invalidate_iterators(begin(), end());
00173       _M_non_dbg_impl = __ht._M_non_dbg_impl;
00174     }
00175     return *this;
00176   }
00177 
00178   void swap(_Self& __ht) {
00179    _M_iter_list._Swap_owners(__ht._M_iter_list);
00180    _M_non_dbg_impl.swap(__ht._M_non_dbg_impl);
00181   }
00182 
00183   iterator begin() { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
00184   iterator end()   { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
00185   local_iterator begin(size_type __n) {
00186     //TODO: Add checks for iterator locality -> avoids comparison between different bucket iterators
00187     _STLP_VERBOSE_ASSERT((__n < bucket_count()), _StlMsg_INVALID_ARGUMENT)
00188     return local_iterator(&_M_iter_list, _M_non_dbg_impl.begin(__n));
00189   }
00190   local_iterator end(size_type __n) {
00191     //TODO: Add checks for iterator locality -> avoids comparison between different bucket iterators
00192     _STLP_VERBOSE_ASSERT((__n < bucket_count()), _StlMsg_INVALID_ARGUMENT)
00193     return local_iterator(&_M_iter_list, _M_non_dbg_impl.end(__n));
00194   }
00195 
00196   const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
00197   const_iterator end() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
00198   const_local_iterator begin(size_type __n) const {
00199     //TODO: Add checks for iterator locality -> avoids comparison between different bucket iterators
00200     _STLP_VERBOSE_ASSERT((__n < bucket_count()), _StlMsg_INVALID_ARGUMENT)
00201     return const_local_iterator(&_M_iter_list, _M_non_dbg_impl.begin(__n));
00202   }
00203   const_local_iterator end(size_type __n) const {
00204     //TODO: Add checks for iterator locality -> avoids comparison between different bucket iterators
00205     _STLP_VERBOSE_ASSERT((__n < bucket_count()), _StlMsg_INVALID_ARGUMENT)
00206     return const_local_iterator(&_M_iter_list, _M_non_dbg_impl.end(__n));
00207   }
00208 
00209   pair<iterator, bool> insert_unique(const value_type& __obj) {
00210     pair<_Base_iterator, bool> __res = _M_non_dbg_impl.insert_unique(__obj);
00211     return pair<iterator, bool>(iterator(&_M_iter_list, __res.first), __res.second);
00212   }
00213 
00214   iterator insert_equal(const value_type& __obj)
00215   { return iterator(&_M_iter_list, _M_non_dbg_impl.insert_equal(__obj)); }
00216 
00217   pair<iterator, bool> insert_unique_noresize(const value_type& __obj) {
00218     pair<_Base_iterator, bool> __res = _M_non_dbg_impl.insert_unique_noresize(__obj);
00219     return pair<iterator, bool>(iterator(&_M_iter_list, __res.first), __res.second);
00220   }
00221 
00222   iterator insert_equal_noresize(const value_type& __obj)
00223   { return iterator(&_M_iter_list, _M_non_dbg_impl.insert_equal_noresize(__obj)); }
00224 
00225 #if defined (_STLP_MEMBER_TEMPLATES)
00226   template <class _InputIterator>
00227   void insert_unique(_InputIterator __f, _InputIterator __l) {
00228     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
00229     _M_non_dbg_impl.insert_unique(_STLP_PRIV _Non_Dbg_iter(__f), _STLP_PRIV _Non_Dbg_iter(__l));
00230   }
00231 
00232   template <class _InputIterator>
00233   void insert_equal(_InputIterator __f, _InputIterator __l){
00234     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
00235     _M_non_dbg_impl.insert_equal(_STLP_PRIV _Non_Dbg_iter(__f), _STLP_PRIV _Non_Dbg_iter(__l));
00236   }
00237 
00238 #else
00239   void insert_unique(const value_type* __f, const value_type* __l) {
00240     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__f, __l))
00241     _M_non_dbg_impl.insert_unique(__f, __l);
00242   }
00243 
00244   void insert_equal(const value_type* __f, const value_type* __l) {
00245     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__f, __l))
00246     _M_non_dbg_impl.insert_equal(__f, __l);
00247   }
00248 
00249   void insert_unique(const_iterator __f, const_iterator __l) {
00250     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
00251     _M_non_dbg_impl.insert_unique(__f._M_iterator, __l._M_iterator);
00252   }
00253 
00254   void insert_equal(const_iterator __f, const_iterator __l) {
00255     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
00256     _M_non_dbg_impl.insert_equal(__f._M_iterator, __l._M_iterator);
00257   }
00258 #endif
00259 
00260   _STLP_TEMPLATE_FOR_CONT_EXT
00261   iterator find(const _KT& __key)
00262   { return iterator(&_M_iter_list, _M_non_dbg_impl.find(__key)); }
00263   _STLP_TEMPLATE_FOR_CONT_EXT
00264   const_iterator find(const _KT& __key) const
00265   { return const_iterator(&_M_iter_list, _M_non_dbg_impl.find(__key)); }
00266 
00267   _STLP_TEMPLATE_FOR_CONT_EXT
00268   size_type count(const _KT& __key) const { return _M_non_dbg_impl.count(__key); }
00269 
00270   _STLP_TEMPLATE_FOR_CONT_EXT
00271   pair<iterator, iterator> equal_range(const _KT& __key) {
00272     pair<_Base_iterator, _Base_iterator> __res = _M_non_dbg_impl.equal_range(__key);
00273     return pair<iterator,iterator> (iterator(&_M_iter_list,__res.first),
00274                                     iterator(&_M_iter_list,__res.second));
00275   }
00276 
00277   _STLP_TEMPLATE_FOR_CONT_EXT
00278   pair<const_iterator, const_iterator> equal_range(const _KT& __key) const {
00279     pair <_Base_const_iterator, _Base_const_iterator> __res = _M_non_dbg_impl.equal_range(__key);
00280     return pair<const_iterator,const_iterator> (const_iterator(&_M_iter_list,__res.first),
00281                                                 const_iterator(&_M_iter_list,__res.second));
00282   }
00283 
00284   size_type erase(const key_type& __key) {
00285     pair<iterator, iterator> __p = equal_range(__key);
00286     size_type __n = _STLP_STD::distance(__p.first, __p.second);
00287     _Invalidate_iterators(__p.first, __p.second);
00288     _M_non_dbg_impl.erase(__p.first._M_iterator, __p.second._M_iterator);
00289     return __n;
00290   }
00291 
00292   void erase(const const_iterator& __it) {
00293     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__it))
00294     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __it))
00295     _Invalidate_iterator(__it);
00296     _M_non_dbg_impl.erase(__it._M_iterator);
00297   }
00298   void erase(const_iterator __first, const_iterator __last) {
00299     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last,
00300                                                const_iterator(begin()), const_iterator(end())))
00301     _Invalidate_iterators(__first, __last);
00302     _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator);
00303   }
00304 
00305   void rehash(size_type __num_buckets_hint) { _M_non_dbg_impl.rehash(__num_buckets_hint); }
00306   void resize(size_type __num_elements_hint) { _M_non_dbg_impl.resize(__num_elements_hint); }
00307 
00308   void clear() {
00309     _Invalidate_iterators(begin(), end());
00310     _M_non_dbg_impl.clear();
00311   }
00312 
00313   reference _M_insert(const value_type& __obj) { return _M_non_dbg_impl._M_insert(__obj); }
00314 
00315   size_type bucket_count() const { return _M_non_dbg_impl.bucket_count(); }
00316   size_type max_bucket_count() const { return _M_non_dbg_impl.max_bucket_count(); }
00317   size_type elems_in_bucket(size_type __n) const {
00318     _STLP_VERBOSE_ASSERT((__n < bucket_count()), _StlMsg_INVALID_ARGUMENT)
00319     return _M_non_dbg_impl.elems_in_bucket(__n);
00320   }
00321   _STLP_TEMPLATE_FOR_CONT_EXT
00322   size_type bucket(const _KT& __k) const { return _M_non_dbg_impl.bucket(__k); }
00323 
00324   float load_factor() const { return _M_non_dbg_impl.load_factor(); }
00325   float max_load_factor() const { return _M_non_dbg_impl.max_load_factor(); }
00326   void max_load_factor(float __z) {
00327     _STLP_VERBOSE_ASSERT((__z > 0.0f), _StlMsg_INVALID_ARGUMENT)
00328     _M_non_dbg_impl.max_load_factor(__z);
00329   }
00330 };
00331 
00332 _STLP_END_NAMESPACE
00333 
00334 #undef _STLP_NON_DBG_HT
00335 
00336 #endif /* _STLP_INTERNAL_HASHTABLE_H */
00337 
00338 // Local Variables:
00339 // mode:C++
00340 // End:

Generated on Fri May 25 2012 04:27:38 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.