-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move sorted_entries closer to where it is used
- Loading branch information
Sebastian Thiel
committed
Jun 5, 2019
1 parent
b0a02d3
commit 50438ef
Showing
5 changed files
with
55 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use dua::traverse::{EntryData, Tree, TreeIndex}; | ||
use itertools::Itertools; | ||
use petgraph::Direction; | ||
|
||
#[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 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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod common; | ||
mod eventloop; | ||
|
||
pub use common::*; | ||
pub use eventloop::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters