rustfmt
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
use std::borrow::BorrowMut;
|
||||
|
||||
use petgraph::*;
|
||||
use petgraph::dot::*;
|
||||
use petgraph::prelude::*;
|
||||
use petgraph::*;
|
||||
|
||||
fn do_weights(g: &mut Graph<(String, u64), ()>, root_dir: NodeIndex<u32>) {
|
||||
for edge in g.clone().edges_directed(root_dir, Outgoing) {
|
||||
@ -29,21 +29,23 @@ fn main() {
|
||||
let new_dir = &line[5..];
|
||||
|
||||
if new_dir == ".." {
|
||||
curr_dir = g.edges_directed(curr_dir, Incoming).next().unwrap().source();
|
||||
curr_dir = g
|
||||
.edges_directed(curr_dir, Incoming)
|
||||
.next()
|
||||
.unwrap()
|
||||
.source();
|
||||
} else {
|
||||
let prev_dir = curr_dir;
|
||||
curr_dir = g.add_node((new_dir.to_string() + "/", 0));
|
||||
if prev_dir == invalid_index {
|
||||
if prev_dir == invalid_index {
|
||||
root_dir = curr_dir;
|
||||
} else {
|
||||
g.add_edge(prev_dir, curr_dir, ());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if line.starts_with("$ ls") {
|
||||
} else if line.starts_with("$ ls") {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
let (size, name) = line.split_once(' ').unwrap();
|
||||
if size == "dir" {
|
||||
continue;
|
||||
@ -60,13 +62,22 @@ fn main() {
|
||||
|
||||
println!("{:?}\n\n", Dot::with_config(&g, &[Config::EdgeNoLabel]));
|
||||
|
||||
let total = g.node_weights().filter(|(n, w)| { n.ends_with("/") && *w <= 100000 }).map(|(_, w)| { w }).sum::<u64>();
|
||||
let total = g
|
||||
.node_weights()
|
||||
.filter(|(n, w)| n.ends_with("/") && *w <= 100000)
|
||||
.map(|(_, w)| w)
|
||||
.sum::<u64>();
|
||||
println!("total: {total}");
|
||||
|
||||
let used_space = g.node_weight(root_dir).unwrap().1;
|
||||
let free_space = 70000000 - used_space;
|
||||
let need_to_free = 30000000 - free_space;
|
||||
|
||||
let delete = g.node_weights().filter(|(n, w)| { n.ends_with("/") && *w > need_to_free }).map(|(_, w)| { w }).min().unwrap();
|
||||
let delete = g
|
||||
.node_weights()
|
||||
.filter(|(n, w)| n.ends_with("/") && *w > need_to_free)
|
||||
.map(|(_, w)| w)
|
||||
.min()
|
||||
.unwrap();
|
||||
println!("delete size: {delete}");
|
||||
}
|
||||
|
Reference in New Issue
Block a user