# tr1_impl/unordered_map

Go to the documentation of this file.

    00001 // TR1 unordered_map -*- C++ -*-
    00002
    00003 // Copyright (C) 2007 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 2, 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 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 /** @file tr1_impl/unordered_map
    00031  *  This is an internal header file, included by other library headers.
    00032  *  You should not attempt to use it directly.
    00033  */
    00034
    00035 namespace std
    00036 {
    00037 _GLIBCXX_BEGIN_NAMESPACE_TR1
    00038
    00039   // XXX When we get typedef templates these class definitions
    00040   // will be unnecessary.
    00041   template<class _Key, class _Tp,
    00042        class _Hash = hash<_Key>,
    00043        class _Pred = std::equal_to<_Key>,
    00044        class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
    00045        bool __cache_hash_code = false>
    00046     class __unordered_map
    00047     : public _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
    00048             std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
    00049             _Hash, __detail::_Mod_range_hashing,
    00050             __detail::_Default_ranged_hash,
    00051             __detail::_Prime_rehash_policy,
    00052             __cache_hash_code, false, true>
    00053     {
    00054       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
    00055              std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
    00056              _Hash, __detail::_Mod_range_hashing,
    00057              __detail::_Default_ranged_hash,
    00058              __detail::_Prime_rehash_policy,
    00059              __cache_hash_code, false, true>
    00060         _Base;
    00061
    00062     public:
    00063       typedef typename _Base::size_type       size_type;
    00064       typedef typename _Base::hasher          hasher;
    00065       typedef typename _Base::key_equal       key_equal;
    00066       typedef typename _Base::allocator_type  allocator_type;
    00067
    00068       explicit
    00069       __unordered_map(size_type __n = 10,
    00070               const hasher& __hf = hasher(),
    00071               const key_equal& __eql = key_equal(),
    00072               const allocator_type& __a = allocator_type())
    00073       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
    00074           __detail::_Default_ranged_hash(),
    00075           __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
    00076       { }
    00077
    00078       template<typename _InputIterator>
    00079         __unordered_map(_InputIterator __f, _InputIterator __l,
    00080             size_type __n = 10,
    00081             const hasher& __hf = hasher(),
    00082             const key_equal& __eql = key_equal(),
    00083             const allocator_type& __a = allocator_type())
    00084     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
    00085         __detail::_Default_ranged_hash(),
    00086         __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
    00087     { }
    00088
    00089 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    00090       __unordered_map(__unordered_map&& __x)
    00091       : _Base(std::forward<_Base>(__x)) { }
    00092 #endif
    00093     };
    00094
    00095   template<class _Key, class _Tp,
    00096        class _Hash = hash<_Key>,
    00097        class _Pred = std::equal_to<_Key>,
    00098        class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
    00099        bool __cache_hash_code = false>
    00100     class __unordered_multimap
    00101     : public _Hashtable<_Key, std::pair<const _Key, _Tp>,
    00102             _Alloc,
    00103             std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
    00104             _Hash, __detail::_Mod_range_hashing,
    00105             __detail::_Default_ranged_hash,
    00106             __detail::_Prime_rehash_policy,
    00107             __cache_hash_code, false, false>
    00108     {
    00109       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>,
    00110              _Alloc,
    00111              std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
    00112              _Hash, __detail::_Mod_range_hashing,
    00113              __detail::_Default_ranged_hash,
    00114              __detail::_Prime_rehash_policy,
    00115              __cache_hash_code, false, false>
    00116         _Base;
    00117
    00118     public:
    00119       typedef typename _Base::size_type       size_type;
    00120       typedef typename _Base::hasher          hasher;
    00121       typedef typename _Base::key_equal       key_equal;
    00122       typedef typename _Base::allocator_type  allocator_type;
    00123
    00124       explicit
    00125       __unordered_multimap(size_type __n = 10,
    00126                const hasher& __hf = hasher(),
    00127                const key_equal& __eql = key_equal(),
    00128                const allocator_type& __a = allocator_type())
    00129       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
    00130           __detail::_Default_ranged_hash(),
    00131           __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
    00132       { }
    00133
    00134
    00135       template<typename _InputIterator>
    00136         __unordered_multimap(_InputIterator __f, _InputIterator __l,
    00137                  typename _Base::size_type __n = 0,
    00138                  const hasher& __hf = hasher(),
    00139                  const key_equal& __eql = key_equal(),
    00140                  const allocator_type& __a = allocator_type())
    00141     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
    00142         __detail::_Default_ranged_hash(),
    00143         __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
    00144         { }
    00145
    00146 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    00147       __unordered_multimap(__unordered_multimap&& __x)
    00148       : _Base(std::forward<_Base>(__x)) { }
    00149 #endif
    00150     };
    00151
    00152   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
    00153        bool __cache_hash_code>
    00154     inline void
    00155     swap(__unordered_map<_Key, _Tp, _Hash, _Pred,
    00156      _Alloc, __cache_hash_code>& __x,
    00157      __unordered_map<_Key, _Tp, _Hash, _Pred,
    00158      _Alloc, __cache_hash_code>& __y)
    00159     { __x.swap(__y); }
    00160
    00161   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
    00162        bool __cache_hash_code>
    00163     inline void
    00164     swap(__unordered_multimap<_Key, _Tp, _Hash, _Pred,
    00165      _Alloc, __cache_hash_code>& __x,
    00166      __unordered_multimap<_Key, _Tp, _Hash, _Pred,
    00167      _Alloc, __cache_hash_code>& __y)
    00168     { __x.swap(__y); }
    00169
    00170
    00171   /// class unordered_map
    00172   template<class _Key, class _Tp,
    00173        class _Hash = hash<_Key>,
    00174        class _Pred = std::equal_to<_Key>,
    00175        class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
    00176     class unordered_map
    00177     : public __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
    00178     {
    00179       typedef __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>  _Base;
    00180
    00181     public:
    00182       typedef typename _Base::size_type       size_type;
    00183       typedef typename _Base::hasher          hasher;
    00184       typedef typename _Base::key_equal       key_equal;
    00185       typedef typename _Base::allocator_type  allocator_type;
    00186
    00187       explicit
    00188       unordered_map(size_type __n = 10,
    00189             const hasher& __hf = hasher(),
    00190             const key_equal& __eql = key_equal(),
    00191             const allocator_type& __a = allocator_type())
    00192       : _Base(__n, __hf, __eql, __a)
    00193       { }
    00194
    00195       template<typename _InputIterator>
    00196         unordered_map(_InputIterator __f, _InputIterator __l,
    00197               size_type __n = 10,
    00198               const hasher& __hf = hasher(),
    00199               const key_equal& __eql = key_equal(),
    00200               const allocator_type& __a = allocator_type())
    00201     : _Base(__f, __l, __n, __hf, __eql, __a)
    00202         { }
    00203
    00204 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    00205       unordered_map(unordered_map&& __x)
    00206       : _Base(std::forward<_Base>(__x)) { }
    00207
    00208       unordered_map&
    00209       operator=(unordered_map&& __x)
    00210       {
    00211     // NB: DR 675.
    00212     this->clear();
    00213     this->swap(__x);
    00214     return *this;
    00215       }
    00216 #endif
    00217     };
    00218
    00219   /// class unordered_multimap
    00220   template<class _Key, class _Tp,
    00221        class _Hash = hash<_Key>,
    00222        class _Pred = std::equal_to<_Key>,
    00223        class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
    00224     class unordered_multimap
    00225     : public __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
    00226     {
    00227       typedef __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>  _Base;
    00228
    00229     public:
    00230       typedef typename _Base::size_type       size_type;
    00231       typedef typename _Base::hasher          hasher;
    00232       typedef typename _Base::key_equal       key_equal;
    00233       typedef typename _Base::allocator_type  allocator_type;
    00234
    00235       explicit
    00236       unordered_multimap(size_type __n = 10,
    00237              const hasher& __hf = hasher(),
    00238              const key_equal& __eql = key_equal(),
    00239              const allocator_type& __a = allocator_type())
    00240       : _Base(__n, __hf, __eql, __a)
    00241       { }
    00242
    00243
    00244       template<typename _InputIterator>
    00245         unordered_multimap(_InputIterator __f, _InputIterator __l,
    00246                typename _Base::size_type __n = 0,
    00247                const hasher& __hf = hasher(),
    00248                const key_equal& __eql = key_equal(),
    00249                const allocator_type& __a = allocator_type())
    00250     : _Base(__f, __l, __n, __hf, __eql, __a)
    00251         { }
    00252
    00253 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    00254       unordered_multimap(unordered_multimap&& __x)
    00255       : _Base(std::forward<_Base>(__x)) { }
    00256
    00257       unordered_multimap&
    00258       operator=(unordered_multimap&& __x)
    00259       {
    00260     // NB: DR 675.
    00261     this->clear();
    00262     this->swap(__x);
    00263     return *this;
    00264       }
    00265 #endif
    00266     };
    00267
    00268   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    00269     inline void
    00270     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    00271      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
    00272     { __x.swap(__y); }
    00273
    00274   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    00275     inline void
    00276     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    00277      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
    00278     { __x.swap(__y); }
    00279
    00280 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    00281   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    00282     inline void
    00283     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
    00284      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
    00285     { __x.swap(__y); }
    00286
    00287   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    00288     inline void
    00289     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    00290      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
    00291     { __x.swap(__y); }
    00292
    00293   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    00294     inline void
    00295     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
    00296      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
    00297     { __x.swap(__y); }
    00298
    00299   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    00300     inline void
    00301     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    00302      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
    00303     { __x.swap(__y); }
    00304 #endif
    00305
    00306 _GLIBCXX_END_NAMESPACE_TR1
    00307 }