1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
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 
22 #include "min_allocator.h"
23 
24 template <class C>
test(const C & c)25 void test(const C& c)
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 
main()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);
61         assert(c.bucket_count() >= 16);
62         test(c);
63     }
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
93 }
94