Skip to content

Commit

Permalink
Factor out debug logging from shortest_path
Browse files Browse the repository at this point in the history
This makes the core logic clearer
  • Loading branch information
Wilfred committed May 29, 2022
1 parent 39be777 commit 1f48149
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/diff/dijkstra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,9 @@ fn shortest_path(start: Vertex, size_hint: usize) -> Vec<(Edge, Vertex)> {

current = node;
}
route.reverse();

debug!("Found a path of {} with cost {}.", route.len(), cost);
let print_length = if env::var("DFT_VERBOSE").is_ok() {
50
} else {
5
};
debug!(
"Initial {} items on path: {:#?}",
print_length,
route
.iter()
.map(|x| {
format!(
"{:20} {:20} --- {:3} {:?}",
x.1.lhs_syntax
.map_or_else(|| "None".into(), Syntax::dbg_content),
x.1.rhs_syntax
.map_or_else(|| "None".into(), Syntax::dbg_content),
x.0.cost(),
x.0,
)
})
.take(print_length)
.collect_vec()
);

route.reverse();
route
}

Expand Down Expand Up @@ -162,6 +138,31 @@ pub fn mark_syntax<'a>(
let start = Vertex::new(lhs_syntax, rhs_syntax);
let route = shortest_path(start, size_hint);

let print_length = if env::var("DFT_VERBOSE").is_ok() {
50
} else {
5
};
debug!(
"Initial {} items on path: {:#?}",
print_length,
route
.iter()
.map(|x| {
format!(
"{:20} {:20} --- {:3} {:?}",
x.1.lhs_syntax
.map_or_else(|| "None".into(), Syntax::dbg_content),
x.1.rhs_syntax
.map_or_else(|| "None".into(), Syntax::dbg_content),
x.0.cost(),
x.0,
)
})
.take(print_length)
.collect_vec()
);

populate_change_map(&route, change_map);
}

Expand Down

0 comments on commit 1f48149

Please # to comment.