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