comparison libstdc++-v3/include/tr1/hashtable.h @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children da32f4b04d38
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // TR1 hashtable.h header -*- C++ -*- 1 // TR1 hashtable.h header -*- C++ -*-
2 2
3 // Copyright (C) 2007-2018 Free Software Foundation, Inc. 3 // Copyright (C) 2007-2020 Free Software Foundation, Inc.
4 // 4 //
5 // This file is part of the GNU ISO C++ Library. This library is free 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 6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the 7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option) 8 // Free Software Foundation; either version 3, or (at your option)
32 #define _GLIBCXX_TR1_HASHTABLE_H 1 32 #define _GLIBCXX_TR1_HASHTABLE_H 1
33 33
34 #pragma GCC system_header 34 #pragma GCC system_header
35 35
36 #include <tr1/hashtable_policy.h> 36 #include <tr1/hashtable_policy.h>
37 #include <ext/alloc_traits.h>
37 38
38 namespace std _GLIBCXX_VISIBILITY(default) 39 namespace std _GLIBCXX_VISIBILITY(default)
39 { 40 {
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION 41 _GLIBCXX_BEGIN_NAMESPACE_VERSION
41 42
123 _RehashPolicy, 124 _RehashPolicy,
124 __cache_hash_code, 125 __cache_hash_code,
125 __constant_iterators, 126 __constant_iterators,
126 __unique_keys> > 127 __unique_keys> >
127 { 128 {
129 typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits;
130
128 public: 131 public:
129 typedef _Allocator allocator_type; 132 typedef _Allocator allocator_type;
130 typedef _Value value_type; 133 typedef _Value value_type;
131 typedef _Key key_type; 134 typedef _Key key_type;
132 typedef _Equal key_equal; 135 typedef _Equal key_equal;
133 // mapped_type, if present, comes from _Map_base. 136 // mapped_type, if present, comes from _Map_base.
134 // hasher, if present, comes from _Hash_code_base. 137 // hasher, if present, comes from _Hash_code_base.
135 typedef typename _Allocator::difference_type difference_type; 138 typedef typename _Allocator::difference_type difference_type;
136 typedef typename _Allocator::size_type size_type; 139 typedef typename _Allocator::size_type size_type;
137 typedef typename _Allocator::pointer pointer; 140 typedef typename _Alloc_traits::pointer pointer;
138 typedef typename _Allocator::const_pointer const_pointer; 141 typedef typename _Alloc_traits::const_pointer const_pointer;
139 typedef typename _Allocator::reference reference; 142 typedef typename _Alloc_traits::reference reference;
140 typedef typename _Allocator::const_reference const_reference; 143 typedef typename _Alloc_traits::const_reference const_reference;
141 144
142 typedef __detail::_Node_iterator<value_type, __constant_iterators, 145 typedef __detail::_Node_iterator<value_type, __constant_iterators,
143 __cache_hash_code> 146 __cache_hash_code>
144 local_iterator; 147 local_iterator;
145 typedef __detail::_Node_const_iterator<value_type, 148 typedef __detail::_Node_const_iterator<value_type,
159 typename _Hashtable2> 162 typename _Hashtable2>
160 friend struct __detail::_Map_base; 163 friend struct __detail::_Map_base;
161 164
162 private: 165 private:
163 typedef __detail::_Hash_node<_Value, __cache_hash_code> _Node; 166 typedef __detail::_Hash_node<_Value, __cache_hash_code> _Node;
164 typedef typename _Allocator::template rebind<_Node>::other 167 typedef typename _Alloc_traits::template rebind<_Node>::other
165 _Node_allocator_type; 168 _Node_allocator_type;
166 typedef typename _Allocator::template rebind<_Node*>::other 169 typedef typename _Alloc_traits::template rebind<_Node*>::other
167 _Bucket_allocator_type; 170 _Bucket_allocator_type;
168 171
169 typedef typename _Allocator::template rebind<_Value>::other 172 typedef typename _Alloc_traits::template rebind<_Value>::other
170 _Value_allocator_type; 173 _Value_allocator_type;
171 174
172 _Node_allocator_type _M_node_allocator; 175 _Node_allocator_type _M_node_allocator;
173 _Node** _M_buckets; 176 _Node** _M_buckets;
174 size_type _M_bucket_count; 177 size_type _M_bucket_count;
175 size_type _M_element_count; 178 size_type _M_element_count;
242 245
243 size_type 246 size_type
244 size() const 247 size() const
245 { return _M_element_count; } 248 { return _M_element_count; }
246 249
247 bool 250 _GLIBCXX_NODISCARD bool
248 empty() const 251 empty() const
249 { return size() == 0; } 252 { return size() == 0; }
250 253
251 allocator_type 254 allocator_type
252 get_allocator() const 255 get_allocator() const
256 _M_get_Value_allocator() const 259 _M_get_Value_allocator() const
257 { return _Value_allocator_type(_M_node_allocator); } 260 { return _Value_allocator_type(_M_node_allocator); }
258 261
259 size_type 262 size_type
260 max_size() const 263 max_size() const
261 { return _M_node_allocator.max_size(); } 264 {
265 typedef __gnu_cxx::__alloc_traits<_Node_allocator_type> _Traits;
266 return _Traits::max_size(_M_node_allocator);
267 }
262 268
263 // Observers 269 // Observers
264 key_equal 270 key_equal
265 key_eq() const 271 key_eq() const
266 { return this->_M_eq; } 272 { return this->_M_eq; }
427 _M_allocate_node(const value_type& __v) 433 _M_allocate_node(const value_type& __v)
428 { 434 {
429 _Node* __n = _M_node_allocator.allocate(1); 435 _Node* __n = _M_node_allocator.allocate(1);
430 __try 436 __try
431 { 437 {
432 _M_get_Value_allocator().construct(&__n->_M_v, __v); 438 _Value_allocator_type __a = _M_get_Value_allocator();
439 typedef __gnu_cxx::__alloc_traits<_Value_allocator_type> _Traits;
440 _Traits::construct(__a, &__n->_M_v, __v);
433 __n->_M_next = 0; 441 __n->_M_next = 0;
434 return __n; 442 return __n;
435 } 443 }
436 __catch(...) 444 __catch(...)
437 { 445 {
447 void 455 void
448 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, 456 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
449 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: 457 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
450 _M_deallocate_node(_Node* __n) 458 _M_deallocate_node(_Node* __n)
451 { 459 {
452 _M_get_Value_allocator().destroy(&__n->_M_v); 460 _Value_allocator_type __a = _M_get_Value_allocator();
461 typedef __gnu_cxx::__alloc_traits<_Value_allocator_type> _Traits;
462 _Traits::destroy(__a, &__n->_M_v);
453 _M_node_allocator.deallocate(__n, 1); 463 _M_node_allocator.deallocate(__n, 1);
454 } 464 }
455 465
456 template<typename _Key, typename _Value, 466 template<typename _Key, typename _Value,
457 typename _Allocator, typename _ExtractKey, typename _Equal, 467 typename _Allocator, typename _ExtractKey, typename _Equal,