OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / tr1 / unordered_map
1 // TR1 unordered_map -*- C++ -*-
2
3 // Copyright (C) 2005 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 /** @file 
31  *  This is a TR1 C++ Library header. 
32  */
33
34 #ifndef GNU_LIBSTDCXX_TR1_UNORDERED_MAP_
35 #define GNU_LIBSTDCXX_TR1_UNORDERED_MAP_
36
37 #include <tr1/hashtable>
38 #include <tr1/functional>
39 #include <tr1/functional>
40 #include <utility>
41 #include <memory>
42
43 namespace std { namespace tr1 {
44
45 // XXX When we get typedef templates these class definitions will be unnecessary.
46
47 template <class Key, class T,
48           class Hash = hash<Key>,
49           class Pred = std::equal_to<Key>,
50           class Alloc = std::allocator<std::pair<const Key, T> >,
51           bool cache_hash_code = false>
52 class unordered_map
53   : public hashtable <Key, std::pair<const Key, T>,
54                       Alloc,
55                       Internal::extract1st<std::pair<const Key, T> >, Pred,
56                       Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
57                       Internal::prime_rehash_policy,
58                       cache_hash_code, true, true>
59 {
60   typedef hashtable <Key, std::pair<const Key, T>,
61                      Alloc,
62                      Internal::extract1st<std::pair<const Key, T> >, Pred,
63                      Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
64                      Internal::prime_rehash_policy,
65                      cache_hash_code, true, true>
66           Base;
67
68 public:
69   typedef typename Base::size_type size_type;
70   typedef typename Base::hasher hasher;
71   typedef typename Base::key_equal key_equal;
72   typedef typename Base::allocator_type allocator_type;
73
74   explicit unordered_map(size_type n = 10,
75                          const hasher& hf = hasher(),
76                          const key_equal& eql = key_equal(),
77                          const allocator_type& a = allocator_type())
78     : Base (n,
79             hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
80             eql, Internal::extract1st<std::pair<const Key, T> >(),
81             a)
82   { }
83
84   template <typename InputIterator>
85   unordered_map(InputIterator f, InputIterator l, 
86                 size_type n = 10,
87                 const hasher& hf = hasher(), 
88                 const key_equal& eql = key_equal(), 
89                 const allocator_type& a = allocator_type())
90     : Base (f, l,
91             n,
92             hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
93             eql, Internal::extract1st<std::pair<const Key, T> >(),
94             a)
95             { }
96 };
97
98 template <class Key, class T,
99           class Hash = hash<Key>,
100           class Pred = std::equal_to<Key>,
101           class Alloc = std::allocator<std::pair<const Key, T> >,
102           bool cache_hash_code = false>
103 class unordered_multimap
104   : public hashtable <Key, std::pair<const Key, T>,
105                       Alloc,
106                       Internal::extract1st<std::pair<const Key, T> >, Pred,
107                       Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
108                       Internal::prime_rehash_policy,
109                       cache_hash_code, true, false>
110 {
111   typedef hashtable <Key, std::pair<const Key, T>,
112                      Alloc,
113                      Internal::extract1st<std::pair<const Key, T> >, Pred,
114                      Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
115                      Internal::prime_rehash_policy,
116                      cache_hash_code, true, false>
117           Base;
118
119 public:
120   typedef typename Base::size_type size_type;
121   typedef typename Base::hasher hasher;
122   typedef typename Base::key_equal key_equal;
123   typedef typename Base::allocator_type allocator_type;
124
125   explicit unordered_multimap(size_type n = 10,
126                               const hasher& hf = hasher(),
127                               const key_equal& eql = key_equal(),
128                               const allocator_type& a = allocator_type())
129     : Base (n,
130             hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
131             eql, Internal::extract1st<std::pair<const Key, T> >(),
132             a)
133   { }
134
135
136   template <typename InputIterator>
137   unordered_multimap(InputIterator f, InputIterator l, 
138                      typename Base::size_type n = 0,
139                      const hasher& hf = hasher(), 
140                      const key_equal& eql = key_equal(), 
141                      const allocator_type& a = allocator_type())
142     : Base (f, l,
143             n,
144             hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
145             eql, Internal::extract1st<std::pair<const Key, T> >(),
146             a)
147   { }
148 };
149
150 template <class Key, class T, class Hash, class Pred, class Alloc, bool cache_hash_code>
151 inline void swap (unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
152                   unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
153 {
154   x.swap(y);
155 }
156
157 template <class Key, class T, class Hash, class Pred, class Alloc, bool cache_hash_code>
158 inline void swap (unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
159                   unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
160 {
161   x.swap(y);
162 }
163
164 } }
165
166 #endif /* GNU_LIBSTDCXX_TR1_UNORDERED_MAP_ */