Debian Codegraph @

debian/rust-vendor/rayon/src/collections/hash_map.rs

raw
1 //! This module contains the parallel iterator types for hash maps
2 //! (`HashMap<K, V>`). You will rarely need to interact with it directly
3 //! unless you have need to name one of the iterator types.
4
5 use std::collections::HashMap;
6 use std::marker::PhantomData;
7
8 use crate::iter::plumbing::*;
9 use crate::iter::*;
10
11 use crate::vec;
12
13 /// Parallel iterator over a hash map
14 #[derive(Debug)] // std doesn't Clone
15 pub struct IntoIter<K, V> {
16 inner: vec::IntoIter<(K, V)>,
17 }
18
19 into_par_vec! {
20 HashMap<K, V, S> => IntoIter<K, V>,
21 impl<K: Send, V: Send, S>
22 }
23
24 delegate_iterator! {
25 IntoIter<K, V> => (K, V),
26 impl<K: Send, V: Send>
27 }
28
29 /// Parallel iterator over an immutable reference to a hash map
30 #[derive(Debug)]
31 pub struct Iter<'a, K, V> {
32 inner: vec::IntoIter<(&'a K, &'a V)>,
33 }
34
35 impl<K, V> Clone for Iter<'_, K, V> {
36 fn clone(&self) -> Self {
37 Iter {
38 inner: self.inner.clone(),
39 }
40 }
41 }
42
43 into_par_vec! {
44 &'a HashMap<K, V, S> => Iter<'a, K, V>,
45 impl<'a, K: Sync, V: Sync, S>
46 }
47
48 delegate_iterator! {
49 Iter<'a, K, V> => (&'a K, &'a V),
50 impl<'a, K: Sync, V: Sync>
51 }
52
53 /// Parallel iterator over a mutable reference to a hash map
54 #[derive(Debug)]
55 pub struct IterMut<'a, K, V> {
56 inner: vec::IntoIter<(&'a K, &'a mut V)>,
57 }
58
59 into_par_vec! {
60 &'a mut HashMap<K, V, S> => IterMut<'a, K, V>,
61 impl<'a, K: Sync, V: Send, S>
62 }
63
64 delegate_iterator! {
65 IterMut<'a, K, V> => (&'a K, &'a mut V),
66 impl<'a, K: Sync, V: Send>
67 }
68
69 /// Draining parallel iterator that moves out of a hash map,
70 /// but keeps the total capacity.
71 #[derive(Debug)]
72 pub struct Drain<'a, K, V> {
73 inner: vec::IntoIter<(K, V)>,
74 marker: PhantomData<&'a mut HashMap<K, V>>,
75 }
76
77 impl<'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
90 delegate_iterator! {
91 Drain<'_, K, V> => (K, V),
92 impl<K: Send, V: Send>
93 }