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