|
7 | 7 | Self: Send, |
8 | 8 | Size: size::Size, |
9 | 9 | { |
10 | | - /// Recursively cull all descendants that do not satisfy given `predicate`, in parallel. |
11 | | - pub fn par_retain(&mut self, predicate: impl Fn(&Self) -> bool + Copy + Sync) { |
12 | | - self.children.retain(predicate); |
| 10 | + /// Internal function to be used by [`Self::par_retain`]. |
| 11 | + fn par_retain_with_depth( |
| 12 | + &mut self, |
| 13 | + current_depth: u64, |
| 14 | + predicate: impl Fn(&Self, u64) -> bool + Copy + Sync, |
| 15 | + ) { |
| 16 | + self.children |
| 17 | + .retain(|child| predicate(child, current_depth)); |
| 18 | + let next_depth = current_depth + 1; |
13 | 19 | self.children |
14 | 20 | .par_iter_mut() |
15 | | - .for_each(|child| child.par_retain(predicate)); |
| 21 | + .for_each(|child| child.par_retain_with_depth(next_depth, predicate)) |
| 22 | + } |
| 23 | + |
| 24 | + /// Recursively cull all descendants that do not satisfy given `predicate`, in parallel. |
| 25 | + pub fn par_retain(&mut self, predicate: impl Fn(&Self, u64) -> bool + Copy + Sync) { |
| 26 | + self.par_retain_with_depth(0, predicate) |
16 | 27 | } |
17 | 28 |
|
18 | 29 | /// Process the tree via [`par_retain`](Self::par_retain) method. |
19 | | - pub fn into_par_retained(mut self, predicate: impl Fn(&Self) -> bool + Copy + Sync) -> Self { |
| 30 | + pub fn into_par_retained( |
| 31 | + mut self, |
| 32 | + predicate: impl Fn(&Self, u64) -> bool + Copy + Sync, |
| 33 | + ) -> Self { |
20 | 34 | self.par_retain(predicate); |
21 | 35 | self |
22 | 36 | } |
|
28 | 42 | Size: Into<u64>, |
29 | 43 | { |
30 | 44 | let minimal = self.size().into() as f32 * min_ratio; |
31 | | - self.par_retain(|descendant| descendant.size().into() as f32 >= minimal); |
| 45 | + self.par_retain(|descendant, _| descendant.size().into() as f32 >= minimal); |
32 | 46 | } |
33 | 47 |
|
34 | 48 | /// Process the tree via [`par_cull_insignificant_data`](Self::par_cull_insignificant_data) method. |
|
0 commit comments