1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use super::DataTree;
use crate::size::Size;
use rayon::prelude::*;
impl<Name, Data> DataTree<Name, Data>
where
Self: Send,
Data: Size,
{
pub fn par_retain(&mut self, predicate: impl Fn(&Self) -> bool + Copy + Sync) {
self.children.retain(predicate);
self.children
.par_iter_mut()
.for_each(|child| child.par_retain(predicate));
}
pub fn into_par_retained(mut self, predicate: impl Fn(&Self) -> bool + Copy + Sync) -> Self {
self.par_retain(predicate);
self
}
#[cfg(feature = "cli")]
pub(crate) fn par_cull_insignificant_data(&mut self, min_ratio: f32)
where
Data: Into<u64>,
{
let minimal = self.data().into() as f32 * min_ratio;
self.par_retain(|descendant| descendant.data().into() as f32 >= minimal);
}
#[cfg(test)]
#[cfg(feature = "cli")]
fn into_insignificant_data_par_culled(mut self, min_ratio: f32) -> Self
where
Data: Into<u64>,
{
self.par_cull_insignificant_data(min_ratio);
self
}
}
#[cfg(test)]
#[cfg(feature = "cli")]
mod test;