Skip to content

Commit

Permalink
probably a bit closer to a correct implementation.
Browse files Browse the repository at this point in the history
It's much harder than expected :(. These graph traversals!
  • Loading branch information
Sebastian Thiel committed Jun 2, 2019
1 parent dec4afc commit f0e53be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
28 changes: 22 additions & 6 deletions src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ mod app {
let mut data = EntryData::default();
match entry {
Ok(entry) => {
dbg!(entry.depth);
data.name = entry.file_name;
let file_size = match entry.metadata {
Some(Ok(ref m)) if !m.is_dir() => m.len(),
Expand All @@ -86,14 +85,26 @@ mod app {
match (entry.depth, previous_depth) {
(n, p) if n > p => {
sizes_per_depth_level.push(current_size_at_depth);
current_size_at_depth = 0;
current_size_at_depth = file_size;
parent_node_idx = previous_node_idx;
}
(n, p) if n < p => {
parent_node_idx = tree
.neighbors_directed(parent_node_idx, Direction::Incoming)
.next()
.expect("every node in the iteration has a parent");
for _ in n..p {
let size_at_level_above = sizes_per_depth_level
.pop()
.expect("sizes per level to be in sync with graph");
tree.node_weight_mut(parent_node_idx)
.expect("node for parent index we just retrieved")
.size = current_size_at_depth;
current_size_at_depth += size_at_level_above;
parent_node_idx = tree
.neighbors_directed(
parent_node_idx,
Direction::Incoming,
)
.next()
.expect("every node in the iteration has a parent");
}
}
_ => {
current_size_at_depth += file_size;
Expand All @@ -111,6 +122,11 @@ mod app {
}
}

dbg!(previous_depth);
dbg!(sizes_per_depth_level);
dbg!(current_size_at_depth);
// TODO finish size computation - there may still be unresolved sizes on the stack

Ok(TerminalApp {
tree,
root_index,
Expand Down
6 changes: 3 additions & 3 deletions tests/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod app {
}
n
};
let root_size = 1259325;
let root_size = 1259070;
let r = add_node("", root_size, None);
{
let s = add_node("sample-01", root_size, Some(r));
Expand All @@ -67,7 +67,7 @@ mod app {
add_node("a", 256, Some(s));
add_node("b.empty", 0, Some(s));
add_node("c.lnk", 1, Some(s));
let d = add_node("dir", 0, Some(s));
let d = add_node("dir", 1258024, Some(s));
{
add_node("1000bytes", 1000, Some(d));
add_node("dir-a.1mb", 1_000_000, Some(d));
Expand All @@ -76,7 +76,7 @@ mod app {
{
add_node(".gitkeep", 0, Some(e));
}
let sub = add_node("sub", 0, Some(d));
let sub = add_node("sub", 256_000, Some(d));
{
add_node("dir-sub-a.256kb", 256_000, Some(sub));
}
Expand Down

0 comments on commit f0e53be

Please sign in to comment.