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 // local_iterator begin (size_type n); 17 // local_iterator end (size_type n); 18 // const_local_iterator begin (size_type n) const; 19 // const_local_iterator end (size_type n) const; 20 // const_local_iterator cbegin(size_type n) const; 21 // const_local_iterator cend (size_type n) const; 22 23 #include <unordered_map> 24 #include <string> 25 #include <cassert> 26 27 int main() 28 { 29 { 30 typedef std::unordered_multimap<int, std::string> C; 31 typedef std::pair<int, std::string> P; 32 typedef C::local_iterator I; 33 P a[] = 34 { 35 P(1, "one"), 36 P(2, "two"), 37 P(3, "three"), 38 P(4, "four"), 39 P(1, "four"), 40 P(2, "four"), 41 }; 42 C c(a, a + sizeof(a)/sizeof(a[0])); 43 assert(c.bucket_count() >= 7); 44 C::size_type b = c.bucket(0); 45 I i = c.begin(b); 46 I j = c.end(b); 47 assert(std::distance(i, j) == 0); 48 49 b = c.bucket(1); 50 i = c.begin(b); 51 j = c.end(b); 52 assert(std::distance(i, j) == 2); 53 assert(i->first == 1); 54 assert(i->second == "one"); 55 ++i; 56 assert(i->first == 1); 57 assert(i->second == "four"); 58 59 b = c.bucket(2); 60 i = c.begin(b); 61 j = c.end(b); 62 assert(std::distance(i, j) == 2); 63 assert(i->first == 2); 64 assert(i->second == "two"); 65 ++i; 66 assert(i->first == 2); 67 assert(i->second == "four"); 68 69 b = c.bucket(3); 70 i = c.begin(b); 71 j = c.end(b); 72 assert(std::distance(i, j) == 1); 73 assert(i->first == 3); 74 assert(i->second == "three"); 75 76 b = c.bucket(4); 77 i = c.begin(b); 78 j = c.end(b); 79 assert(std::distance(i, j) == 1); 80 assert(i->first == 4); 81 assert(i->second == "four"); 82 83 b = c.bucket(5); 84 i = c.begin(b); 85 j = c.end(b); 86 assert(std::distance(i, j) == 0); 87 88 b = c.bucket(6); 89 i = c.begin(b); 90 j = c.end(b); 91 assert(std::distance(i, j) == 0); 92 } 93 { 94 typedef std::unordered_multimap<int, std::string> C; 95 typedef std::pair<int, std::string> P; 96 typedef C::const_local_iterator I; 97 P a[] = 98 { 99 P(1, "one"), 100 P(2, "two"), 101 P(3, "three"), 102 P(4, "four"), 103 P(1, "four"), 104 P(2, "four"), 105 }; 106 const C c(a, a + sizeof(a)/sizeof(a[0])); 107 assert(c.bucket_count() >= 7); 108 C::size_type b = c.bucket(0); 109 I i = c.begin(b); 110 I j = c.end(b); 111 assert(std::distance(i, j) == 0); 112 113 b = c.bucket(1); 114 i = c.begin(b); 115 j = c.end(b); 116 assert(std::distance(i, j) == 2); 117 assert(i->first == 1); 118 assert(i->second == "one"); 119 ++i; 120 assert(i->first == 1); 121 assert(i->second == "four"); 122 123 b = c.bucket(2); 124 i = c.begin(b); 125 j = c.end(b); 126 assert(std::distance(i, j) == 2); 127 assert(i->first == 2); 128 assert(i->second == "two"); 129 ++i; 130 assert(i->first == 2); 131 assert(i->second == "four"); 132 133 b = c.bucket(3); 134 i = c.begin(b); 135 j = c.end(b); 136 assert(std::distance(i, j) == 1); 137 assert(i->first == 3); 138 assert(i->second == "three"); 139 140 b = c.bucket(4); 141 i = c.begin(b); 142 j = c.end(b); 143 assert(std::distance(i, j) == 1); 144 assert(i->first == 4); 145 assert(i->second == "four"); 146 147 b = c.bucket(5); 148 i = c.begin(b); 149 j = c.end(b); 150 assert(std::distance(i, j) == 0); 151 152 b = c.bucket(6); 153 i = c.begin(b); 154 j = c.end(b); 155 assert(std::distance(i, j) == 0); 156 } 157 { 158 typedef std::unordered_multimap<int, std::string> C; 159 typedef std::pair<int, std::string> P; 160 typedef C::const_local_iterator I; 161 P a[] = 162 { 163 P(1, "one"), 164 P(2, "two"), 165 P(3, "three"), 166 P(4, "four"), 167 P(1, "four"), 168 P(2, "four"), 169 }; 170 C c(a, a + sizeof(a)/sizeof(a[0])); 171 assert(c.bucket_count() >= 7); 172 C::size_type b = c.bucket(0); 173 I i = c.cbegin(b); 174 I j = c.cend(b); 175 assert(std::distance(i, j) == 0); 176 177 b = c.bucket(1); 178 i = c.cbegin(b); 179 j = c.cend(b); 180 assert(std::distance(i, j) == 2); 181 assert(i->first == 1); 182 assert(i->second == "one"); 183 ++i; 184 assert(i->first == 1); 185 assert(i->second == "four"); 186 187 b = c.bucket(2); 188 i = c.cbegin(b); 189 j = c.cend(b); 190 assert(std::distance(i, j) == 2); 191 assert(i->first == 2); 192 assert(i->second == "two"); 193 ++i; 194 assert(i->first == 2); 195 assert(i->second == "four"); 196 197 b = c.bucket(3); 198 i = c.cbegin(b); 199 j = c.cend(b); 200 assert(std::distance(i, j) == 1); 201 assert(i->first == 3); 202 assert(i->second == "three"); 203 204 b = c.bucket(4); 205 i = c.cbegin(b); 206 j = c.cend(b); 207 assert(std::distance(i, j) == 1); 208 assert(i->first == 4); 209 assert(i->second == "four"); 210 211 b = c.bucket(5); 212 i = c.cbegin(b); 213 j = c.cend(b); 214 assert(std::distance(i, j) == 0); 215 216 b = c.bucket(6); 217 i = c.cbegin(b); 218 j = c.cend(b); 219 assert(std::distance(i, j) == 0); 220 } 221 { 222 typedef std::unordered_multimap<int, std::string> C; 223 typedef std::pair<int, std::string> P; 224 typedef C::const_local_iterator I; 225 P a[] = 226 { 227 P(1, "one"), 228 P(2, "two"), 229 P(3, "three"), 230 P(4, "four"), 231 P(1, "four"), 232 P(2, "four"), 233 }; 234 const C c(a, a + sizeof(a)/sizeof(a[0])); 235 assert(c.bucket_count() >= 7); 236 C::size_type b = c.bucket(0); 237 I i = c.cbegin(b); 238 I j = c.cend(b); 239 assert(std::distance(i, j) == 0); 240 241 b = c.bucket(1); 242 i = c.cbegin(b); 243 j = c.cend(b); 244 assert(std::distance(i, j) == 2); 245 assert(i->first == 1); 246 assert(i->second == "one"); 247 ++i; 248 assert(i->first == 1); 249 assert(i->second == "four"); 250 251 b = c.bucket(2); 252 i = c.cbegin(b); 253 j = c.cend(b); 254 assert(std::distance(i, j) == 2); 255 assert(i->first == 2); 256 assert(i->second == "two"); 257 ++i; 258 assert(i->first == 2); 259 assert(i->second == "four"); 260 261 b = c.bucket(3); 262 i = c.cbegin(b); 263 j = c.cend(b); 264 assert(std::distance(i, j) == 1); 265 assert(i->first == 3); 266 assert(i->second == "three"); 267 268 b = c.bucket(4); 269 i = c.cbegin(b); 270 j = c.cend(b); 271 assert(std::distance(i, j) == 1); 272 assert(i->first == 4); 273 assert(i->second == "four"); 274 275 b = c.bucket(5); 276 i = c.cbegin(b); 277 j = c.cend(b); 278 assert(std::distance(i, j) == 0); 279 280 b = c.bucket(6); 281 i = c.cbegin(b); 282 j = c.cend(b); 283 assert(std::distance(i, j) == 0); 284 } 285 } 286