tr1_impl/unordered_map

Go to the documentation of this file.
00001 // TR1 unordered_map -*- C++ -*-
00002 
00003 // Copyright (C) 2007, 2009 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 tr1_impl/unordered_map
00026  *  This is an internal header file, included by other library headers.
00027  *  You should not attempt to use it directly.
00028  */
00029 
00030 namespace std
00031 {
00032 _GLIBCXX_BEGIN_NAMESPACE_TR1
00033 
00034   // XXX When we get typedef templates these class definitions
00035   // will be unnecessary.
00036   template<class _Key, class _Tp,
00037        class _Hash = hash<_Key>,
00038        class _Pred = std::equal_to<_Key>,
00039        class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
00040        bool __cache_hash_code = false>
00041     class __unordered_map
00042     : public _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
00043             std::_Select1st<std::pair<const _Key, _Tp> >, _Pred, 
00044             _Hash, __detail::_Mod_range_hashing,
00045             __detail::_Default_ranged_hash,
00046             __detail::_Prime_rehash_policy,
00047             __cache_hash_code, false, true>
00048     {
00049       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
00050              std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
00051              _Hash, __detail::_Mod_range_hashing,
00052              __detail::_Default_ranged_hash,
00053              __detail::_Prime_rehash_policy,
00054              __cache_hash_code, false, true>
00055         _Base;
00056 
00057     public:
00058       typedef typename _Base::size_type       size_type;
00059       typedef typename _Base::hasher          hasher;
00060       typedef typename _Base::key_equal       key_equal;
00061       typedef typename _Base::allocator_type  allocator_type;
00062 
00063       explicit
00064       __unordered_map(size_type __n = 10,
00065               const hasher& __hf = hasher(),
00066               const key_equal& __eql = key_equal(),
00067               const allocator_type& __a = allocator_type())
00068       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
00069           __detail::_Default_ranged_hash(),
00070           __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
00071       { }
00072 
00073       template<typename _InputIterator>
00074         __unordered_map(_InputIterator __f, _InputIterator __l, 
00075             size_type __n = 10,
00076             const hasher& __hf = hasher(), 
00077             const key_equal& __eql = key_equal(), 
00078             const allocator_type& __a = allocator_type())
00079     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
00080         __detail::_Default_ranged_hash(),
00081         __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
00082     { }
00083 
00084 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
00085       __unordered_map(__unordered_map&& __x)
00086       : _Base(std::forward<_Base>(__x)) { }
00087 #endif
00088     };
00089   
00090   template<class _Key, class _Tp,
00091        class _Hash = hash<_Key>,
00092        class _Pred = std::equal_to<_Key>,
00093        class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
00094        bool __cache_hash_code = false>
00095     class __unordered_multimap
00096     : public _Hashtable<_Key, std::pair<const _Key, _Tp>,
00097             _Alloc,
00098             std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
00099             _Hash, __detail::_Mod_range_hashing,
00100             __detail::_Default_ranged_hash,
00101             __detail::_Prime_rehash_policy,
00102             __cache_hash_code, false, false>
00103     {
00104       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>,
00105              _Alloc,
00106              std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
00107              _Hash, __detail::_Mod_range_hashing,
00108              __detail::_Default_ranged_hash,
00109              __detail::_Prime_rehash_policy,
00110              __cache_hash_code, false, false>
00111         _Base;
00112 
00113     public:
00114       typedef typename _Base::size_type       size_type;
00115       typedef typename _Base::hasher          hasher;
00116       typedef typename _Base::key_equal       key_equal;
00117       typedef typename _Base::allocator_type  allocator_type;
00118       
00119       explicit
00120       __unordered_multimap(size_type __n = 10,
00121                const hasher& __hf = hasher(),
00122                const key_equal& __eql = key_equal(),
00123                const allocator_type& __a = allocator_type())
00124       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
00125           __detail::_Default_ranged_hash(),
00126           __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
00127       { }
00128 
00129 
00130       template<typename _InputIterator>
00131         __unordered_multimap(_InputIterator __f, _InputIterator __l, 
00132                  typename _Base::size_type __n = 0,
00133                  const hasher& __hf = hasher(), 
00134                  const key_equal& __eql = key_equal(), 
00135                  const allocator_type& __a = allocator_type())
00136     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
00137         __detail::_Default_ranged_hash(),
00138         __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
00139         { }
00140 
00141 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
00142       __unordered_multimap(__unordered_multimap&& __x)
00143       : _Base(std::forward<_Base>(__x)) { }
00144 #endif
00145     };
00146 
00147   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
00148        bool __cache_hash_code>
00149     inline void
00150     swap(__unordered_map<_Key, _Tp, _Hash, _Pred,
00151      _Alloc, __cache_hash_code>& __x,
00152      __unordered_map<_Key, _Tp, _Hash, _Pred,
00153      _Alloc, __cache_hash_code>& __y)
00154     { __x.swap(__y); }
00155 
00156   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
00157        bool __cache_hash_code>
00158     inline void
00159     swap(__unordered_multimap<_Key, _Tp, _Hash, _Pred,
00160      _Alloc, __cache_hash_code>& __x,
00161      __unordered_multimap<_Key, _Tp, _Hash, _Pred,
00162      _Alloc, __cache_hash_code>& __y)
00163     { __x.swap(__y); }
00164 
00165 
00166   /**
00167    *  @brief A standard container composed of unique keys (containing
00168    *  at most one of each key value) that associates values of another type
00169    *  with the keys.
00170    *
00171    *  @ingroup unordered_associative_containers
00172    *
00173    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
00174    *  <a href="tables.html#xx">unordered associative container</a>
00175    *
00176    *  @param  Key  Type of key objects.
00177    *  @param  Tp  Type of mapped objects.
00178    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
00179    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
00180    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
00181    *
00182    * The resulting value type of the container is std::pair<const Key, Tp>.
00183    */
00184   template<class _Key, class _Tp,
00185        class _Hash = hash<_Key>,
00186        class _Pred = std::equal_to<_Key>,
00187        class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
00188     class unordered_map
00189     : public __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
00190     {
00191       typedef __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>  _Base;
00192 
00193     public:
00194       typedef typename _Base::value_type      value_type;
00195       typedef typename _Base::size_type       size_type;
00196       typedef typename _Base::hasher          hasher;
00197       typedef typename _Base::key_equal       key_equal;
00198       typedef typename _Base::allocator_type  allocator_type;
00199 
00200       explicit
00201       unordered_map(size_type __n = 10,
00202             const hasher& __hf = hasher(),
00203             const key_equal& __eql = key_equal(),
00204             const allocator_type& __a = allocator_type())
00205       : _Base(__n, __hf, __eql, __a)
00206       { }
00207 
00208       template<typename _InputIterator>
00209         unordered_map(_InputIterator __f, _InputIterator __l, 
00210               size_type __n = 10,
00211               const hasher& __hf = hasher(), 
00212               const key_equal& __eql = key_equal(), 
00213               const allocator_type& __a = allocator_type())
00214     : _Base(__f, __l, __n, __hf, __eql, __a)
00215         { }
00216 
00217 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
00218       unordered_map(unordered_map&& __x)
00219       : _Base(std::forward<_Base>(__x)) { }
00220 
00221       unordered_map(initializer_list<value_type> __l,
00222             size_type __n = 10,
00223             const hasher& __hf = hasher(),
00224             const key_equal& __eql = key_equal(),
00225             const allocator_type& __a = allocator_type())
00226     : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
00227       { }
00228 
00229       unordered_map&
00230       operator=(unordered_map&& __x)
00231       {
00232     // NB: DR 675.
00233     this->clear();
00234     this->swap(__x); 
00235     return *this;   
00236       }
00237 
00238       unordered_map&
00239       operator=(initializer_list<value_type> __l)
00240       {
00241     this->clear();
00242     this->insert(__l.begin(), __l.end());
00243     return *this;
00244       }
00245 #endif
00246     };
00247   
00248   /**
00249    *  @brief A standard container composed of equivalent keys
00250    *  (possibly containing multiple of each key value) that associates
00251    *  values of another type with the keys.
00252    *
00253    *  @ingroup unordered_associative_containers
00254    *
00255    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
00256    *  <a href="tables.html#xx">unordered associative container</a>
00257    *
00258    *  @param  Key  Type of key objects.
00259    *  @param  Tp  Type of mapped objects.
00260    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
00261    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
00262    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
00263    *
00264    * The resulting value type of the container is std::pair<const Key, Tp>.
00265    */
00266   template<class _Key, class _Tp,
00267        class _Hash = hash<_Key>,
00268        class _Pred = std::equal_to<_Key>,
00269        class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
00270     class unordered_multimap
00271     : public __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
00272     {
00273       typedef __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>  _Base;
00274 
00275     public:
00276       typedef typename _Base::value_type      value_type;
00277       typedef typename _Base::size_type       size_type;
00278       typedef typename _Base::hasher          hasher;
00279       typedef typename _Base::key_equal       key_equal;
00280       typedef typename _Base::allocator_type  allocator_type;
00281       
00282       explicit
00283       unordered_multimap(size_type __n = 10,
00284              const hasher& __hf = hasher(),
00285              const key_equal& __eql = key_equal(),
00286              const allocator_type& __a = allocator_type())
00287       : _Base(__n, __hf, __eql, __a)
00288       { }
00289 
00290 
00291       template<typename _InputIterator>
00292         unordered_multimap(_InputIterator __f, _InputIterator __l, 
00293                typename _Base::size_type __n = 0,
00294                const hasher& __hf = hasher(), 
00295                const key_equal& __eql = key_equal(), 
00296                const allocator_type& __a = allocator_type())
00297     : _Base(__f, __l, __n, __hf, __eql, __a)
00298         { }
00299 
00300 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
00301       unordered_multimap(unordered_multimap&& __x)
00302       : _Base(std::forward<_Base>(__x)) { }
00303 
00304       unordered_multimap(initializer_list<value_type> __l,
00305              size_type __n = 10,
00306              const hasher& __hf = hasher(),
00307              const key_equal& __eql = key_equal(),
00308              const allocator_type& __a = allocator_type())
00309     : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
00310       { }
00311 
00312       unordered_multimap&
00313       operator=(unordered_multimap&& __x)
00314       {
00315     // NB: DR 675.
00316     this->clear();
00317     this->swap(__x); 
00318     return *this;   
00319       }
00320 
00321       unordered_multimap&
00322       operator=(initializer_list<value_type> __l)
00323       {
00324     this->clear();
00325     this->insert(__l.begin(), __l.end());
00326     return *this;
00327       }
00328 #endif
00329     };
00330 
00331   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
00332     inline void
00333     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00334      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00335     { __x.swap(__y); }
00336 
00337   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
00338     inline void
00339     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00340      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00341     { __x.swap(__y); }
00342 
00343 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
00344   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
00345     inline void
00346     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
00347      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00348     { __x.swap(__y); }
00349 
00350   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
00351     inline void
00352     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00353      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
00354     { __x.swap(__y); }
00355 
00356   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
00357     inline void
00358     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
00359      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00360     { __x.swap(__y); }
00361 
00362   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
00363     inline void
00364     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00365      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
00366     { __x.swap(__y); }
00367 #endif
00368 
00369 _GLIBCXX_END_NAMESPACE_TR1
00370 }

Generated on Tue Apr 21 13:13:36 2009 for libstdc++ by  doxygen 1.5.8