1 // Profiling unordered_set/unordered_multiset implementation -*- C++ -*-
3 // Copyright (C) 2009-2014 Free Software Foundation, Inc.
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)
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.
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.
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING3. If not see
22 // <http://www.gnu.org/licenses/>.
24 /** @file profile/unordered_set
25 * This file is a GNU profile extension to the Standard C++ Library.
28 #ifndef _GLIBCXX_PROFILE_UNORDERED_SET
29 #define _GLIBCXX_PROFILE_UNORDERED_SET 1
31 #if __cplusplus < 201103L
32 # include <bits/c++0x_warning.h>
34 # include <unordered_set>
36 #include <profile/base.h>
37 #include <profile/unordered_base.h>
39 #define _GLIBCXX_BASE unordered_set<_Key, _Hash, _Pred, _Alloc>
40 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_C::_GLIBCXX_BASE
42 namespace std _GLIBCXX_VISIBILITY(default)
46 /** @brief Unordered_set wrapper with performance instrumentation. */
47 template<typename _Key,
48 typename _Hash = std::hash<_Key>,
49 typename _Pred = std::equal_to<_Key>,
50 typename _Alloc = std::allocator<_Key> >
52 : public _GLIBCXX_STD_BASE,
53 public _Unordered_profile<unordered_set<_Key, _Hash, _Pred, _Alloc>,
56 typedef _GLIBCXX_STD_BASE _Base;
59 _M_base() noexcept { return *this; }
62 _M_base() const noexcept { return *this; }
65 typedef typename _Base::size_type size_type;
66 typedef typename _Base::hasher hasher;
67 typedef typename _Base::key_equal key_equal;
68 typedef typename _Base::allocator_type allocator_type;
69 typedef typename _Base::key_type key_type;
70 typedef typename _Base::value_type value_type;
71 typedef typename _Base::difference_type difference_type;
72 typedef typename _Base::reference reference;
73 typedef typename _Base::const_reference const_reference;
75 typedef typename _Base::iterator iterator;
76 typedef typename _Base::const_iterator const_iterator;
78 unordered_set() = default;
81 unordered_set(size_type __n,
82 const hasher& __hf = hasher(),
83 const key_equal& __eql = key_equal(),
84 const allocator_type& __a = allocator_type())
85 : _Base(__n, __hf, __eql, __a)
88 template<typename _InputIterator>
89 unordered_set(_InputIterator __f, _InputIterator __l,
91 const hasher& __hf = hasher(),
92 const key_equal& __eql = key_equal(),
93 const allocator_type& __a = allocator_type())
94 : _Base(__f, __l, __n, __hf, __eql, __a)
97 unordered_set(const unordered_set&) = default;
99 unordered_set(const _Base& __x)
103 unordered_set(unordered_set&&) = default;
106 unordered_set(const allocator_type& __a)
110 unordered_set(const unordered_set& __uset,
111 const allocator_type& __a)
112 : _Base(__uset._M_base(), __a)
115 unordered_set(unordered_set&& __uset,
116 const allocator_type& __a)
117 : _Base(std::move(__uset._M_base()), __a)
120 unordered_set(initializer_list<value_type> __l,
122 const hasher& __hf = hasher(),
123 const key_equal& __eql = key_equal(),
124 const allocator_type& __a = allocator_type())
125 : _Base(__l, __n, __hf, __eql, __a)
129 operator=(const unordered_set&) = default;
132 operator=(unordered_set&&) = default;
135 operator=(initializer_list<value_type> __l)
137 this->_M_profile_destruct();
139 this->_M_profile_construct();
144 swap(unordered_set& __x)
145 noexcept( noexcept(__x._M_base().swap(__x)) )
154 this->_M_profile_destruct();
156 this->_M_profile_construct();
159 template<typename... _Args>
160 std::pair<iterator, bool>
161 emplace(_Args&&... __args)
163 size_type __old_size = _Base::bucket_count();
164 std::pair<iterator, bool> __res
165 = _Base::emplace(std::forward<_Args>(__args)...);
166 this->_M_profile_resize(__old_size);
170 template<typename... _Args>
172 emplace_hint(const_iterator __it, _Args&&... __args)
174 size_type __old_size = _Base::bucket_count();
176 = _Base::emplace_hint(__it, std::forward<_Args>(__args)...);
177 this->_M_profile_resize(__old_size);
182 insert(std::initializer_list<value_type> __l)
184 size_type __old_size = _Base::bucket_count();
186 this->_M_profile_resize(__old_size);
189 std::pair<iterator, bool>
190 insert(const value_type& __obj)
192 size_type __old_size = _Base::bucket_count();
193 std::pair<iterator, bool> __res = _Base::insert(__obj);
194 this->_M_profile_resize(__old_size);
199 insert(const_iterator __iter, const value_type& __v)
201 size_type __old_size = _Base::bucket_count();
202 iterator __res = _Base::insert(__iter, __v);
203 this->_M_profile_resize(__old_size);
207 std::pair<iterator, bool>
208 insert(value_type&& __obj)
210 size_type __old_size = _Base::bucket_count();
211 std::pair<iterator, bool> __res = _Base::insert(std::move(__obj));
212 this->_M_profile_resize(__old_size);
217 insert(const_iterator __iter, value_type&& __v)
219 size_type __old_size = _Base::bucket_count();
220 iterator __res = _Base::insert(__iter, std::move(__v));
221 this->_M_profile_resize(__old_size);
225 template<typename _InputIter>
227 insert(_InputIter __first, _InputIter __last)
229 size_type __old_size = _Base::bucket_count();
230 _Base::insert(__first, __last);
231 this->_M_profile_resize(__old_size);
235 rehash(size_type __n)
237 size_type __old_size = _Base::bucket_count();
239 this->_M_profile_resize(__old_size);
243 template<typename _Key, typename _Hash, typename _Pred, typename _Alloc>
245 swap(unordered_set<_Key, _Hash, _Pred, _Alloc>& __x,
246 unordered_set<_Key, _Hash, _Pred, _Alloc>& __y)
249 template<typename _Key, typename _Hash, typename _Pred, typename _Alloc>
251 operator==(const unordered_set<_Key, _Hash, _Pred, _Alloc>& __x,
252 const unordered_set<_Key, _Hash, _Pred, _Alloc>& __y)
253 { return static_cast<const _GLIBCXX_STD_BASE&>(__x) == __y; }
255 template<typename _Key, typename _Hash, typename _Pred, typename _Alloc>
257 operator!=(const unordered_set<_Key, _Hash, _Pred, _Alloc>& __x,
258 const unordered_set<_Key, _Hash, _Pred, _Alloc>& __y)
259 { return !(__x == __y); }
262 #undef _GLIBCXX_STD_BASE
263 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_C::_GLIBCXX_BASE
264 #define _GLIBCXX_BASE unordered_multiset<_Value, _Hash, _Pred, _Alloc>
266 /** @brief Unordered_multiset wrapper with performance instrumentation. */
267 template<typename _Value,
268 typename _Hash = std::hash<_Value>,
269 typename _Pred = std::equal_to<_Value>,
270 typename _Alloc = std::allocator<_Value> >
271 class unordered_multiset
272 : public _GLIBCXX_STD_BASE,
273 public _Unordered_profile<unordered_multiset<_Value,
274 _Hash, _Pred, _Alloc>,
277 typedef _GLIBCXX_STD_BASE _Base;
280 _M_base() noexcept { return *this; }
283 _M_base() const noexcept { return *this; }
286 typedef typename _Base::size_type size_type;
287 typedef typename _Base::hasher hasher;
288 typedef typename _Base::key_equal key_equal;
289 typedef typename _Base::allocator_type allocator_type;
290 typedef typename _Base::key_type key_type;
291 typedef typename _Base::value_type value_type;
292 typedef typename _Base::difference_type difference_type;
293 typedef typename _Base::reference reference;
294 typedef typename _Base::const_reference const_reference;
296 typedef typename _Base::iterator iterator;
297 typedef typename _Base::const_iterator const_iterator;
299 unordered_multiset() = default;
302 unordered_multiset(size_type __n,
303 const hasher& __hf = hasher(),
304 const key_equal& __eql = key_equal(),
305 const allocator_type& __a = allocator_type())
306 : _Base(__n, __hf, __eql, __a)
309 template<typename _InputIterator>
310 unordered_multiset(_InputIterator __f, _InputIterator __l,
312 const hasher& __hf = hasher(),
313 const key_equal& __eql = key_equal(),
314 const allocator_type& __a = allocator_type())
315 : _Base(__f, __l, __n, __hf, __eql, __a)
318 unordered_multiset(const unordered_multiset&) = default;
320 unordered_multiset(const _Base& __x)
324 unordered_multiset(unordered_multiset&&) = default;
327 unordered_multiset(const allocator_type& __a)
331 unordered_multiset(const unordered_multiset& __umset,
332 const allocator_type& __a)
333 : _Base(__umset._M_base(), __a)
336 unordered_multiset(unordered_multiset&& __umset,
337 const allocator_type& __a)
338 : _Base(std::move(__umset._M_base()), __a)
341 unordered_multiset(initializer_list<value_type> __l,
343 const hasher& __hf = hasher(),
344 const key_equal& __eql = key_equal(),
345 const allocator_type& __a = allocator_type())
346 : _Base(__l, __n, __hf, __eql, __a)
350 operator=(const unordered_multiset&) = default;
353 operator=(unordered_multiset&&) = default;
356 operator=(initializer_list<value_type> __l)
358 this->_M_profile_destruct();
360 this->_M_profile_construct();
365 swap(unordered_multiset& __x)
366 noexcept( noexcept(__x._M_base().swap(__x)) )
375 this->_M_profile_destruct();
377 this->_M_profile_construct();
380 template<typename... _Args>
382 emplace(_Args&&... __args)
384 size_type __old_size = _Base::bucket_count();
385 iterator __res = _Base::emplace(std::forward<_Args>(__args)...);
386 this->_M_profile_resize(__old_size);
390 template<typename... _Args>
392 emplace_hint(const_iterator __it, _Args&&... __args)
394 size_type __old_size = _Base::bucket_count();
396 = _Base::emplace_hint(__it, std::forward<_Args>(__args)...);
397 this->_M_profile_resize(__old_size);
402 insert(std::initializer_list<value_type> __l)
404 size_type __old_size = _Base::bucket_count();
406 this->_M_profile_resize(__old_size);
410 insert(const value_type& __obj)
412 size_type __old_size = _Base::bucket_count();
413 iterator __res = _Base::insert(__obj);
414 this->_M_profile_resize(__old_size);
419 insert(const_iterator __iter, const value_type& __v)
421 size_type __old_size = _Base::bucket_count();
422 iterator __res = _Base::insert(__iter, __v);
423 this->_M_profile_resize(__old_size);
428 insert(value_type&& __obj)
430 size_type __old_size = _Base::bucket_count();
431 iterator __res = _Base::insert(std::move(__obj));
432 this->_M_profile_resize(__old_size);
437 insert(const_iterator __iter, value_type&& __v)
439 size_type __old_size = _Base::bucket_count();
440 iterator __res = _Base::insert(__iter, std::move(__v));
441 this->_M_profile_resize(__old_size);
445 template<typename _InputIter>
447 insert(_InputIter __first, _InputIter __last)
449 size_type __old_size = _Base::bucket_count();
450 _Base::insert(__first, __last);
451 this->_M_profile_resize(__old_size);
455 rehash(size_type __n)
457 size_type __old_size = _Base::bucket_count();
459 this->_M_profile_resize(__old_size);
463 template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
465 swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
466 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
469 template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
471 operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
472 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
473 { return static_cast<const _GLIBCXX_STD_BASE&>(__x) == __y; }
475 template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
477 operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
478 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
479 { return !(__x == __y); }
481 } // namespace __profile
485 #undef _GLIBCXX_STD_BASE