1use hicc::{AbiType, ClassMutPtr};
2use std::iter::Iterator;
3use std::marker::PhantomData;
4
5hicc::cpp! {
6 #include <map>
7}
8
9hicc::import_class! {
10 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::map<K, V, Compare, Allocator>")]
11 pub class map<K, V> {
12 hicc::cpp! {
13 typedef typename Self::iterator iterator;
14 typedef typename Self::reverse_iterator reverse_iterator;
15 typedef typename Self::const_iterator const_iterator;
16 typedef typename Self::const_reverse_iterator const_reverse_iterator;
17 }
18 #[cpp(method = "bool empty() const")]
24 pub fn is_empty(&self) -> bool;
25
26 #[cpp(method = "size_t size() const")]
32 pub fn size(&self) -> usize;
33
34 #[cpp(method = "size_t max_size() const")]
40 pub fn max_size(&self) -> usize;
41
42 #[cpp(method = "void clear()")]
51 pub fn clear(&mut self);
52
53 #[cpp(method = "void swap(Self&)")]
63 pub fn swap(&mut self, other: &mut Self);
64
65 #[cpp(method = "size_t count(const K&) const")]
73 pub fn count(&self, key: &K) -> usize;
74
75 hicc::cpp! {
76 static bool contains(const Self& self, const K& key) {
77 return self.find(key) != self.end();
78 }
79 }
80 #[cpp(func = "bool SelfMethods::contains(const Self&, const K&)")]
88 pub fn contains(&self, key: &K) -> bool;
89
90 #[cpp(func = "void hicc::make_assign<Self, Self>(Self&, const Self&)")]
98 pub fn assign(&mut self, other: &Self);
99
100 hicc::cpp! {
101 static bool insert(Self& self, const K& key, const V& val) {
102 return self.insert(std::make_pair(key, val)).second;
103 }
104 }
105 #[cpp(func = "bool SelfMethods::insert(Self&, const K&, const V&)")]
113 pub fn insert(&mut self, key: &K, val: &V) -> bool;
114
115 #[cpp(method = "size_t erase(const K&)")]
123 pub fn erase(&mut self, key: &K) -> usize;
124
125 #[cpp(method = "const_iterator find(const K&) const")]
126 unsafe fn find(&self, key: &K) -> *mut CppMapIter<K, V>;
127 #[cpp(method = "iterator find(const K&)")]
128 unsafe fn find_mut(&mut self, key: &K) -> *mut CppMapIterMut<K, V>;
129 #[cpp(method = "const_iterator lower_bound(const K&) const")]
130 unsafe fn lower_bound(&self, key: &K) -> *mut CppMapIter<K, V>;
131 #[cpp(method = "iterator lower_bound(const K&)")]
132 unsafe fn lower_bound_mut(&mut self, key: &K) -> *mut CppMapIterMut<K, V>;
133 #[cpp(method = "const_iterator upper_bound(const K&) const")]
134 unsafe fn upper_bound(&self, key: &K) -> *mut CppMapIter<K, V>;
135 #[cpp(method = "iterator upper_bound(const K&)")]
136 unsafe fn upper_bound_mut(&mut self, key: &K) -> *mut CppMapIterMut<K, V>;
137
138 #[cpp(method = "const_iterator begin() const")]
139 unsafe fn begin(&self) -> *mut CppMapIter<K, V>;
140 #[cpp(method = "iterator begin()")]
141 unsafe fn begin_mut(&mut self) -> *mut CppMapIterMut<K, V>;
142 #[cpp(method = "const_iterator end() const")]
143 unsafe fn end(&self) -> *mut CppMapIter<K, V>;
144 #[cpp(method = "iterator end()")]
145 unsafe fn end_mut(&mut self) -> *mut CppMapIterMut<K, V>;
146 #[cpp(method = "const_reverse_iterator rbegin() const")]
147 unsafe fn rbegin(&self) -> *mut CppMapRevIter<K, V>;
148 #[cpp(method = "reverse_iterator rbegin()")]
149 unsafe fn rbegin_mut(&mut self) -> *mut CppMapRevIterMut<K, V>;
150 #[cpp(method = "const_reverse_iterator rend() const")]
151 unsafe fn rend(&self) -> *mut CppMapRevIter<K, V>;
152 #[cpp(method = "reverse_iterator rend()")]
153 unsafe fn rend_mut(&mut self) -> *mut CppMapRevIterMut<K, V>;
154 }
155
156 unsafe impl<K: AbiType + Sync, V: AbiType + Sync> Send for map<K, V> {}
157 unsafe impl<K: AbiType + Sync, V: AbiType + Sync> Sync for map<K, V> {}
158
159 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::map<K, V, Compare, Allocator>::const_iterator")]
160 class CppMapIter<K, V> {
161 hicc::cpp! {
162 typedef typename SelfContainer::const_reverse_iterator const_reverse_iterator;
163 static void next(Self& self) {
164 ++self;
165 }
166 static const K& key(const Self& self) {
167 return self->first;
168 }
169 static const V& value(const Self& self) {
170 return self->second;
171 }
172 }
173 #[cpp(func = "void SelfMethods::next(Self&)")]
174 unsafe fn next(&mut self);
175 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
176 unsafe fn as_key(&self) -> &K;
177 #[cpp(func = "const V& SelfMethods::value(const Self&)")]
178 unsafe fn as_value(&self) -> &V;
179 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
180 fn equal(&self, other: &Self) -> bool;
181 #[cpp(func = "const_reverse_iterator hicc::make_constructor<const_reverse_iterator, Self>(Self&&)")]
182 fn into_reverse(self) -> *mut CppMapRevIter<K, V>;
183 }
184
185 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::map<K, V, Compare, Allocator>::iterator")]
186 class CppMapIterMut<K, V> {
187 hicc::cpp! {
188 typedef typename SelfContainer::reverse_iterator reverse_iterator;
189 static void next(Self& self) {
190 ++self;
191 }
192 static const K& key(const Self& self) {
193 return self->first;
194 }
195 static V& value(Self& self) {
196 return self->second;
197 }
198 }
199 #[cpp(func = "void SelfMethods::next(Self&)")]
200 unsafe fn next(&mut self);
201 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
202 unsafe fn as_key(&self) -> &K;
203 #[cpp(func = "V& SelfMethods::value(Self&)")]
204 unsafe fn as_value(&mut self) -> &mut V;
205 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
206 fn equal(&self, other: &Self) -> bool;
207 #[cpp(func = "reverse_iterator hicc::make_constructor<reverse_iterator, Self>(Self&&)")]
208 fn into_reverse(self) -> *mut CppMapRevIterMut<K, V>;
209 }
210
211 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::map<K, V, Compare, Allocator>::const_reverse_iterator")]
212 class CppMapRevIter<K, V> {
213 hicc::cpp! {
214 static void next(Self& self) {
215 ++self;
216 }
217 static const K& key(const Self& self) {
218 return self->first;
219 }
220 static const V& value(const Self& self) {
221 return self->second;
222 }
223 }
224 #[cpp(func = "void SelfMethods::next(Self&)")]
225 unsafe fn next(&mut self);
226 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
227 unsafe fn as_key(&self) -> &K;
228 #[cpp(func = "const V& SelfMethods::value(const Self&)")]
229 unsafe fn as_value(&self) -> &V;
230 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
231 fn equal(&self, other: &Self) -> bool;
232 }
233
234 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::map<K, V, Compare, Allocator>::reverse_iterator")]
235 class CppMapRevIterMut<K, V> {
236 hicc::cpp! {
237 static void next(Self& self) {
238 ++self;
239 }
240 static const K& key(const Self& self) {
241 return self->first;
242 }
243 static V& value(Self& self) {
244 return self->second;
245 }
246 }
247 #[cpp(func = "void SelfMethods::next(Self&)")]
248 unsafe fn next(&mut self);
249 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
250 unsafe fn as_key(&self) -> &K;
251 #[cpp(func = "V& SelfMethods::value(Self&)")]
252 unsafe fn as_value(&mut self) -> &mut V;
253 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
254 fn equal(&self, other: &Self) -> bool;
255 }
256}
257
258impl<K: AbiType, V: AbiType> map<K, V> {
259 pub fn get(&self, key: &K::InputType) -> Option<V::OutputRef<'_>> {
267 unsafe {
268 let it = self.find(key);
269 if !it.equal(&self.end()) {
270 return Some(it.as_deref().as_value());
271 }
272 }
273 None
274 }
275 pub fn get_mut(&mut self, key: &K::InputType) -> Option<V::OutputRefMut<'_>> {
291 unsafe {
292 let end = self.end_mut().into_value();
293 let mut it = self.find_mut(key);
294 if !it.equal(&end) {
295 return Some(it.as_deref_mut().as_value());
296 }
297 }
298 None
299 }
300
301 pub fn iter(&self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
312 MapIter {
313 beg: unsafe { self.begin() },
314 end: unsafe { self.end() },
315 mark: PhantomData,
316 }
317 }
318
319 pub fn iter_mut(&mut self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
331 let beg = unsafe { self.begin_mut() };
332 let end = unsafe { self.end_mut() };
333 MapIterMut {
334 beg,
335 end,
336 mark: PhantomData,
337 }
338 }
339
340 pub fn rev_iter(&self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
351 MapRevIter {
352 beg: unsafe { self.rbegin() },
353 end: unsafe { self.rend() },
354 mark: PhantomData,
355 }
356 }
357
358 pub fn rev_iter_mut(
370 &mut self,
371 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
372 let beg = unsafe { self.rbegin_mut() };
373 let end = unsafe { self.rend_mut() };
374 MapRevIterMut {
375 beg,
376 end,
377 mark: PhantomData,
378 }
379 }
380
381 pub fn iter_lower_upper_bound(
393 &self,
394 lower_key: Option<&K::InputType>,
395 upper_key: Option<&K::InputType>,
396 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
397 let beg = if let Some(key) = lower_key {
398 unsafe { self.lower_bound(key) }
399 } else {
400 unsafe { self.begin() }
401 };
402 let end = if let Some(key) = upper_key {
403 unsafe { self.upper_bound(key) }
404 } else {
405 unsafe { self.end() }
406 };
407 MapIter {
408 beg,
409 end,
410 mark: PhantomData,
411 }
412 }
413
414 pub fn iter_lower_upper_bound_mut(
427 &mut self,
428 lower_key: Option<&K::InputType>,
429 upper_key: Option<&K::InputType>,
430 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
431 let beg = if let Some(key) = lower_key {
432 unsafe { self.lower_bound_mut(key) }
433 } else {
434 unsafe { self.begin_mut() }
435 };
436 let end = if let Some(key) = upper_key {
437 unsafe { self.upper_bound_mut(key) }
438 } else {
439 unsafe { self.end_mut() }
440 };
441 MapIterMut {
442 beg,
443 end,
444 mark: PhantomData,
445 }
446 }
447
448 pub fn rev_iter_lower_upper_bound(
460 &self,
461 lower_key: Option<&K::InputType>,
462 upper_key: Option<&K::InputType>,
463 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
464 let beg = if let Some(key) = upper_key {
465 unsafe { self.upper_bound(key).into_value().into_reverse() }
466 } else {
467 unsafe { self.rbegin() }
468 };
469 let end = if let Some(key) = lower_key {
470 unsafe { self.lower_bound(key).into_value().into_reverse() }
471 } else {
472 unsafe { self.rend() }
473 };
474 MapRevIter {
475 beg,
476 end,
477 mark: PhantomData,
478 }
479 }
480
481 pub fn rev_iter_lower_upper_bound_mut(
494 &mut self,
495 lower_key: Option<&K::InputType>,
496 upper_key: Option<&K::InputType>,
497 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
498 let beg = if let Some(key) = upper_key {
499 unsafe { self.upper_bound_mut(key).into_value() }.into_reverse()
500 } else {
501 unsafe { self.rbegin_mut() }
502 };
503 let end = if let Some(key) = lower_key {
504 unsafe { self.lower_bound_mut(key).into_value() }.into_reverse()
505 } else {
506 unsafe { self.rend_mut() }
507 };
508 MapRevIterMut {
509 beg,
510 end,
511 mark: PhantomData,
512 }
513 }
514}
515
516struct MapIter<'a, K: AbiType + 'static, V: AbiType + 'static> {
518 beg: ClassMutPtr<'static, CppMapIter<K, V>>,
519 end: ClassMutPtr<'static, CppMapIter<K, V>>,
520 mark: PhantomData<&'a map<K, V>>,
521}
522
523impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MapIter<'a, K, V> {
524 type Item = (K::OutputRef<'a>, V::OutputRef<'a>);
525 fn next(&mut self) -> Option<Self::Item> {
526 if self.beg.equal(&self.end) {
527 return None;
528 }
529 let key = unsafe { self.beg.as_deref().as_key() };
530 let val = unsafe { self.beg.as_deref().as_value() };
531 unsafe { self.beg.next() };
532 Some((key, val))
533 }
534}
535
536struct MapIterMut<'a, K: AbiType + 'static, V: AbiType + 'static> {
538 beg: ClassMutPtr<'static, CppMapIterMut<K, V>>,
539 end: ClassMutPtr<'static, CppMapIterMut<K, V>>,
540 mark: PhantomData<&'a mut map<K, V>>,
541}
542
543impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MapIterMut<'a, K, V> {
544 type Item = (K::OutputRef<'a>, V::OutputRefMut<'a>);
545 fn next(&mut self) -> Option<Self::Item> {
546 if self.beg.equal(&self.end) {
547 return None;
548 }
549 let key = unsafe { self.beg.as_deref().as_key() };
550 let val = unsafe { self.beg.as_deref_mut().as_value() };
551 unsafe { self.beg.next() };
552 Some((key, val))
553 }
554}
555
556struct MapRevIter<'a, K: AbiType + 'static, V: AbiType + 'static> {
558 beg: ClassMutPtr<'static, CppMapRevIter<K, V>>,
559 end: ClassMutPtr<'static, CppMapRevIter<K, V>>,
560 mark: PhantomData<&'a map<K, V>>,
561}
562
563impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MapRevIter<'a, K, V> {
564 type Item = (K::OutputRef<'a>, V::OutputRef<'a>);
565 fn next(&mut self) -> Option<Self::Item> {
566 if self.beg.equal(&self.end) {
567 return None;
568 }
569 let key = unsafe { self.beg.as_deref().as_key() };
570 let val = unsafe { self.beg.as_deref().as_value() };
571 unsafe { self.beg.next() };
572 Some((key, val))
573 }
574}
575
576struct MapRevIterMut<'a, K: AbiType + 'static, V: AbiType + 'static> {
578 beg: ClassMutPtr<'static, CppMapRevIterMut<K, V>>,
579 end: ClassMutPtr<'static, CppMapRevIterMut<K, V>>,
580 mark: PhantomData<&'a mut map<K, V>>,
581}
582
583impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MapRevIterMut<'a, K, V> {
584 type Item = (K::OutputRef<'a>, V::OutputRefMut<'a>);
585 fn next(&mut self) -> Option<Self::Item> {
586 if self.beg.equal(&self.end) {
587 return None;
588 }
589 let key = unsafe { self.beg.as_deref().as_key() };
590 let val = unsafe { self.beg.as_deref_mut().as_value() };
591 unsafe { self.beg.next() };
592 Some((key, val))
593 }
594}
595
596hicc::import_class! {
597 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::multimap<K, V, Compare, Allocator>")]
601 pub class multimap<K, V> {
602 hicc::cpp! {
603 typedef typename Self::iterator iterator;
604 typedef typename Self::const_iterator const_iterator;
605 typedef typename Self::reverse_iterator reverse_iterator;
606 typedef typename Self::const_reverse_iterator const_reverse_iterator;
607 }
608 #[cpp(method = "bool empty() const")]
614 pub fn is_empty(&self) -> bool;
615
616 #[cpp(method = "size_t size() const")]
622 pub fn size(&self) -> usize;
623
624 #[cpp(method = "size_t max_size() const")]
630 pub fn max_size(&self) -> usize;
631
632 #[cpp(method = "void clear()")]
641 pub fn clear(&mut self);
642
643 #[cpp(method = "void swap(Self&)")]
653 pub fn swap(&mut self, other: &mut Self);
654
655 #[cpp(method = "size_t count(const K&) const")]
664 pub fn count(&self, key: &K) -> usize;
665
666 hicc::cpp! {
667 static bool contains(const Self& self, const K& key) {
668 return self.find(key) != self.end();
669 }
670 }
671 #[cpp(func = "bool SelfMethods::contains(const Self&, const K&)")]
679 pub fn contains(&self, key: &K) -> bool;
680
681 #[cpp(func = "void hicc::make_assign<Self, Self>(Self&, const Self&)")]
689 pub fn assign(&mut self, other: &Self);
690
691 hicc::cpp! {
692 static void insert(Self& self, const K& key, const V& val) {
693 self.insert(std::make_pair(key, val));
694 }
695 }
696 #[cpp(func = "void SelfMethods::insert(Self&, const K&, const V&)")]
704 pub fn insert(&mut self, key: &K, val: &V);
705
706 #[cpp(method = "size_t erase(const K&)")]
714 pub fn erase(&mut self, key: &K) -> usize;
715
716 #[cpp(method = "const_iterator find(const K&) const")]
717 unsafe fn find(&self, key: &K) -> *mut CppMultiMapIter<K, V>;
718 #[cpp(method = "iterator find(const K&)")]
719 unsafe fn find_mut(&mut self, key: &K) -> *mut CppMultiMapIterMut<K, V>;
720 #[cpp(method = "const_iterator lower_bound(const K&) const")]
721 unsafe fn lower_bound(&self, key: &K) -> *mut CppMultiMapIter<K, V>;
722 #[cpp(method = "iterator lower_bound(const K&)")]
723 unsafe fn lower_bound_mut(&mut self, key: &K) -> *mut CppMultiMapIterMut<K, V>;
724 #[cpp(method = "const_iterator upper_bound(const K&) const")]
725 unsafe fn upper_bound(&self, key: &K) -> *mut CppMultiMapIter<K, V>;
726 #[cpp(method = "iterator upper_bound(const K&)")]
727 unsafe fn upper_bound_mut(&mut self, key: &K) -> *mut CppMultiMapIterMut<K, V>;
728 #[cpp(method = "const_iterator begin() const")]
729 unsafe fn begin(&self) -> *mut CppMultiMapIter<K, V>;
730 #[cpp(method = "iterator begin() ")]
731 unsafe fn begin_mut(&mut self) -> *mut CppMultiMapIterMut<K, V>;
732 #[cpp(method = "const_iterator end() const")]
733 unsafe fn end(&self) -> *mut CppMultiMapIter<K, V>;
734 #[cpp(method = "iterator end() ")]
735 unsafe fn end_mut(&mut self) -> *mut CppMultiMapIterMut<K, V>;
736 #[cpp(method = "const_reverse_iterator rbegin() const")]
737 unsafe fn rbegin(&self) -> *mut CppMultiMapRevIter<K, V>;
738 #[cpp(method = "reverse_iterator rbegin()")]
739 unsafe fn rbegin_mut(&mut self) -> *mut CppMultiMapRevIterMut<K, V>;
740 #[cpp(method = "const_reverse_iterator rend() const")]
741 unsafe fn rend(&self) -> *mut CppMultiMapRevIter<K, V>;
742 #[cpp(method = "reverse_iterator rend()")]
743 unsafe fn rend_mut(&mut self) -> *mut CppMultiMapRevIterMut<K, V>;
744 }
745
746 unsafe impl<K: AbiType + Sync, V: AbiType + Sync> Send for multimap<K, V> {}
747 unsafe impl<K: AbiType + Sync, V: AbiType + Sync> Sync for multimap<K, V> {}
748
749 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::multimap<K, V, Compare, Allocator>::const_iterator")]
750 class CppMultiMapIter<K, V> {
751 hicc::cpp! {
752 typedef typename SelfContainer::const_reverse_iterator const_reverse_iterator;
753 static void next(Self& self) {
754 ++self;
755 }
756 static const K& key(const Self& self) {
757 return self->first;
758 }
759 static const V& value(const Self& self) {
760 return self->second;
761 }
762 }
763 #[cpp(func = "void SelfMethods::next(Self&)")]
764 fn next(&mut self);
765 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
766 fn as_key(&self) -> &K;
767 #[cpp(func = "const V& SelfMethods::value(const Self&)")]
768 fn as_value(&self) -> &V;
769 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
770 fn equal(&self, other: &Self) -> bool;
771 #[cpp(func = "const_reverse_iterator hicc::make_constructor<const_reverse_iterator, Self>(Self&&)")]
772 fn into_reverse(self) -> *mut CppMultiMapRevIter<K, V>;
773 }
774
775 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::multimap<K, V, Compare, Allocator>::iterator")]
776 class CppMultiMapIterMut<K, V> {
777 hicc::cpp! {
778 typedef typename SelfContainer::reverse_iterator reverse_iterator;
779 static void next(Self& self) {
780 ++self;
781 }
782 static const K& key(const Self& self) {
783 return self->first;
784 }
785 static V& value(Self& self) {
786 return self->second;
787 }
788 }
789 #[cpp(func = "void SelfMethods::next(Self&)")]
790 fn next(&mut self);
791 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
792 fn as_key(&self) -> &K;
793 #[cpp(func = "V& SelfMethods::value(Self&)")]
794 fn as_value(&mut self) -> &mut V;
795 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
796 fn equal(&self, other: &Self) -> bool;
797 #[cpp(func = "reverse_iterator hicc::make_constructor<reverse_iterator, Self>(Self&&)")]
798 fn into_reverse(self) -> *mut CppMultiMapRevIterMut<K, V>;
799 }
800
801 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::multimap<K, V, Compare, Allocator>::const_reverse_iterator")]
802 class CppMultiMapRevIter<K, V> {
803 hicc::cpp! {
804 static void next(Self& self) {
805 ++self;
806 }
807 static const K& key(const Self& self) {
808 return self->first;
809 }
810 static const V& value(const Self& self) {
811 return self->second;
812 }
813 }
814 #[cpp(func = "void SelfMethods::next(Self&)")]
815 fn next(&mut self);
816 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
817 fn as_key(&self) -> &K;
818 #[cpp(func = "const V& SelfMethods::value(const Self&)")]
819 fn as_value(&self) -> &V;
820 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
821 fn equal(&self, other: &Self) -> bool;
822 }
823
824 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::multimap<K, V, Compare, Allocator>::reverse_iterator")]
825 class CppMultiMapRevIterMut<K, V> {
826 hicc::cpp! {
827 static void next(Self& self) {
828 ++self;
829 }
830 static const K& key(const Self& self) {
831 return self->first;
832 }
833 static V& value(Self& self) {
834 return self->second;
835 }
836 }
837 #[cpp(func = "void SelfMethods::next(Self&)")]
838 fn next(&mut self);
839 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
840 fn as_key(&self) -> &K;
841 #[cpp(func = "V& SelfMethods::value(Self&)")]
842 fn as_value(&mut self) -> &mut V;
843 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
844 fn equal(&self, other: &Self) -> bool;
845 }
846}
847
848impl<K: AbiType + 'static, V: AbiType + 'static> multimap<K, V> {
849 pub fn iter(&self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
857 MultiMapIter {
858 beg: unsafe { self.begin() },
859 end: unsafe { self.end() },
860 mark: PhantomData,
861 }
862 }
863
864 pub fn iter_mut(&mut self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
876 let beg = unsafe { self.begin_mut() };
877 let end = unsafe { self.end_mut() };
878 MultiMapIterMut {
879 beg,
880 end,
881 mark: PhantomData,
882 }
883 }
884
885 pub fn rev_iter(&self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
893 MultiMapRevIter {
894 beg: unsafe { self.rbegin() },
895 end: unsafe { self.rend() },
896 mark: PhantomData,
897 }
898 }
899
900 pub fn rev_iter_mut(
912 &mut self,
913 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
914 let beg = unsafe { self.rbegin_mut() };
915 let end = unsafe { self.rend_mut() };
916 MultiMapRevIterMut {
917 beg,
918 end,
919 mark: PhantomData,
920 }
921 }
922
923 pub fn iter_lower_upper_bound(
935 &self,
936 lower_key: Option<&K::InputType>,
937 upper_key: Option<&K::InputType>,
938 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
939 let beg = if let Some(key) = lower_key {
940 unsafe { self.lower_bound(key) }
941 } else {
942 unsafe { self.begin() }
943 };
944 let end = if let Some(key) = upper_key {
945 unsafe { self.upper_bound(key) }
946 } else {
947 unsafe { self.end() }
948 };
949 MultiMapIter {
950 beg,
951 end,
952 mark: PhantomData,
953 }
954 }
955
956 pub fn iter_lower_upper_bound_mut(
969 &mut self,
970 lower_key: Option<&K::InputType>,
971 upper_key: Option<&K::InputType>,
972 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
973 let beg = if let Some(key) = lower_key {
974 unsafe { self.lower_bound_mut(key) }
975 } else {
976 unsafe { self.begin_mut() }
977 };
978 let end = if let Some(key) = upper_key {
979 unsafe { self.upper_bound_mut(key) }
980 } else {
981 unsafe { self.end_mut() }
982 };
983 MultiMapIterMut {
984 beg,
985 end,
986 mark: PhantomData,
987 }
988 }
989
990 pub fn rev_iter_lower_upper_bound(
1002 &self,
1003 lower_key: Option<&K::InputType>,
1004 upper_key: Option<&K::InputType>,
1005 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
1006 let beg = if let Some(key) = upper_key {
1007 unsafe { self.upper_bound(key).into_value() }.into_reverse()
1008 } else {
1009 unsafe { self.rbegin() }
1010 };
1011 let end = if let Some(key) = lower_key {
1012 unsafe { self.lower_bound(key).into_value() }.into_reverse()
1013 } else {
1014 unsafe { self.rend() }
1015 };
1016 MultiMapRevIter {
1017 beg,
1018 end,
1019 mark: PhantomData,
1020 }
1021 }
1022
1023 pub fn rev_iter_lower_upper_bound_mut(
1036 &mut self,
1037 lower_key: Option<&K::InputType>,
1038 upper_key: Option<&K::InputType>,
1039 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
1040 let beg = if let Some(key) = upper_key {
1041 unsafe { self.upper_bound_mut(key).into_value() }.into_reverse()
1042 } else {
1043 unsafe { self.rbegin_mut() }
1044 };
1045 let end = if let Some(key) = lower_key {
1046 unsafe { self.lower_bound_mut(key).into_value() }.into_reverse()
1047 } else {
1048 unsafe { self.rend_mut() }
1049 };
1050 MultiMapRevIterMut {
1051 beg,
1052 end,
1053 mark: PhantomData,
1054 }
1055 }
1056}
1057
1058struct MultiMapIter<'a, K: AbiType + 'static, V: AbiType + 'static> {
1060 beg: ClassMutPtr<'static, CppMultiMapIter<K, V>>,
1061 end: ClassMutPtr<'static, CppMultiMapIter<K, V>>,
1062 mark: PhantomData<&'a multimap<K, V>>,
1063}
1064
1065impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MultiMapIter<'a, K, V> {
1066 type Item = (K::OutputRef<'a>, V::OutputRef<'a>);
1067 fn next(&mut self) -> Option<Self::Item> {
1068 if !self.beg.equal(&self.end) {
1069 unsafe {
1070 let key = self.beg.as_deref().as_key();
1071 let val = self.beg.as_deref().as_value();
1072 self.beg.next();
1073 return Some((key, val));
1074 }
1075 }
1076 None
1077 }
1078}
1079
1080struct MultiMapRevIter<'a, K: AbiType + 'static, V: AbiType + 'static> {
1082 beg: ClassMutPtr<'static, CppMultiMapRevIter<K, V>>,
1083 end: ClassMutPtr<'static, CppMultiMapRevIter<K, V>>,
1084 mark: PhantomData<&'a multimap<K, V>>,
1085}
1086
1087impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MultiMapRevIter<'a, K, V> {
1088 type Item = (K::OutputRef<'a>, V::OutputRef<'a>);
1089 fn next(&mut self) -> Option<Self::Item> {
1090 if !self.beg.equal(&self.end) {
1091 unsafe {
1092 let key = self.beg.as_deref().as_key();
1093 let val = self.beg.as_deref().as_value();
1094 self.beg.next();
1095 return Some((key, val));
1096 }
1097 }
1098 None
1099 }
1100}
1101
1102struct MultiMapIterMut<'a, K: AbiType + 'static, V: AbiType + 'static> {
1104 beg: ClassMutPtr<'static, CppMultiMapIterMut<K, V>>,
1105 end: ClassMutPtr<'static, CppMultiMapIterMut<K, V>>,
1106 mark: PhantomData<&'a mut multimap<K, V>>,
1107}
1108
1109impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MultiMapIterMut<'a, K, V> {
1110 type Item = (K::OutputRef<'a>, V::OutputRefMut<'a>);
1111 fn next(&mut self) -> Option<Self::Item> {
1112 if !self.beg.equal(&self.end) {
1113 unsafe {
1114 let key = self.beg.as_deref().as_key();
1115 let val = self.beg.as_deref_mut().as_value();
1116 self.beg.next();
1117 return Some((key, val));
1118 }
1119 }
1120 None
1121 }
1122}
1123
1124struct MultiMapRevIterMut<'a, K: AbiType + 'static, V: AbiType + 'static> {
1126 beg: ClassMutPtr<'static, CppMultiMapRevIterMut<K, V>>,
1127 end: ClassMutPtr<'static, CppMultiMapRevIterMut<K, V>>,
1128 mark: PhantomData<&'a mut multimap<K, V>>,
1129}
1130
1131impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MultiMapRevIterMut<'a, K, V> {
1132 type Item = (K::OutputRef<'a>, V::OutputRefMut<'a>);
1133 fn next(&mut self) -> Option<Self::Item> {
1134 if !self.beg.equal(&self.end) {
1135 unsafe {
1136 let key = self.beg.as_deref().as_key();
1137 let val = self.beg.as_deref_mut().as_value();
1138 self.beg.next();
1139 return Some((key, val));
1140 }
1141 }
1142 None
1143 }
1144}