1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <unordered_set> |
10 | |
11 | // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
12 | // class Alloc = allocator<Value>> |
13 | // class unordered_multiset |
14 | |
15 | // void rehash(size_type n); |
16 | |
17 | #include <unordered_set> |
18 | #include <cassert> |
19 | |
20 | #include "test_macros.h" |
21 | #include "min_allocator.h" |
22 | |
23 | template <class C> |
24 | void rehash_postcondition(const C& c, std::size_t n) { |
25 | assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); |
26 | } |
27 | |
28 | template <class C> |
29 | void test(const C& c) { |
30 | assert(c.size() == 6); |
31 | assert(c.count(1) == 2); |
32 | assert(c.count(2) == 2); |
33 | assert(c.count(3) == 1); |
34 | assert(c.count(4) == 1); |
35 | } |
36 | |
37 | int main(int, char**) { |
38 | { |
39 | typedef std::unordered_multiset<int> C; |
40 | typedef int P; |
41 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
42 | C c(a, a + sizeof(a) / sizeof(a[0])); |
43 | test(c); |
44 | assert(c.bucket_count() >= 7); |
45 | c.rehash(n: 3); |
46 | rehash_postcondition(c, n: 3); |
47 | LIBCPP_ASSERT(c.bucket_count() == 7); |
48 | test(c); |
49 | c.max_load_factor(z: 2); |
50 | c.rehash(n: 3); |
51 | rehash_postcondition(c, n: 3); |
52 | LIBCPP_ASSERT(c.bucket_count() == 3); |
53 | test(c); |
54 | c.rehash(n: 31); |
55 | rehash_postcondition(c, n: 31); |
56 | LIBCPP_ASSERT(c.bucket_count() == 31); |
57 | test(c); |
58 | } |
59 | #if TEST_STD_VER >= 11 |
60 | { |
61 | typedef std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; |
62 | typedef int P; |
63 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
64 | C c(a, a + sizeof(a) / sizeof(a[0])); |
65 | test(c); |
66 | assert(c.bucket_count() >= 7); |
67 | c.rehash(3); |
68 | rehash_postcondition(c, 3); |
69 | LIBCPP_ASSERT(c.bucket_count() == 7); |
70 | test(c); |
71 | c.max_load_factor(2); |
72 | c.rehash(3); |
73 | rehash_postcondition(c, 3); |
74 | LIBCPP_ASSERT(c.bucket_count() == 3); |
75 | test(c); |
76 | c.rehash(31); |
77 | rehash_postcondition(c, 31); |
78 | LIBCPP_ASSERT(c.bucket_count() == 31); |
79 | test(c); |
80 | } |
81 | #endif |
82 | |
83 | return 0; |
84 | } |
85 | |