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