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, 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 
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
00044 {
00045 namespace tr1
00046 {
00047   // XXX When we get typedef templates these class definitions
00048   // will be unnecessary.
00049 
00050   template<class Key, class T,
00051        class Hash = hash<Key>,
00052        class Pred = std::equal_to<Key>,
00053        class Alloc = std::allocator<std::pair<const Key, T> >,
00054        bool cache_hash_code = false>
00055     class unordered_map
00056     : public hashtable <Key, std::pair<const Key, T>,
00057             Alloc,
00058             Internal::extract1st<std::pair<const Key, T> >, Pred,
00059             Hash, Internal::mod_range_hashing,
00060             Internal::default_ranged_hash,
00061             Internal::prime_rehash_policy,
00062             cache_hash_code, false, true>
00063     {
00064       typedef hashtable <Key, std::pair<const Key, T>,
00065              Alloc,
00066              Internal::extract1st<std::pair<const Key, T> >, Pred,
00067              Hash, Internal::mod_range_hashing,
00068              Internal::default_ranged_hash,
00069              Internal::prime_rehash_policy,
00070              cache_hash_code, false, true>
00071         Base;
00072 
00073     public:
00074       typedef typename Base::size_type size_type;
00075       typedef typename Base::hasher hasher;
00076       typedef typename Base::key_equal key_equal;
00077       typedef typename Base::allocator_type allocator_type;
00078 
00079       explicit
00080       unordered_map(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(n, hf, Internal::mod_range_hashing(),
00085          Internal::default_ranged_hash(),
00086          eql, Internal::extract1st<std::pair<const Key, T> >(), a)
00087       { }
00088 
00089       template<typename InputIterator>
00090         unordered_map(InputIterator f, InputIterator l, 
00091               size_type n = 10,
00092               const hasher& hf = hasher(), 
00093               const key_equal& eql = key_equal(), 
00094               const allocator_type& a = allocator_type())
00095     : Base (f, l, n, hf, Internal::mod_range_hashing(),
00096         Internal::default_ranged_hash(),
00097         eql, Internal::extract1st<std::pair<const Key, T> >(), a)
00098     { }
00099     };
00100   
00101   template<class Key, class T,
00102        class Hash = hash<Key>,
00103        class Pred = std::equal_to<Key>,
00104        class Alloc = std::allocator<std::pair<const Key, T> >,
00105        bool cache_hash_code = false>
00106     class unordered_multimap
00107     : public hashtable <Key, std::pair<const Key, T>,
00108             Alloc,
00109             Internal::extract1st<std::pair<const Key, T> >, Pred,
00110             Hash, Internal::mod_range_hashing,
00111             Internal::default_ranged_hash,
00112             Internal::prime_rehash_policy,
00113             cache_hash_code, false, false>
00114     {
00115       typedef hashtable <Key, std::pair<const Key, T>,
00116              Alloc,
00117              Internal::extract1st<std::pair<const Key, T> >, Pred,
00118              Hash, Internal::mod_range_hashing,
00119              Internal::default_ranged_hash,
00120              Internal::prime_rehash_policy,
00121              cache_hash_code, false, false>
00122         Base;
00123 
00124     public:
00125       typedef typename Base::size_type size_type;
00126       typedef typename Base::hasher hasher;
00127       typedef typename Base::key_equal key_equal;
00128       typedef typename Base::allocator_type allocator_type;
00129       
00130       explicit
00131       unordered_multimap(size_type n = 10,
00132              const hasher& hf = hasher(),
00133              const key_equal& eql = key_equal(),
00134              const allocator_type& a = allocator_type())
00135       : Base (n, hf, Internal::mod_range_hashing(),
00136           Internal::default_ranged_hash(),
00137           eql, Internal::extract1st<std::pair<const Key, T> >(), a)
00138       { }
00139 
00140 
00141       template<typename InputIterator>
00142         unordered_multimap(InputIterator f, InputIterator l, 
00143                typename Base::size_type n = 0,
00144                const hasher& hf = hasher(), 
00145                const key_equal& eql = key_equal(), 
00146                const allocator_type& a = allocator_type())
00147     : Base (f, l, n, hf, Internal::mod_range_hashing(),
00148         Internal::default_ranged_hash(),
00149         eql, Internal::extract1st<std::pair<const Key, T> >(), a)
00150         { }
00151     };
00152 
00153   template<class Key, class T, class Hash, class Pred, class Alloc,
00154        bool cache_hash_code>
00155     inline void
00156     swap(unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
00157      unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
00158     { x.swap(y); }
00159 
00160   template<class Key, class T, class Hash, class Pred, class Alloc,
00161        bool cache_hash_code>
00162     inline void
00163     swap(unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
00164      unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
00165     { x.swap(y); }
00166 
00167 }
00168 }
00169 
00170 #endif /* GNU_LIBSTDCXX_TR1_UNORDERED_MAP_ */

Generated on Tue Feb 2 16:56:53 2010 for GNU C++ STL by  doxygen 1.4.7