unordered_map.h

Go to the documentation of this file.
00001 // unordered_map implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2010 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file bits/unordered_map.h
00026  *  This is an internal header file, included by other library headers.
00027  *  You should not attempt to use it directly.
00028  */
00029 
00030 #ifndef _UNORDERED_MAP_H
00031 #define _UNORDERED_MAP_H
00032 
00033 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
00034 
00035   // XXX When we get typedef templates these class definitions
00036   // will be unnecessary.
00037   template<class _Key, class _Tp,
00038        class _Hash = hash<_Key>,
00039        class _Pred = std::equal_to<_Key>,
00040        class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
00041        bool __cache_hash_code = false>
00042     class __unordered_map
00043     : public _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
00044             std::_Select1st<std::pair<const _Key, _Tp> >, _Pred, 
00045             _Hash, __detail::_Mod_range_hashing,
00046             __detail::_Default_ranged_hash,
00047             __detail::_Prime_rehash_policy,
00048             __cache_hash_code, false, true>
00049     {
00050       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
00051              std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
00052              _Hash, __detail::_Mod_range_hashing,
00053              __detail::_Default_ranged_hash,
00054              __detail::_Prime_rehash_policy,
00055              __cache_hash_code, false, true>
00056         _Base;
00057 
00058     public:
00059       typedef typename _Base::size_type       size_type;
00060       typedef typename _Base::hasher          hasher;
00061       typedef typename _Base::key_equal       key_equal;
00062       typedef typename _Base::allocator_type  allocator_type;
00063 
00064       explicit
00065       __unordered_map(size_type __n = 10,
00066               const hasher& __hf = hasher(),
00067               const key_equal& __eql = key_equal(),
00068               const allocator_type& __a = allocator_type())
00069       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
00070           __detail::_Default_ranged_hash(),
00071           __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
00072       { }
00073 
00074       template<typename _InputIterator>
00075         __unordered_map(_InputIterator __f, _InputIterator __l, 
00076             size_type __n = 10,
00077             const hasher& __hf = hasher(), 
00078             const key_equal& __eql = key_equal(), 
00079             const allocator_type& __a = allocator_type())
00080     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
00081         __detail::_Default_ranged_hash(),
00082         __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
00083     { }
00084 
00085       __unordered_map(__unordered_map&& __x)
00086       : _Base(std::forward<_Base>(__x)) { }
00087     };
00088   
00089   template<class _Key, class _Tp,
00090        class _Hash = hash<_Key>,
00091        class _Pred = std::equal_to<_Key>,
00092        class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
00093        bool __cache_hash_code = false>
00094     class __unordered_multimap
00095     : public _Hashtable<_Key, std::pair<const _Key, _Tp>,
00096             _Alloc,
00097             std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
00098             _Hash, __detail::_Mod_range_hashing,
00099             __detail::_Default_ranged_hash,
00100             __detail::_Prime_rehash_policy,
00101             __cache_hash_code, false, false>
00102     {
00103       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>,
00104              _Alloc,
00105              std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
00106              _Hash, __detail::_Mod_range_hashing,
00107              __detail::_Default_ranged_hash,
00108              __detail::_Prime_rehash_policy,
00109              __cache_hash_code, false, false>
00110         _Base;
00111 
00112     public:
00113       typedef typename _Base::size_type       size_type;
00114       typedef typename _Base::hasher          hasher;
00115       typedef typename _Base::key_equal       key_equal;
00116       typedef typename _Base::allocator_type  allocator_type;
00117       
00118       explicit
00119       __unordered_multimap(size_type __n = 10,
00120                const hasher& __hf = hasher(),
00121                const key_equal& __eql = key_equal(),
00122                const allocator_type& __a = allocator_type())
00123       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
00124           __detail::_Default_ranged_hash(),
00125           __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
00126       { }
00127 
00128 
00129       template<typename _InputIterator>
00130         __unordered_multimap(_InputIterator __f, _InputIterator __l, 
00131                  typename _Base::size_type __n = 0,
00132                  const hasher& __hf = hasher(), 
00133                  const key_equal& __eql = key_equal(), 
00134                  const allocator_type& __a = allocator_type())
00135     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
00136         __detail::_Default_ranged_hash(),
00137         __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
00138         { }
00139 
00140       __unordered_multimap(__unordered_multimap&& __x)
00141       : _Base(std::forward<_Base>(__x)) { }
00142     };
00143 
00144   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
00145        bool __cache_hash_code>
00146     inline void
00147     swap(__unordered_map<_Key, _Tp, _Hash, _Pred,
00148      _Alloc, __cache_hash_code>& __x,
00149      __unordered_map<_Key, _Tp, _Hash, _Pred,
00150      _Alloc, __cache_hash_code>& __y)
00151     { __x.swap(__y); }
00152 
00153   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
00154        bool __cache_hash_code>
00155     inline void
00156     swap(__unordered_multimap<_Key, _Tp, _Hash, _Pred,
00157      _Alloc, __cache_hash_code>& __x,
00158      __unordered_multimap<_Key, _Tp, _Hash, _Pred,
00159      _Alloc, __cache_hash_code>& __y)
00160     { __x.swap(__y); }
00161 
00162 
00163   /**
00164    *  @brief A standard container composed of unique keys (containing
00165    *  at most one of each key value) that associates values of another type
00166    *  with the keys.
00167    *
00168    *  @ingroup unordered_associative_containers
00169    *
00170    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
00171    *  <a href="tables.html#xx">unordered associative container</a>
00172    *
00173    *  @param  Key  Type of key objects.
00174    *  @param  Tp  Type of mapped objects.
00175    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
00176    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
00177    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
00178    *
00179    * The resulting value type of the container is std::pair<const Key, Tp>.
00180    */
00181   template<class _Key, class _Tp,
00182        class _Hash = hash<_Key>,
00183        class _Pred = std::equal_to<_Key>,
00184        class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
00185     class unordered_map
00186     : public __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
00187     {
00188       typedef __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>  _Base;
00189 
00190     public:
00191       typedef typename _Base::value_type      value_type;
00192       typedef typename _Base::size_type       size_type;
00193       typedef typename _Base::hasher          hasher;
00194       typedef typename _Base::key_equal       key_equal;
00195       typedef typename _Base::allocator_type  allocator_type;
00196 
00197       explicit
00198       unordered_map(size_type __n = 10,
00199             const hasher& __hf = hasher(),
00200             const key_equal& __eql = key_equal(),
00201             const allocator_type& __a = allocator_type())
00202       : _Base(__n, __hf, __eql, __a)
00203       { }
00204 
00205       template<typename _InputIterator>
00206         unordered_map(_InputIterator __f, _InputIterator __l, 
00207               size_type __n = 10,
00208               const hasher& __hf = hasher(), 
00209               const key_equal& __eql = key_equal(), 
00210               const allocator_type& __a = allocator_type())
00211     : _Base(__f, __l, __n, __hf, __eql, __a)
00212         { }
00213 
00214       unordered_map(unordered_map&& __x)
00215       : _Base(std::forward<_Base>(__x)) { }
00216 
00217       unordered_map(initializer_list<value_type> __l,
00218             size_type __n = 10,
00219             const hasher& __hf = hasher(),
00220             const key_equal& __eql = key_equal(),
00221             const allocator_type& __a = allocator_type())
00222     : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
00223       { }
00224 
00225       unordered_map&
00226       operator=(unordered_map&& __x)
00227       {
00228     // NB: DR 1204.
00229     // NB: DR 675.
00230     this->clear();
00231     this->swap(__x);
00232     return *this;   
00233       }
00234 
00235       unordered_map&
00236       operator=(initializer_list<value_type> __l)
00237       {
00238     this->clear();
00239     this->insert(__l.begin(), __l.end());
00240     return *this;
00241       }
00242     };
00243   
00244   /**
00245    *  @brief A standard container composed of equivalent keys
00246    *  (possibly containing multiple of each key value) that associates
00247    *  values of another type with the keys.
00248    *
00249    *  @ingroup unordered_associative_containers
00250    *
00251    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
00252    *  <a href="tables.html#xx">unordered associative container</a>
00253    *
00254    *  @param  Key  Type of key objects.
00255    *  @param  Tp  Type of mapped objects.
00256    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
00257    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
00258    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
00259    *
00260    * The resulting value type of the container is std::pair<const Key, Tp>.
00261    */
00262   template<class _Key, class _Tp,
00263        class _Hash = hash<_Key>,
00264        class _Pred = std::equal_to<_Key>,
00265        class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
00266     class unordered_multimap
00267     : public __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
00268     {
00269       typedef __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>  _Base;
00270 
00271     public:
00272       typedef typename _Base::value_type      value_type;
00273       typedef typename _Base::size_type       size_type;
00274       typedef typename _Base::hasher          hasher;
00275       typedef typename _Base::key_equal       key_equal;
00276       typedef typename _Base::allocator_type  allocator_type;
00277       
00278       explicit
00279       unordered_multimap(size_type __n = 10,
00280              const hasher& __hf = hasher(),
00281              const key_equal& __eql = key_equal(),
00282              const allocator_type& __a = allocator_type())
00283       : _Base(__n, __hf, __eql, __a)
00284       { }
00285 
00286 
00287       template<typename _InputIterator>
00288         unordered_multimap(_InputIterator __f, _InputIterator __l, 
00289                typename _Base::size_type __n = 0,
00290                const hasher& __hf = hasher(), 
00291                const key_equal& __eql = key_equal(), 
00292                const allocator_type& __a = allocator_type())
00293     : _Base(__f, __l, __n, __hf, __eql, __a)
00294         { }
00295 
00296       unordered_multimap(unordered_multimap&& __x)
00297       : _Base(std::forward<_Base>(__x)) { }
00298 
00299       unordered_multimap(initializer_list<value_type> __l,
00300              size_type __n = 10,
00301              const hasher& __hf = hasher(),
00302              const key_equal& __eql = key_equal(),
00303              const allocator_type& __a = allocator_type())
00304     : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
00305       { }
00306 
00307       unordered_multimap&
00308       operator=(unordered_multimap&& __x)
00309       {
00310     // NB: DR 1204.
00311     // NB: DR 675.
00312     this->clear();
00313     this->swap(__x);
00314     return *this;   
00315       }
00316 
00317       unordered_multimap&
00318       operator=(initializer_list<value_type> __l)
00319       {
00320     this->clear();
00321     this->insert(__l.begin(), __l.end());
00322     return *this;
00323       }
00324     };
00325 
00326   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
00327     inline void
00328     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00329      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00330     { __x.swap(__y); }
00331 
00332   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
00333     inline void
00334     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00335      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00336     { __x.swap(__y); }
00337 
00338 _GLIBCXX_END_NESTED_NAMESPACE
00339 
00340 #endif /* _UNORDERED_MAP_H */

Generated on 12 Mar 2010 for libstdc++ by  doxygen 1.6.1