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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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
43namespace std
44{
45namespace tr1
46{
47  // XXX When we get typedef templates these class definitions
48  // will be unnecessary.
49
50  template<class Key, class T,
51	   class Hash = hash<Key>,
52	   class Pred = std::equal_to<Key>,
53	   class Alloc = std::allocator<std::pair<const Key, T> >,
54	   bool cache_hash_code = false>
55    class unordered_map
56    : public hashtable <Key, std::pair<const Key, T>,
57			Alloc,
58			Internal::extract1st<std::pair<const Key, T> >, Pred,
59			Hash, Internal::mod_range_hashing,
60			Internal::default_ranged_hash,
61			Internal::prime_rehash_policy,
62			cache_hash_code, false, true>
63    {
64      typedef hashtable <Key, std::pair<const Key, T>,
65			 Alloc,
66			 Internal::extract1st<std::pair<const Key, T> >, Pred,
67			 Hash, Internal::mod_range_hashing,
68			 Internal::default_ranged_hash,
69			 Internal::prime_rehash_policy,
70			 cache_hash_code, false, true>
71        Base;
72
73    public:
74      typedef typename Base::size_type size_type;
75      typedef typename Base::hasher hasher;
76      typedef typename Base::key_equal key_equal;
77      typedef typename Base::allocator_type allocator_type;
78
79      explicit
80      unordered_map(size_type n = 10,
81		    const hasher& hf = hasher(),
82		    const key_equal& eql = key_equal(),
83		    const allocator_type& a = allocator_type())
84      : Base(n, hf, Internal::mod_range_hashing(),
85	     Internal::default_ranged_hash(),
86	     eql, Internal::extract1st<std::pair<const Key, T> >(), a)
87      { }
88
89      template<typename InputIterator>
90        unordered_map(InputIterator f, InputIterator l, 
91		      size_type n = 10,
92		      const hasher& hf = hasher(), 
93		      const key_equal& eql = key_equal(), 
94		      const allocator_type& a = allocator_type())
95	: Base (f, l, n, hf, Internal::mod_range_hashing(),
96		Internal::default_ranged_hash(),
97		eql, Internal::extract1st<std::pair<const Key, T> >(), a)
98	{ }
99    };
100  
101  template<class Key, class T,
102	   class Hash = hash<Key>,
103	   class Pred = std::equal_to<Key>,
104	   class Alloc = std::allocator<std::pair<const Key, T> >,
105	   bool cache_hash_code = false>
106    class unordered_multimap
107    : public hashtable <Key, std::pair<const Key, T>,
108			Alloc,
109			Internal::extract1st<std::pair<const Key, T> >, Pred,
110			Hash, Internal::mod_range_hashing,
111			Internal::default_ranged_hash,
112			Internal::prime_rehash_policy,
113			cache_hash_code, false, false>
114    {
115      typedef hashtable <Key, std::pair<const Key, T>,
116			 Alloc,
117			 Internal::extract1st<std::pair<const Key, T> >, Pred,
118			 Hash, Internal::mod_range_hashing,
119			 Internal::default_ranged_hash,
120			 Internal::prime_rehash_policy,
121			 cache_hash_code, false, false>
122        Base;
123
124    public:
125      typedef typename Base::size_type size_type;
126      typedef typename Base::hasher hasher;
127      typedef typename Base::key_equal key_equal;
128      typedef typename Base::allocator_type allocator_type;
129      
130      explicit
131      unordered_multimap(size_type n = 10,
132			 const hasher& hf = hasher(),
133			 const key_equal& eql = key_equal(),
134			 const allocator_type& a = allocator_type())
135      : Base (n, hf, Internal::mod_range_hashing(),
136	      Internal::default_ranged_hash(),
137	      eql, Internal::extract1st<std::pair<const Key, T> >(), a)
138      { }
139
140
141      template<typename InputIterator>
142        unordered_multimap(InputIterator f, InputIterator l, 
143			   typename Base::size_type n = 0,
144			   const hasher& hf = hasher(), 
145			   const key_equal& eql = key_equal(), 
146			   const allocator_type& a = allocator_type())
147	: Base (f, l, n, hf, Internal::mod_range_hashing(),
148		Internal::default_ranged_hash(),
149		eql, Internal::extract1st<std::pair<const Key, T> >(), a)
150        { }
151    };
152
153  template<class Key, class T, class Hash, class Pred, class Alloc,
154	   bool cache_hash_code>
155    inline void
156    swap(unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
157	 unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
158    { x.swap(y); }
159
160  template<class Key, class T, class Hash, class Pred, class Alloc,
161	   bool cache_hash_code>
162    inline void
163    swap(unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
164	 unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
165    { x.swap(y); }
166
167}
168}
169
170#endif /* GNU_LIBSTDCXX_TR1_UNORDERED_MAP_ */
171