xref: /dflybsd-src/contrib/gcc-4.7/libstdc++-v3/include/tr1/hashtable.h (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino // TR1 hashtable.h header -*- C++ -*-
2*e4b17023SJohn Marino 
3*e4b17023SJohn Marino // Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
4*e4b17023SJohn Marino //
5*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library.  This library is free
6*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the
7*e4b17023SJohn Marino // terms of the GNU General Public License as published by the
8*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option)
9*e4b17023SJohn Marino // any later version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful,
12*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*e4b17023SJohn Marino // GNU General Public License for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional
17*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version
18*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation.
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and
21*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program;
22*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>.
24*e4b17023SJohn Marino 
25*e4b17023SJohn Marino /** @file tr1/hashtable.h
26*e4b17023SJohn Marino  *  This is an internal header file, included by other library headers.
27*e4b17023SJohn Marino  *  Do not attempt to use it directly.
28*e4b17023SJohn Marino  *  @headername{tr1/unordered_set, tr1/unordered_map}
29*e4b17023SJohn Marino  */
30*e4b17023SJohn Marino 
31*e4b17023SJohn Marino #ifndef _GLIBCXX_TR1_HASHTABLE_H
32*e4b17023SJohn Marino #define _GLIBCXX_TR1_HASHTABLE_H 1
33*e4b17023SJohn Marino 
34*e4b17023SJohn Marino #pragma GCC system_header
35*e4b17023SJohn Marino 
36*e4b17023SJohn Marino #include <tr1/hashtable_policy.h>
37*e4b17023SJohn Marino 
_GLIBCXX_VISIBILITY(default)38*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default)
39*e4b17023SJohn Marino {
40*e4b17023SJohn Marino namespace tr1
41*e4b17023SJohn Marino {
42*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION
43*e4b17023SJohn Marino 
44*e4b17023SJohn Marino   // Class template _Hashtable, class definition.
45*e4b17023SJohn Marino 
46*e4b17023SJohn Marino   // Meaning of class template _Hashtable's template parameters
47*e4b17023SJohn Marino 
48*e4b17023SJohn Marino   // _Key and _Value: arbitrary CopyConstructible types.
49*e4b17023SJohn Marino 
50*e4b17023SJohn Marino   // _Allocator: an allocator type ([lib.allocator.requirements]) whose
51*e4b17023SJohn Marino   // value type is Value.  As a conforming extension, we allow for
52*e4b17023SJohn Marino   // value type != Value.
53*e4b17023SJohn Marino 
54*e4b17023SJohn Marino   // _ExtractKey: function object that takes a object of type Value
55*e4b17023SJohn Marino   // and returns a value of type _Key.
56*e4b17023SJohn Marino 
57*e4b17023SJohn Marino   // _Equal: function object that takes two objects of type k and returns
58*e4b17023SJohn Marino   // a bool-like value that is true if the two objects are considered equal.
59*e4b17023SJohn Marino 
60*e4b17023SJohn Marino   // _H1: the hash function.  A unary function object with argument type
61*e4b17023SJohn Marino   // Key and result type size_t.  Return values should be distributed
62*e4b17023SJohn Marino   // over the entire range [0, numeric_limits<size_t>:::max()].
63*e4b17023SJohn Marino 
64*e4b17023SJohn Marino   // _H2: the range-hashing function (in the terminology of Tavori and
65*e4b17023SJohn Marino   // Dreizin).  A binary function object whose argument types and result
66*e4b17023SJohn Marino   // type are all size_t.  Given arguments r and N, the return value is
67*e4b17023SJohn Marino   // in the range [0, N).
68*e4b17023SJohn Marino 
69*e4b17023SJohn Marino   // _Hash: the ranged hash function (Tavori and Dreizin). A binary function
70*e4b17023SJohn Marino   // whose argument types are _Key and size_t and whose result type is
71*e4b17023SJohn Marino   // size_t.  Given arguments k and N, the return value is in the range
72*e4b17023SJohn Marino   // [0, N).  Default: hash(k, N) = h2(h1(k), N).  If _Hash is anything other
73*e4b17023SJohn Marino   // than the default, _H1 and _H2 are ignored.
74*e4b17023SJohn Marino 
75*e4b17023SJohn Marino   // _RehashPolicy: Policy class with three members, all of which govern
76*e4b17023SJohn Marino   // the bucket count. _M_next_bkt(n) returns a bucket count no smaller
77*e4b17023SJohn Marino   // than n.  _M_bkt_for_elements(n) returns a bucket count appropriate
78*e4b17023SJohn Marino   // for an element count of n.  _M_need_rehash(n_bkt, n_elt, n_ins)
79*e4b17023SJohn Marino   // determines whether, if the current bucket count is n_bkt and the
80*e4b17023SJohn Marino   // current element count is n_elt, we need to increase the bucket
81*e4b17023SJohn Marino   // count.  If so, returns make_pair(true, n), where n is the new
82*e4b17023SJohn Marino   // bucket count.  If not, returns make_pair(false, <anything>).
83*e4b17023SJohn Marino 
84*e4b17023SJohn Marino   // ??? Right now it is hard-wired that the number of buckets never
85*e4b17023SJohn Marino   // shrinks.  Should we allow _RehashPolicy to change that?
86*e4b17023SJohn Marino 
87*e4b17023SJohn Marino   // __cache_hash_code: bool.  true if we store the value of the hash
88*e4b17023SJohn Marino   // function along with the value.  This is a time-space tradeoff.
89*e4b17023SJohn Marino   // Storing it may improve lookup speed by reducing the number of times
90*e4b17023SJohn Marino   // we need to call the Equal function.
91*e4b17023SJohn Marino 
92*e4b17023SJohn Marino   // __constant_iterators: bool.  true if iterator and const_iterator are
93*e4b17023SJohn Marino   // both constant iterator types.  This is true for unordered_set and
94*e4b17023SJohn Marino   // unordered_multiset, false for unordered_map and unordered_multimap.
95*e4b17023SJohn Marino 
96*e4b17023SJohn Marino   // __unique_keys: bool.  true if the return value of _Hashtable::count(k)
97*e4b17023SJohn Marino   // is always at most one, false if it may be an arbitrary number.  This
98*e4b17023SJohn Marino   // true for unordered_set and unordered_map, false for unordered_multiset
99*e4b17023SJohn Marino   // and unordered_multimap.
100*e4b17023SJohn Marino 
101*e4b17023SJohn Marino   template<typename _Key, typename _Value, typename _Allocator,
102*e4b17023SJohn Marino 	   typename _ExtractKey, typename _Equal,
103*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash,
104*e4b17023SJohn Marino 	   typename _RehashPolicy,
105*e4b17023SJohn Marino 	   bool __cache_hash_code,
106*e4b17023SJohn Marino 	   bool __constant_iterators,
107*e4b17023SJohn Marino 	   bool __unique_keys>
108*e4b17023SJohn Marino     class _Hashtable
109*e4b17023SJohn Marino     : public __detail::_Rehash_base<_RehashPolicy,
110*e4b17023SJohn Marino 				    _Hashtable<_Key, _Value, _Allocator,
111*e4b17023SJohn Marino 					       _ExtractKey,
112*e4b17023SJohn Marino 					       _Equal, _H1, _H2, _Hash,
113*e4b17023SJohn Marino 					       _RehashPolicy,
114*e4b17023SJohn Marino 					       __cache_hash_code,
115*e4b17023SJohn Marino 					       __constant_iterators,
116*e4b17023SJohn Marino 					       __unique_keys> >,
117*e4b17023SJohn Marino       public __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal,
118*e4b17023SJohn Marino 				       _H1, _H2, _Hash, __cache_hash_code>,
119*e4b17023SJohn Marino       public __detail::_Map_base<_Key, _Value, _ExtractKey, __unique_keys,
120*e4b17023SJohn Marino 				 _Hashtable<_Key, _Value, _Allocator,
121*e4b17023SJohn Marino 					    _ExtractKey,
122*e4b17023SJohn Marino 					    _Equal, _H1, _H2, _Hash,
123*e4b17023SJohn Marino 					    _RehashPolicy,
124*e4b17023SJohn Marino 					    __cache_hash_code,
125*e4b17023SJohn Marino 					    __constant_iterators,
126*e4b17023SJohn Marino 					    __unique_keys> >
127*e4b17023SJohn Marino     {
128*e4b17023SJohn Marino     public:
129*e4b17023SJohn Marino       typedef _Allocator                                  allocator_type;
130*e4b17023SJohn Marino       typedef _Value                                      value_type;
131*e4b17023SJohn Marino       typedef _Key                                        key_type;
132*e4b17023SJohn Marino       typedef _Equal                                      key_equal;
133*e4b17023SJohn Marino       // mapped_type, if present, comes from _Map_base.
134*e4b17023SJohn Marino       // hasher, if present, comes from _Hash_code_base.
135*e4b17023SJohn Marino       typedef typename _Allocator::difference_type        difference_type;
136*e4b17023SJohn Marino       typedef typename _Allocator::size_type              size_type;
137*e4b17023SJohn Marino       typedef typename _Allocator::pointer                pointer;
138*e4b17023SJohn Marino       typedef typename _Allocator::const_pointer          const_pointer;
139*e4b17023SJohn Marino       typedef typename _Allocator::reference              reference;
140*e4b17023SJohn Marino       typedef typename _Allocator::const_reference        const_reference;
141*e4b17023SJohn Marino 
142*e4b17023SJohn Marino       typedef __detail::_Node_iterator<value_type, __constant_iterators,
143*e4b17023SJohn Marino 				       __cache_hash_code>
144*e4b17023SJohn Marino 							  local_iterator;
145*e4b17023SJohn Marino       typedef __detail::_Node_const_iterator<value_type,
146*e4b17023SJohn Marino 					     __constant_iterators,
147*e4b17023SJohn Marino 					     __cache_hash_code>
148*e4b17023SJohn Marino 							  const_local_iterator;
149*e4b17023SJohn Marino 
150*e4b17023SJohn Marino       typedef __detail::_Hashtable_iterator<value_type, __constant_iterators,
151*e4b17023SJohn Marino 					    __cache_hash_code>
152*e4b17023SJohn Marino 							  iterator;
153*e4b17023SJohn Marino       typedef __detail::_Hashtable_const_iterator<value_type,
154*e4b17023SJohn Marino 						  __constant_iterators,
155*e4b17023SJohn Marino 						  __cache_hash_code>
156*e4b17023SJohn Marino 							  const_iterator;
157*e4b17023SJohn Marino 
158*e4b17023SJohn Marino       template<typename _Key2, typename _Value2, typename _Ex2, bool __unique2,
159*e4b17023SJohn Marino 	       typename _Hashtable2>
160*e4b17023SJohn Marino 	friend struct __detail::_Map_base;
161*e4b17023SJohn Marino 
162*e4b17023SJohn Marino     private:
163*e4b17023SJohn Marino       typedef __detail::_Hash_node<_Value, __cache_hash_code> _Node;
164*e4b17023SJohn Marino       typedef typename _Allocator::template rebind<_Node>::other
165*e4b17023SJohn Marino 							_Node_allocator_type;
166*e4b17023SJohn Marino       typedef typename _Allocator::template rebind<_Node*>::other
167*e4b17023SJohn Marino 							_Bucket_allocator_type;
168*e4b17023SJohn Marino 
169*e4b17023SJohn Marino       typedef typename _Allocator::template rebind<_Value>::other
170*e4b17023SJohn Marino 							_Value_allocator_type;
171*e4b17023SJohn Marino 
172*e4b17023SJohn Marino       _Node_allocator_type   _M_node_allocator;
173*e4b17023SJohn Marino       _Node**                _M_buckets;
174*e4b17023SJohn Marino       size_type              _M_bucket_count;
175*e4b17023SJohn Marino       size_type              _M_element_count;
176*e4b17023SJohn Marino       _RehashPolicy          _M_rehash_policy;
177*e4b17023SJohn Marino 
178*e4b17023SJohn Marino       _Node*
179*e4b17023SJohn Marino       _M_allocate_node(const value_type& __v);
180*e4b17023SJohn Marino 
181*e4b17023SJohn Marino       void
182*e4b17023SJohn Marino       _M_deallocate_node(_Node* __n);
183*e4b17023SJohn Marino 
184*e4b17023SJohn Marino       void
185*e4b17023SJohn Marino       _M_deallocate_nodes(_Node**, size_type);
186*e4b17023SJohn Marino 
187*e4b17023SJohn Marino       _Node**
188*e4b17023SJohn Marino       _M_allocate_buckets(size_type __n);
189*e4b17023SJohn Marino 
190*e4b17023SJohn Marino       void
191*e4b17023SJohn Marino       _M_deallocate_buckets(_Node**, size_type __n);
192*e4b17023SJohn Marino 
193*e4b17023SJohn Marino     public:
194*e4b17023SJohn Marino       // Constructor, destructor, assignment, swap
195*e4b17023SJohn Marino       _Hashtable(size_type __bucket_hint,
196*e4b17023SJohn Marino 		 const _H1&, const _H2&, const _Hash&,
197*e4b17023SJohn Marino 		 const _Equal&, const _ExtractKey&,
198*e4b17023SJohn Marino 		 const allocator_type&);
199*e4b17023SJohn Marino 
200*e4b17023SJohn Marino       template<typename _InputIterator>
201*e4b17023SJohn Marino 	_Hashtable(_InputIterator __first, _InputIterator __last,
202*e4b17023SJohn Marino 		   size_type __bucket_hint,
203*e4b17023SJohn Marino 		   const _H1&, const _H2&, const _Hash&,
204*e4b17023SJohn Marino 		   const _Equal&, const _ExtractKey&,
205*e4b17023SJohn Marino 		   const allocator_type&);
206*e4b17023SJohn Marino 
207*e4b17023SJohn Marino       _Hashtable(const _Hashtable&);
208*e4b17023SJohn Marino 
209*e4b17023SJohn Marino       _Hashtable&
210*e4b17023SJohn Marino       operator=(const _Hashtable&);
211*e4b17023SJohn Marino 
212*e4b17023SJohn Marino       ~_Hashtable();
213*e4b17023SJohn Marino 
214*e4b17023SJohn Marino       void swap(_Hashtable&);
215*e4b17023SJohn Marino 
216*e4b17023SJohn Marino       // Basic container operations
217*e4b17023SJohn Marino       iterator
218*e4b17023SJohn Marino       begin()
219*e4b17023SJohn Marino       {
220*e4b17023SJohn Marino 	iterator __i(_M_buckets);
221*e4b17023SJohn Marino 	if (!__i._M_cur_node)
222*e4b17023SJohn Marino 	  __i._M_incr_bucket();
223*e4b17023SJohn Marino 	return __i;
224*e4b17023SJohn Marino       }
225*e4b17023SJohn Marino 
226*e4b17023SJohn Marino       const_iterator
227*e4b17023SJohn Marino       begin() const
228*e4b17023SJohn Marino       {
229*e4b17023SJohn Marino 	const_iterator __i(_M_buckets);
230*e4b17023SJohn Marino 	if (!__i._M_cur_node)
231*e4b17023SJohn Marino 	  __i._M_incr_bucket();
232*e4b17023SJohn Marino 	return __i;
233*e4b17023SJohn Marino       }
234*e4b17023SJohn Marino 
235*e4b17023SJohn Marino       iterator
236*e4b17023SJohn Marino       end()
237*e4b17023SJohn Marino       { return iterator(_M_buckets + _M_bucket_count); }
238*e4b17023SJohn Marino 
239*e4b17023SJohn Marino       const_iterator
240*e4b17023SJohn Marino       end() const
241*e4b17023SJohn Marino       { return const_iterator(_M_buckets + _M_bucket_count); }
242*e4b17023SJohn Marino 
243*e4b17023SJohn Marino       size_type
244*e4b17023SJohn Marino       size() const
245*e4b17023SJohn Marino       { return _M_element_count; }
246*e4b17023SJohn Marino 
247*e4b17023SJohn Marino       bool
248*e4b17023SJohn Marino       empty() const
249*e4b17023SJohn Marino       { return size() == 0; }
250*e4b17023SJohn Marino 
251*e4b17023SJohn Marino       allocator_type
252*e4b17023SJohn Marino       get_allocator() const
253*e4b17023SJohn Marino       { return allocator_type(_M_node_allocator); }
254*e4b17023SJohn Marino 
255*e4b17023SJohn Marino       _Value_allocator_type
256*e4b17023SJohn Marino       _M_get_Value_allocator() const
257*e4b17023SJohn Marino       { return _Value_allocator_type(_M_node_allocator); }
258*e4b17023SJohn Marino 
259*e4b17023SJohn Marino       size_type
260*e4b17023SJohn Marino       max_size() const
261*e4b17023SJohn Marino       { return _M_node_allocator.max_size(); }
262*e4b17023SJohn Marino 
263*e4b17023SJohn Marino       // Observers
264*e4b17023SJohn Marino       key_equal
265*e4b17023SJohn Marino       key_eq() const
266*e4b17023SJohn Marino       { return this->_M_eq; }
267*e4b17023SJohn Marino 
268*e4b17023SJohn Marino       // hash_function, if present, comes from _Hash_code_base.
269*e4b17023SJohn Marino 
270*e4b17023SJohn Marino       // Bucket operations
271*e4b17023SJohn Marino       size_type
272*e4b17023SJohn Marino       bucket_count() const
273*e4b17023SJohn Marino       { return _M_bucket_count; }
274*e4b17023SJohn Marino 
275*e4b17023SJohn Marino       size_type
276*e4b17023SJohn Marino       max_bucket_count() const
277*e4b17023SJohn Marino       { return max_size(); }
278*e4b17023SJohn Marino 
279*e4b17023SJohn Marino       size_type
280*e4b17023SJohn Marino       bucket_size(size_type __n) const
281*e4b17023SJohn Marino       { return std::distance(begin(__n), end(__n)); }
282*e4b17023SJohn Marino 
283*e4b17023SJohn Marino       size_type
284*e4b17023SJohn Marino       bucket(const key_type& __k) const
285*e4b17023SJohn Marino       {
286*e4b17023SJohn Marino 	return this->_M_bucket_index(__k, this->_M_hash_code(__k),
287*e4b17023SJohn Marino 				     bucket_count());
288*e4b17023SJohn Marino       }
289*e4b17023SJohn Marino 
290*e4b17023SJohn Marino       local_iterator
291*e4b17023SJohn Marino       begin(size_type __n)
292*e4b17023SJohn Marino       { return local_iterator(_M_buckets[__n]); }
293*e4b17023SJohn Marino 
294*e4b17023SJohn Marino       local_iterator
295*e4b17023SJohn Marino       end(size_type)
296*e4b17023SJohn Marino       { return local_iterator(0); }
297*e4b17023SJohn Marino 
298*e4b17023SJohn Marino       const_local_iterator
299*e4b17023SJohn Marino       begin(size_type __n) const
300*e4b17023SJohn Marino       { return const_local_iterator(_M_buckets[__n]); }
301*e4b17023SJohn Marino 
302*e4b17023SJohn Marino       const_local_iterator
303*e4b17023SJohn Marino       end(size_type) const
304*e4b17023SJohn Marino       { return const_local_iterator(0); }
305*e4b17023SJohn Marino 
306*e4b17023SJohn Marino       float
307*e4b17023SJohn Marino       load_factor() const
308*e4b17023SJohn Marino       {
309*e4b17023SJohn Marino 	return static_cast<float>(size()) / static_cast<float>(bucket_count());
310*e4b17023SJohn Marino       }
311*e4b17023SJohn Marino 
312*e4b17023SJohn Marino       // max_load_factor, if present, comes from _Rehash_base.
313*e4b17023SJohn Marino 
314*e4b17023SJohn Marino       // Generalization of max_load_factor.  Extension, not found in TR1.  Only
315*e4b17023SJohn Marino       // useful if _RehashPolicy is something other than the default.
316*e4b17023SJohn Marino       const _RehashPolicy&
317*e4b17023SJohn Marino       __rehash_policy() const
318*e4b17023SJohn Marino       { return _M_rehash_policy; }
319*e4b17023SJohn Marino 
320*e4b17023SJohn Marino       void
321*e4b17023SJohn Marino       __rehash_policy(const _RehashPolicy&);
322*e4b17023SJohn Marino 
323*e4b17023SJohn Marino       // Lookup.
324*e4b17023SJohn Marino       iterator
325*e4b17023SJohn Marino       find(const key_type& __k);
326*e4b17023SJohn Marino 
327*e4b17023SJohn Marino       const_iterator
328*e4b17023SJohn Marino       find(const key_type& __k) const;
329*e4b17023SJohn Marino 
330*e4b17023SJohn Marino       size_type
331*e4b17023SJohn Marino       count(const key_type& __k) const;
332*e4b17023SJohn Marino 
333*e4b17023SJohn Marino       std::pair<iterator, iterator>
334*e4b17023SJohn Marino       equal_range(const key_type& __k);
335*e4b17023SJohn Marino 
336*e4b17023SJohn Marino       std::pair<const_iterator, const_iterator>
337*e4b17023SJohn Marino       equal_range(const key_type& __k) const;
338*e4b17023SJohn Marino 
339*e4b17023SJohn Marino     private:			// Find, insert and erase helper functions
340*e4b17023SJohn Marino       // ??? This dispatching is a workaround for the fact that we don't
341*e4b17023SJohn Marino       // have partial specialization of member templates; it would be
342*e4b17023SJohn Marino       // better to just specialize insert on __unique_keys.  There may be a
343*e4b17023SJohn Marino       // cleaner workaround.
344*e4b17023SJohn Marino       typedef typename __gnu_cxx::__conditional_type<__unique_keys,
345*e4b17023SJohn Marino 		       	    std::pair<iterator, bool>, iterator>::__type
346*e4b17023SJohn Marino 	_Insert_Return_Type;
347*e4b17023SJohn Marino 
348*e4b17023SJohn Marino       typedef typename __gnu_cxx::__conditional_type<__unique_keys,
349*e4b17023SJohn Marino 					  std::_Select1st<_Insert_Return_Type>,
350*e4b17023SJohn Marino 				  	  std::_Identity<_Insert_Return_Type>
351*e4b17023SJohn Marino 				   >::__type
352*e4b17023SJohn Marino 	_Insert_Conv_Type;
353*e4b17023SJohn Marino 
354*e4b17023SJohn Marino       _Node*
355*e4b17023SJohn Marino       _M_find_node(_Node*, const key_type&,
356*e4b17023SJohn Marino 		   typename _Hashtable::_Hash_code_type) const;
357*e4b17023SJohn Marino 
358*e4b17023SJohn Marino       iterator
359*e4b17023SJohn Marino       _M_insert_bucket(const value_type&, size_type,
360*e4b17023SJohn Marino 		       typename _Hashtable::_Hash_code_type);
361*e4b17023SJohn Marino 
362*e4b17023SJohn Marino       std::pair<iterator, bool>
363*e4b17023SJohn Marino       _M_insert(const value_type&, std::tr1::true_type);
364*e4b17023SJohn Marino 
365*e4b17023SJohn Marino       iterator
366*e4b17023SJohn Marino       _M_insert(const value_type&, std::tr1::false_type);
367*e4b17023SJohn Marino 
368*e4b17023SJohn Marino       void
369*e4b17023SJohn Marino       _M_erase_node(_Node*, _Node**);
370*e4b17023SJohn Marino 
371*e4b17023SJohn Marino     public:
372*e4b17023SJohn Marino       // Insert and erase
373*e4b17023SJohn Marino       _Insert_Return_Type
374*e4b17023SJohn Marino       insert(const value_type& __v)
375*e4b17023SJohn Marino       { return _M_insert(__v, std::tr1::integral_constant<bool,
376*e4b17023SJohn Marino 			 __unique_keys>()); }
377*e4b17023SJohn Marino 
378*e4b17023SJohn Marino       iterator
379*e4b17023SJohn Marino       insert(iterator, const value_type& __v)
380*e4b17023SJohn Marino       { return iterator(_Insert_Conv_Type()(this->insert(__v))); }
381*e4b17023SJohn Marino 
382*e4b17023SJohn Marino       const_iterator
383*e4b17023SJohn Marino       insert(const_iterator, const value_type& __v)
384*e4b17023SJohn Marino       { return const_iterator(_Insert_Conv_Type()(this->insert(__v))); }
385*e4b17023SJohn Marino 
386*e4b17023SJohn Marino       template<typename _InputIterator>
387*e4b17023SJohn Marino 	void
388*e4b17023SJohn Marino 	insert(_InputIterator __first, _InputIterator __last);
389*e4b17023SJohn Marino 
390*e4b17023SJohn Marino       iterator
391*e4b17023SJohn Marino       erase(iterator);
392*e4b17023SJohn Marino 
393*e4b17023SJohn Marino       const_iterator
394*e4b17023SJohn Marino       erase(const_iterator);
395*e4b17023SJohn Marino 
396*e4b17023SJohn Marino       size_type
397*e4b17023SJohn Marino       erase(const key_type&);
398*e4b17023SJohn Marino 
399*e4b17023SJohn Marino       iterator
400*e4b17023SJohn Marino       erase(iterator, iterator);
401*e4b17023SJohn Marino 
402*e4b17023SJohn Marino       const_iterator
403*e4b17023SJohn Marino       erase(const_iterator, const_iterator);
404*e4b17023SJohn Marino 
405*e4b17023SJohn Marino       void
406*e4b17023SJohn Marino       clear();
407*e4b17023SJohn Marino 
408*e4b17023SJohn Marino       // Set number of buckets to be appropriate for container of n element.
409*e4b17023SJohn Marino       void rehash(size_type __n);
410*e4b17023SJohn Marino 
411*e4b17023SJohn Marino     private:
412*e4b17023SJohn Marino       // Unconditionally change size of bucket array to n.
413*e4b17023SJohn Marino       void _M_rehash(size_type __n);
414*e4b17023SJohn Marino     };
415*e4b17023SJohn Marino 
416*e4b17023SJohn Marino 
417*e4b17023SJohn Marino   // Definitions of class template _Hashtable's out-of-line member functions.
418*e4b17023SJohn Marino   template<typename _Key, typename _Value,
419*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
420*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
421*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
422*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
423*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
424*e4b17023SJohn Marino 			__chc, __cit, __uk>::_Node*
425*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
426*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
427*e4b17023SJohn Marino     _M_allocate_node(const value_type& __v)
428*e4b17023SJohn Marino     {
429*e4b17023SJohn Marino       _Node* __n = _M_node_allocator.allocate(1);
430*e4b17023SJohn Marino       __try
431*e4b17023SJohn Marino 	{
432*e4b17023SJohn Marino 	  _M_get_Value_allocator().construct(&__n->_M_v, __v);
433*e4b17023SJohn Marino 	  __n->_M_next = 0;
434*e4b17023SJohn Marino 	  return __n;
435*e4b17023SJohn Marino 	}
436*e4b17023SJohn Marino       __catch(...)
437*e4b17023SJohn Marino 	{
438*e4b17023SJohn Marino 	  _M_node_allocator.deallocate(__n, 1);
439*e4b17023SJohn Marino 	  __throw_exception_again;
440*e4b17023SJohn Marino 	}
441*e4b17023SJohn Marino     }
442*e4b17023SJohn Marino 
443*e4b17023SJohn Marino   template<typename _Key, typename _Value,
444*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
445*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
446*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
447*e4b17023SJohn Marino     void
448*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
449*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
450*e4b17023SJohn Marino     _M_deallocate_node(_Node* __n)
451*e4b17023SJohn Marino     {
452*e4b17023SJohn Marino       _M_get_Value_allocator().destroy(&__n->_M_v);
453*e4b17023SJohn Marino       _M_node_allocator.deallocate(__n, 1);
454*e4b17023SJohn Marino     }
455*e4b17023SJohn Marino 
456*e4b17023SJohn Marino   template<typename _Key, typename _Value,
457*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
458*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
459*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
460*e4b17023SJohn Marino     void
461*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
462*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
463*e4b17023SJohn Marino     _M_deallocate_nodes(_Node** __array, size_type __n)
464*e4b17023SJohn Marino     {
465*e4b17023SJohn Marino       for (size_type __i = 0; __i < __n; ++__i)
466*e4b17023SJohn Marino 	{
467*e4b17023SJohn Marino 	  _Node* __p = __array[__i];
468*e4b17023SJohn Marino 	  while (__p)
469*e4b17023SJohn Marino 	    {
470*e4b17023SJohn Marino 	      _Node* __tmp = __p;
471*e4b17023SJohn Marino 	      __p = __p->_M_next;
472*e4b17023SJohn Marino 	      _M_deallocate_node(__tmp);
473*e4b17023SJohn Marino 	    }
474*e4b17023SJohn Marino 	  __array[__i] = 0;
475*e4b17023SJohn Marino 	}
476*e4b17023SJohn Marino     }
477*e4b17023SJohn Marino 
478*e4b17023SJohn Marino   template<typename _Key, typename _Value,
479*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
480*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
481*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
482*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
483*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
484*e4b17023SJohn Marino 			__chc, __cit, __uk>::_Node**
485*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
486*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
487*e4b17023SJohn Marino     _M_allocate_buckets(size_type __n)
488*e4b17023SJohn Marino     {
489*e4b17023SJohn Marino       _Bucket_allocator_type __alloc(_M_node_allocator);
490*e4b17023SJohn Marino 
491*e4b17023SJohn Marino       // We allocate one extra bucket to hold a sentinel, an arbitrary
492*e4b17023SJohn Marino       // non-null pointer.  Iterator increment relies on this.
493*e4b17023SJohn Marino       _Node** __p = __alloc.allocate(__n + 1);
494*e4b17023SJohn Marino       std::fill(__p, __p + __n, (_Node*) 0);
495*e4b17023SJohn Marino       __p[__n] = reinterpret_cast<_Node*>(0x1000);
496*e4b17023SJohn Marino       return __p;
497*e4b17023SJohn Marino     }
498*e4b17023SJohn Marino 
499*e4b17023SJohn Marino   template<typename _Key, typename _Value,
500*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
501*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
502*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
503*e4b17023SJohn Marino     void
504*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
505*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
506*e4b17023SJohn Marino     _M_deallocate_buckets(_Node** __p, size_type __n)
507*e4b17023SJohn Marino     {
508*e4b17023SJohn Marino       _Bucket_allocator_type __alloc(_M_node_allocator);
509*e4b17023SJohn Marino       __alloc.deallocate(__p, __n + 1);
510*e4b17023SJohn Marino     }
511*e4b17023SJohn Marino 
512*e4b17023SJohn Marino   template<typename _Key, typename _Value,
513*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
514*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
515*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
516*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
517*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
518*e4b17023SJohn Marino     _Hashtable(size_type __bucket_hint,
519*e4b17023SJohn Marino 	       const _H1& __h1, const _H2& __h2, const _Hash& __h,
520*e4b17023SJohn Marino 	       const _Equal& __eq, const _ExtractKey& __exk,
521*e4b17023SJohn Marino 	       const allocator_type& __a)
522*e4b17023SJohn Marino     : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(),
523*e4b17023SJohn Marino       __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal,
524*e4b17023SJohn Marino 				_H1, _H2, _Hash, __chc>(__exk, __eq,
525*e4b17023SJohn Marino 							__h1, __h2, __h),
526*e4b17023SJohn Marino       __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(),
527*e4b17023SJohn Marino       _M_node_allocator(__a),
528*e4b17023SJohn Marino       _M_bucket_count(0),
529*e4b17023SJohn Marino       _M_element_count(0),
530*e4b17023SJohn Marino       _M_rehash_policy()
531*e4b17023SJohn Marino     {
532*e4b17023SJohn Marino       _M_bucket_count = _M_rehash_policy._M_next_bkt(__bucket_hint);
533*e4b17023SJohn Marino       _M_buckets = _M_allocate_buckets(_M_bucket_count);
534*e4b17023SJohn Marino     }
535*e4b17023SJohn Marino 
536*e4b17023SJohn Marino   template<typename _Key, typename _Value,
537*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
538*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
539*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
540*e4b17023SJohn Marino     template<typename _InputIterator>
541*e4b17023SJohn Marino       _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
542*e4b17023SJohn Marino 		 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
543*e4b17023SJohn Marino       _Hashtable(_InputIterator __f, _InputIterator __l,
544*e4b17023SJohn Marino 		 size_type __bucket_hint,
545*e4b17023SJohn Marino 		 const _H1& __h1, const _H2& __h2, const _Hash& __h,
546*e4b17023SJohn Marino 		 const _Equal& __eq, const _ExtractKey& __exk,
547*e4b17023SJohn Marino 		 const allocator_type& __a)
548*e4b17023SJohn Marino       : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(),
549*e4b17023SJohn Marino 	__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal,
550*e4b17023SJohn Marino 				  _H1, _H2, _Hash, __chc>(__exk, __eq,
551*e4b17023SJohn Marino 							  __h1, __h2, __h),
552*e4b17023SJohn Marino 	__detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(),
553*e4b17023SJohn Marino 	_M_node_allocator(__a),
554*e4b17023SJohn Marino 	_M_bucket_count(0),
555*e4b17023SJohn Marino 	_M_element_count(0),
556*e4b17023SJohn Marino 	_M_rehash_policy()
557*e4b17023SJohn Marino       {
558*e4b17023SJohn Marino 	_M_bucket_count = std::max(_M_rehash_policy._M_next_bkt(__bucket_hint),
559*e4b17023SJohn Marino 				   _M_rehash_policy.
560*e4b17023SJohn Marino 				   _M_bkt_for_elements(__detail::
561*e4b17023SJohn Marino 						       __distance_fw(__f,
562*e4b17023SJohn Marino 								     __l)));
563*e4b17023SJohn Marino 	_M_buckets = _M_allocate_buckets(_M_bucket_count);
564*e4b17023SJohn Marino 	__try
565*e4b17023SJohn Marino 	  {
566*e4b17023SJohn Marino 	    for (; __f != __l; ++__f)
567*e4b17023SJohn Marino 	      this->insert(*__f);
568*e4b17023SJohn Marino 	  }
569*e4b17023SJohn Marino 	__catch(...)
570*e4b17023SJohn Marino 	  {
571*e4b17023SJohn Marino 	    clear();
572*e4b17023SJohn Marino 	    _M_deallocate_buckets(_M_buckets, _M_bucket_count);
573*e4b17023SJohn Marino 	    __throw_exception_again;
574*e4b17023SJohn Marino 	  }
575*e4b17023SJohn Marino       }
576*e4b17023SJohn Marino 
577*e4b17023SJohn Marino   template<typename _Key, typename _Value,
578*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
579*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
580*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
581*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
582*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
583*e4b17023SJohn Marino     _Hashtable(const _Hashtable& __ht)
584*e4b17023SJohn Marino     : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(__ht),
585*e4b17023SJohn Marino       __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal,
586*e4b17023SJohn Marino 				_H1, _H2, _Hash, __chc>(__ht),
587*e4b17023SJohn Marino       __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(__ht),
588*e4b17023SJohn Marino       _M_node_allocator(__ht._M_node_allocator),
589*e4b17023SJohn Marino       _M_bucket_count(__ht._M_bucket_count),
590*e4b17023SJohn Marino       _M_element_count(__ht._M_element_count),
591*e4b17023SJohn Marino       _M_rehash_policy(__ht._M_rehash_policy)
592*e4b17023SJohn Marino     {
593*e4b17023SJohn Marino       _M_buckets = _M_allocate_buckets(_M_bucket_count);
594*e4b17023SJohn Marino       __try
595*e4b17023SJohn Marino 	{
596*e4b17023SJohn Marino 	  for (size_type __i = 0; __i < __ht._M_bucket_count; ++__i)
597*e4b17023SJohn Marino 	    {
598*e4b17023SJohn Marino 	      _Node* __n = __ht._M_buckets[__i];
599*e4b17023SJohn Marino 	      _Node** __tail = _M_buckets + __i;
600*e4b17023SJohn Marino 	      while (__n)
601*e4b17023SJohn Marino 		{
602*e4b17023SJohn Marino 		  *__tail = _M_allocate_node(__n->_M_v);
603*e4b17023SJohn Marino 		  this->_M_copy_code(*__tail, __n);
604*e4b17023SJohn Marino 		  __tail = &((*__tail)->_M_next);
605*e4b17023SJohn Marino 		  __n = __n->_M_next;
606*e4b17023SJohn Marino 		}
607*e4b17023SJohn Marino 	    }
608*e4b17023SJohn Marino 	}
609*e4b17023SJohn Marino       __catch(...)
610*e4b17023SJohn Marino 	{
611*e4b17023SJohn Marino 	  clear();
612*e4b17023SJohn Marino 	  _M_deallocate_buckets(_M_buckets, _M_bucket_count);
613*e4b17023SJohn Marino 	  __throw_exception_again;
614*e4b17023SJohn Marino 	}
615*e4b17023SJohn Marino     }
616*e4b17023SJohn Marino 
617*e4b17023SJohn Marino   template<typename _Key, typename _Value,
618*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
619*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
620*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
621*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
622*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>&
623*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
624*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
625*e4b17023SJohn Marino     operator=(const _Hashtable& __ht)
626*e4b17023SJohn Marino     {
627*e4b17023SJohn Marino       _Hashtable __tmp(__ht);
628*e4b17023SJohn Marino       this->swap(__tmp);
629*e4b17023SJohn Marino       return *this;
630*e4b17023SJohn Marino     }
631*e4b17023SJohn Marino 
632*e4b17023SJohn Marino   template<typename _Key, typename _Value,
633*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
634*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
635*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
636*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
637*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
638*e4b17023SJohn Marino     ~_Hashtable()
639*e4b17023SJohn Marino     {
640*e4b17023SJohn Marino       clear();
641*e4b17023SJohn Marino       _M_deallocate_buckets(_M_buckets, _M_bucket_count);
642*e4b17023SJohn Marino     }
643*e4b17023SJohn Marino 
644*e4b17023SJohn Marino   template<typename _Key, typename _Value,
645*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
646*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
647*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
648*e4b17023SJohn Marino     void
649*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
650*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
651*e4b17023SJohn Marino     swap(_Hashtable& __x)
652*e4b17023SJohn Marino     {
653*e4b17023SJohn Marino       // The only base class with member variables is hash_code_base.  We
654*e4b17023SJohn Marino       // define _Hash_code_base::_M_swap because different specializations
655*e4b17023SJohn Marino       // have different members.
656*e4b17023SJohn Marino       __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal,
657*e4b17023SJohn Marino 	_H1, _H2, _Hash, __chc>::_M_swap(__x);
658*e4b17023SJohn Marino 
659*e4b17023SJohn Marino       // _GLIBCXX_RESOLVE_LIB_DEFECTS
660*e4b17023SJohn Marino       // 431. Swapping containers with unequal allocators.
661*e4b17023SJohn Marino       std::__alloc_swap<_Node_allocator_type>::_S_do_it(_M_node_allocator,
662*e4b17023SJohn Marino 							__x._M_node_allocator);
663*e4b17023SJohn Marino 
664*e4b17023SJohn Marino       std::swap(_M_rehash_policy, __x._M_rehash_policy);
665*e4b17023SJohn Marino       std::swap(_M_buckets, __x._M_buckets);
666*e4b17023SJohn Marino       std::swap(_M_bucket_count, __x._M_bucket_count);
667*e4b17023SJohn Marino       std::swap(_M_element_count, __x._M_element_count);
668*e4b17023SJohn Marino     }
669*e4b17023SJohn Marino 
670*e4b17023SJohn Marino   template<typename _Key, typename _Value,
671*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
672*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
673*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
674*e4b17023SJohn Marino     void
675*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
676*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
677*e4b17023SJohn Marino     __rehash_policy(const _RehashPolicy& __pol)
678*e4b17023SJohn Marino     {
679*e4b17023SJohn Marino       _M_rehash_policy = __pol;
680*e4b17023SJohn Marino       size_type __n_bkt = __pol._M_bkt_for_elements(_M_element_count);
681*e4b17023SJohn Marino       if (__n_bkt > _M_bucket_count)
682*e4b17023SJohn Marino 	_M_rehash(__n_bkt);
683*e4b17023SJohn Marino     }
684*e4b17023SJohn Marino 
685*e4b17023SJohn Marino   template<typename _Key, typename _Value,
686*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
687*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
688*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
689*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
690*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
691*e4b17023SJohn Marino 			__chc, __cit, __uk>::iterator
692*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
693*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
694*e4b17023SJohn Marino     find(const key_type& __k)
695*e4b17023SJohn Marino     {
696*e4b17023SJohn Marino       typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
697*e4b17023SJohn Marino       std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count);
698*e4b17023SJohn Marino       _Node* __p = _M_find_node(_M_buckets[__n], __k, __code);
699*e4b17023SJohn Marino       return __p ? iterator(__p, _M_buckets + __n) : this->end();
700*e4b17023SJohn Marino     }
701*e4b17023SJohn Marino 
702*e4b17023SJohn Marino   template<typename _Key, typename _Value,
703*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
704*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
705*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
706*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
707*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
708*e4b17023SJohn Marino 			__chc, __cit, __uk>::const_iterator
709*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
710*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
711*e4b17023SJohn Marino     find(const key_type& __k) const
712*e4b17023SJohn Marino     {
713*e4b17023SJohn Marino       typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
714*e4b17023SJohn Marino       std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count);
715*e4b17023SJohn Marino       _Node* __p = _M_find_node(_M_buckets[__n], __k, __code);
716*e4b17023SJohn Marino       return __p ? const_iterator(__p, _M_buckets + __n) : this->end();
717*e4b17023SJohn Marino     }
718*e4b17023SJohn Marino 
719*e4b17023SJohn Marino   template<typename _Key, typename _Value,
720*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
721*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
722*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
723*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
724*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
725*e4b17023SJohn Marino 			__chc, __cit, __uk>::size_type
726*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
727*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
728*e4b17023SJohn Marino     count(const key_type& __k) const
729*e4b17023SJohn Marino     {
730*e4b17023SJohn Marino       typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
731*e4b17023SJohn Marino       std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count);
732*e4b17023SJohn Marino       std::size_t __result = 0;
733*e4b17023SJohn Marino       for (_Node* __p = _M_buckets[__n]; __p; __p = __p->_M_next)
734*e4b17023SJohn Marino 	if (this->_M_compare(__k, __code, __p))
735*e4b17023SJohn Marino 	  ++__result;
736*e4b17023SJohn Marino       return __result;
737*e4b17023SJohn Marino     }
738*e4b17023SJohn Marino 
739*e4b17023SJohn Marino   template<typename _Key, typename _Value,
740*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
741*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
742*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
743*e4b17023SJohn Marino     std::pair<typename _Hashtable<_Key, _Value, _Allocator,
744*e4b17023SJohn Marino 				  _ExtractKey, _Equal, _H1,
745*e4b17023SJohn Marino 				  _H2, _Hash, _RehashPolicy,
746*e4b17023SJohn Marino 				  __chc, __cit, __uk>::iterator,
747*e4b17023SJohn Marino 	      typename _Hashtable<_Key, _Value, _Allocator,
748*e4b17023SJohn Marino 				  _ExtractKey, _Equal, _H1,
749*e4b17023SJohn Marino 				  _H2, _Hash, _RehashPolicy,
750*e4b17023SJohn Marino 				  __chc, __cit, __uk>::iterator>
751*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
752*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
753*e4b17023SJohn Marino     equal_range(const key_type& __k)
754*e4b17023SJohn Marino     {
755*e4b17023SJohn Marino       typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
756*e4b17023SJohn Marino       std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count);
757*e4b17023SJohn Marino       _Node** __head = _M_buckets + __n;
758*e4b17023SJohn Marino       _Node* __p = _M_find_node(*__head, __k, __code);
759*e4b17023SJohn Marino 
760*e4b17023SJohn Marino       if (__p)
761*e4b17023SJohn Marino 	{
762*e4b17023SJohn Marino 	  _Node* __p1 = __p->_M_next;
763*e4b17023SJohn Marino 	  for (; __p1; __p1 = __p1->_M_next)
764*e4b17023SJohn Marino 	    if (!this->_M_compare(__k, __code, __p1))
765*e4b17023SJohn Marino 	      break;
766*e4b17023SJohn Marino 
767*e4b17023SJohn Marino 	  iterator __first(__p, __head);
768*e4b17023SJohn Marino 	  iterator __last(__p1, __head);
769*e4b17023SJohn Marino 	  if (!__p1)
770*e4b17023SJohn Marino 	    __last._M_incr_bucket();
771*e4b17023SJohn Marino 	  return std::make_pair(__first, __last);
772*e4b17023SJohn Marino 	}
773*e4b17023SJohn Marino       else
774*e4b17023SJohn Marino 	return std::make_pair(this->end(), this->end());
775*e4b17023SJohn Marino     }
776*e4b17023SJohn Marino 
777*e4b17023SJohn Marino   template<typename _Key, typename _Value,
778*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
779*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
780*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
781*e4b17023SJohn Marino     std::pair<typename _Hashtable<_Key, _Value, _Allocator,
782*e4b17023SJohn Marino 				  _ExtractKey, _Equal, _H1,
783*e4b17023SJohn Marino 				  _H2, _Hash, _RehashPolicy,
784*e4b17023SJohn Marino 				  __chc, __cit, __uk>::const_iterator,
785*e4b17023SJohn Marino 	      typename _Hashtable<_Key, _Value, _Allocator,
786*e4b17023SJohn Marino 				  _ExtractKey, _Equal, _H1,
787*e4b17023SJohn Marino 				  _H2, _Hash, _RehashPolicy,
788*e4b17023SJohn Marino 				  __chc, __cit, __uk>::const_iterator>
789*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
790*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
791*e4b17023SJohn Marino     equal_range(const key_type& __k) const
792*e4b17023SJohn Marino     {
793*e4b17023SJohn Marino       typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
794*e4b17023SJohn Marino       std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count);
795*e4b17023SJohn Marino       _Node** __head = _M_buckets + __n;
796*e4b17023SJohn Marino       _Node* __p = _M_find_node(*__head, __k, __code);
797*e4b17023SJohn Marino 
798*e4b17023SJohn Marino       if (__p)
799*e4b17023SJohn Marino 	{
800*e4b17023SJohn Marino 	  _Node* __p1 = __p->_M_next;
801*e4b17023SJohn Marino 	  for (; __p1; __p1 = __p1->_M_next)
802*e4b17023SJohn Marino 	    if (!this->_M_compare(__k, __code, __p1))
803*e4b17023SJohn Marino 	      break;
804*e4b17023SJohn Marino 
805*e4b17023SJohn Marino 	  const_iterator __first(__p, __head);
806*e4b17023SJohn Marino 	  const_iterator __last(__p1, __head);
807*e4b17023SJohn Marino 	  if (!__p1)
808*e4b17023SJohn Marino 	    __last._M_incr_bucket();
809*e4b17023SJohn Marino 	  return std::make_pair(__first, __last);
810*e4b17023SJohn Marino 	}
811*e4b17023SJohn Marino       else
812*e4b17023SJohn Marino 	return std::make_pair(this->end(), this->end());
813*e4b17023SJohn Marino     }
814*e4b17023SJohn Marino 
815*e4b17023SJohn Marino   // Find the node whose key compares equal to k, beginning the search
816*e4b17023SJohn Marino   // at p (usually the head of a bucket).  Return zero if no node is found.
817*e4b17023SJohn Marino   template<typename _Key, typename _Value,
818*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
819*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
820*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
821*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey,
822*e4b17023SJohn Marino 			_Equal, _H1, _H2, _Hash, _RehashPolicy,
823*e4b17023SJohn Marino 			__chc, __cit, __uk>::_Node*
824*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
825*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
826*e4b17023SJohn Marino     _M_find_node(_Node* __p, const key_type& __k,
827*e4b17023SJohn Marino 		typename _Hashtable::_Hash_code_type __code) const
828*e4b17023SJohn Marino     {
829*e4b17023SJohn Marino       for (; __p; __p = __p->_M_next)
830*e4b17023SJohn Marino 	if (this->_M_compare(__k, __code, __p))
831*e4b17023SJohn Marino 	  return __p;
832*e4b17023SJohn Marino       return 0;
833*e4b17023SJohn Marino     }
834*e4b17023SJohn Marino 
835*e4b17023SJohn Marino   // Insert v in bucket n (assumes no element with its key already present).
836*e4b17023SJohn Marino   template<typename _Key, typename _Value,
837*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
838*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
839*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
840*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
841*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
842*e4b17023SJohn Marino 			__chc, __cit, __uk>::iterator
843*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
844*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
845*e4b17023SJohn Marino     _M_insert_bucket(const value_type& __v, size_type __n,
846*e4b17023SJohn Marino 		    typename _Hashtable::_Hash_code_type __code)
847*e4b17023SJohn Marino     {
848*e4b17023SJohn Marino       std::pair<bool, std::size_t> __do_rehash
849*e4b17023SJohn Marino 	= _M_rehash_policy._M_need_rehash(_M_bucket_count,
850*e4b17023SJohn Marino 					  _M_element_count, 1);
851*e4b17023SJohn Marino 
852*e4b17023SJohn Marino       // Allocate the new node before doing the rehash so that we don't
853*e4b17023SJohn Marino       // do a rehash if the allocation throws.
854*e4b17023SJohn Marino       _Node* __new_node = _M_allocate_node(__v);
855*e4b17023SJohn Marino 
856*e4b17023SJohn Marino       __try
857*e4b17023SJohn Marino 	{
858*e4b17023SJohn Marino 	  if (__do_rehash.first)
859*e4b17023SJohn Marino 	    {
860*e4b17023SJohn Marino 	      const key_type& __k = this->_M_extract(__v);
861*e4b17023SJohn Marino 	      __n = this->_M_bucket_index(__k, __code, __do_rehash.second);
862*e4b17023SJohn Marino 	      _M_rehash(__do_rehash.second);
863*e4b17023SJohn Marino 	    }
864*e4b17023SJohn Marino 
865*e4b17023SJohn Marino 	  __new_node->_M_next = _M_buckets[__n];
866*e4b17023SJohn Marino 	  this->_M_store_code(__new_node, __code);
867*e4b17023SJohn Marino 	  _M_buckets[__n] = __new_node;
868*e4b17023SJohn Marino 	  ++_M_element_count;
869*e4b17023SJohn Marino 	  return iterator(__new_node, _M_buckets + __n);
870*e4b17023SJohn Marino 	}
871*e4b17023SJohn Marino       __catch(...)
872*e4b17023SJohn Marino 	{
873*e4b17023SJohn Marino 	  _M_deallocate_node(__new_node);
874*e4b17023SJohn Marino 	  __throw_exception_again;
875*e4b17023SJohn Marino 	}
876*e4b17023SJohn Marino     }
877*e4b17023SJohn Marino 
878*e4b17023SJohn Marino   // Insert v if no element with its key is already present.
879*e4b17023SJohn Marino   template<typename _Key, typename _Value,
880*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
881*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
882*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
883*e4b17023SJohn Marino     std::pair<typename _Hashtable<_Key, _Value, _Allocator,
884*e4b17023SJohn Marino 				  _ExtractKey, _Equal, _H1,
885*e4b17023SJohn Marino 				  _H2, _Hash, _RehashPolicy,
886*e4b17023SJohn Marino 				  __chc, __cit, __uk>::iterator, bool>
887*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
888*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
889*e4b17023SJohn Marino   _M_insert(const value_type& __v, std::tr1::true_type)
890*e4b17023SJohn Marino     {
891*e4b17023SJohn Marino       const key_type& __k = this->_M_extract(__v);
892*e4b17023SJohn Marino       typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
893*e4b17023SJohn Marino       size_type __n = this->_M_bucket_index(__k, __code, _M_bucket_count);
894*e4b17023SJohn Marino 
895*e4b17023SJohn Marino       if (_Node* __p = _M_find_node(_M_buckets[__n], __k, __code))
896*e4b17023SJohn Marino 	return std::make_pair(iterator(__p, _M_buckets + __n), false);
897*e4b17023SJohn Marino       return std::make_pair(_M_insert_bucket(__v, __n, __code), true);
898*e4b17023SJohn Marino     }
899*e4b17023SJohn Marino 
900*e4b17023SJohn Marino   // Insert v unconditionally.
901*e4b17023SJohn Marino   template<typename _Key, typename _Value,
902*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
903*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
904*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
905*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
906*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
907*e4b17023SJohn Marino 			__chc, __cit, __uk>::iterator
908*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
909*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
910*e4b17023SJohn Marino     _M_insert(const value_type& __v, std::tr1::false_type)
911*e4b17023SJohn Marino     {
912*e4b17023SJohn Marino       std::pair<bool, std::size_t> __do_rehash
913*e4b17023SJohn Marino 	= _M_rehash_policy._M_need_rehash(_M_bucket_count,
914*e4b17023SJohn Marino 					  _M_element_count, 1);
915*e4b17023SJohn Marino       if (__do_rehash.first)
916*e4b17023SJohn Marino 	_M_rehash(__do_rehash.second);
917*e4b17023SJohn Marino 
918*e4b17023SJohn Marino       const key_type& __k = this->_M_extract(__v);
919*e4b17023SJohn Marino       typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
920*e4b17023SJohn Marino       size_type __n = this->_M_bucket_index(__k, __code, _M_bucket_count);
921*e4b17023SJohn Marino 
922*e4b17023SJohn Marino       // First find the node, avoid leaking new_node if compare throws.
923*e4b17023SJohn Marino       _Node* __prev = _M_find_node(_M_buckets[__n], __k, __code);
924*e4b17023SJohn Marino       _Node* __new_node = _M_allocate_node(__v);
925*e4b17023SJohn Marino 
926*e4b17023SJohn Marino       if (__prev)
927*e4b17023SJohn Marino 	{
928*e4b17023SJohn Marino 	  __new_node->_M_next = __prev->_M_next;
929*e4b17023SJohn Marino 	  __prev->_M_next = __new_node;
930*e4b17023SJohn Marino 	}
931*e4b17023SJohn Marino       else
932*e4b17023SJohn Marino 	{
933*e4b17023SJohn Marino 	  __new_node->_M_next = _M_buckets[__n];
934*e4b17023SJohn Marino 	  _M_buckets[__n] = __new_node;
935*e4b17023SJohn Marino 	}
936*e4b17023SJohn Marino       this->_M_store_code(__new_node, __code);
937*e4b17023SJohn Marino 
938*e4b17023SJohn Marino       ++_M_element_count;
939*e4b17023SJohn Marino       return iterator(__new_node, _M_buckets + __n);
940*e4b17023SJohn Marino     }
941*e4b17023SJohn Marino 
942*e4b17023SJohn Marino   // For erase(iterator) and erase(const_iterator).
943*e4b17023SJohn Marino   template<typename _Key, typename _Value,
944*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
945*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
946*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
947*e4b17023SJohn Marino     void
948*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
949*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
950*e4b17023SJohn Marino     _M_erase_node(_Node* __p, _Node** __b)
951*e4b17023SJohn Marino     {
952*e4b17023SJohn Marino       _Node* __cur = *__b;
953*e4b17023SJohn Marino       if (__cur == __p)
954*e4b17023SJohn Marino 	*__b = __cur->_M_next;
955*e4b17023SJohn Marino       else
956*e4b17023SJohn Marino 	{
957*e4b17023SJohn Marino 	  _Node* __next = __cur->_M_next;
958*e4b17023SJohn Marino 	  while (__next != __p)
959*e4b17023SJohn Marino 	    {
960*e4b17023SJohn Marino 	      __cur = __next;
961*e4b17023SJohn Marino 	      __next = __cur->_M_next;
962*e4b17023SJohn Marino 	    }
963*e4b17023SJohn Marino 	  __cur->_M_next = __next->_M_next;
964*e4b17023SJohn Marino 	}
965*e4b17023SJohn Marino 
966*e4b17023SJohn Marino       _M_deallocate_node(__p);
967*e4b17023SJohn Marino       --_M_element_count;
968*e4b17023SJohn Marino     }
969*e4b17023SJohn Marino 
970*e4b17023SJohn Marino   template<typename _Key, typename _Value,
971*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
972*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
973*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
974*e4b17023SJohn Marino     template<typename _InputIterator>
975*e4b17023SJohn Marino       void
976*e4b17023SJohn Marino       _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
977*e4b17023SJohn Marino 		 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
978*e4b17023SJohn Marino       insert(_InputIterator __first, _InputIterator __last)
979*e4b17023SJohn Marino       {
980*e4b17023SJohn Marino 	size_type __n_elt = __detail::__distance_fw(__first, __last);
981*e4b17023SJohn Marino 	std::pair<bool, std::size_t> __do_rehash
982*e4b17023SJohn Marino 	  = _M_rehash_policy._M_need_rehash(_M_bucket_count,
983*e4b17023SJohn Marino 					    _M_element_count, __n_elt);
984*e4b17023SJohn Marino 	if (__do_rehash.first)
985*e4b17023SJohn Marino 	  _M_rehash(__do_rehash.second);
986*e4b17023SJohn Marino 
987*e4b17023SJohn Marino 	for (; __first != __last; ++__first)
988*e4b17023SJohn Marino 	  this->insert(*__first);
989*e4b17023SJohn Marino       }
990*e4b17023SJohn Marino 
991*e4b17023SJohn Marino   template<typename _Key, typename _Value,
992*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
993*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
994*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
995*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
996*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
997*e4b17023SJohn Marino 			__chc, __cit, __uk>::iterator
998*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
999*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1000*e4b17023SJohn Marino     erase(iterator __it)
1001*e4b17023SJohn Marino     {
1002*e4b17023SJohn Marino       iterator __result = __it;
1003*e4b17023SJohn Marino       ++__result;
1004*e4b17023SJohn Marino       _M_erase_node(__it._M_cur_node, __it._M_cur_bucket);
1005*e4b17023SJohn Marino       return __result;
1006*e4b17023SJohn Marino     }
1007*e4b17023SJohn Marino 
1008*e4b17023SJohn Marino   template<typename _Key, typename _Value,
1009*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
1010*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
1011*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
1012*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1013*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
1014*e4b17023SJohn Marino 			__chc, __cit, __uk>::const_iterator
1015*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1016*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1017*e4b17023SJohn Marino     erase(const_iterator __it)
1018*e4b17023SJohn Marino     {
1019*e4b17023SJohn Marino       const_iterator __result = __it;
1020*e4b17023SJohn Marino       ++__result;
1021*e4b17023SJohn Marino       _M_erase_node(__it._M_cur_node, __it._M_cur_bucket);
1022*e4b17023SJohn Marino       return __result;
1023*e4b17023SJohn Marino     }
1024*e4b17023SJohn Marino 
1025*e4b17023SJohn Marino   template<typename _Key, typename _Value,
1026*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
1027*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
1028*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
1029*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1030*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
1031*e4b17023SJohn Marino 			__chc, __cit, __uk>::size_type
1032*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1033*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1034*e4b17023SJohn Marino     erase(const key_type& __k)
1035*e4b17023SJohn Marino     {
1036*e4b17023SJohn Marino       typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
1037*e4b17023SJohn Marino       std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count);
1038*e4b17023SJohn Marino       size_type __result = 0;
1039*e4b17023SJohn Marino 
1040*e4b17023SJohn Marino       _Node** __slot = _M_buckets + __n;
1041*e4b17023SJohn Marino       while (*__slot && !this->_M_compare(__k, __code, *__slot))
1042*e4b17023SJohn Marino 	__slot = &((*__slot)->_M_next);
1043*e4b17023SJohn Marino 
1044*e4b17023SJohn Marino       _Node** __saved_slot = 0;
1045*e4b17023SJohn Marino       while (*__slot && this->_M_compare(__k, __code, *__slot))
1046*e4b17023SJohn Marino 	{
1047*e4b17023SJohn Marino 	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
1048*e4b17023SJohn Marino 	  // 526. Is it undefined if a function in the standard changes
1049*e4b17023SJohn Marino 	  // in parameters?
1050*e4b17023SJohn Marino 	  if (&this->_M_extract((*__slot)->_M_v) != &__k)
1051*e4b17023SJohn Marino 	    {
1052*e4b17023SJohn Marino 	      _Node* __p = *__slot;
1053*e4b17023SJohn Marino 	      *__slot = __p->_M_next;
1054*e4b17023SJohn Marino 	      _M_deallocate_node(__p);
1055*e4b17023SJohn Marino 	      --_M_element_count;
1056*e4b17023SJohn Marino 	      ++__result;
1057*e4b17023SJohn Marino 	    }
1058*e4b17023SJohn Marino 	  else
1059*e4b17023SJohn Marino 	    {
1060*e4b17023SJohn Marino 	      __saved_slot = __slot;
1061*e4b17023SJohn Marino 	      __slot = &((*__slot)->_M_next);
1062*e4b17023SJohn Marino 	    }
1063*e4b17023SJohn Marino 	}
1064*e4b17023SJohn Marino 
1065*e4b17023SJohn Marino       if (__saved_slot)
1066*e4b17023SJohn Marino 	{
1067*e4b17023SJohn Marino 	  _Node* __p = *__saved_slot;
1068*e4b17023SJohn Marino 	  *__saved_slot = __p->_M_next;
1069*e4b17023SJohn Marino 	  _M_deallocate_node(__p);
1070*e4b17023SJohn Marino 	  --_M_element_count;
1071*e4b17023SJohn Marino 	  ++__result;
1072*e4b17023SJohn Marino 	}
1073*e4b17023SJohn Marino 
1074*e4b17023SJohn Marino       return __result;
1075*e4b17023SJohn Marino     }
1076*e4b17023SJohn Marino 
1077*e4b17023SJohn Marino   // ??? This could be optimized by taking advantage of the bucket
1078*e4b17023SJohn Marino   // structure, but it's not clear that it's worth doing.  It probably
1079*e4b17023SJohn Marino   // wouldn't even be an optimization unless the load factor is large.
1080*e4b17023SJohn Marino   template<typename _Key, typename _Value,
1081*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
1082*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
1083*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
1084*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1085*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
1086*e4b17023SJohn Marino 			__chc, __cit, __uk>::iterator
1087*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1088*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1089*e4b17023SJohn Marino     erase(iterator __first, iterator __last)
1090*e4b17023SJohn Marino     {
1091*e4b17023SJohn Marino       while (__first != __last)
1092*e4b17023SJohn Marino 	__first = this->erase(__first);
1093*e4b17023SJohn Marino       return __last;
1094*e4b17023SJohn Marino     }
1095*e4b17023SJohn Marino 
1096*e4b17023SJohn Marino   template<typename _Key, typename _Value,
1097*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
1098*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
1099*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
1100*e4b17023SJohn Marino     typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1101*e4b17023SJohn Marino 			_H1, _H2, _Hash, _RehashPolicy,
1102*e4b17023SJohn Marino 			__chc, __cit, __uk>::const_iterator
1103*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1104*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1105*e4b17023SJohn Marino     erase(const_iterator __first, const_iterator __last)
1106*e4b17023SJohn Marino     {
1107*e4b17023SJohn Marino       while (__first != __last)
1108*e4b17023SJohn Marino 	__first = this->erase(__first);
1109*e4b17023SJohn Marino       return __last;
1110*e4b17023SJohn Marino     }
1111*e4b17023SJohn Marino 
1112*e4b17023SJohn Marino   template<typename _Key, typename _Value,
1113*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
1114*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
1115*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
1116*e4b17023SJohn Marino     void
1117*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1118*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1119*e4b17023SJohn Marino     clear()
1120*e4b17023SJohn Marino     {
1121*e4b17023SJohn Marino       _M_deallocate_nodes(_M_buckets, _M_bucket_count);
1122*e4b17023SJohn Marino       _M_element_count = 0;
1123*e4b17023SJohn Marino     }
1124*e4b17023SJohn Marino 
1125*e4b17023SJohn Marino   template<typename _Key, typename _Value,
1126*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
1127*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
1128*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
1129*e4b17023SJohn Marino     void
1130*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1131*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1132*e4b17023SJohn Marino     rehash(size_type __n)
1133*e4b17023SJohn Marino     {
1134*e4b17023SJohn Marino       _M_rehash(std::max(_M_rehash_policy._M_next_bkt(__n),
1135*e4b17023SJohn Marino 			 _M_rehash_policy._M_bkt_for_elements(_M_element_count
1136*e4b17023SJohn Marino 							      + 1)));
1137*e4b17023SJohn Marino     }
1138*e4b17023SJohn Marino 
1139*e4b17023SJohn Marino   template<typename _Key, typename _Value,
1140*e4b17023SJohn Marino 	   typename _Allocator, typename _ExtractKey, typename _Equal,
1141*e4b17023SJohn Marino 	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
1142*e4b17023SJohn Marino 	   bool __chc, bool __cit, bool __uk>
1143*e4b17023SJohn Marino     void
1144*e4b17023SJohn Marino     _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1145*e4b17023SJohn Marino 	       _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1146*e4b17023SJohn Marino     _M_rehash(size_type __n)
1147*e4b17023SJohn Marino     {
1148*e4b17023SJohn Marino       _Node** __new_array = _M_allocate_buckets(__n);
1149*e4b17023SJohn Marino       __try
1150*e4b17023SJohn Marino 	{
1151*e4b17023SJohn Marino 	  for (size_type __i = 0; __i < _M_bucket_count; ++__i)
1152*e4b17023SJohn Marino 	    while (_Node* __p = _M_buckets[__i])
1153*e4b17023SJohn Marino 	      {
1154*e4b17023SJohn Marino 		std::size_t __new_index = this->_M_bucket_index(__p, __n);
1155*e4b17023SJohn Marino 		_M_buckets[__i] = __p->_M_next;
1156*e4b17023SJohn Marino 		__p->_M_next = __new_array[__new_index];
1157*e4b17023SJohn Marino 		__new_array[__new_index] = __p;
1158*e4b17023SJohn Marino 	      }
1159*e4b17023SJohn Marino 	  _M_deallocate_buckets(_M_buckets, _M_bucket_count);
1160*e4b17023SJohn Marino 	  _M_bucket_count = __n;
1161*e4b17023SJohn Marino 	  _M_buckets = __new_array;
1162*e4b17023SJohn Marino 	}
1163*e4b17023SJohn Marino       __catch(...)
1164*e4b17023SJohn Marino 	{
1165*e4b17023SJohn Marino 	  // A failure here means that a hash function threw an exception.
1166*e4b17023SJohn Marino 	  // We can't restore the previous state without calling the hash
1167*e4b17023SJohn Marino 	  // function again, so the only sensible recovery is to delete
1168*e4b17023SJohn Marino 	  // everything.
1169*e4b17023SJohn Marino 	  _M_deallocate_nodes(__new_array, __n);
1170*e4b17023SJohn Marino 	  _M_deallocate_buckets(__new_array, __n);
1171*e4b17023SJohn Marino 	  _M_deallocate_nodes(_M_buckets, _M_bucket_count);
1172*e4b17023SJohn Marino 	  _M_element_count = 0;
1173*e4b17023SJohn Marino 	  __throw_exception_again;
1174*e4b17023SJohn Marino 	}
1175*e4b17023SJohn Marino     }
1176*e4b17023SJohn Marino 
1177*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION
1178*e4b17023SJohn Marino } // namespace tr1
1179*e4b17023SJohn Marino } // namespace std
1180*e4b17023SJohn Marino 
1181*e4b17023SJohn Marino #endif // _GLIBCXX_TR1_HASHTABLE_H
1182