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_map 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_map<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() >= 5); 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) == 1); 53 assert(i->first == 1); 54 assert(i->second == "one"); 55 56 b = c.bucket(2); 57 i = c.begin(b); 58 j = c.end(b); 59 assert(std::distance(i, j) == 1); 60 assert(i->first == 2); 61 assert(i->second == "two"); 62 63 b = c.bucket(3); 64 i = c.begin(b); 65 j = c.end(b); 66 assert(std::distance(i, j) == 1); 67 assert(i->first == 3); 68 assert(i->second == "three"); 69 70 b = c.bucket(4); 71 i = c.begin(b); 72 j = c.end(b); 73 assert(std::distance(i, j) == 1); 74 assert(i->first == 4); 75 assert(i->second == "four"); 76 } 77 { 78 typedef std::unordered_map<int, std::string> C; 79 typedef std::pair<int, std::string> P; 80 typedef C::const_local_iterator I; 81 P a[] = 82 { 83 P(1, "one"), 84 P(2, "two"), 85 P(3, "three"), 86 P(4, "four"), 87 P(1, "four"), 88 P(2, "four"), 89 }; 90 const C c(a, a + sizeof(a)/sizeof(a[0])); 91 assert(c.bucket_count() >= 5); 92 C::size_type b = c.bucket(0); 93 I i = c.begin(b); 94 I j = c.end(b); 95 assert(std::distance(i, j) == 0); 96 97 b = c.bucket(1); 98 i = c.begin(b); 99 j = c.end(b); 100 assert(std::distance(i, j) == 1); 101 assert(i->first == 1); 102 assert(i->second == "one"); 103 104 b = c.bucket(2); 105 i = c.begin(b); 106 j = c.end(b); 107 assert(std::distance(i, j) == 1); 108 assert(i->first == 2); 109 assert(i->second == "two"); 110 111 b = c.bucket(3); 112 i = c.begin(b); 113 j = c.end(b); 114 assert(std::distance(i, j) == 1); 115 assert(i->first == 3); 116 assert(i->second == "three"); 117 118 b = c.bucket(4); 119 i = c.begin(b); 120 j = c.end(b); 121 assert(std::distance(i, j) == 1); 122 assert(i->first == 4); 123 assert(i->second == "four"); 124 } 125 { 126 typedef std::unordered_map<int, std::string> C; 127 typedef std::pair<int, std::string> P; 128 typedef C::const_local_iterator I; 129 P a[] = 130 { 131 P(1, "one"), 132 P(2, "two"), 133 P(3, "three"), 134 P(4, "four"), 135 P(1, "four"), 136 P(2, "four"), 137 }; 138 C c(a, a + sizeof(a)/sizeof(a[0])); 139 assert(c.bucket_count() >= 5); 140 C::size_type b = c.bucket(0); 141 I i = c.cbegin(b); 142 I j = c.cend(b); 143 assert(std::distance(i, j) == 0); 144 145 b = c.bucket(1); 146 i = c.cbegin(b); 147 j = c.cend(b); 148 assert(std::distance(i, j) == 1); 149 assert(i->first == 1); 150 assert(i->second == "one"); 151 152 b = c.bucket(2); 153 i = c.cbegin(b); 154 j = c.cend(b); 155 assert(std::distance(i, j) == 1); 156 assert(i->first == 2); 157 assert(i->second == "two"); 158 159 b = c.bucket(3); 160 i = c.cbegin(b); 161 j = c.cend(b); 162 assert(std::distance(i, j) == 1); 163 assert(i->first == 3); 164 assert(i->second == "three"); 165 166 b = c.bucket(4); 167 i = c.cbegin(b); 168 j = c.cend(b); 169 assert(std::distance(i, j) == 1); 170 assert(i->first == 4); 171 assert(i->second == "four"); 172 } 173 { 174 typedef std::unordered_map<int, std::string> C; 175 typedef std::pair<int, std::string> P; 176 typedef C::const_local_iterator I; 177 P a[] = 178 { 179 P(1, "one"), 180 P(2, "two"), 181 P(3, "three"), 182 P(4, "four"), 183 P(1, "four"), 184 P(2, "four"), 185 }; 186 const C c(a, a + sizeof(a)/sizeof(a[0])); 187 assert(c.bucket_count() >= 5); 188 C::size_type b = c.bucket(0); 189 I i = c.cbegin(b); 190 I j = c.cend(b); 191 assert(std::distance(i, j) == 0); 192 193 b = c.bucket(1); 194 i = c.cbegin(b); 195 j = c.cend(b); 196 assert(std::distance(i, j) == 1); 197 assert(i->first == 1); 198 assert(i->second == "one"); 199 200 b = c.bucket(2); 201 i = c.cbegin(b); 202 j = c.cend(b); 203 assert(std::distance(i, j) == 1); 204 assert(i->first == 2); 205 assert(i->second == "two"); 206 207 b = c.bucket(3); 208 i = c.cbegin(b); 209 j = c.cend(b); 210 assert(std::distance(i, j) == 1); 211 assert(i->first == 3); 212 assert(i->second == "three"); 213 214 b = c.bucket(4); 215 i = c.cbegin(b); 216 j = c.cend(b); 217 assert(std::distance(i, j) == 1); 218 assert(i->first == 4); 219 assert(i->second == "four"); 220 } 221 } 222