diff options
author | Canop <cano.petrole@gmail.com> | 2019-09-19 22:44:07 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2019-09-19 22:44:07 +0200 |
commit | 2b2bd822f29de4b737cb086f9fada0588f678b40 (patch) | |
tree | 71875c81dbfeec704a7303e48f7d2292ad373005 | |
parent | 8c4f81b79907817fdab60c6581454249df111a65 (diff) |
prevent pruning of line with best score
-rw-r--r-- | src/flat_tree.rs | 18 | ||||
-rw-r--r-- | src/tree_build.rs | 2 |
2 files changed, 15 insertions, 5 deletions
diff --git a/src/flat_tree.rs b/src/flat_tree.rs index 9700dee..5966166 100644 --- a/src/flat_tree.rs +++ b/src/flat_tree.rs @@ -174,7 +174,11 @@ impl Tree { // we sort the lines (this is mandatory to avoid crashes) self.lines[1..].sort(); + let mut best_index = 0; // index of the line with the best score for i in 1..self.lines.len() { + if self.lines[i].score > self.lines[best_index].score { + best_index = i; + } for d in 0..self.lines[i].left_branchs.len() { self.lines[i].left_branchs[d] = false; } @@ -208,11 +212,15 @@ impl Tree { // the line at end_index is the last listed child of the line at parent_index let unlisted = self.lines[parent_index].unlisted; if unlisted > 0 && self.lines[end_index].nb_kept_children == 0 { - self.lines[end_index].line_type = LineType::Pruning; - self.lines[end_index].unlisted = unlisted + 1; - self.lines[end_index].name = - format!("{} unlisted", unlisted + 1).to_owned(); - self.lines[parent_index].unlisted = 0; + if best_index==end_index { + debug!("Avoiding to prune the line with best score"); + } else { + debug!("turning {:?} into Pruning", self.lines[end_index].path); + self.lines[end_index].line_type = LineType::Pruning; + self.lines[end_index].unlisted = unlisted + 1; + self.lines[end_index].name = format!("{} unlisted", unlisted + 1).to_owned(); + self.lines[parent_index].unlisted = 0; + } } last_parent_index = parent_index; } diff --git a/src/tree_build.rs b/src/tree_build.rs index 7b791db..3563aa8 100644 --- a/src/tree_build.rs +++ b/src/tree_build.rs @@ -174,6 +174,7 @@ impl BLine { LineType::File }; let unlisted = if let Some(children) = &self.children { + // number of not listed children children.len() - self.next_child_idx } else { 0 @@ -417,6 +418,7 @@ impl TreeBuilder { let trim_root = self.options.trim_root && !self.options.show_sizes; for idx in out_blines[1..].iter() { if self.blines[*idx].has_match { + //debug!("bline before trimming: {:?}", &self.blines[*idx].path); count += 1; let parent_idx = self.blines[*idx].parent_idx; self.blines[parent_idx].nb_kept_children += 1; |