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_map>
10
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
14
15 // size_type bucket_size(size_type n) const
16
17 #include <unordered_map>
18 #include <string>
19 #include <cassert>
20 #include <iterator>
21
22 #include "test_macros.h"
23 #include "min_allocator.h"
24
main(int,char **)25 int main(int, char**)
26 {
27 {
28 typedef std::unordered_map<int, std::string> C;
29 typedef std::pair<int, std::string> P;
30 P a[] =
31 {
32 P(1, "one"),
33 P(2, "two"),
34 P(3, "three"),
35 P(4, "four"),
36 P(1, "four"),
37 P(2, "four"),
38 };
39 const C c(std::begin(a), std::end(a));
40 assert(c.bucket_count() >= 5);
41 LIBCPP_ASSERT(c.bucket_size(0) == 0);
42 LIBCPP_ASSERT(c.bucket_size(1) == 1);
43 LIBCPP_ASSERT(c.bucket_size(2) == 1);
44 LIBCPP_ASSERT(c.bucket_size(3) == 1);
45 LIBCPP_ASSERT(c.bucket_size(4) == 1);
46 }
47 #if TEST_STD_VER >= 11
48 {
49 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
50 min_allocator<std::pair<const int, std::string>>> C;
51 typedef std::pair<int, std::string> P;
52 P a[] =
53 {
54 P(1, "one"),
55 P(2, "two"),
56 P(3, "three"),
57 P(4, "four"),
58 P(1, "four"),
59 P(2, "four"),
60 };
61 const C c(std::begin(a), std::end(a));
62 assert(c.bucket_count() >= 5);
63 LIBCPP_ASSERT(c.bucket_size(0) == 0);
64 LIBCPP_ASSERT(c.bucket_size(1) == 1);
65 LIBCPP_ASSERT(c.bucket_size(2) == 1);
66 LIBCPP_ASSERT(c.bucket_size(3) == 1);
67 LIBCPP_ASSERT(c.bucket_size(4) == 1);
68 }
69 #endif
70
71 return 0;
72 }
73