1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
12 // class Alloc = allocator<pair<const Key, T>>>
13 // class unordered_map
15 // void rehash(size_type n);
17 #include <unordered_map>
21 #include "test_macros.h"
22 #include "min_allocator.h"
25 void rehash_postcondition(const C
& c
, std::size_t n
)
27 assert(c
.bucket_count() >= c
.size() / c
.max_load_factor() && c
.bucket_count() >= n
);
33 assert(c
.size() == 4);
34 assert(c
.at(1) == "one");
35 assert(c
.at(2) == "two");
36 assert(c
.at(3) == "three");
37 assert(c
.at(4) == "four");
43 typedef std::unordered_map
<int, std::string
> C
;
44 typedef std::pair
<int, std::string
> P
;
54 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
56 assert(c
.bucket_count() >= 5);
58 rehash_postcondition(c
, 3);
59 LIBCPP_ASSERT(c
.bucket_count() == 5);
63 rehash_postcondition(c
, 3);
64 LIBCPP_ASSERT(c
.bucket_count() == 3);
67 rehash_postcondition(c
, 31);
68 LIBCPP_ASSERT(c
.bucket_count() == 31);
71 #if TEST_STD_VER >= 11
73 typedef std::unordered_map
<int, std::string
, std::hash
<int>, std::equal_to
<int>,
74 min_allocator
<std::pair
<const int, std::string
>>> C
;
75 typedef std::pair
<int, std::string
> P
;
85 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
87 assert(c
.bucket_count() >= 5);
89 rehash_postcondition(c
, 3);
90 LIBCPP_ASSERT(c
.bucket_count() == 5);
94 rehash_postcondition(c
, 3);
95 LIBCPP_ASSERT(c
.bucket_count() == 3);
98 rehash_postcondition(c
, 31);
99 LIBCPP_ASSERT(c
.bucket_count() == 31);