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);
}

View File

@ -1,10 +1,10 @@
use aoc_runner_derive::aoc;
use itertools::Itertools;
use std::collections::HashMap;
use rustc_hash::FxHashMap;
use std::iter::repeat;
type IntType = u64;
type CacheType = HashMap<Stone, IntType>;
type CacheType = FxHashMap<Stone, IntType>;
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
struct Stone(IntType);
@ -66,7 +66,7 @@ fn count_blinks(stone: &Stone, blink: usize, cache: &mut Vec<CacheType>) -> IntT
}
fn blink_stones(stones: Stones, blinks: usize) -> IntType {
let mut cache = Vec::from_iter(repeat(CacheType::new()).take(blinks));
let mut cache = Vec::from_iter(repeat(CacheType::default()).take(blinks));
stones
.0
.iter()

View File

@ -1,9 +1,11 @@
use aoc_runner_derive::{aoc, aoc_generator};
use grid::Grid;
use itertools::Itertools;
use std::collections::HashSet;
use rustc_hash::FxHashSet;
use std::io::BufRead;
type HashSet<T> = FxHashSet<T>;
#[aoc_generator(day8)]
pub fn get_input(input: &[u8]) -> AntennaMap {
AntennaMap::from(input)