hicc_std/
std_unordered_map.rs

1use hicc::{AbiType, ClassMutPtr};
2use std::iter::Iterator;
3use std::marker::PhantomData;
4
5hicc::cpp! {
6    #include <unordered_map>
7}
8
9hicc::import_class! {
10    #[cpp(class = "template <class K, class V, class Hash, class Pred, class Allocator> std::unordered_map<K, V, Hash, Pred, Allocator>")]
11    pub class unordered_map<K, V> {
12        hicc::cpp! {
13            typedef typename Self::iterator iterator;
14            typedef typename Self::const_iterator const_iterator;
15        }
16        /// ```
17        /// use hicc_std::UnorderedMapIntInt;
18        /// let map = UnorderedMapIntInt::new();
19        /// assert!(map.is_empty());
20        /// ```
21        #[cpp(method = "bool empty() const")]
22        pub fn is_empty(&self) -> bool;
23
24        /// ```
25        /// use hicc_std::UnorderedMapIntInt;
26        /// let map = UnorderedMapIntInt::new();
27        /// assert_eq!(map.size(), 0_usize);
28        /// ```
29        #[cpp(method = "size_t size() const")]
30        pub fn size(&self) -> usize;
31
32        /// ```
33        /// use hicc_std::UnorderedMapIntInt;
34        /// let map = UnorderedMapIntInt::new();
35        /// println!("map.max_size() = {}", map.max_size());
36        /// ```
37        #[cpp(method = "size_t max_size() const")]
38        pub fn max_size(&self) -> usize;
39
40        /// ```
41        /// use hicc_std::UnorderedMapIntInt;
42        /// let mut map = UnorderedMapIntInt::new();
43        /// map.insert(&1, &2);
44        /// assert_eq!(map.size(), 1_usize);
45        /// map.clear();
46        /// assert_eq!(map.size(), 0_usize);
47        /// ```
48        #[cpp(method = "void clear()")]
49        pub fn clear(&mut self);
50
51        /// ```
52        /// use hicc_std::UnorderedMapIntInt;
53        /// let mut map1 = UnorderedMapIntInt::new();
54        /// map1.insert(&1, &2);
55        /// let mut map2 = UnorderedMapIntInt::new();
56        /// map2.swap(&mut map1);
57        /// assert_eq!(map1.size(), 0_usize);
58        /// assert_eq!(map2.size(), 1_usize);
59        /// ```
60        #[cpp(method = "void swap(Self&)")]
61        pub fn swap(&mut self, other: &mut Self);
62
63        /// ```
64        /// use hicc_std::UnorderedMapIntInt;
65        /// let mut map = UnorderedMapIntInt::new();
66        /// map.insert(&1, &2);
67        /// assert_eq!(map.count(&1), 1);
68        /// assert_eq!(map.count(&2), 0);
69        /// ```
70        #[cpp(method = "size_t count(const K&) const")]
71        pub fn count(&self, key: &K) -> usize;
72
73        hicc::cpp! {
74            static bool contains(const Self& self, const K& key) {
75                return self.find(key) != self.end();
76            }
77        }
78        /// ```
79        /// use hicc_std::UnorderedMapIntInt;
80        /// let mut map = UnorderedMapIntInt::new();
81        /// map.insert(&1, &2);
82        /// assert!(map.contains(&1));
83        /// assert!(!map.contains(&2));
84        /// ```
85        #[cpp(func = "bool SelfMethods::contains(const Self&, const K&)")]
86        pub fn contains(&self, key: &K) -> bool;
87
88        /// ```
89        /// use hicc_std::UnorderedMapIntInt;
90        /// let mut map = UnorderedMapIntInt::new();
91        /// map.insert(&1, &2);
92        /// map.assign(&mut UnorderedMapIntInt::new());
93        /// assert!(map.is_empty());
94        /// ```
95        #[cpp(func = "void hicc::make_assign<Self, Self>(Self&, const Self&)")]
96        pub fn assign(&mut self, other: &Self);
97
98        hicc::cpp! {
99            static bool insert(Self& self, const K& key, const V& val) {
100                return self.insert(std::make_pair(key, val)).second;
101            }
102        }
103        /// ```
104        /// use hicc_std::UnorderedMapIntInt;
105        /// let mut map = UnorderedMapIntInt::new();
106        /// assert!(map.insert(&1, &2));
107        /// assert!(!map.insert(&1, &2));
108        /// assert_eq!(map.get(&1), Some(&2));
109        /// ```
110        #[cpp(func = "bool SelfMethods::insert(Self&, const K&, const V&)")]
111        pub fn insert(&mut self, key: &K, val: &V) -> bool;
112
113        /// ```
114        /// use hicc_std::UnorderedMapIntInt;
115        /// let mut map = UnorderedMapIntInt::new();
116        /// assert_eq!(map.erase(&1), 0_usize);
117        /// assert!(map.insert(&1, &2));
118        /// assert_eq!(map.erase(&1), 1_usize);
119        /// ```
120        #[cpp(method = "size_t erase(const K&)")]
121        pub fn erase(&mut self, key: &K) -> usize;
122
123        #[cpp(method = "const_iterator find(const K&) const")]
124        unsafe fn find(&self, key: &K) -> *mut CppUnorderedMapIter<K, V>;
125        #[cpp(method = "iterator find(const K&)")]
126        unsafe fn find_mut(&mut self, key: &K) -> *mut CppUnorderedMapIterMut<K, V>;
127        #[cpp(method = "const_iterator begin() const")]
128        unsafe fn begin(&self) -> *mut CppUnorderedMapIter<K, V>;
129        #[cpp(method = "iterator begin()")]
130        unsafe fn begin_mut(&mut self) -> *mut CppUnorderedMapIterMut<K, V>;
131        #[cpp(method = "const_iterator end() const")]
132        unsafe fn end(&self) -> *mut CppUnorderedMapIter<K, V>;
133        #[cpp(method = "iterator end()")]
134        unsafe fn end_mut(&mut self) -> *mut CppUnorderedMapIterMut<K, V>;
135    }
136
137    unsafe impl<K: AbiType + Sync, V: AbiType + Sync> Send for unordered_map<K, V> {}
138    unsafe impl<K: AbiType + Sync, V: AbiType + Sync> Sync for unordered_map<K, V> {}
139
140    #[cpp(class = "template <class K, class V, class Hash, class Pred, class Allocator> std::unordered_map<K, V, Hash, Pred, Allocator>::const_iterator")]
141    class CppUnorderedMapIter<K, V> {
142        hicc::cpp! {
143            static void next(Self& self) {
144                ++self;
145            }
146            static const K& key(const Self& self) {
147                return self->first;
148            }
149            static const V& value(const Self& self) {
150                return self->second;
151            }
152        }
153        #[cpp(func = "void SelfMethods::next(Self&)")]
154        fn next(&mut self);
155        #[cpp(func = "const K& SelfMethods::key(const Self&)")]
156        fn as_key(&self) -> &K;
157        #[cpp(func = "const V& SelfMethods::value(const Self&)")]
158        fn as_value(&self) -> &V;
159        #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
160        fn equal(&self, other: &Self) -> bool;
161    }
162
163    #[cpp(class = "template <class K, class V, class Hash, class Pred, class Allocator> std::unordered_map<K, V, Hash, Pred, Allocator>::iterator")]
164    class CppUnorderedMapIterMut<K, V> {
165        hicc::cpp! {
166            static void next(Self& self) {
167                ++self;
168            }
169            static const K& key(const Self& self) {
170                return self->first;
171            }
172            static V& value(Self& self) {
173                return self->second;
174            }
175        }
176        #[cpp(func = "void SelfMethods::next(Self&)")]
177        fn next(&mut self);
178        #[cpp(func = "const K& SelfMethods::key(const Self&)")]
179        fn as_key(&self) -> &K;
180        #[cpp(func = "V& SelfMethods::value(Self&)")]
181        fn as_value(&mut self) -> &mut V;
182        #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
183        fn equal(&self, other: &Self) -> bool;
184    }
185}
186
187impl<K: AbiType + 'static, V: AbiType + 'static> unordered_map<K, V> {
188    /// ```
189    /// use hicc_std::UnorderedMapIntInt;
190    /// let mut map = UnorderedMapIntInt::new();
191    /// map.insert(&1, &2);
192    /// assert!(map.get(&2).is_none());
193    /// assert_eq!(map.get(&1), Some(&2));
194    /// ```
195    pub fn get(&self, key: &K::InputType) -> Option<V::OutputRef<'_>> {
196        unsafe {
197            let it = self.find(key);
198            if !it.equal(&self.end()) {
199                return Some(it.as_deref().as_value());
200            }
201        }
202        None
203    }
204    /// ```
205    /// use hicc_std::UnorderedMapIntInt;
206    /// let mut map = UnorderedMapIntInt::new();
207    /// map.insert(&1, &2);
208    /// *map.get_mut(&1).unwrap() = 0;
209    /// assert_eq!(map.get(&1), Some(&0));
210    ///
211    /// use hicc_std::{string, UnorderedMapIntString};
212    /// use hicc::AbiClass;
213    /// let mut map = UnorderedMapIntString::new();
214    /// map.insert(&1, &string::from(c"hello"));
215    /// map.get_mut(&1).unwrap().write(string::from(c"world"));
216    /// assert!(*map.get(&1).unwrap() == string::from(c"world"));
217    /// ```
218    pub fn get_mut(&mut self, key: &K::InputType) -> Option<V::OutputRefMut<'_>> {
219        unsafe {
220            let mut it = self.find_mut(key);
221            if !it.equal(&self.end_mut()) {
222                return Some(it.as_deref_mut().as_value());
223            }
224        }
225        None
226    }
227    /// ```
228    /// use hicc_std::UnorderedMapIntInt;
229    /// let mut map = UnorderedMapIntInt::new();
230    /// map.insert(&1, &2);
231    /// map.insert(&2, &1);
232    /// map.iter().for_each(|(k, v)| println!("key = {k}, value = {v}"));
233    /// ```
234    pub fn iter(&self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
235        UnorderedMapIter {
236            beg: unsafe { self.begin() },
237            end: unsafe { self.end() },
238            mark: PhantomData,
239        }
240    }
241
242    /// ```
243    /// use hicc_std::UnorderedMapIntInt;
244    /// let mut map = UnorderedMapIntInt::new();
245    /// map.insert(&1, &2);
246    /// map.insert(&2, &1);
247    /// map.iter_mut().for_each(|(_, v)| *v += 1);
248    /// assert_eq!(map.get(&1), Some(&3));
249    /// assert_eq!(map.get(&2), Some(&2));
250    /// ```
251    pub fn iter_mut(&mut self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
252        let beg = unsafe { self.begin_mut() };
253        let end = unsafe { self.end_mut() };
254        UnorderedMapIterMut {
255            beg,
256            end,
257            mark: PhantomData,
258        }
259    }
260}
261
262/// 对应`std::unordered_map<K, V>::const_iterator`
263struct UnorderedMapIter<'a, K: AbiType + 'static, V: AbiType + 'static> {
264    beg: ClassMutPtr<'static, CppUnorderedMapIter<K, V>>,
265    end: ClassMutPtr<'static, CppUnorderedMapIter<K, V>>,
266    mark: PhantomData<&'a unordered_map<K, V>>,
267}
268
269impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for UnorderedMapIter<'a, K, V> {
270    type Item = (K::OutputRef<'a>, V::OutputRef<'a>);
271    fn next(&mut self) -> Option<Self::Item> {
272        if !self.beg.equal(&self.end) {
273            unsafe {
274                let key = self.beg.as_deref().as_key();
275                let val = self.beg.as_deref().as_value();
276                self.beg.next();
277                return Some((key, val));
278            }
279        }
280        None
281    }
282}
283
284/// 对应`std::unordered_map<K, V>::iterator`
285struct UnorderedMapIterMut<'a, K: AbiType + 'static, V: AbiType + 'static> {
286    beg: ClassMutPtr<'static, CppUnorderedMapIterMut<K, V>>,
287    end: ClassMutPtr<'static, CppUnorderedMapIterMut<K, V>>,
288    mark: PhantomData<&'a mut unordered_map<K, V>>,
289}
290
291impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for UnorderedMapIterMut<'a, K, V> {
292    type Item = (K::OutputRef<'a>, V::OutputRefMut<'a>);
293    fn next(&mut self) -> Option<Self::Item> {
294        if !self.beg.equal(&self.end) {
295            unsafe {
296                let key = self.beg.as_deref().as_key();
297                let val = self.beg.as_deref_mut().as_value();
298                self.beg.next();
299                return Some((key, val));
300            }
301        }
302        None
303    }
304}
305
306hicc::import_class! {
307    #[cpp(class = "template <class K, class V, class Hash, class Pred, class Allocator> std::unordered_multimap<K, V, Hash, Pred, Allocator>")]
308    pub class unordered_multimap<K, V> {
309        hicc::cpp! {
310            typedef typename Self::iterator iterator;
311            typedef typename Self::const_iterator const_iterator;
312        }
313        /// ```
314        /// use hicc_std::UnorderedMultiMapIntInt;
315        /// let map = UnorderedMultiMapIntInt::new();
316        /// assert!(map.is_empty());
317        /// ```
318        #[cpp(method = "bool empty() const")]
319        pub fn is_empty(&self) -> bool;
320
321        /// ```
322        /// use hicc_std::UnorderedMultiMapIntInt;
323        /// let map = UnorderedMultiMapIntInt::new();
324        /// assert_eq!(map.size(), 0_usize);
325        /// ```
326        #[cpp(method = "size_t size() const")]
327        pub fn size(&self) -> usize;
328
329        /// ```
330        /// use hicc_std::UnorderedMultiMapIntInt;
331        /// let map = UnorderedMultiMapIntInt::new();
332        /// println!("map.max_size() = {}", map.max_size());
333        /// ```
334        #[cpp(method = "size_t max_size() const")]
335        pub fn max_size(&self) -> usize;
336
337        /// ```
338        /// use hicc_std::UnorderedMultiMapIntInt;
339        /// let mut map = UnorderedMultiMapIntInt::new();
340        /// map.insert(&1, &2);
341        /// assert_eq!(map.size(), 1_usize);
342        /// map.clear();
343        /// assert_eq!(map.size(), 0_usize);
344        /// ```
345        #[cpp(method = "void clear()")]
346        pub fn clear(&mut self);
347
348        /// ```
349        /// use hicc_std::UnorderedMultiMapIntInt;
350        /// let mut map1 = UnorderedMultiMapIntInt::new();
351        /// map1.insert(&1, &2);
352        /// let mut map2 = UnorderedMultiMapIntInt::new();
353        /// map2.swap(&mut map1);
354        /// assert_eq!(map1.size(), 0_usize);
355        /// assert_eq!(map2.size(), 1_usize);
356        /// ```
357        #[cpp(method = "void swap(Self&)")]
358        pub fn swap(&mut self, other: &mut Self);
359
360        /// ```
361        /// use hicc_std::UnorderedMultiMapIntInt;
362        /// let mut map = UnorderedMultiMapIntInt::new();
363        /// map.insert(&1, &2);
364        /// map.insert(&1, &2);
365        /// assert_eq!(map.count(&1), 2_usize);
366        /// assert_eq!(map.count(&2), 0);
367        /// ```
368        #[cpp(method = "size_t count(const K&) const")]
369        pub fn count(&self, key: &K) -> usize;
370
371        hicc::cpp! {
372            static bool contains(const Self& self, const K& key) {
373                return self.find(key) != self.end();
374            }
375        }
376        /// ```
377        /// use hicc_std::UnorderedMultiMapIntInt;
378        /// let mut map = UnorderedMultiMapIntInt::new();
379        /// map.insert(&1, &2);
380        /// assert!(map.contains(&1));
381        /// assert!(!map.contains(&2));
382        /// ```
383        #[cpp(func = "bool SelfMethods::contains(const Self&, const K&)")]
384        pub fn contains(&self, key: &K) -> bool;
385
386
387        /// ```
388        /// use hicc_std::UnorderedMultiMapIntInt;
389        /// let mut map = UnorderedMultiMapIntInt::new();
390        /// map.insert(&1, &2);
391        /// map.assign(&mut UnorderedMultiMapIntInt::new());
392        /// assert!(map.is_empty());
393        /// ```
394        #[cpp(func = "void hicc::make_assign<Self, Self>(Self&, const Self&)")]
395        pub fn assign(&mut self, other: &Self);
396
397        hicc::cpp! {
398            static void insert(Self& self, const K& key, const V& val) {
399                self.insert(std::make_pair(key, val));
400            }
401        }
402        /// ```
403        /// use hicc_std::UnorderedMultiMapIntInt;
404        /// let mut map = UnorderedMultiMapIntInt::new();
405        /// map.insert(&1, &2);
406        /// map.insert(&1, &3);
407        /// assert_eq!(map.count(&1), 2);
408        /// ```
409        #[cpp(func = "void SelfMethods::insert(Self&, const K&, const V&)")]
410        pub fn insert(&mut self, key: &K, val: &V);
411
412        /// ```
413        /// use hicc_std::UnorderedMultiMapIntInt;
414        /// let mut map = UnorderedMultiMapIntInt::new();
415        /// map.insert(&1, &2);
416        /// map.insert(&1, &3);
417        /// assert_eq!(map.erase(&1), 2);
418        /// ```
419        #[cpp(method = "size_t erase(const K&)")]
420        pub fn erase(&mut self, key: &K) -> usize;
421
422        #[cpp(method = "const_iterator find(const K&) const")]
423        unsafe fn find(&self, key: &K) -> *mut CppUnorderedMultiMapIter<K, V>;
424        #[cpp(method = "iterator find(const K&)")]
425        unsafe fn find_mut(&mut self, key: &K) -> *mut CppUnorderedMultiMapIterMut<K, V>;
426        #[cpp(method = "const_iterator begin() const")]
427        unsafe fn begin(&self) -> *mut CppUnorderedMultiMapIter<K, V>;
428        #[cpp(method = "iterator begin()")]
429        unsafe fn begin_mut(&mut self) -> *mut CppUnorderedMultiMapIterMut<K, V>;
430        #[cpp(method = "const_iterator end() const")]
431        unsafe fn end(&self) -> *mut CppUnorderedMultiMapIter<K, V>;
432        #[cpp(method = "iterator end()")]
433        unsafe fn end_mut(&mut self) -> *mut CppUnorderedMultiMapIterMut<K, V>;
434    }
435
436    unsafe impl<K: AbiType + Sync, V: AbiType + Sync> Send for unordered_multimap<K, V> {}
437    unsafe impl<K: AbiType + Sync, V: AbiType + Sync> Sync for unordered_multimap<K, V> {}
438
439    #[cpp(class = "template <class K, class V, class Hash, class Pred, class Allocator> std::unordered_multimap<K, V, Hash, Pred, Allocator>::const_iterator")]
440    class CppUnorderedMultiMapIter<K, V> {
441        hicc::cpp! {
442            static void next(Self& self) {
443                ++self;
444            }
445            static const K& key(const Self& self) {
446                return self->first;
447            }
448            static const V& value(const Self& self) {
449                return self->second;
450            }
451        }
452        #[cpp(func = "void SelfMethods::next(Self&)")]
453        fn next(&mut self);
454        #[cpp(func = "const K& SelfMethods::key(const Self&)")]
455        fn as_key(&self) -> &K;
456        #[cpp(func = "const V& SelfMethods::value(const Self&)")]
457        fn as_value(&self) -> &V;
458        #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
459        fn equal(&self, other: &Self) -> bool;
460    }
461
462    #[cpp(class = "template <class K, class V, class Hash, class Pred, class Allocator> std::unordered_multimap<K, V, Hash, Pred, Allocator>::iterator")]
463    class CppUnorderedMultiMapIterMut<K, V> {
464        hicc::cpp! {
465            static void next(Self& self) {
466                ++self;
467            }
468            static const K& key(const Self& self) {
469                return self->first;
470            }
471            static V& value(Self& self) {
472                return self->second;
473            }
474        }
475        #[cpp(func = "void SelfMethods::next(Self&)")]
476        fn next(&mut self);
477        #[cpp(func = "const K& SelfMethods::key(const Self&)")]
478        fn as_key(&self) -> &K;
479        #[cpp(func = "V& SelfMethods::value(Self&)")]
480        fn as_value(&mut self) -> &mut V;
481        #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
482        fn equal(&self, other: &Self) -> bool;
483    }
484}
485
486impl<K: AbiType, V: AbiType> unordered_multimap<K, V> {
487    /// ```
488    /// use hicc_std::UnorderedMultiMapIntInt;
489    /// let mut map = UnorderedMultiMapIntInt::new();
490    /// map.insert(&1, &2);
491    /// assert!(map.get(&2).is_none());
492    /// assert_eq!(map.get(&1), Some(&2));
493    /// ```
494    pub fn get(&self, key: &K::InputType) -> Option<V::OutputRef<'_>> {
495        unsafe {
496            let it = self.find(key);
497            if !it.equal(&self.end()) {
498                return Some(it.as_deref().as_value());
499            }
500        }
501        None
502    }
503    /// ```
504    /// use hicc_std::UnorderedMultiMapIntInt;
505    /// let mut map = UnorderedMultiMapIntInt::new();
506    /// map.insert(&1, &2);
507    /// *map.get_mut(&1).unwrap() = 0;
508    /// assert_eq!(map.get(&1), Some(&0));
509    ///
510    /// use hicc_std::{string, UnorderedMultiMapIntString};
511    /// use hicc::AbiClass;
512    /// let mut map = UnorderedMultiMapIntString::new();
513    /// map.insert(&1, &string::from(c"hello"));
514    /// map.get_mut(&1).unwrap().write(string::from(c"world"));
515    /// assert!(*map.get(&1).unwrap() == string::from(c"world"));
516    /// ```
517    pub fn get_mut(&mut self, key: &K::InputType) -> Option<V::OutputRefMut<'_>> {
518        unsafe {
519            let mut it = self.find_mut(key);
520            if !it.equal(&self.end_mut()) {
521                return Some(it.as_deref_mut().as_value());
522            }
523        }
524        None
525    }
526
527    /// ```
528    /// use hicc_std::UnorderedMultiMapIntInt;
529    /// let mut map = UnorderedMultiMapIntInt::new();
530    /// map.insert(&1, &2);
531    /// map.insert(&1, &1);
532    /// map.iter().for_each(|(k, v)| println!("key = {k}, value = {v}"));
533    /// ```
534    pub fn iter(&self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRef<'_>)> {
535        UnorderedMultiMapIter {
536            beg: unsafe { self.begin() },
537            end: unsafe { self.end() },
538            mark: PhantomData,
539        }
540    }
541
542    /// ```
543    /// use hicc_std::UnorderedMultiMapIntInt;
544    /// let mut map = UnorderedMultiMapIntInt::new();
545    /// map.insert(&1, &2);
546    /// map.insert(&2, &1);
547    /// map.iter_mut().for_each(|(_, v)| *v += 1);
548    /// assert_eq!(map.get(&1), Some(&3));
549    /// assert_eq!(map.get(&2), Some(&2));
550    /// ```
551    pub fn iter_mut(&mut self) -> impl Iterator<Item = (K::OutputRef<'_>, V::OutputRefMut<'_>)> {
552        let beg = unsafe { self.begin_mut() };
553        let end = unsafe { self.end_mut() };
554        UnorderedMultiMapIterMut {
555            beg,
556            end,
557            mark: PhantomData,
558        }
559    }
560}
561
562/// 对应`std::unordered_multimap<K, V>::const_iterator`
563struct UnorderedMultiMapIter<'a, K: AbiType + 'static, V: AbiType + 'static> {
564    beg: ClassMutPtr<'static, CppUnorderedMultiMapIter<K, V>>,
565    end: ClassMutPtr<'static, CppUnorderedMultiMapIter<K, V>>,
566    mark: PhantomData<&'a unordered_multimap<K, V>>,
567}
568
569impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator for UnorderedMultiMapIter<'a, K, V> {
570    type Item = (K::OutputRef<'a>, V::OutputRef<'a>);
571    fn next(&mut self) -> Option<Self::Item> {
572        if !self.beg.equal(&self.end) {
573            unsafe {
574                let key = self.beg.as_deref().as_key();
575                let val = self.beg.as_deref().as_value();
576                self.beg.next();
577                return Some((key, val));
578            }
579        }
580        None
581    }
582}
583/// 对应`std::unordered_multimap<K, V>::iterator`
584struct UnorderedMultiMapIterMut<'a, K: AbiType + 'static, V: AbiType + 'static> {
585    beg: ClassMutPtr<'static, CppUnorderedMultiMapIterMut<K, V>>,
586    end: ClassMutPtr<'static, CppUnorderedMultiMapIterMut<K, V>>,
587    mark: PhantomData<&'a unordered_multimap<K, V>>,
588}
589
590impl<'a, K: AbiType + 'static, V: AbiType + 'static> Iterator
591    for UnorderedMultiMapIterMut<'a, K, V>
592{
593    type Item = (K::OutputRef<'a>, V::OutputRefMut<'a>);
594    fn next(&mut self) -> Option<Self::Item> {
595        if !self.beg.equal(&self.end) {
596            unsafe {
597                let key = self.beg.as_deref().as_key();
598                let val = self.beg.as_deref_mut().as_value();
599                self.beg.next();
600                return Some((key, val));
601            }
602        }
603        None
604    }
605}