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