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 1204.
00233     // NB: DR 675.
00234     this->clear();
00235     this->swap(__x);
00236     return *this;   
00237       }
00238 
00239       unordered_map&
00240       operator=(initializer_list<value_type> __l)
00241       {
00242     this->clear();
00243     this->insert(__l.begin(), __l.end());
00244     return *this;
00245       }
00246 #endif
00247     };
00248   
00249   /**
00250    *  @brief A standard container composed of equivalent keys
00251    *  (possibly containing multiple of each key value) that associates
00252    *  values of another type with the keys.
00253    *
00254    *  @ingroup unordered_associative_containers
00255    *
00256    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
00257    *  <a href="tables.html#xx">unordered associative container</a>
00258    *
00259    *  @param  Key  Type of key objects.
00260    *  @param  Tp  Type of mapped objects.
00261    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
00262    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
00263    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
00264    *
00265    * The resulting value type of the container is std::pair<const Key, Tp>.
00266    */
00267   template<class _Key, class _Tp,
00268        class _Hash = hash<_Key>,
00269        class _Pred = std::equal_to<_Key>,
00270        class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
00271     class unordered_multimap
00272     : public __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
00273     {
00274       typedef __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>  _Base;
00275 
00276     public:
00277       typedef typename _Base::value_type      value_type;
00278       typedef typename _Base::size_type       size_type;
00279       typedef typename _Base::hasher          hasher;
00280       typedef typename _Base::key_equal       key_equal;
00281       typedef typename _Base::allocator_type  allocator_type;
00282       
00283       explicit
00284       unordered_multimap(size_type __n = 10,
00285              const hasher& __hf = hasher(),
00286              const key_equal& __eql = key_equal(),
00287              const allocator_type& __a = allocator_type())
00288       : _Base(__n, __hf, __eql, __a)
00289       { }
00290 
00291 
00292       template<typename _InputIterator>
00293         unordered_multimap(_InputIterator __f, _InputIterator __l, 
00294                typename _Base::size_type __n = 0,
00295                const hasher& __hf = hasher(), 
00296                const key_equal& __eql = key_equal(), 
00297                const allocator_type& __a = allocator_type())
00298     : _Base(__f, __l, __n, __hf, __eql, __a)
00299         { }
00300 
00301 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
00302       unordered_multimap(unordered_multimap&& __x)
00303       : _Base(std::forward<_Base>(__x)) { }
00304 
00305       unordered_multimap(initializer_list<value_type> __l,
00306              size_type __n = 10,
00307              const hasher& __hf = hasher(),
00308              const key_equal& __eql = key_equal(),
00309              const allocator_type& __a = allocator_type())
00310     : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
00311       { }
00312 
00313       unordered_multimap&
00314       operator=(unordered_multimap&& __x)
00315       {
00316     // NB: DR 1204.
00317     // NB: DR 675.
00318     this->clear();
00319     this->swap(__x);
00320     return *this;   
00321       }
00322 
00323       unordered_multimap&
00324       operator=(initializer_list<value_type> __l)
00325       {
00326     this->clear();
00327     this->insert(__l.begin(), __l.end());
00328     return *this;
00329       }
00330 #endif
00331     };
00332 
00333   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
00334     inline void
00335     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00336      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00337     { __x.swap(__y); }
00338 
00339   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
00340     inline void
00341     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00342      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00343     { __x.swap(__y); }
00344 
00345 _GLIBCXX_END_NAMESPACE_TR1
00346 }

Generated on 11 Jan 2010 for libstdc++ by  doxygen 1.6.1