]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2016-2023 Free Software Foundation, Inc. |
29dbb034 FD |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | // | |
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | // | |
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | // | |
52066eae | 18 | // { dg-do run { target c++11 } } |
29dbb034 FD |
19 | |
20 | #include <unordered_set> | |
21 | ||
22 | #include <testsuite_hooks.h> | |
23 | ||
24 | template<typename _USet> | |
de6f5f57 FD |
25 | void |
26 | test(_USet& us, int threshold) | |
29dbb034 | 27 | { |
29dbb034 FD |
28 | auto nb_reserved = us.bucket_count(); |
29 | us.reserve(nb_reserved); | |
30 | auto bkts = us.bucket_count(); | |
de6f5f57 | 31 | for (int nb_insert = 1; nb_insert <= threshold; ++nb_insert) |
29dbb034 | 32 | { |
de6f5f57 | 33 | if (nb_insert > nb_reserved) |
29dbb034 FD |
34 | { |
35 | nb_reserved = bkts; | |
36 | us.reserve(nb_reserved); | |
37 | bkts = us.bucket_count(); | |
38 | } | |
39 | ||
de6f5f57 | 40 | us.insert(nb_insert); |
29dbb034 FD |
41 | |
42 | VERIFY( us.bucket_count() == bkts ); | |
43 | } | |
44 | } | |
45 | ||
46 | template<typename _Value> | |
47 | using unordered_set_power2_rehash = | |
48 | std::_Hashtable<_Value, _Value, std::allocator<_Value>, | |
49 | std::__detail::_Identity, | |
50 | std::equal_to<_Value>, | |
51 | std::hash<_Value>, | |
52 | std::__detail::_Mask_range_hashing, | |
53 | std::__detail::_Default_ranged_hash, | |
54 | std::__detail::_Power2_rehash_policy, | |
55 | std::__detail::_Hashtable_traits<false, true, true>>; | |
56 | ||
de6f5f57 FD |
57 | template<typename _USet> |
58 | void | |
59 | test_cont() | |
60 | { | |
61 | _USet us; | |
62 | test(us, 150); | |
63 | ||
64 | us.clear(); | |
65 | us.rehash(0); | |
66 | ||
67 | test(us, 150); | |
68 | } | |
69 | ||
29dbb034 FD |
70 | int main() |
71 | { | |
de6f5f57 FD |
72 | test_cont<std::unordered_set<int>>(); |
73 | test_cont<unordered_set_power2_rehash<int>>(); | |
29dbb034 FD |
74 | return 0; |
75 | } |