diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-05 08:13:16 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-05 08:13:16 +0530 |
commit | 50438ef584d5f2ade0a0501ebca151c99893580f (patch) | |
tree | 1f65c4058681a21f76298bfefc65cb5b86ea48cd /src/common.rs | |
parent | b0a02d30f97d15e0c6fc19e5f4f7b8c56500ff7a (diff) |
move sorted_entries closer to where it is used
Diffstat (limited to 'src/common.rs')
-rw-r--r-- | src/common.rs | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/src/common.rs b/src/common.rs index 2e25e9e..f9fda92 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,32 +1,8 @@ use crate::traverse::{EntryData, Tree, TreeIndex}; use byte_unit::{n_gb_bytes, n_gib_bytes, n_mb_bytes, n_mib_bytes, ByteUnit}; -use itertools::Itertools; use jwalk::WalkDir; -use petgraph::Direction; use std::{fmt, path::Path, path::PathBuf}; -#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Eq)] -pub enum SortMode { - SizeDescending, - SizeAscending, -} - -impl SortMode { - pub fn toggle_size(&mut self) { - use SortMode::*; - *self = match self { - SizeAscending => SizeDescending, - SizeDescending => SizeAscending, - } - } -} - -impl Default for SortMode { - fn default() -> Self { - SortMode::SizeDescending - } -} - pub fn path_of(tree: &Tree, mut node_idx: TreeIndex) -> PathBuf { const THE_ROOT: usize = 1; let mut entries = Vec::new(); @@ -55,21 +31,6 @@ pub(crate) fn get_size_or_panic(tree: &Tree, node_idx: TreeIndex) -> u64 { get_entry_or_panic(tree, node_idx).size } -pub fn sorted_entries( - tree: &Tree, - node_idx: TreeIndex, - sorting: SortMode, -) -> Vec<(TreeIndex, &EntryData)> { - use SortMode::*; - tree.neighbors_directed(node_idx, Direction::Outgoing) - .filter_map(|idx| tree.node_weight(idx).map(|w| (idx, w))) - .sorted_by(|(_, l), (_, r)| match sorting { - SizeDescending => r.size.cmp(&l.size), - SizeAscending => l.size.cmp(&r.size), - }) - .collect() -} - /// Specifies a way to format bytes #[derive(Clone, Copy)] pub enum ByteFormat { |