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