hicc_std/
std_unordered_set.rs1use hicc::{AbiType, ClassMutPtr};
2use std::iter::Iterator;
3
4hicc::cpp! {
5 #include <unordered_set>
6}
7
8hicc::import_class! {
9 #[cpp(class = "template <class T, class Hash, class Pred, class Allocator> std::unordered_set<T, Hash, Pred, Allocator>")]
10 pub class unordered_set<T> {
11 hicc::cpp! {
12 typedef typename Self::iterator iterator;
13 typedef typename Self::const_iterator const_iterator;
14 }
15 #[cpp(method = "bool empty() const")]
21 pub fn is_empty(&self) -> bool;
22
23 #[cpp(method = "size_t size() const")]
29 pub fn size(&self) -> usize;
30
31 #[cpp(method = "size_t max_size() const")]
37 pub fn max_size(&self) -> usize;
38
39 #[cpp(method = "void clear()")]
47 pub fn clear(&mut self);
48
49 #[cpp(method = "void swap(Self&)")]
57 pub fn swap(&mut self, other: &mut Self);
58
59 #[cpp(method = "size_t count(const T&) const")]
66 pub fn count(&self, val: &T) -> usize;
67
68 hicc::cpp! {
69 static bool contains(const Self& self, const T& val) {
70 return self.find(val) != self.end();
71 }
72 }
73 #[cpp(func = "bool SelfMethods::contains(const Self&, const T&)")]
80 pub fn contains(&self, val: &T) -> bool;
81
82 #[cpp(func = "void hicc::make_assign<Self, Self>(Self&, const Self&)")]
90 pub fn assign(&mut self, other: &Self);
91
92 hicc::cpp! {
93 static bool insert(Self& self, const T& val) {
94 return self.insert(val).second;
95 }
96 }
97 #[cpp(func = "bool SelfMethods::insert(Self&, const T&)")]
104 pub fn insert(&mut self, val: &T) -> bool;
105
106 #[cpp(method = "size_t erase(const T&)")]
113 pub fn erase(&mut self, val: &T) -> usize;
114
115 #[cpp(method = "const_iterator begin() const")]
116 unsafe fn begin(&self) -> *mut CppUnorderedSetIter<T>;
117 #[cpp(method = "const_iterator end() const")]
118 unsafe fn end(&self) -> *mut CppUnorderedSetIter<T>;
119
120 }
121
122 unsafe impl<T: AbiType + Sync> Send for unordered_set<T> {}
123 unsafe impl<T: AbiType + Sync> Sync for unordered_set<T> {}
124
125 #[cpp(class = "template <class T, class Hash, class Pred, class Allocator> std::unordered_set<T, Hash, Pred, Allocator>::const_iterator")]
126 class CppUnorderedSetIter<T> {
127 hicc::cpp! {
128 static const T& next(Self& self) {
129 return *self++;
130 }
131 }
132 #[cpp(func = "const T& next(Self&)")]
133 unsafe fn next(&mut self) -> &T;
134 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
135 fn equal(&self, other: &Self) -> bool;
136 }
137}
138
139impl<T: AbiType> unordered_set<T> {
140 pub fn iter(&self) -> impl Iterator<Item = T::OutputRef<'_>> {
148 UnorderedSetIter {
149 beg: unsafe { self.begin() },
150 end: unsafe { self.end() },
151 }
152 }
153}
154
155struct UnorderedSetIter<'a, T: AbiType + 'static> {
157 beg: ClassMutPtr<'a, CppUnorderedSetIter<T>>,
158 end: ClassMutPtr<'a, CppUnorderedSetIter<T>>,
159}
160
161impl<'a, T: AbiType + 'static> Iterator for UnorderedSetIter<'a, T> {
162 type Item = T::OutputRef<'a>;
163 fn next(&mut self) -> Option<Self::Item> {
164 if !self.beg.equal(&self.end) {
165 return unsafe { Some(self.beg.as_deref_mut().next()) };
166 }
167 None
168 }
169}
170
171hicc::import_class! {
172 #[cpp(class = "template <class T, class Hash, class Pred, class Allocator> std::unordered_multiset<T, Hash, Pred, Allocator>")]
173 pub class unordered_multiset<T> {
174 hicc::cpp! {
175 typedef typename Self::iterator iterator;
176 typedef typename Self::const_iterator const_iterator;
177 }
178 #[cpp(method = "bool empty() const")]
184 pub fn is_empty(&self) -> bool;
185
186 #[cpp(method = "size_t size() const")]
192 pub fn size(&self) -> usize;
193
194 #[cpp(method = "size_t max_size() const")]
200 pub fn max_size(&self) -> usize;
201
202 #[cpp(method = "void clear()")]
210 pub fn clear(&mut self);
211
212 #[cpp(method = "void swap(Self&)")]
220 pub fn swap(&mut self, other: &mut Self);
221
222 #[cpp(method = "size_t count(const T&) const")]
229 pub fn count(&self, val: &T) -> usize;
230
231 hicc::cpp! {
232 static bool contains(const Self& self, const T& val) {
233 return self.find(val) != self.end();
234 }
235 }
236 #[cpp(func = "bool SelfMethods::contains(const Self&, const T&)")]
243 pub fn contains(&self, val: &T) -> bool;
244
245 #[cpp(func = "void hicc::make_assign<Self, Self>(Self&, const Self&)")]
253 pub fn assign(&mut self, other: &Self);
254
255 #[cpp(method = "iterator insert(const T&)")]
263 pub fn insert(&mut self, val: &T);
264
265 #[cpp(method = "size_t erase(const T&)")]
273 pub fn erase(&mut self, val: &T) -> usize;
274
275 #[cpp(method = "const_iterator begin() const")]
276 unsafe fn begin(&self) -> *mut CppUnorderedMultiSetIter<T>;
277 #[cpp(method = "const_iterator end() const")]
278 unsafe fn end(&self) -> *mut CppUnorderedMultiSetIter<T>;
279
280 }
281
282 unsafe impl<T: AbiType + Sync> Send for unordered_multiset<T> {}
283 unsafe impl<T: AbiType + Sync> Sync for unordered_multiset<T> {}
284
285 #[cpp(class = "template <class T, class Hash, class Pred, class Allocator> std::unordered_multiset<T, Hash, Pred, Allocator>::const_iterator")]
286 class CppUnorderedMultiSetIter<T> {
287 hicc::cpp! {
288 static const T& next(Self& self) {
289 return *self++;
290 }
291 }
292 #[cpp(func = "const T& SelfMethods::next(Self&)")]
293 fn next(&mut self) -> &T;
294 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
295 fn equal(&self, other: &Self) -> bool;
296 }
297}
298
299impl<T: AbiType> unordered_multiset<T> {
300 pub fn iter(&self) -> impl Iterator<Item = T::OutputRef<'_>> {
309 UnorderedMultiSetIter {
310 beg: unsafe { self.begin() },
311 end: unsafe { self.end() },
312 }
313 }
314}
315
316struct UnorderedMultiSetIter<'a, T: AbiType + 'static> {
318 beg: ClassMutPtr<'a, CppUnorderedMultiSetIter<T>>,
319 end: ClassMutPtr<'a, CppUnorderedMultiSetIter<T>>,
320}
321
322impl<'a, T: AbiType + 'static> Iterator for UnorderedMultiSetIter<'a, T> {
323 type Item = T::OutputRef<'a>;
324 fn next(&mut self) -> Option<Self::Item> {
325 if self.beg.equal(&self.end) {
326 return unsafe { Some(self.beg.as_deref_mut().next()) };
327 }
328 None
329 }
330}