multiple: Use FxHashMap for s p e e d
This commit is contained in:
parent
447ff5c62c
commit
6022d2cc39
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -51,6 +51,7 @@ dependencies = [
|
|||||||
"itertools",
|
"itertools",
|
||||||
"rayon",
|
"rayon",
|
||||||
"regex",
|
"regex",
|
||||||
|
"rustc-hash",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -195,6 +196,12 @@ version = "0.8.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-hash"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
|
@ -11,6 +11,7 @@ grid = { version = "0.1.0", path = "utils/grid" }
|
|||||||
itertools = "0.13.0"
|
itertools = "0.13.0"
|
||||||
rayon = "1.10.0"
|
rayon = "1.10.0"
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
|
rustc-hash = "2.1.0"
|
||||||
thread_local = "1.1.8"
|
thread_local = "1.1.8"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use aoc_runner_derive::{aoc, aoc_generator};
|
use aoc_runner_derive::{aoc, aoc_generator};
|
||||||
use std::collections::HashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use std::io::{BufRead, Lines};
|
use std::io::{BufRead, Lines};
|
||||||
|
|
||||||
|
type HashMap<K, V> = FxHashMap<K, V>;
|
||||||
|
|
||||||
#[aoc_generator(day1)]
|
#[aoc_generator(day1)]
|
||||||
pub fn get_input(input: &[u8]) -> Locations {
|
pub fn get_input(input: &[u8]) -> Locations {
|
||||||
Locations::from(input.lines())
|
Locations::from(input.lines())
|
||||||
@ -32,7 +34,7 @@ impl Locations {
|
|||||||
self.right.sort();
|
self.right.sort();
|
||||||
}
|
}
|
||||||
fn right_count(&self) -> HashMap<u64, u64> {
|
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 {
|
for rval in &self.right {
|
||||||
right_count.insert(*rval, *right_count.get(rval).unwrap_or(&0) + 1);
|
right_count.insert(*rval, *right_count.get(rval).unwrap_or(&0) + 1);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use aoc_runner_derive::aoc;
|
use aoc_runner_derive::aoc;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::collections::HashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use std::iter::repeat;
|
use std::iter::repeat;
|
||||||
|
|
||||||
type IntType = u64;
|
type IntType = u64;
|
||||||
type CacheType = HashMap<Stone, IntType>;
|
type CacheType = FxHashMap<Stone, IntType>;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
||||||
struct Stone(IntType);
|
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 {
|
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
|
stones
|
||||||
.0
|
.0
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
use aoc_runner_derive::{aoc, aoc_generator};
|
use aoc_runner_derive::{aoc, aoc_generator};
|
||||||
use grid::Grid;
|
use grid::Grid;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::collections::HashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
|
|
||||||
|
type HashSet<T> = FxHashSet<T>;
|
||||||
|
|
||||||
#[aoc_generator(day8)]
|
#[aoc_generator(day8)]
|
||||||
pub fn get_input(input: &[u8]) -> AntennaMap {
|
pub fn get_input(input: &[u8]) -> AntennaMap {
|
||||||
AntennaMap::from(input)
|
AntennaMap::from(input)
|
||||||
|
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