# unordered_map

Go to the documentation of this file.

    00001 // TR1 unordered_map -*- C++ -*-
    00002
    00003 // Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    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
    00031  *  This is a TR1 C++ Library header.
    00032  */
    00033
    00034 #ifndef GNU_LIBSTDCXX_TR1_UNORDERED_MAP_
    00035 #define GNU_LIBSTDCXX_TR1_UNORDERED_MAP_
    00036
    00037 #include <tr1/hashtable>
    00038 #include <tr1/functional>
    00039 #include <tr1/functional>
    00040 #include <utility>
    00041 #include <memory>
    00042
    00043 namespace std { namespace tr1 {
    00044
    00045 // XXX When we get typedef templates these class definitions will be unnecessary.
    00046
    00047 template <class Key, class T,
    00048       class Hash = hash<Key>,
    00049       class Pred = std::equal_to<Key>,
    00050       class Alloc = std::allocator<std::pair<const Key, T> >,
    00051       bool cache_hash_code = false>
    00052 class unordered_map
    00053   : public hashtable <Key, std::pair<const Key, T>,
    00054               Alloc,
    00055               Internal::extract1st<std::pair<const Key, T> >, Pred,
    00056               Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
    00057               Internal::prime_rehash_policy,
    00058               cache_hash_code, true, true>
    00059 {
    00060   typedef hashtable <Key, std::pair<const Key, T>,
    00061              Alloc,
    00062              Internal::extract1st<std::pair<const Key, T> >, Pred,
    00063              Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
    00064              Internal::prime_rehash_policy,
    00065              cache_hash_code, true, true>
    00066           Base;
    00067
    00068 public:
    00069   typedef typename Base::size_type size_type;
    00070   typedef typename Base::hasher hasher;
    00071   typedef typename Base::key_equal key_equal;
    00072   typedef typename Base::allocator_type allocator_type;
    00073
    00074   explicit 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,
    00079         hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
    00080         eql, Internal::extract1st<std::pair<const Key, T> >(),
    00081         a)
    00082   { }
    00083
    00084   template <typename InputIterator>
    00085   unordered_map(InputIterator f, InputIterator l,
    00086         size_type n = 10,
    00087         const hasher& hf = hasher(),
    00088         const key_equal& eql = key_equal(),
    00089         const allocator_type& a = allocator_type())
    00090     : Base (f, l,
    00091         n,
    00092         hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
    00093         eql, Internal::extract1st<std::pair<const Key, T> >(),
    00094         a)
    00095         { }
    00096 };
    00097
    00098 template <class Key, class T,
    00099       class Hash = hash<Key>,
    00100       class Pred = std::equal_to<Key>,
    00101       class Alloc = std::allocator<std::pair<const Key, T> >,
    00102       bool cache_hash_code = false>
    00103 class unordered_multimap
    00104   : public hashtable <Key, std::pair<const Key, T>,
    00105               Alloc,
    00106               Internal::extract1st<std::pair<const Key, T> >, Pred,
    00107               Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
    00108               Internal::prime_rehash_policy,
    00109               cache_hash_code, true, false>
    00110 {
    00111   typedef hashtable <Key, std::pair<const Key, T>,
    00112              Alloc,
    00113              Internal::extract1st<std::pair<const Key, T> >, Pred,
    00114              Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
    00115              Internal::prime_rehash_policy,
    00116              cache_hash_code, true, false>
    00117           Base;
    00118
    00119 public:
    00120   typedef typename Base::size_type size_type;
    00121   typedef typename Base::hasher hasher;
    00122   typedef typename Base::key_equal key_equal;
    00123   typedef typename Base::allocator_type allocator_type;
    00124
    00125   explicit 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,
    00130         hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
    00131         eql, Internal::extract1st<std::pair<const Key, T> >(),
    00132         a)
    00133   { }
    00134
    00135
    00136   template <typename InputIterator>
    00137   unordered_multimap(InputIterator f, InputIterator l,
    00138              typename Base::size_type n = 0,
    00139              const hasher& hf = hasher(),
    00140              const key_equal& eql = key_equal(),
    00141              const allocator_type& a = allocator_type())
    00142     : Base (f, l,
    00143         n,
    00144         hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
    00145         eql, Internal::extract1st<std::pair<const Key, T> >(),
    00146         a)
    00147   { }
    00148 };
    00149
    00150 template <class Key, class T, class Hash, class Pred, class Alloc, bool cache_hash_code>
    00151 inline void swap (unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
    00152           unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
    00153 {
    00154   x.swap(y);
    00155 }
    00156
    00157 template <class Key, class T, class Hash, class Pred, class Alloc, bool cache_hash_code>
    00158 inline void swap (unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
    00159           unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
    00160 {
    00161   x.swap(y);
    00162 }
    00163
    00164 } }
    00165
    00166 #endif /* GNU_LIBSTDCXX_TR1_UNORDERED_MAP_ */