2022: clippies
This commit is contained in:
3 files changed
+15
-18
No files matched your search
+6
-9
@@ -42,16 +42,16 @@ fn dir_usage(fs: &Filesystem, path: &str) -> u64 {
|
||||
fn parse(input: &str) -> Filesystem {
|
||||
let mut cwd = "/".to_owned();
|
||||
let mut fs = Filesystem::new();
|
||||
let mut lines = input.lines();
|
||||
let lines = input.lines();
|
||||
|
||||
while let Some(line) = lines.next() {
|
||||
for line in lines {
|
||||
let tokens = line.split_ascii_whitespace().collect_vec();
|
||||
if tokens[0] == "$" {
|
||||
// command
|
||||
match tokens[1] {
|
||||
"cd" => {
|
||||
cwd = new_cwd(&cwd, tokens[2]);
|
||||
fs.entry(cwd.to_owned()).or_insert(HashMap::new());
|
||||
fs.entry(cwd.to_owned()).or_default();
|
||||
}
|
||||
"ls" => {}
|
||||
s => {
|
||||
@@ -67,7 +67,7 @@ fn parse(input: &str) -> Filesystem {
|
||||
}
|
||||
// dir entry
|
||||
else {
|
||||
fs.entry(cwd.to_owned() + tokens[1] + "/").or_insert(HashMap::new());
|
||||
fs.entry(cwd.to_owned() + tokens[1] + "/").or_default();
|
||||
fs.entry(cwd.to_owned()).and_modify(|e| {
|
||||
e.insert(tokens[1].into(), DirEntry::Directory);
|
||||
});
|
||||
@@ -83,15 +83,12 @@ const MIN_FREE: u64 = 30000000;
|
||||
|
||||
#[aoc(day7, part1)]
|
||||
fn part1(fs: &Filesystem) -> u64 {
|
||||
fs.keys()
|
||||
.map(|path| dir_usage(&fs, path))
|
||||
.filter(|v| *v <= 100000)
|
||||
.sum()
|
||||
fs.keys().map(|path| dir_usage(fs, path)).filter(|v| *v <= 100000).sum()
|
||||
}
|
||||
|
||||
#[aoc(day7, part2)]
|
||||
fn part2(fs: &Filesystem) -> u64 {
|
||||
let mut usages = fs.keys().map(|path| dir_usage(&fs, path)).sorted().collect_vec();
|
||||
let mut usages = fs.keys().map(|path| dir_usage(fs, path)).sorted().collect_vec();
|
||||
|
||||
let total_usage = usages.pop().unwrap(); // sorted list, largest dir will always be the root which can't be deleted
|
||||
let need_to_free_at_least = MIN_FREE - (AVAIL_DISK - total_usage);
|
||||
|
||||
Reference in new issue
Block a user