parallel_disk_usage/data_tree/
sort.rs

1use 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    /// Sort all descendants recursively, in parallel.
12    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    /// Process the tree via [`par_sort_by`](Self::par_sort_by) method.
20    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}