multiple: Use FxHashMap for s p e e d
This commit is contained in:
parent
447ff5c62c
commit
bf00657911
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -51,6 +51,7 @@ dependencies = [
|
||||
"itertools",
|
||||
"rayon",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"thread_local",
|
||||
]
|
||||
|
||||
@ -195,6 +196,12 @@ version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.18"
|
||||
|
@ -11,7 +11,8 @@ grid = { version = "0.1.0", path = "utils/grid" }
|
||||
itertools = "0.13.0"
|
||||
rayon = "1.10.0"
|
||||
regex = "1.11.1"
|
||||
rustc-hash = "2.1.0"
|
||||
thread_local = "1.1.8"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
lto = true
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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()
|
||||
|
7
utils/grid/Cargo.lock
generated
Normal file
7
utils/grid/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "grid"
|
||||
version = "0.1.0"
|
Loading…
x
Reference in New Issue
Block a user