cargo fmt
parent
ce63f9771b
commit
3905fdb350
|
@ -1,6 +1,6 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use std::fs;
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct Dir {
|
struct Dir {
|
||||||
|
@ -68,7 +68,7 @@ fn part_two_sizes<'a>(dir: &'a Dir, needed: u32) -> Option<(u32, &'a str)> {
|
||||||
|
|
||||||
for (key, val) in map.iter() {
|
for (key, val) in map.iter() {
|
||||||
if *key >= needed {
|
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) {
|
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() {
|
for subdir in dir.directories.iter() {
|
||||||
part_two_recurse(map, subdir);
|
part_two_recurse(map, subdir);
|
||||||
}
|
}
|
||||||
|
@ -165,10 +168,18 @@ pub fn run() -> Result<()> {
|
||||||
let min_free_space = 30000000;
|
let min_free_space = 30000000;
|
||||||
let free_space = total_disk - root.total_size as u32;
|
let free_space = total_disk - root.total_size as u32;
|
||||||
let needed_space = min_free_space - free_space;
|
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) {
|
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 {
|
} else {
|
||||||
println!("could not find part 2");
|
println!("could not find part 2");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue