1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
use hicc::{AbiType, ClassMutPtr};
use std::iter::Iterator;
hicc::cpp! {
#include <unordered_set>
}
hicc::import_class! {
#[cpp(class = "template <class T, class Hash, class Pred, class Allocator> std::unordered_set<T, Hash, Pred, Allocator>")]
pub class unordered_set<T> {
hicc::cpp! {
typedef typename Self::iterator iterator;
typedef typename Self::const_iterator const_iterator;
}
/// ```
/// use hicc_std::UnorderedSetInt;
/// let set = UnorderedSetInt::new();
/// assert!(set.is_empty());
/// ```
#[cpp(method = "bool empty() const")]
pub fn is_empty(&self) -> bool;
/// ```
/// use hicc_std::UnorderedSetInt;
/// let set = UnorderedSetInt::new();
/// assert_eq!(set.size(), 0);
/// ```
#[cpp(method = "size_t size() const")]
pub fn size(&self) -> usize;
/// ```
/// use hicc_std::UnorderedSetInt;
/// let set = UnorderedSetInt::new();
/// println!("set.max_size = {}", set.max_size());
/// ```
#[cpp(method = "size_t max_size() const")]
pub fn max_size(&self) -> usize;
/// ```
/// use hicc_std::UnorderedSetInt;
/// let mut set = UnorderedSetInt::new();
/// set.insert(&1);
/// set.clear();
/// assert!(set.is_empty());
/// ```
#[cpp(method = "void clear()")]
pub fn clear(&mut self);
/// ```
/// use hicc_std::UnorderedSetInt;
/// let mut set = UnorderedSetInt::new();
/// set.insert(&1);
/// set.swap(&mut UnorderedSetInt::new());
/// assert!(set.is_empty());
/// ```
#[cpp(method = "void swap(Self&)")]
pub fn swap(&mut self, other: &mut Self);
/// ```
/// use hicc_std::UnorderedSetInt;
/// let mut set = UnorderedSetInt::new();
/// set.insert(&1);
/// assert_eq!(set.count(&1), 1);
/// ```
#[cpp(method = "size_t count(const T&) const")]
pub fn count(&self, val: &T) -> usize;
hicc::cpp! {
static bool contains(const Self& self, const T& val) {
return self.find(val) != self.end();
}
}
/// ```
/// use hicc_std::UnorderedSetInt;
/// let mut set = UnorderedSetInt::new();
/// set.insert(&1);
/// assert!(set.contains(&1));
/// ```
#[cpp(func = "bool SelfMethods::contains(const Self&, const T&)")]
pub fn contains(&self, val: &T) -> bool;
/// ```
/// use hicc_std::UnorderedSetInt;
/// let mut set = UnorderedSetInt::new();
/// set.insert(&1);
/// set.assign(&UnorderedSetInt::new());
/// assert!(set.is_empty());
/// ```
#[cpp(func = "void hicc::make_assign<Self, Self>(Self&, const Self&)")]
pub fn assign(&mut self, other: &Self);
hicc::cpp! {
static bool insert(Self& self, const T& val) {
return self.insert(val).second;
}
}
/// ```
/// use hicc_std::UnorderedSetInt;
/// let mut set = UnorderedSetInt::new();
/// assert!(set.insert(&1));
/// assert!(!set.insert(&1));
/// ```
#[cpp(func = "bool SelfMethods::insert(Self&, const T&)")]
pub fn insert(&mut self, val: &T) -> bool;
/// ```
/// use hicc_std::UnorderedSetInt;
/// let mut set = UnorderedSetInt::new();
/// set.insert(&1);
/// assert_eq!(set.erase(&1), 1);
/// ```
#[cpp(method = "size_t erase(const T&)")]
pub fn erase(&mut self, val: &T) -> usize;
#[cpp(method = "const_iterator begin() const")]
unsafe fn begin(&self) -> *mut CppUnorderedSetIter<T>;
#[cpp(method = "const_iterator end() const")]
unsafe fn end(&self) -> *mut CppUnorderedSetIter<T>;
}
unsafe impl<T: AbiType + Sync> Send for unordered_set<T> {}
unsafe impl<T: AbiType + Sync> Sync for unordered_set<T> {}
#[cpp(class = "template <class T, class Hash, class Pred, class Allocator> std::unordered_set<T, Hash, Pred, Allocator>::const_iterator")]
class CppUnorderedSetIter<T> {
hicc::cpp! {
static const T& next(Self& self) {
return *self++;
}
}
#[cpp(func = "const T& next(Self&)")]
unsafe fn next(&mut self) -> &T;
#[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
fn equal(&self, other: &Self) -> bool;
}
}
impl<T: AbiType> unordered_set<T> {
/// ```
/// use hicc_std::UnorderedSetInt;
/// let mut set = UnorderedSetInt::new();
/// set.insert(&1);
/// set.insert(&2);
/// set.iter().for_each(|v| {println!("{v}");});
/// ```
pub fn iter(&self) -> impl Iterator<Item = T::OutputRef<'_>> {
UnorderedSetIter {
beg: unsafe { self.begin() },
end: unsafe { self.end() },
}
}
}
/// 对应`std::unordered_set<T>::const_iterator`
struct UnorderedSetIter<'a, T: AbiType + 'static> {
beg: ClassMutPtr<'a, CppUnorderedSetIter<T>>,
end: ClassMutPtr<'a, CppUnorderedSetIter<T>>,
}
impl<'a, T: AbiType + 'static> Iterator for UnorderedSetIter<'a, T> {
type Item = T::OutputRef<'a>;
fn next(&mut self) -> Option<Self::Item> {
if !self.beg.equal(&self.end) {
return unsafe { Some(self.beg.as_deref_mut().next()) };
}
None
}
}
hicc::import_class! {
#[cpp(class = "template <class T, class Hash, class Pred, class Allocator> std::unordered_multiset<T, Hash, Pred, Allocator>")]
pub class unordered_multiset<T> {
hicc::cpp! {
typedef typename Self::iterator iterator;
typedef typename Self::const_iterator const_iterator;
}
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let set = UnorderedMultiSetInt::new();
/// assert!(set.is_empty());
/// ```
#[cpp(method = "bool empty() const")]
pub fn is_empty(&self) -> bool;
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let set = UnorderedMultiSetInt::new();
/// assert_eq!(set.size(), 0);
/// ```
#[cpp(method = "size_t size() const")]
pub fn size(&self) -> usize;
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let set = UnorderedMultiSetInt::new();
/// println!("set.max_size = {}", set.max_size());
/// ```
#[cpp(method = "size_t max_size() const")]
pub fn max_size(&self) -> usize;
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let mut set = UnorderedMultiSetInt::new();
/// set.insert(&1);
/// set.clear();
/// assert!(set.is_empty());
/// ```
#[cpp(method = "void clear()")]
pub fn clear(&mut self);
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let mut set = UnorderedMultiSetInt::new();
/// set.insert(&1);
/// set.swap(&mut UnorderedMultiSetInt::new());
/// assert!(set.is_empty());
/// ```
#[cpp(method = "void swap(Self&)")]
pub fn swap(&mut self, other: &mut Self);
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let mut set = UnorderedMultiSetInt::new();
/// set.insert(&1);
/// assert_eq!(set.count(&1), 1);
/// ```
#[cpp(method = "size_t count(const T&) const")]
pub fn count(&self, val: &T) -> usize;
hicc::cpp! {
static bool contains(const Self& self, const T& val) {
return self.find(val) != self.end();
}
}
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let mut set = UnorderedMultiSetInt::new();
/// set.contains(&1);
/// assert!(set.is_empty());
/// ```
#[cpp(func = "bool SelfMethods::contains(const Self&, const T&)")]
pub fn contains(&self, val: &T) -> bool;
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let mut set = UnorderedMultiSetInt::new();
/// set.insert(&1);
/// set.assign(&UnorderedMultiSetInt::new());
/// assert!(set.is_empty());
/// ```
#[cpp(func = "void hicc::make_assign<Self, Self>(Self&, const Self&)")]
pub fn assign(&mut self, other: &Self);
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let mut set = UnorderedMultiSetInt::new();
/// set.insert(&1);
/// set.insert(&1);
/// assert_eq!(set.size(), 2);
/// ```
#[cpp(method = "iterator insert(const T&)")]
pub fn insert(&mut self, val: &T);
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let mut set = UnorderedMultiSetInt::new();
/// set.insert(&1);
/// set.insert(&1);
/// assert_eq!(set.erase(&1), 2);
/// ```
#[cpp(method = "size_t erase(const T&)")]
pub fn erase(&mut self, val: &T) -> usize;
#[cpp(method = "const_iterator begin() const")]
unsafe fn begin(&self) -> *mut CppUnorderedMultiSetIter<T>;
#[cpp(method = "const_iterator end() const")]
unsafe fn end(&self) -> *mut CppUnorderedMultiSetIter<T>;
}
unsafe impl<T: AbiType + Sync> Send for unordered_multiset<T> {}
unsafe impl<T: AbiType + Sync> Sync for unordered_multiset<T> {}
#[cpp(class = "template <class T, class Hash, class Pred, class Allocator> std::unordered_multiset<T, Hash, Pred, Allocator>::const_iterator")]
class CppUnorderedMultiSetIter<T> {
hicc::cpp! {
static const T& next(Self& self) {
return *self++;
}
}
#[cpp(func = "const T& SelfMethods::next(Self&)")]
fn next(&mut self) -> &T;
#[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
fn equal(&self, other: &Self) -> bool;
}
}
impl<T: AbiType> unordered_multiset<T> {
/// ```
/// use hicc_std::UnorderedMultiSetInt;
/// let mut set = UnorderedMultiSetInt::new();
/// set.insert(&1);
/// set.insert(&2);
/// set.insert(&1);
/// set.iter().for_each(|v| { println!("{v}"); });
/// ```
pub fn iter(&self) -> impl Iterator<Item = T::OutputRef<'_>> {
UnorderedMultiSetIter {
beg: unsafe { self.begin() },
end: unsafe { self.end() },
}
}
}
/// 对应`std::unordered_multiset<T>::const_iterator`
struct UnorderedMultiSetIter<'a, T: AbiType + 'static> {
beg: ClassMutPtr<'a, CppUnorderedMultiSetIter<T>>,
end: ClassMutPtr<'a, CppUnorderedMultiSetIter<T>>,
}
impl<'a, T: AbiType + 'static> Iterator for UnorderedMultiSetIter<'a, T> {
type Item = T::OutputRef<'a>;
fn next(&mut self) -> Option<Self::Item> {
if self.beg.equal(&self.end) {
return unsafe { Some(self.beg.as_deref_mut().next()) };
}
None
}
}