# unordered_map

Go to the documentation of this file.

    00001 // TR1 unordered_map -*- C++ -*-
    00002
    00003 // Copyright (C) 2005, 2006, 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/unordered_map
    00031  *  This is a TR1 C++ Library header.
    00032  */
    00033
    00034 #ifndef _TR1_UNORDERED_MAP
    00035 #define _TR1_UNORDERED_MAP 1
    00036
    00037 #include <tr1/hashtable>
    00038 #include <tr1/functional_hash.h>
    00039
    00040 namespace std
    00041 {
    00042 _GLIBCXX_BEGIN_NAMESPACE(tr1)
    00043
    00044   // XXX When we get typedef templates these class definitions
    00045   // will be unnecessary.
    00046   template<class _Key, class _Tp,
    00047        class _Hash = hash<_Key>,
    00048        class _Pred = std::equal_to<_Key>,
    00049        class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
    00050        bool __cache_hash_code = false>
    00051     class unordered_map
    00052     : public _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
    00053             std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
    00054             _Hash, __detail::_Mod_range_hashing,
    00055             __detail::_Default_ranged_hash,
    00056             __detail::_Prime_rehash_policy,
    00057             __cache_hash_code, false, true>
    00058     {
    00059       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
    00060              std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
    00061              _Hash, __detail::_Mod_range_hashing,
    00062              __detail::_Default_ranged_hash,
    00063              __detail::_Prime_rehash_policy,
    00064              __cache_hash_code, false, true>
    00065         _Base;
    00066
    00067     public:
    00068       typedef typename _Base::size_type       size_type;
    00069       typedef typename _Base::hasher          hasher;
    00070       typedef typename _Base::key_equal       key_equal;
    00071       typedef typename _Base::allocator_type  allocator_type;
    00072
    00073       explicit
    00074       unordered_map(size_type __n = 10,
    00075             const hasher& __hf = hasher(),
    00076             const key_equal& __eql = key_equal(),
    00077             const allocator_type& __a = allocator_type())
    00078       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
    00079           __detail::_Default_ranged_hash(),
    00080           __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
    00081       { }
    00082
    00083       template<typename _InputIterator>
    00084         unordered_map(_InputIterator __f, _InputIterator __l,
    00085               size_type __n = 10,
    00086               const hasher& __hf = hasher(),
    00087               const key_equal& __eql = key_equal(),
    00088               const allocator_type& __a = allocator_type())
    00089     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
    00090         __detail::_Default_ranged_hash(),
    00091         __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
    00092     { }
    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
    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 _GLIBCXX_END_NAMESPACE
    00166 }
    00167
    00168 #endif // _TR1_UNORDERED_MAP