Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <unordered_map> |
| 11 | |
| 12 | // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 13 | // class Alloc = allocator<pair<const Key, T>>> |
| 14 | // class unordered_map |
| 15 | |
| 16 | // void reserve(size_type n); |
| 17 | |
| 18 | #include <unordered_map> |
| 19 | #include <string> |
| 20 | #include <cassert> |
| 21 | |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 22 | #include "min_allocator.h" |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 23 | |
| 24 | template <class C> |
| 25 | void test(const C& c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | { |
| 27 | assert(c.size() == 4); |
| 28 | assert(c.at(1) == "one"); |
| 29 | assert(c.at(2) == "two"); |
| 30 | assert(c.at(3) == "three"); |
| 31 | assert(c.at(4) == "four"); |
| 32 | } |
| 33 | |
| 34 | int main() |
| 35 | { |
| 36 | { |
| 37 | typedef std::unordered_map<int, std::string> C; |
| 38 | typedef std::pair<int, std::string> P; |
| 39 | P a[] = |
| 40 | { |
| 41 | P(1, "one"), |
| 42 | P(2, "two"), |
| 43 | P(3, "three"), |
| 44 | P(4, "four"), |
| 45 | P(1, "four"), |
| 46 | P(2, "four"), |
| 47 | }; |
| 48 | C c(a, a + sizeof(a)/sizeof(a[0])); |
| 49 | test(c); |
| 50 | assert(c.bucket_count() >= 5); |
| 51 | c.reserve(3); |
| 52 | assert(c.bucket_count() == 5); |
| 53 | test(c); |
| 54 | c.max_load_factor(2); |
| 55 | c.reserve(3); |
| 56 | assert(c.bucket_count() >= 2); |
| 57 | test(c); |
| 58 | c.reserve(31); |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 59 | assert(c.bucket_count() >= 16); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 60 | test(c); |
| 61 | } |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 62 | #if __cplusplus >= 201103L |
| 63 | { |
| 64 | typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, |
| 65 | min_allocator<std::pair<const int, std::string>>> C; |
| 66 | typedef std::pair<int, std::string> P; |
| 67 | P a[] = |
| 68 | { |
| 69 | P(1, "one"), |
| 70 | P(2, "two"), |
| 71 | P(3, "three"), |
| 72 | P(4, "four"), |
| 73 | P(1, "four"), |
| 74 | P(2, "four"), |
| 75 | }; |
| 76 | C c(a, a + sizeof(a)/sizeof(a[0])); |
| 77 | test(c); |
| 78 | assert(c.bucket_count() >= 5); |
| 79 | c.reserve(3); |
| 80 | assert(c.bucket_count() == 5); |
| 81 | test(c); |
| 82 | c.max_load_factor(2); |
| 83 | c.reserve(3); |
| 84 | assert(c.bucket_count() >= 2); |
| 85 | test(c); |
| 86 | c.reserve(31); |
| 87 | assert(c.bucket_count() >= 16); |
| 88 | test(c); |
| 89 | } |
| 90 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 91 | } |