mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
00c7ce8f15
Code changes: Removed ignore & channel crates. Using a single reciever thread to build a hashmap to prevend duplicate inodes being reported gave a severe performance penalty Using rayon crate with some hand crafted file traversal has improved performance aprox 10X Behaviour changes: Removed parameter 'limit by filesystem' - don't think this is used, and I only added it as it was easy to add with the ignore crate. Sym links will now not appear in the output tree unless using '-s' 'apparent-size' flag Change behaviour of multiple args so that it unifies them and compares them under one tree instead of treating them individually: https://github.com/bootandy/dust/issues/136
47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
use std::cmp::Ordering;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug, Eq, Clone)]
|
|
pub struct DisplayNode {
|
|
pub name: PathBuf, //todo: consider moving to a string?
|
|
pub size: u64,
|
|
pub children: Vec<DisplayNode>,
|
|
}
|
|
|
|
impl Ord for DisplayNode {
|
|
fn cmp(&self, other: &Self) -> Ordering {
|
|
if self.size == other.size {
|
|
self.name.cmp(&other.name)
|
|
} else {
|
|
self.size.cmp(&other.size)
|
|
}
|
|
}
|
|
}
|
|
|
|
impl PartialOrd for DisplayNode {
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
Some(self.cmp(other))
|
|
}
|
|
}
|
|
|
|
impl PartialEq for DisplayNode {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
self.name == other.name && self.size == other.size && self.children == other.children
|
|
}
|
|
}
|
|
|
|
impl DisplayNode {
|
|
pub fn num_siblings(&self) -> u64 {
|
|
self.children.len() as u64
|
|
}
|
|
|
|
pub fn get_children_from_node(&self, is_reversed: bool) -> impl Iterator<Item = DisplayNode> {
|
|
if is_reversed {
|
|
let children: Vec<DisplayNode> = self.children.clone().into_iter().rev().collect();
|
|
children.into_iter()
|
|
} else {
|
|
self.children.clone().into_iter()
|
|
}
|
|
}
|
|
}
|