rayon/collections/
hash_map.rs1use std::collections::HashMap;
6use std::marker::PhantomData;
7
8use crate::iter::plumbing::*;
9use crate::iter::*;
10
11use crate::vec;
12
13#[derive(Debug)] pub struct IntoIter<K, V> {
16 inner: vec::IntoIter<(K, V)>,
17}
18
19into_par_vec! {
20 HashMap<K, V, S> => IntoIter<K, V>,
21 impl<K: Send, V: Send, S>
22}
23
24delegate_iterator! {
25 IntoIter<K, V> => (K, V),
26 impl<K: Send, V: Send>
27}
28
29#[derive(Debug)]
31pub struct Iter<'a, K, V> {
32 inner: vec::IntoIter<(&'a K, &'a V)>,
33}
34
35impl<K, V> Clone for Iter<'_, K, V> {
36 fn clone(&self) -> Self {
37 Iter {
38 inner: self.inner.clone(),
39 }
40 }
41}
42
43into_par_vec! {
44 &'a HashMap<K, V, S> => Iter<'a, K, V>,
45 impl<'a, K: Sync, V: Sync, S>
46}
47
48delegate_iterator! {
49 Iter<'a, K, V> => (&'a K, &'a V),
50 impl<'a, K: Sync, V: Sync>
51}
52
53#[derive(Debug)]
55pub struct IterMut<'a, K, V> {
56 inner: vec::IntoIter<(&'a K, &'a mut V)>,
57}
58
59into_par_vec! {
60 &'a mut HashMap<K, V, S> => IterMut<'a, K, V>,
61 impl<'a, K: Sync, V: Send, S>
62}
63
64delegate_iterator! {
65 IterMut<'a, K, V> => (&'a K, &'a mut V),
66 impl<'a, K: Sync, V: Send>
67}
68
69#[derive(Debug)]
72pub struct Drain<'a, K, V> {
73 inner: vec::IntoIter<(K, V)>,
74 marker: PhantomData<&'a mut HashMap<K, V>>,
75}
76
77impl<'a, K: Send, V: Send, S> ParallelDrainFull for &'a mut HashMap<K, V, S> {
78 type Iter = Drain<'a, K, V>;
79 type Item = (K, V);
80
81 fn par_drain(self) -> Self::Iter {
82 let vec: Vec<_> = self.drain().collect();
83 Drain {
84 inner: vec.into_par_iter(),
85 marker: PhantomData,
86 }
87 }
88}
89
90delegate_iterator! {
91 Drain<'_, K, V> => (K, V),
92 impl<K: Send, V: Send>
93}