blob: 801c74457d74c2c430ff2863be8f6851a896ef71 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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 Clow061d0cc2013-11-26 20:58:02 +000022#include "min_allocator.h"
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +000023
24template <class C>
25void test(const C& c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000026{
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
36int 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 Hinnant7a445152012-07-06 17:31:14 +000061 assert(c.bucket_count() >= 16);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000062 test(c);
63 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +000064#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 Hinnantbc8d3f92010-05-11 19:42:16 +000093}