Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ derive_setters = "0.1.8"
fmt-iter = "0.2.1"
into-sorted = "0.0.3"
itertools = "0.14.0"
orx-parallel = "2.3.0"
pipe-trait = "0.4.0"
rayon = "1.10.0"
rounded-div = "0.1.2"
serde = { version = "1.0.219", optional = true }
serde_json = { version = "1.0.141", optional = true }
Expand All @@ -77,3 +77,4 @@ maplit = "1.0.2"
normalize-path = "0.2.1"
pretty_assertions = "1.4.1"
rand = "0.9.2"
rayon = "1.10.0" # TODO: replace this with orx-parallel
9 changes: 3 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl App {
.map_err(RuntimeError::DeserializationFailure)?
.body;

trait VisualizeJsonTree: size::Size + Into<u64> + Send {
trait VisualizeJsonTree: size::Size + Into<u64> + Send + Sync {
fn visualize_json_tree(
tree: JsonTree<Self>,
bytes_format: Self::DisplayFormat,
Expand Down Expand Up @@ -103,7 +103,7 @@ impl App {
}
}

impl<Size: size::Size + Into<u64> + Send> VisualizeJsonTree for Size {}
impl<Size: size::Size + Into<u64> + Send + Sync> VisualizeJsonTree for Size {}

macro_rules! visualize {
($tree:expr, $bytes_format:expr) => {
Expand Down Expand Up @@ -149,10 +149,7 @@ impl App {
};

if let Some(threads) = threads {
rayon::ThreadPoolBuilder::new()
.num_threads(threads)
.build_global()
.unwrap_or_else(|_| eprintln!("warning: Failed to set thread limit to {threads}"));
todo!("Set number of threads to {threads}");
}

if cfg!(unix) && self.args.deduplicate_hardlinks && self.args.files.len() > 1 {
Expand Down
7 changes: 4 additions & 3 deletions src/data_tree/hardlink.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::DataTree;
use crate::size;
use assert_cmp::debug_assert_op;
use rayon::prelude::*;
use orx_parallel::*;
use std::{ffi::OsStr, path::Path};

impl<Name, Size> DataTree<Name, Size>
where
Self: Send,
Self: Send + Sync,
Name: AsRef<OsStr>,
Size: size::Size + Sync,
{
Expand Down Expand Up @@ -39,7 +39,8 @@ where
}

self.children
.par_iter_mut()
.iter_mut() // TODO: request orx-parallel to add par_mut
.iter_into_par()
.for_each(|child| child.par_deduplicate_hardlinks(&sub_hardlink_info))
}
}
18 changes: 11 additions & 7 deletions src/data_tree/reflection/par_methods.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::{ConversionError, Reflection};
use crate::{data_tree::DataTree, size};
use rayon::prelude::*;
use orx_parallel::*;
use std::{ffi::OsStr, iter::once};

impl<Name, Size> Reflection<Name, Size>
where
Name: Send,
Size: size::Size + Send,
Name: Send + Sync,
Size: size::Size + Send + Sync,
{
/// Attempting to convert a [`Reflection`] into a valid [`DataTree`].
pub fn par_try_into_tree(self) -> Result<DataTree<Name, Size>, ConversionError<Name, Size>> {
Expand All @@ -25,8 +25,10 @@ where
return Err(ConversionError::ExcessiveChildren { path, size, child });
}
let children: Result<Vec<_>, _> = children
.into_par_iter()
.into_par()
.map(Self::par_try_into_tree)
.collect::<Vec<Result<_, _>>>() // TODO: request orx-parallel to make collecting Result possible
.into_iter()
.collect();
let children = match children {
Ok(children) => children,
Expand All @@ -52,9 +54,9 @@ where
transform: Transform,
) -> Result<Reflection<TargetName, TargetSize>, Error>
where
TargetName: Send,
TargetName: Send + Sync,
TargetSize: size::Size + Send + Sync,
Error: Send,
Error: Send + Sync,
Transform: Fn(Name, Size) -> Result<(TargetName, TargetSize), Error> + Copy + Sync,
{
let Reflection {
Expand All @@ -63,8 +65,10 @@ where
children,
} = self;
let children = children
.into_par_iter()
.into_par()
.map(|child| child.par_try_map(transform))
.collect::<Vec<Result<_, _>>>() // TODO: request orx-parallel to make collecting Result possible
.into_iter()
.collect::<Result<Vec<_>, _>>()?;
let (name, size) = transform(name, size)?;
Ok(Reflection {
Expand Down
7 changes: 4 additions & 3 deletions src/data_tree/retain.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::DataTree;
use crate::size;
use rayon::prelude::*;
use orx_parallel::*;

impl<Name, Size> DataTree<Name, Size>
where
Self: Send,
Self: Send + Sync,
Size: size::Size,
{
/// Internal function to be used by [`Self::par_retain`].
Expand All @@ -17,7 +17,8 @@ where
.retain(|child| predicate(child, current_depth));
let next_depth = current_depth + 1;
self.children
.par_iter_mut()
.iter_mut() // TODO: request orx-parallel to add par_mut
.iter_into_par()
.for_each(|child| child.par_retain_with_depth(next_depth, predicate))
}

Expand Down
7 changes: 4 additions & 3 deletions src/data_tree/sort.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use super::DataTree;
use crate::size;
use rayon::prelude::*;
use orx_parallel::*;
use std::cmp::Ordering;

impl<Name, Size> DataTree<Name, Size>
where
Self: Send,
Self: Send + Sync,
Size: size::Size,
{
/// Sort all descendants recursively, in parallel.
pub fn par_sort_by(&mut self, compare: impl Fn(&Self, &Self) -> Ordering + Copy + Sync) {
self.children
.par_iter_mut()
.iter_mut() // TODO: request orx-parallel to add par_mut
.iter_into_par()
.for_each(|child| child.par_sort_by(compare));
self.children.sort_unstable_by(compare);
}
Expand Down
6 changes: 3 additions & 3 deletions src/tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod info;
pub use info::Info;

use super::{data_tree::DataTree, size};
use rayon::prelude::*;
use orx_parallel::*;

/// Collection of functions and starting points in order to build a [`DataTree`] with [`From`] or [`Into`].
#[derive(Debug)]
Expand Down Expand Up @@ -34,7 +34,7 @@ where
Name: Send + Sync,
GetInfo: Fn(&Path) -> Info<Name, Size> + Copy + Send + Sync,
JoinPath: Fn(&Path, &Name) -> Path + Copy + Send + Sync,
Size: size::Size + Send,
Size: size::Size + Send + Sync,
{
/// Create a [`DataTree`] from a [`TreeBuilder`].
fn from(builder: TreeBuilder<Path, Name, Size, GetInfo, JoinPath>) -> Self {
Expand All @@ -50,7 +50,7 @@ where
let max_depth = max_depth.saturating_sub(1);

let children = children
.into_par_iter()
.into_par()
.map(|name| TreeBuilder {
path: join_path(&path, &name),
name,
Expand Down
Loading
Loading