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_set> 11 12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, 13 // class Alloc = allocator<Value>> 14 // class unordered_set 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_set> 24 #include <cassert> 25 26 int main() 27 { 28 { 29 typedef std::unordered_set<int> C; 30 typedef int P; 31 typedef C::local_iterator I; 32 P a[] = 33 { 34 P(1), 35 P(2), 36 P(3), 37 P(4), 38 P(1), 39 P(2) 40 }; 41 C c(a, a + sizeof(a)/sizeof(a[0])); 42 assert(c.bucket_count() >= 5); 43 C::size_type b = c.bucket(0); 44 I i = c.begin(b); 45 I j = c.end(b); 46 assert(std::distance(i, j) == 0); 47 48 b = c.bucket(1); 49 i = c.begin(b); 50 j = c.end(b); 51 assert(std::distance(i, j) == 1); 52 assert(*i == 1); 53 54 b = c.bucket(2); 55 i = c.begin(b); 56 j = c.end(b); 57 assert(std::distance(i, j) == 1); 58 assert(*i == 2); 59 60 b = c.bucket(3); 61 i = c.begin(b); 62 j = c.end(b); 63 assert(std::distance(i, j) == 1); 64 assert(*i == 3); 65 66 b = c.bucket(4); 67 i = c.begin(b); 68 j = c.end(b); 69 assert(std::distance(i, j) == 1); 70 assert(*i == 4); 71 } 72 { 73 typedef std::unordered_set<int> C; 74 typedef int P; 75 typedef C::const_local_iterator I; 76 P a[] = 77 { 78 P(1), 79 P(2), 80 P(3), 81 P(4), 82 P(1), 83 P(2) 84 }; 85 const C c(a, a + sizeof(a)/sizeof(a[0])); 86 assert(c.bucket_count() >= 5); 87 C::size_type b = c.bucket(0); 88 I i = c.begin(b); 89 I j = c.end(b); 90 assert(std::distance(i, j) == 0); 91 92 b = c.bucket(1); 93 i = c.begin(b); 94 j = c.end(b); 95 assert(std::distance(i, j) == 1); 96 assert(*i == 1); 97 98 b = c.bucket(2); 99 i = c.begin(b); 100 j = c.end(b); 101 assert(std::distance(i, j) == 1); 102 assert(*i == 2); 103 104 b = c.bucket(3); 105 i = c.begin(b); 106 j = c.end(b); 107 assert(std::distance(i, j) == 1); 108 assert(*i == 3); 109 110 b = c.bucket(4); 111 i = c.begin(b); 112 j = c.end(b); 113 assert(std::distance(i, j) == 1); 114 assert(*i == 4); 115 } 116 { 117 typedef std::unordered_set<int> C; 118 typedef int P; 119 typedef C::const_local_iterator I; 120 P a[] = 121 { 122 P(1), 123 P(2), 124 P(3), 125 P(4), 126 P(1), 127 P(2) 128 }; 129 C c(a, a + sizeof(a)/sizeof(a[0])); 130 assert(c.bucket_count() >= 5); 131 C::size_type b = c.bucket(0); 132 I i = c.cbegin(b); 133 I j = c.cend(b); 134 assert(std::distance(i, j) == 0); 135 136 b = c.bucket(1); 137 i = c.cbegin(b); 138 j = c.cend(b); 139 assert(std::distance(i, j) == 1); 140 assert(*i == 1); 141 142 b = c.bucket(2); 143 i = c.cbegin(b); 144 j = c.cend(b); 145 assert(std::distance(i, j) == 1); 146 assert(*i == 2); 147 148 b = c.bucket(3); 149 i = c.cbegin(b); 150 j = c.cend(b); 151 assert(std::distance(i, j) == 1); 152 assert(*i == 3); 153 154 b = c.bucket(4); 155 i = c.cbegin(b); 156 j = c.cend(b); 157 assert(std::distance(i, j) == 1); 158 assert(*i == 4); 159 } 160 { 161 typedef std::unordered_set<int> C; 162 typedef int P; 163 typedef C::const_local_iterator I; 164 P a[] = 165 { 166 P(1), 167 P(2), 168 P(3), 169 P(4), 170 P(1), 171 P(2) 172 }; 173 const C c(a, a + sizeof(a)/sizeof(a[0])); 174 assert(c.bucket_count() >= 5); 175 C::size_type b = c.bucket(0); 176 I i = c.cbegin(b); 177 I j = c.cend(b); 178 assert(std::distance(i, j) == 0); 179 180 b = c.bucket(1); 181 i = c.cbegin(b); 182 j = c.cend(b); 183 assert(std::distance(i, j) == 1); 184 assert(*i == 1); 185 186 b = c.bucket(2); 187 i = c.cbegin(b); 188 j = c.cend(b); 189 assert(std::distance(i, j) == 1); 190 assert(*i == 2); 191 192 b = c.bucket(3); 193 i = c.cbegin(b); 194 j = c.cend(b); 195 assert(std::distance(i, j) == 1); 196 assert(*i == 3); 197 198 b = c.bucket(4); 199 i = c.cbegin(b); 200 j = c.cend(b); 201 assert(std::distance(i, j) == 1); 202 assert(*i == 4); 203 } 204 } 205