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_multimap |
| 15 | |
| 16 | // void rehash(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() == 6); |
| 28 | assert(c.find(1)->second == "one"); |
| 29 | assert(next(c.find(1))->second == "four"); |
| 30 | assert(c.find(2)->second == "two"); |
| 31 | assert(next(c.find(2))->second == "four"); |
| 32 | assert(c.find(3)->second == "three"); |
| 33 | assert(c.find(4)->second == "four"); |
| 34 | } |
| 35 | |
| 36 | int main() |
| 37 | { |
| 38 | { |
| 39 | typedef std::unordered_multimap<int, std::string> C; |
| 40 | typedef std::pair<int, std::string> P; |
| 41 | P a[] = |
| 42 | { |
| 43 | P(1, "one"), |
| 44 | P(2, "two"), |
| 45 | P(3, "three"), |
| 46 | P(4, "four"), |
| 47 | P(1, "four"), |
| 48 | P(2, "four"), |
| 49 | }; |
| 50 | C c(a, a + sizeof(a)/sizeof(a[0])); |
| 51 | test(c); |
| 52 | assert(c.bucket_count() >= 7); |
| 53 | c.reserve(3); |
| 54 | assert(c.bucket_count() == 7); |
| 55 | test(c); |
| 56 | c.max_load_factor(2); |
| 57 | c.reserve(3); |
| 58 | assert(c.bucket_count() == 3); |
| 59 | test(c); |
| 60 | c.reserve(31); |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 61 | assert(c.bucket_count() >= 16); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | test(c); |
| 63 | } |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 64 | #if __cplusplus >= 201103L |
| 65 | { |
| 66 | typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>, |
| 67 | min_allocator<std::pair<const int, std::string>>> C; |
| 68 | typedef std::pair<int, std::string> P; |
| 69 | P a[] = |
| 70 | { |
| 71 | P(1, "one"), |
| 72 | P(2, "two"), |
| 73 | P(3, "three"), |
| 74 | P(4, "four"), |
| 75 | P(1, "four"), |
| 76 | P(2, "four"), |
| 77 | }; |
| 78 | C c(a, a + sizeof(a)/sizeof(a[0])); |
| 79 | test(c); |
| 80 | assert(c.bucket_count() >= 7); |
| 81 | c.reserve(3); |
| 82 | assert(c.bucket_count() == 7); |
| 83 | test(c); |
| 84 | c.max_load_factor(2); |
| 85 | c.reserve(3); |
| 86 | assert(c.bucket_count() == 3); |
| 87 | test(c); |
| 88 | c.reserve(31); |
| 89 | assert(c.bucket_count() >= 16); |
| 90 | test(c); |
| 91 | } |
| 92 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 93 | } |