1
0
Fork 0

cargo fmt

main
Andrew Coleman 2022-12-07 14:11:37 -05:00
parent ce63f9771b
commit 3905fdb350
1 changed files with 17 additions and 6 deletions

View File

@ -1,8 +1,8 @@
use anyhow::{anyhow, Result};
use std::fs;
use std::collections::BTreeMap;
use std::fs;
#[derive(Debug,Default)]
#[derive(Debug, Default)]
struct Dir {
name: String,
files: Vec<File>,
@ -68,7 +68,7 @@ fn part_two_sizes<'a>(dir: &'a Dir, needed: u32) -> Option<(u32, &'a str)> {
for (key, val) in map.iter() {
if *key >= needed {
return Some((*key, val))
return Some((*key, val));
}
}
@ -76,7 +76,10 @@ fn part_two_sizes<'a>(dir: &'a Dir, needed: u32) -> Option<(u32, &'a str)> {
}
fn part_two_recurse<'a>(map: &mut BTreeMap<u32, &'a str>, dir: &'a Dir) {
map.insert((dir.total_size as u32).try_into().unwrap(), dir.name.as_str());
map.insert(
(dir.total_size as u32).try_into().unwrap(),
dir.name.as_str(),
);
for subdir in dir.directories.iter() {
part_two_recurse(map, subdir);
}
@ -165,10 +168,18 @@ pub fn run() -> Result<()> {
let min_free_space = 30000000;
let free_space = total_disk - root.total_size as u32;
let needed_space = min_free_space - free_space;
println!("total size used {} free {} needed {}", root.total_size, free_space, needed_space);
println!(
"total size used {} free {} needed {}",
root.total_size, free_space, needed_space
);
if let Some((rm_space, rm_name)) = part_two_sizes(&root, needed_space) {
println!("part two: should delete {} to reclaim {} total free space {}", rm_name, rm_space, free_space + rm_space);
println!(
"part two: should delete {} to reclaim {} total free space {}",
rm_name,
rm_space,
free_space + rm_space
);
} else {
println!("could not find part 2");
}