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>")]
598 pub class multimap<K, V> {
599 hicc::cpp! {
600 typedef typename Self::iterator iterator;
601 typedef typename Self::const_iterator const_iterator;
602 typedef typename Self::reverse_iterator reverse_iterator;
603 typedef typename Self::const_reverse_iterator const_reverse_iterator;
604 }
605 #[cpp(method = "bool empty() const")]
611 pub fn is_empty(&self) -> bool;
612
613 #[cpp(method = "size_t size() const")]
619 pub fn size(&self) -> usize;
620
621 #[cpp(method = "size_t max_size() const")]
627 pub fn max_size(&self) -> usize;
628
629 #[cpp(method = "void clear()")]
638 pub fn clear(&mut self);
639
640 #[cpp(method = "void swap(Self&)")]
650 pub fn swap(&mut self, other: &mut Self);
651
652 #[cpp(method = "size_t count(const K&) const")]
661 pub fn count(&self, key: &K) -> usize;
662
663 hicc::cpp! {
664 static bool contains(const Self& self, const K& key) {
665 return self.find(key) != self.end();
666 }
667 }
668 #[cpp(func = "bool SelfMethods::contains(const Self&, const K&)")]
676 pub fn contains(&self, key: &K) -> bool;
677
678 #[cpp(func = "void hicc::make_assign<Self, Self>(Self&, const Self&)")]
686 pub fn assign(&mut self, other: &Self);
687
688 hicc::cpp! {
689 static void insert(Self& self, const K& key, const V& val) {
690 self.insert(std::make_pair(key, val));
691 }
692 }
693 #[cpp(func = "void SelfMethods::insert(Self&, const K&, const V&)")]
701 pub fn insert(&mut self, key: &K, val: &V);
702
703 #[cpp(method = "size_t erase(const K&)")]
711 pub fn erase(&mut self, key: &K) -> usize;
712
713 #[cpp(method = "const_iterator find(const K&) const")]
714 unsafe fn find(&self, key: &K) -> *mut CppMultiMapIter<K, V>;
715 #[cpp(method = "iterator find(const K&)")]
716 unsafe fn find_mut(&mut self, key: &K) -> *mut CppMultiMapIterMut<K, V>;
717 #[cpp(method = "const_iterator lower_bound(const K&) const")]
718 unsafe fn lower_bound(&self, key: &K) -> *mut CppMultiMapIter<K, V>;
719 #[cpp(method = "iterator lower_bound(const K&)")]
720 unsafe fn lower_bound_mut(&mut self, key: &K) -> *mut CppMultiMapIterMut<K, V>;
721 #[cpp(method = "const_iterator upper_bound(const K&) const")]
722 unsafe fn upper_bound(&self, key: &K) -> *mut CppMultiMapIter<K, V>;
723 #[cpp(method = "iterator upper_bound(const K&)")]
724 unsafe fn upper_bound_mut(&mut self, key: &K) -> *mut CppMultiMapIterMut<K, V>;
725 #[cpp(method = "const_iterator begin() const")]
726 unsafe fn begin(&self) -> *mut CppMultiMapIter<K, V>;
727 #[cpp(method = "iterator begin() ")]
728 unsafe fn begin_mut(&mut self) -> *mut CppMultiMapIterMut<K, V>;
729 #[cpp(method = "const_iterator end() const")]
730 unsafe fn end(&self) -> *mut CppMultiMapIter<K, V>;
731 #[cpp(method = "iterator end() ")]
732 unsafe fn end_mut(&mut self) -> *mut CppMultiMapIterMut<K, V>;
733 #[cpp(method = "const_reverse_iterator rbegin() const")]
734 unsafe fn rbegin(&self) -> *mut CppMultiMapRevIter<K, V>;
735 #[cpp(method = "reverse_iterator rbegin()")]
736 unsafe fn rbegin_mut(&mut self) -> *mut CppMultiMapRevIterMut<K, V>;
737 #[cpp(method = "const_reverse_iterator rend() const")]
738 unsafe fn rend(&self) -> *mut CppMultiMapRevIter<K, V>;
739 #[cpp(method = "reverse_iterator rend()")]
740 unsafe fn rend_mut(&mut self) -> *mut CppMultiMapRevIterMut<K, V>;
741 }
742
743 unsafe impl<K: AbiType + Sync, V: AbiType + Sync> Send for multimap<K, V> {}
744 unsafe impl<K: AbiType + Sync, V: AbiType + Sync> Sync for multimap<K, V> {}
745
746 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::multimap<K, V, Compare, Allocator>::const_iterator")]
747 class CppMultiMapIter<K, V> {
748 hicc::cpp! {
749 typedef typename SelfContainer::const_reverse_iterator const_reverse_iterator;
750 static void next(Self& self) {
751 ++self;
752 }
753 static const K& key(const Self& self) {
754 return self->first;
755 }
756 static const V& value(const Self& self) {
757 return self->second;
758 }
759 }
760 #[cpp(func = "void SelfMethods::next(Self&)")]
761 fn next(&mut self);
762 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
763 fn as_key(&self) -> &K;
764 #[cpp(func = "const V& SelfMethods::value(const Self&)")]
765 fn as_value(&self) -> &V;
766 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
767 fn equal(&self, other: &Self) -> bool;
768 #[cpp(func = "const_reverse_iterator hicc::make_constructor<const_reverse_iterator, Self>(Self&&)")]
769 fn into_reverse(self) -> *mut CppMultiMapRevIter<K, V>;
770 }
771
772 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::multimap<K, V, Compare, Allocator>::iterator")]
773 class CppMultiMapIterMut<K, V> {
774 hicc::cpp! {
775 typedef typename SelfContainer::reverse_iterator reverse_iterator;
776 static void next(Self& self) {
777 ++self;
778 }
779 static const K& key(const Self& self) {
780 return self->first;
781 }
782 static V& value(Self& self) {
783 return self->second;
784 }
785 }
786 #[cpp(func = "void SelfMethods::next(Self&)")]
787 fn next(&mut self);
788 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
789 fn as_key(&self) -> &K;
790 #[cpp(func = "V& SelfMethods::value(Self&)")]
791 fn as_value(&mut self) -> &mut V;
792 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
793 fn equal(&self, other: &Self) -> bool;
794 #[cpp(func = "reverse_iterator hicc::make_constructor<reverse_iterator, Self>(Self&&)")]
795 fn into_reverse(self) -> *mut CppMultiMapRevIterMut<K, V>;
796 }
797
798 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::multimap<K, V, Compare, Allocator>::const_reverse_iterator")]
799 class CppMultiMapRevIter<K, V> {
800 hicc::cpp! {
801 static void next(Self& self) {
802 ++self;
803 }
804 static const K& key(const Self& self) {
805 return self->first;
806 }
807 static const V& value(const Self& self) {
808 return self->second;
809 }
810 }
811 #[cpp(func = "void SelfMethods::next(Self&)")]
812 fn next(&mut self);
813 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
814 fn as_key(&self) -> &K;
815 #[cpp(func = "const V& SelfMethods::value(const Self&)")]
816 fn as_value(&self) -> &V;
817 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
818 fn equal(&self, other: &Self) -> bool;
819 }
820
821 #[cpp(class = "template<class K, class V, class Compare, class Allocator> std::multimap<K, V, Compare, Allocator>::reverse_iterator")]
822 class CppMultiMapRevIterMut<K, V> {
823 hicc::cpp! {
824 static void next(Self& self) {
825 ++self;
826 }
827 static const K& key(const Self& self) {
828 return self->first;
829 }
830 static V& value(Self& self) {
831 return self->second;
832 }
833 }
834 #[cpp(func = "void SelfMethods::next(Self&)")]
835 fn next(&mut self);
836 #[cpp(func = "const K& SelfMethods::key(const Self&)")]
837 fn as_key(&self) -> &K;
838 #[cpp(func = "V& SelfMethods::value(Self&)")]
839 fn as_value(&mut self) -> &mut V;
840 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
841 fn equal(&self, other: &Self) -> bool;
842 }
843}
844
845impl<K: AbiType + 'static, V: AbiType + 'static> multimap<K, V> {
846 pub fn iter(&self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
854 MultiMapIter {
855 beg: unsafe { self.begin() },
856 end: unsafe { self.end() },
857 mark: PhantomData,
858 }
859 }
860
861 pub fn iter_mut(&mut self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
873 let beg = unsafe { self.begin_mut() };
874 let end = unsafe { self.end_mut() };
875 MultiMapIterMut {
876 beg,
877 end,
878 mark: PhantomData,
879 }
880 }
881
882 pub fn rev_iter(&self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
890 MultiMapRevIter {
891 beg: unsafe { self.rbegin() },
892 end: unsafe { self.rend() },
893 mark: PhantomData,
894 }
895 }
896
897 pub fn rev_iter_mut(
909 &mut self,
910 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
911 let beg = unsafe { self.rbegin_mut() };
912 let end = unsafe { self.rend_mut() };
913 MultiMapRevIterMut {
914 beg,
915 end,
916 mark: PhantomData,
917 }
918 }
919
920 pub fn iter_lower_upper_bound(
932 &self,
933 lower_key: Option<&K::InputType>,
934 upper_key: Option<&K::InputType>,
935 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
936 let beg = if let Some(key) = lower_key {
937 unsafe { self.lower_bound(key) }
938 } else {
939 unsafe { self.begin() }
940 };
941 let end = if let Some(key) = upper_key {
942 unsafe { self.upper_bound(key) }
943 } else {
944 unsafe { self.end() }
945 };
946 MultiMapIter {
947 beg,
948 end,
949 mark: PhantomData,
950 }
951 }
952
953 pub fn iter_lower_upper_bound_mut(
966 &mut self,
967 lower_key: Option<&K::InputType>,
968 upper_key: Option<&K::InputType>,
969 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
970 let beg = if let Some(key) = lower_key {
971 unsafe { self.lower_bound_mut(key) }
972 } else {
973 unsafe { self.begin_mut() }
974 };
975 let end = if let Some(key) = upper_key {
976 unsafe { self.upper_bound_mut(key) }
977 } else {
978 unsafe { self.end_mut() }
979 };
980 MultiMapIterMut {
981 beg,
982 end,
983 mark: PhantomData,
984 }
985 }
986
987 pub fn rev_iter_lower_upper_bound(
999 &self,
1000 lower_key: Option<&K::InputType>,
1001 upper_key: Option<&K::InputType>,
1002 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
1003 let beg = if let Some(key) = upper_key {
1004 unsafe { self.upper_bound(key).into_value() }.into_reverse()
1005 } else {
1006 unsafe { self.rbegin() }
1007 };
1008 let end = if let Some(key) = lower_key {
1009 unsafe { self.lower_bound(key).into_value() }.into_reverse()
1010 } else {
1011 unsafe { self.rend() }
1012 };
1013 MultiMapRevIter {
1014 beg,
1015 end,
1016 mark: PhantomData,
1017 }
1018 }
1019
1020 pub fn rev_iter_lower_upper_bound_mut(
1033 &mut self,
1034 lower_key: Option<&K::InputType>,
1035 upper_key: Option<&K::InputType>,
1036 ) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
1037 let beg = if let Some(key) = upper_key {
1038 unsafe { self.upper_bound_mut(key).into_value() }.into_reverse()
1039 } else {
1040 unsafe { self.rbegin_mut() }
1041 };
1042 let end = if let Some(key) = lower_key {
1043 unsafe { self.lower_bound_mut(key).into_value() }.into_reverse()
1044 } else {
1045 unsafe { self.rend_mut() }
1046 };
1047 MultiMapRevIterMut {
1048 beg,
1049 end,
1050 mark: PhantomData,
1051 }
1052 }
1053}
1054
1055struct MultiMapIter<'a, K: AbiType + 'static, V: AbiType + 'static> {
1057 beg: ClassMutPtr<'static, CppMultiMapIter<K, V>>,
1058 end: ClassMutPtr<'static, CppMultiMapIter<K, V>>,
1059 mark: PhantomData<&'a multimap<K, V>>,
1060}
1061
1062impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MultiMapIter<'a, K, V> {
1063 type Item = (K::OutputRef<'a>, V::OutputRef<'a>);
1064 fn next(&mut self) -> Option<Self::Item> {
1065 if !self.beg.equal(&self.end) {
1066 unsafe {
1067 let key = self.beg.as_deref().as_key();
1068 let val = self.beg.as_deref().as_value();
1069 self.beg.next();
1070 return Some((key, val));
1071 }
1072 }
1073 None
1074 }
1075}
1076
1077struct MultiMapRevIter<'a, K: AbiType + 'static, V: AbiType + 'static> {
1079 beg: ClassMutPtr<'static, CppMultiMapRevIter<K, V>>,
1080 end: ClassMutPtr<'static, CppMultiMapRevIter<K, V>>,
1081 mark: PhantomData<&'a multimap<K, V>>,
1082}
1083
1084impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MultiMapRevIter<'a, K, V> {
1085 type Item = (K::OutputRef<'a>, V::OutputRef<'a>);
1086 fn next(&mut self) -> Option<Self::Item> {
1087 if !self.beg.equal(&self.end) {
1088 unsafe {
1089 let key = self.beg.as_deref().as_key();
1090 let val = self.beg.as_deref().as_value();
1091 self.beg.next();
1092 return Some((key, val));
1093 }
1094 }
1095 None
1096 }
1097}
1098
1099struct MultiMapIterMut<'a, K: AbiType + 'static, V: AbiType + 'static> {
1101 beg: ClassMutPtr<'static, CppMultiMapIterMut<K, V>>,
1102 end: ClassMutPtr<'static, CppMultiMapIterMut<K, V>>,
1103 mark: PhantomData<&'a mut multimap<K, V>>,
1104}
1105
1106impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MultiMapIterMut<'a, K, V> {
1107 type Item = (K::OutputRef<'a>, V::OutputRefMut<'a>);
1108 fn next(&mut self) -> Option<Self::Item> {
1109 if !self.beg.equal(&self.end) {
1110 unsafe {
1111 let key = self.beg.as_deref().as_key();
1112 let val = self.beg.as_deref_mut().as_value();
1113 self.beg.next();
1114 return Some((key, val));
1115 }
1116 }
1117 None
1118 }
1119}
1120
1121struct MultiMapRevIterMut<'a, K: AbiType + 'static, V: AbiType + 'static> {
1123 beg: ClassMutPtr<'static, CppMultiMapRevIterMut<K, V>>,
1124 end: ClassMutPtr<'static, CppMultiMapRevIterMut<K, V>>,
1125 mark: PhantomData<&'a mut multimap<K, V>>,
1126}
1127
1128impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for MultiMapRevIterMut<'a, K, V> {
1129 type Item = (K::OutputRef<'a>, V::OutputRefMut<'a>);
1130 fn next(&mut self) -> Option<Self::Item> {
1131 if !self.beg.equal(&self.end) {
1132 unsafe {
1133 let key = self.beg.as_deref().as_key();
1134 let val = self.beg.as_deref_mut().as_value();
1135 self.beg.next();
1136 return Some((key, val));
1137 }
1138 }
1139 None
1140 }
1141}