1 // Copyright (C) 2011-2023 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++11 } }
20 #include <unordered_set>
22 #include <testsuite_hooks.h>
24 template<typename _USet
>
28 typedef typename
_USet::size_type size_type
;
29 bool rehashed
= false;
30 for (int i
= 0; i
!= 100000; ++i
)
32 size_type bkt_count
= us
.bucket_count();
34 if (bkt_count
!= us
.bucket_count())
36 // Container has been rehashed, lets check that it won't be rehash
37 // again if we remove and restore the last 2 inserted elements:
39 bkt_count
= us
.bucket_count();
40 VERIFY( us
.erase(i
) == 1 );
41 VERIFY( bkt_count
== us
.bucket_count() );
44 VERIFY( us
.erase(i
- 1) == 1 );
45 VERIFY( bkt_count
== us
.bucket_count() );
47 VERIFY( us
.insert(i
- 1).second
);
48 VERIFY( bkt_count
== us
.bucket_count() );
50 VERIFY( us
.insert(i
).second
);
51 VERIFY( bkt_count
== us
.bucket_count() );
55 // At lest we check a rehash once:
59 template<typename _Value
>
60 using unordered_set_power2_rehash
=
61 std::_Hashtable
<_Value
, _Value
, std::allocator
<_Value
>,
62 std::__detail::_Identity
,
63 std::equal_to
<_Value
>,
65 std::__detail::_Mask_range_hashing
,
66 std::__detail::_Default_ranged_hash
,
67 std::__detail::_Power2_rehash_policy
,
68 std::__detail::_Hashtable_traits
<false, true, true>>;
72 test
<std::unordered_set
<int>>();
73 test
<unordered_set_power2_rehash
<int>>();