Verified Commit e4136ca4 authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

Simplify generating the rebuild order using a single DFS

Instead of iterating over pkgnames and creating two DFS's, create a
single DFS by adding all pkgnames to the public 'stack' field.

https://github.com/petgraph/petgraph/issues/230#issuecomment-438748717
parent 22c8eaf0
......@@ -143,16 +143,19 @@ pub fn run(
};
}
// Visit nodes in our graph in a depth-first-search adding nodes in post-order. The provided
// packages are added first to the stack.
let mut rebuild_order_packages = Vec::new();
for pkg in &pkgnames {
if let Some(pkgname) = cache_node.get(pkg.as_str()) {
let mut bfs = DfsPostOrder::new(&graph, *pkgname);
while let Some(nx) = bfs.next(&graph) {
let node = graph[nx];
rebuild_order_packages.push(node);
}
}
let mut bfs = DfsPostOrder::empty(&graph);
bfs.stack.extend(
pkgnames
.iter()
.filter_map(|pkg| cache_node.get(pkg.as_str())),
);
while let Some(nx) = bfs.next(&graph) {
let node = graph[nx];
rebuild_order_packages.push(node);
}
// Reverse the rebuild order as DfsPostOrder starts with the first pkgname and therefore
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment