OSDN Git Service

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