epoc32/include/tools/stlport/stl/debug/_hashtable.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  *
     3  * Copyright (c) 1994
     4  * Hewlett-Packard Company
     5  *
     6  * Copyright (c) 1996,1997
     7  * Silicon Graphics Computer Systems, Inc.
     8  *
     9  * Copyright (c) 1997
    10  * Moscow Center for SPARC Technology
    11  *
    12  * Copyright (c) 1999
    13  * Boris Fomitchev
    14  *
    15  * This material is provided "as is", with absolutely no warranty expressed
    16  * or implied. Any use is at your own risk.
    17  *
    18  * Permission to use or copy this software for any purpose is hereby granted
    19  * without fee, provided the above notices are retained on all copies.
    20  * Permission to modify the code and to distribute modified code is granted,
    21  * provided the above notices are retained, and a notice that the code was
    22  * modified is included with the above copyright notice.
    23  *
    24  */
    25 
    26 /* NOTE: This is an internal header file, included by other STL headers.
    27  *   You should not attempt to use it directly.
    28  */
    29 
    30 #ifndef _STLP_INTERNAL_DBG_HASHTABLE_H
    31 #define _STLP_INTERNAL_DBG_HASHTABLE_H
    32 
    33 // Hashtable class, used to implement the hashed associative containers
    34 // hash_set, hash_map, hash_multiset, and hash_multimap,
    35 // unordered_set, unordered_map, unordered_multiset, unordered_multimap
    36 
    37 #ifndef _STLP_DBG_ITERATOR_H
    38 #  include <stl/debug/_iterator.h>
    39 #endif
    40 
    41 _STLP_BEGIN_NAMESPACE
    42 
    43 _STLP_MOVE_TO_PRIV_NAMESPACE
    44 
    45 template <class _Key, class _Equal>
    46 class _DbgEqual {
    47 public:
    48   _DbgEqual() {}
    49   _DbgEqual(const _Equal& __eq) : _M_non_dbg_eq(__eq) {}
    50   _DbgEqual(const _DbgEqual& __eq) : _M_non_dbg_eq(__eq._M_non_dbg_eq) {}
    51 
    52 #if !defined (_STLP_USE_CONTAINERS_EXTENSION)
    53   bool operator () (const _Key& __lhs, const _Key& __rhs) const {
    54 #else
    55   template <class _Kp1, class _Kp2>
    56   bool operator () (const _Kp1& __lhs, const _Kp2& __rhs) const {
    57 #endif
    58     if (_M_non_dbg_eq(__lhs, __rhs)) {
    59       _STLP_VERBOSE_ASSERT(_M_non_dbg_eq(__rhs, __lhs), _StlMsg_INVALID_EQUIVALENT_PREDICATE)
    60       return true;
    61     }
    62     else {
    63       _STLP_VERBOSE_ASSERT(!_M_non_dbg_eq(__rhs, __lhs), _StlMsg_INVALID_EQUIVALENT_PREDICATE)
    64       return false;
    65     }
    66   }
    67 
    68   _Equal non_dbg_key_eq() const { return _M_non_dbg_eq; }
    69 private:
    70   _Equal _M_non_dbg_eq;
    71 };
    72 
    73 _STLP_MOVE_TO_STD_NAMESPACE
    74 
    75 #define _STLP_NON_DBG_HT \
    76 _STLP_PRIV _STLP_NON_DBG_NAME(hashtable) <_Val, _Key, _HF, _Traits, _ExK, _STLP_PRIV _DbgEqual<_Key, _EqK>, _All>
    77 
    78 #if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
    79 template <class _Val, class _Key, class _HF,
    80           class _ExK, class _EqK, class _All>
    81 inline _Val*
    82 value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_HT >&)
    83 { return (_Val*)0; }
    84 
    85 template <class _Val, class _Key, class _HF,
    86           class _ExK, class _EqK, class _All>
    87 inline forward_iterator_tag
    88 iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_HT >&)
    89 { return forward_iterator_tag(); }
    90 #endif
    91 
    92 template <class _Val, class _Key, class _HF,
    93           class _Traits, class _ExK, class _EqK, class _All>
    94 class hashtable {
    95   typedef hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All> _Self;
    96   typedef _STLP_NON_DBG_HT _Base;
    97 
    98   typedef typename _Traits::_NonConstTraits _NonConstTraits;
    99   typedef typename _Traits::_ConstTraits _ConstTraits;
   100   typedef typename _Traits::_NonConstLocalTraits _NonConstLocalTraits;
   101   typedef typename _Traits::_ConstLocalTraits _ConstLocalTraits;
   102 
   103   _Base _M_non_dbg_impl;
   104   _STLP_PRIV __owned_list _M_iter_list;
   105 
   106 public:
   107   typedef _Key key_type;
   108   typedef _HF hasher;
   109   typedef _EqK key_equal;
   110 
   111   __IMPORT_CONTAINER_TYPEDEFS(_Base)
   112 
   113   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_NonConstTraits> > iterator;
   114   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_ConstTraits> >    const_iterator;
   115   //typedef _STLP_PRIV _DBG_iter<_Base, _DbgTraits<_NonConstLocalTraits> > local_iterator;
   116   typedef iterator local_iterator;
   117   //typedef _STLP_PRIV _DBG_iter<_Base, _DbgTraits<_ConstLocalTraits> >    const_local_iterator;
   118   typedef const_iterator const_local_iterator;
   119 
   120   typedef typename _Base::iterator _Base_iterator;
   121   typedef typename _Base::const_iterator _Base_const_iterator;
   122 
   123   hasher hash_funct() const { return _M_non_dbg_impl.hash_funct(); }
   124   key_equal key_eq() const { return _M_non_dbg_impl.key_eq().non_dbg_key_eq(); }
   125 
   126 private:
   127   void _Invalidate_iterator(const const_iterator& __it)
   128   { _STLP_PRIV __invalidate_iterator(&_M_iter_list, __it); }
   129   void _Invalidate_iterators(const const_iterator& __first, const const_iterator& __last)
   130   { _STLP_PRIV __invalidate_range(&_M_iter_list, __first, __last); }
   131 
   132   _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
   133 
   134 public:
   135   allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
   136 
   137   hashtable(size_type __n,
   138             const _HF&  __hf,
   139             const _EqK& __eql,
   140             const _ExK& __ext,
   141             const allocator_type& __a = allocator_type())
   142     : _M_non_dbg_impl(__n, __hf, __eql, __ext, __a),
   143       _M_iter_list(&_M_non_dbg_impl) {}
   144 
   145   hashtable(size_type __n,
   146             const _HF&    __hf,
   147             const _EqK&   __eql,
   148             const allocator_type& __a = allocator_type())
   149     : _M_non_dbg_impl(__n, __hf, __eql, __a),
   150       _M_iter_list(&_M_non_dbg_impl) {}
   151 
   152   hashtable(const _Self& __ht)
   153     : _M_non_dbg_impl(__ht._M_non_dbg_impl),
   154       _M_iter_list(&_M_non_dbg_impl) {}
   155 
   156   hashtable(__move_source<_Self> src)
   157     : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
   158       _M_iter_list(&_M_non_dbg_impl) {
   159 #if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
   160     src.get()._M_iter_list._Invalidate_all();
   161 #else
   162     src.get()._M_iter_list._Set_owner(_M_iter_list);
   163 #endif
   164   }
   165 
   166   size_type size() const { return _M_non_dbg_impl.size(); }
   167   size_type max_size() const { return _M_non_dbg_impl.max_size(); }
   168   bool empty() const { return _M_non_dbg_impl.empty(); }
   169 
   170   _Self& operator=(const _Self& __ht) {
   171     if (this != &__ht) {
   172       //Should not invalidate end iterator
   173       _Invalidate_iterators(begin(), end());
   174       _M_non_dbg_impl = __ht._M_non_dbg_impl;
   175     }
   176     return *this;
   177   }
   178 
   179   void swap(_Self& __ht) {
   180    _M_iter_list._Swap_owners(__ht._M_iter_list);
   181    _M_non_dbg_impl.swap(__ht._M_non_dbg_impl);
   182   }
   183 
   184   iterator begin() { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
   185   iterator end()   { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
   186   local_iterator begin(size_type __n) {
   187     //TODO: Add checks for iterator locality -> avoids comparison between different bucket iterators
   188     _STLP_VERBOSE_ASSERT((__n < bucket_count()), _StlMsg_INVALID_ARGUMENT)
   189     return local_iterator(&_M_iter_list, _M_non_dbg_impl.begin(__n));
   190   }
   191   local_iterator end(size_type __n) {
   192     //TODO: Add checks for iterator locality -> avoids comparison between different bucket iterators
   193     _STLP_VERBOSE_ASSERT((__n < bucket_count()), _StlMsg_INVALID_ARGUMENT)
   194     return local_iterator(&_M_iter_list, _M_non_dbg_impl.end(__n));
   195   }
   196 
   197   const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
   198   const_iterator end() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
   199   const_local_iterator begin(size_type __n) const {
   200     //TODO: Add checks for iterator locality -> avoids comparison between different bucket iterators
   201     _STLP_VERBOSE_ASSERT((__n < bucket_count()), _StlMsg_INVALID_ARGUMENT)
   202     return const_local_iterator(&_M_iter_list, _M_non_dbg_impl.begin(__n));
   203   }
   204   const_local_iterator end(size_type __n) const {
   205     //TODO: Add checks for iterator locality -> avoids comparison between different bucket iterators
   206     _STLP_VERBOSE_ASSERT((__n < bucket_count()), _StlMsg_INVALID_ARGUMENT)
   207     return const_local_iterator(&_M_iter_list, _M_non_dbg_impl.end(__n));
   208   }
   209 
   210   pair<iterator, bool> insert_unique(const value_type& __obj) {
   211     pair<_Base_iterator, bool> __res = _M_non_dbg_impl.insert_unique(__obj);
   212     return pair<iterator, bool>(iterator(&_M_iter_list, __res.first), __res.second);
   213   }
   214 
   215   iterator insert_equal(const value_type& __obj)
   216   { return iterator(&_M_iter_list, _M_non_dbg_impl.insert_equal(__obj)); }
   217 
   218   pair<iterator, bool> insert_unique_noresize(const value_type& __obj) {
   219     pair<_Base_iterator, bool> __res = _M_non_dbg_impl.insert_unique_noresize(__obj);
   220     return pair<iterator, bool>(iterator(&_M_iter_list, __res.first), __res.second);
   221   }
   222 
   223   iterator insert_equal_noresize(const value_type& __obj)
   224   { return iterator(&_M_iter_list, _M_non_dbg_impl.insert_equal_noresize(__obj)); }
   225 
   226 #if defined (_STLP_MEMBER_TEMPLATES)
   227   template <class _InputIterator>
   228   void insert_unique(_InputIterator __f, _InputIterator __l) {
   229     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
   230     _M_non_dbg_impl.insert_unique(_STLP_PRIV _Non_Dbg_iter(__f), _STLP_PRIV _Non_Dbg_iter(__l));
   231   }
   232 
   233   template <class _InputIterator>
   234   void insert_equal(_InputIterator __f, _InputIterator __l){
   235     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
   236     _M_non_dbg_impl.insert_equal(_STLP_PRIV _Non_Dbg_iter(__f), _STLP_PRIV _Non_Dbg_iter(__l));
   237   }
   238 
   239 #else
   240   void insert_unique(const value_type* __f, const value_type* __l) {
   241     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__f, __l))
   242     _M_non_dbg_impl.insert_unique(__f, __l);
   243   }
   244 
   245   void insert_equal(const value_type* __f, const value_type* __l) {
   246     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__f, __l))
   247     _M_non_dbg_impl.insert_equal(__f, __l);
   248   }
   249 
   250   void insert_unique(const_iterator __f, const_iterator __l) {
   251     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
   252     _M_non_dbg_impl.insert_unique(__f._M_iterator, __l._M_iterator);
   253   }
   254 
   255   void insert_equal(const_iterator __f, const_iterator __l) {
   256     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
   257     _M_non_dbg_impl.insert_equal(__f._M_iterator, __l._M_iterator);
   258   }
   259 #endif
   260 
   261   _STLP_TEMPLATE_FOR_CONT_EXT
   262   iterator find(const _KT& __key)
   263   { return iterator(&_M_iter_list, _M_non_dbg_impl.find(__key)); }
   264   _STLP_TEMPLATE_FOR_CONT_EXT
   265   const_iterator find(const _KT& __key) const
   266   { return const_iterator(&_M_iter_list, _M_non_dbg_impl.find(__key)); }
   267 
   268   _STLP_TEMPLATE_FOR_CONT_EXT
   269   size_type count(const _KT& __key) const { return _M_non_dbg_impl.count(__key); }
   270 
   271   _STLP_TEMPLATE_FOR_CONT_EXT
   272   pair<iterator, iterator> equal_range(const _KT& __key) {
   273     pair<_Base_iterator, _Base_iterator> __res = _M_non_dbg_impl.equal_range(__key);
   274     return pair<iterator,iterator> (iterator(&_M_iter_list,__res.first),
   275                                     iterator(&_M_iter_list,__res.second));
   276   }
   277 
   278   _STLP_TEMPLATE_FOR_CONT_EXT
   279   pair<const_iterator, const_iterator> equal_range(const _KT& __key) const {
   280     pair <_Base_const_iterator, _Base_const_iterator> __res = _M_non_dbg_impl.equal_range(__key);
   281     return pair<const_iterator,const_iterator> (const_iterator(&_M_iter_list,__res.first),
   282                                                 const_iterator(&_M_iter_list,__res.second));
   283   }
   284 
   285   size_type erase(const key_type& __key) {
   286     pair<_Base_iterator, _Base_iterator> __p = _M_non_dbg_impl.equal_range(__key);
   287     size_type __n = _STLP_STD::distance(__p.first, __p.second);
   288     _Invalidate_iterators(const_iterator(&_M_iter_list, __p.first), const_iterator(&_M_iter_list, __p.second));
   289     _M_non_dbg_impl.erase(__p.first, __p.second);
   290     return __n;
   291   }
   292 
   293   void erase(const const_iterator& __it) {
   294     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__it))
   295     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __it))
   296     _Invalidate_iterator(__it);
   297     _M_non_dbg_impl.erase(__it._M_iterator);
   298   }
   299   void erase(const_iterator __first, const_iterator __last) {
   300     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last,
   301                                                const_iterator(begin()), const_iterator(end())))
   302     _Invalidate_iterators(__first, __last);
   303     _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator);
   304   }
   305 
   306   void rehash(size_type __num_buckets_hint) { _M_non_dbg_impl.rehash(__num_buckets_hint); }
   307   void resize(size_type __num_elements_hint) { _M_non_dbg_impl.resize(__num_elements_hint); }
   308 
   309   void clear() {
   310     _Invalidate_iterators(begin(), end());
   311     _M_non_dbg_impl.clear();
   312   }
   313 
   314   reference _M_insert(const value_type& __obj) { return _M_non_dbg_impl._M_insert(__obj); }
   315 
   316   size_type bucket_count() const { return _M_non_dbg_impl.bucket_count(); }
   317   size_type max_bucket_count() const { return _M_non_dbg_impl.max_bucket_count(); }
   318   size_type elems_in_bucket(size_type __n) const {
   319     _STLP_VERBOSE_ASSERT((__n < bucket_count()), _StlMsg_INVALID_ARGUMENT)
   320     return _M_non_dbg_impl.elems_in_bucket(__n);
   321   }
   322   _STLP_TEMPLATE_FOR_CONT_EXT
   323   size_type bucket(const _KT& __k) const { return _M_non_dbg_impl.bucket(__k); }
   324 
   325   float load_factor() const { return _M_non_dbg_impl.load_factor(); }
   326   float max_load_factor() const { return _M_non_dbg_impl.max_load_factor(); }
   327   void max_load_factor(float __z) {
   328     _STLP_VERBOSE_ASSERT((__z > 0.0f), _StlMsg_INVALID_ARGUMENT)
   329     _M_non_dbg_impl.max_load_factor(__z);
   330   }
   331 };
   332 
   333 _STLP_END_NAMESPACE
   334 
   335 #undef _STLP_NON_DBG_HT
   336 
   337 #endif /* _STLP_INTERNAL_HASHTABLE_H */
   338 
   339 // Local Variables:
   340 // mode:C++
   341 // End: