]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/load_factor.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_set / hash_policy / load_factor.cc
CommitLineData
8d9254fc 1// Copyright (C) 2011-2020 Free Software Foundation, Inc.
4f7b188f
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 } }
4f7b188f
FD
19
20#include <unordered_set>
732eb076 21
4f7b188f
FD
22#include <testsuite_hooks.h>
23
732eb076
FD
24template<typename _USet>
25 void test()
4f7b188f 26 {
4f7b188f 27 {
732eb076
FD
28 _USet us;
29 for (int i = 0; i != 100000; ++i)
30 {
31 us.insert(i);
32 VERIFY( us.load_factor() <= us.max_load_factor() );
33 }
4f7b188f 34 }
4f7b188f 35 {
732eb076
FD
36 _USet us;
37 us.max_load_factor(3.f);
38 for (int i = 0; i != 100000; ++i)
39 {
40 us.insert(i);
41 VERIFY( us.load_factor() <= us.max_load_factor() );
42 }
4f7b188f 43 }
4f7b188f 44 {
732eb076
FD
45 _USet us;
46 us.max_load_factor(.3f);
47 for (int i = 0; i != 100000; ++i)
48 {
49 us.insert(i);
50 VERIFY( us.load_factor() <= us.max_load_factor() );
51 }
4f7b188f
FD
52 }
53 }
732eb076
FD
54
55template<typename _Value>
56 using unordered_set_power2_rehash =
57 std::_Hashtable<_Value, _Value, std::allocator<_Value>,
58 std::__detail::_Identity,
59 std::equal_to<_Value>,
60 std::hash<_Value>,
61 std::__detail::_Mask_range_hashing,
62 std::__detail::_Default_ranged_hash,
63 std::__detail::_Power2_rehash_policy,
64 std::__detail::_Hashtable_traits<false, true, true>>;
4f7b188f
FD
65
66int main()
67{
732eb076
FD
68 test<std::unordered_set<int>>();
69 test<unordered_set_power2_rehash<int>>();
4f7b188f
FD
70 return 0;
71}