1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
16 // void rehash(size_type n);
18 #include <unordered_map>
24 #include "min_allocator.h"
27 void rehash_postcondition(const C& c, size_t n)
29 assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n);
35 assert(c.size() == 6);
36 typedef std::pair<typename C::const_iterator, typename C::const_iterator> Eq;
37 Eq eq = c.equal_range(1);
38 assert(std::distance(eq.first, eq.second) == 2);
39 typename C::const_iterator i = eq.first;
40 assert(i->first == 1);
41 assert(i->second == "one");
43 assert(i->first == 1);
44 assert(i->second == "four");
45 eq = c.equal_range(2);
46 assert(std::distance(eq.first, eq.second) == 2);
48 assert(i->first == 2);
49 assert(i->second == "two");
51 assert(i->first == 2);
52 assert(i->second == "four");
54 eq = c.equal_range(3);
55 assert(std::distance(eq.first, eq.second) == 1);
57 assert(i->first == 3);
58 assert(i->second == "three");
59 eq = c.equal_range(4);
60 assert(std::distance(eq.first, eq.second) == 1);
62 assert(i->first == 4);
63 assert(i->second == "four");
64 assert(std::distance(c.begin(), c.end()) == c.size());
65 assert(std::distance(c.cbegin(), c.cend()) == c.size());
66 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
72 typedef std::unordered_multimap<int, std::string> C;
73 typedef std::pair<int, std::string> P;
83 C c(a, a + sizeof(a)/sizeof(a[0]));
85 assert(c.bucket_count() >= 7);
87 rehash_postcondition(c, 3);
88 assert(c.bucket_count() == 7);
92 rehash_postcondition(c, 3);
93 assert(c.bucket_count() == 3);
96 rehash_postcondition(c, 31);
97 assert(c.bucket_count() == 31);
100 #if TEST_STD_VER >= 11
102 typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
103 min_allocator<std::pair<const int, std::string>>> C;
104 typedef std::pair<int, std::string> P;
114 C c(a, a + sizeof(a)/sizeof(a[0]));
116 assert(c.bucket_count() >= 7);
118 rehash_postcondition(c, 3);
119 assert(c.bucket_count() == 7);
121 c.max_load_factor(2);
123 rehash_postcondition(c, 3);
124 assert(c.bucket_count() == 3);
127 rehash_postcondition(c, 31);
128 assert(c.bucket_count() == 31);