multiple: Use FxHashMap for s p e e d

This commit is contained in:
2024-12-12 14:01:04 -08:00
parent 447ff5c62c
commit 6022d2cc39
6 changed files with 26 additions and 7 deletions

View File

@ -1,7 +1,9 @@
use aoc_runner_derive::{aoc, aoc_generator};
use std::collections::HashMap;
use rustc_hash::FxHashMap;
use std::io::{BufRead, Lines};
type HashMap<K, V> = FxHashMap<K, V>;
#[aoc_generator(day1)]
pub fn get_input(input: &[u8]) -> Locations {
Locations::from(input.lines())
@ -32,7 +34,7 @@ impl Locations {
self.right.sort();
}
fn right_count(&self) -> HashMap<u64, u64> {
let mut right_count: HashMap<u64, u64> = HashMap::new();
let mut right_count: HashMap<u64, u64> = HashMap::default();
for rval in &self.right {
right_count.insert(*rval, *right_count.get(rval).unwrap_or(&0) + 1);
}