parallel_disk_usage/data_tree/
sort.rs1use super::DataTree;
2use crate::size;
3use rayon::prelude::*;
4use std::cmp::Ordering;
5
6impl<Name, Size> DataTree<Name, Size>
7where
8 Self: Send,
9 Size: size::Size,
10{
11 pub fn par_sort_by(&mut self, compare: impl Fn(&Self, &Self) -> Ordering + Copy + Sync) {
13 self.children
14 .par_iter_mut()
15 .for_each(|child| child.par_sort_by(compare));
16 self.children.sort_by(compare);
17 }
18
19 pub fn into_par_sorted(
21 mut self,
22 compare: impl Fn(&Self, &Self) -> Ordering + Copy + Sync,
23 ) -> Self {
24 self.par_sort_by(compare);
25 self
26 }
27}