| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <unordered_set> |
| 10 | |
| 11 | // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
| 12 | // class Alloc = allocator<Value>> |
| 13 | // class unordered_set |
| 14 | |
| 15 | // local_iterator begin (size_type n); |
| 16 | // local_iterator end (size_type n); |
| 17 | // const_local_iterator begin (size_type n) const; |
| 18 | // const_local_iterator end (size_type n) const; |
| 19 | // const_local_iterator cbegin(size_type n) const; |
| 20 | // const_local_iterator cend (size_type n) const; |
| 21 | |
| 22 | #include <unordered_set> |
| 23 | #include <cassert> |
| 24 | |
| 25 | int main(int, char**) { |
| 26 | { |
| 27 | typedef std::unordered_set<int> C; |
| 28 | typedef int P; |
| 29 | typedef C::local_iterator I; |
| 30 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
| 31 | C c(a, a + sizeof(a) / sizeof(a[0])); |
| 32 | assert(c.bucket_count() >= 5); |
| 33 | C::size_type b = c.bucket(key: 0); |
| 34 | I i = c.begin(n: b); |
| 35 | I j = c.end(n: b); |
| 36 | assert(std::distance(i, j) == 0); |
| 37 | |
| 38 | b = c.bucket(key: 1); |
| 39 | i = c.begin(n: b); |
| 40 | j = c.end(n: b); |
| 41 | assert(std::distance(i, j) == 2); |
| 42 | assert(*i == 1); |
| 43 | ++i; |
| 44 | assert(*i == 1); |
| 45 | *i = 2; |
| 46 | |
| 47 | b = c.bucket(key: 2); |
| 48 | i = c.begin(n: b); |
| 49 | j = c.end(n: b); |
| 50 | assert(std::distance(i, j) == 2); |
| 51 | assert(*i == 2); |
| 52 | ++i; |
| 53 | assert(*i == 2); |
| 54 | |
| 55 | b = c.bucket(key: 3); |
| 56 | i = c.begin(n: b); |
| 57 | j = c.end(n: b); |
| 58 | assert(std::distance(i, j) == 1); |
| 59 | assert(*i == 3); |
| 60 | |
| 61 | b = c.bucket(key: 4); |
| 62 | i = c.begin(n: b); |
| 63 | j = c.end(n: b); |
| 64 | assert(std::distance(i, j) == 1); |
| 65 | assert(*i == 4); |
| 66 | |
| 67 | b = c.bucket(key: 5); |
| 68 | i = c.begin(n: b); |
| 69 | j = c.end(n: b); |
| 70 | assert(std::distance(i, j) == 0); |
| 71 | |
| 72 | b = c.bucket(key: 6); |
| 73 | i = c.begin(n: b); |
| 74 | j = c.end(n: b); |
| 75 | assert(std::distance(i, j) == 0); |
| 76 | } |
| 77 | { |
| 78 | typedef std::unordered_set<int> C; |
| 79 | typedef int P; |
| 80 | typedef C::const_local_iterator I; |
| 81 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
| 82 | const C c(a, a + sizeof(a) / sizeof(a[0])); |
| 83 | assert(c.bucket_count() >= 5); |
| 84 | C::size_type b = c.bucket(key: 0); |
| 85 | I i = c.begin(n: b); |
| 86 | I j = c.end(n: b); |
| 87 | assert(std::distance(i, j) == 0); |
| 88 | |
| 89 | b = c.bucket(key: 1); |
| 90 | i = c.begin(n: b); |
| 91 | j = c.end(n: b); |
| 92 | assert(std::distance(i, j) == 2); |
| 93 | assert(*i == 1); |
| 94 | ++i; |
| 95 | assert(*i == 1); |
| 96 | |
| 97 | b = c.bucket(key: 2); |
| 98 | i = c.begin(n: b); |
| 99 | j = c.end(n: b); |
| 100 | assert(std::distance(i, j) == 2); |
| 101 | assert(*i == 2); |
| 102 | ++i; |
| 103 | assert(*i == 2); |
| 104 | |
| 105 | b = c.bucket(key: 3); |
| 106 | i = c.begin(n: b); |
| 107 | j = c.end(n: b); |
| 108 | assert(std::distance(i, j) == 1); |
| 109 | assert(*i == 3); |
| 110 | |
| 111 | b = c.bucket(key: 4); |
| 112 | i = c.begin(n: b); |
| 113 | j = c.end(n: b); |
| 114 | assert(std::distance(i, j) == 1); |
| 115 | assert(*i == 4); |
| 116 | |
| 117 | b = c.bucket(key: 5); |
| 118 | i = c.begin(n: b); |
| 119 | j = c.end(n: b); |
| 120 | assert(std::distance(i, j) == 0); |
| 121 | |
| 122 | b = c.bucket(key: 6); |
| 123 | i = c.begin(n: b); |
| 124 | j = c.end(n: b); |
| 125 | assert(std::distance(i, j) == 0); |
| 126 | } |
| 127 | { |
| 128 | typedef std::unordered_set<int> C; |
| 129 | typedef int P; |
| 130 | typedef C::const_local_iterator I; |
| 131 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
| 132 | C c(a, a + sizeof(a) / sizeof(a[0])); |
| 133 | assert(c.bucket_count() >= 5); |
| 134 | C::size_type b = c.bucket(key: 0); |
| 135 | I i = c.cbegin(n: b); |
| 136 | I j = c.cend(n: b); |
| 137 | assert(std::distance(i, j) == 0); |
| 138 | |
| 139 | b = c.bucket(key: 1); |
| 140 | i = c.cbegin(n: b); |
| 141 | j = c.cend(n: b); |
| 142 | assert(std::distance(i, j) == 2); |
| 143 | assert(*i == 1); |
| 144 | ++i; |
| 145 | assert(*i == 1); |
| 146 | |
| 147 | b = c.bucket(key: 2); |
| 148 | i = c.cbegin(n: b); |
| 149 | j = c.cend(n: b); |
| 150 | assert(std::distance(i, j) == 2); |
| 151 | assert(*i == 2); |
| 152 | ++i; |
| 153 | assert(*i == 2); |
| 154 | |
| 155 | b = c.bucket(key: 3); |
| 156 | i = c.cbegin(n: b); |
| 157 | j = c.cend(n: b); |
| 158 | assert(std::distance(i, j) == 1); |
| 159 | assert(*i == 3); |
| 160 | |
| 161 | b = c.bucket(key: 4); |
| 162 | i = c.cbegin(n: b); |
| 163 | j = c.cend(n: b); |
| 164 | assert(std::distance(i, j) == 1); |
| 165 | assert(*i == 4); |
| 166 | |
| 167 | b = c.bucket(key: 5); |
| 168 | i = c.cbegin(n: b); |
| 169 | j = c.cend(n: b); |
| 170 | assert(std::distance(i, j) == 0); |
| 171 | |
| 172 | b = c.bucket(key: 6); |
| 173 | i = c.cbegin(n: b); |
| 174 | j = c.cend(n: b); |
| 175 | assert(std::distance(i, j) == 0); |
| 176 | } |
| 177 | { |
| 178 | typedef std::unordered_set<int> C; |
| 179 | typedef int P; |
| 180 | typedef C::const_local_iterator I; |
| 181 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
| 182 | const C c(a, a + sizeof(a) / sizeof(a[0])); |
| 183 | assert(c.bucket_count() >= 5); |
| 184 | C::size_type b = c.bucket(key: 0); |
| 185 | I i = c.cbegin(n: b); |
| 186 | I j = c.cend(n: b); |
| 187 | assert(std::distance(i, j) == 0); |
| 188 | |
| 189 | b = c.bucket(key: 1); |
| 190 | i = c.cbegin(n: b); |
| 191 | j = c.cend(n: b); |
| 192 | assert(std::distance(i, j) == 2); |
| 193 | assert(*i == 1); |
| 194 | ++i; |
| 195 | assert(*i == 1); |
| 196 | |
| 197 | b = c.bucket(key: 2); |
| 198 | i = c.cbegin(n: b); |
| 199 | j = c.cend(n: b); |
| 200 | assert(std::distance(i, j) == 2); |
| 201 | assert(*i == 2); |
| 202 | ++i; |
| 203 | assert(*i == 2); |
| 204 | |
| 205 | b = c.bucket(key: 3); |
| 206 | i = c.cbegin(n: b); |
| 207 | j = c.cend(n: b); |
| 208 | assert(std::distance(i, j) == 1); |
| 209 | assert(*i == 3); |
| 210 | |
| 211 | b = c.bucket(key: 4); |
| 212 | i = c.cbegin(n: b); |
| 213 | j = c.cend(n: b); |
| 214 | assert(std::distance(i, j) == 1); |
| 215 | assert(*i == 4); |
| 216 | |
| 217 | b = c.bucket(key: 5); |
| 218 | i = c.cbegin(n: b); |
| 219 | j = c.cend(n: b); |
| 220 | assert(std::distance(i, j) == 0); |
| 221 | |
| 222 | b = c.bucket(key: 6); |
| 223 | i = c.cbegin(n: b); |
| 224 | j = c.cend(n: b); |
| 225 | assert(std::distance(i, j) == 0); |
| 226 | } |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |