Use FX Hash
This commit is contained in:
parent
172b33b63c
commit
c9bd84ebdb
3 changed files with 19 additions and 14 deletions
|
|
@ -1,9 +1,6 @@
|
|||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
hash::Hash,
|
||||
ops::RangeInclusive,
|
||||
time::Instant,
|
||||
};
|
||||
use std::{collections::HashSet, hash::Hash, ops::RangeInclusive, time::Instant};
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use aoc_2025::{load, print_res};
|
||||
use bstr::BString;
|
||||
|
|
@ -184,7 +181,7 @@ impl Polygon {
|
|||
}
|
||||
}
|
||||
|
||||
struct InsertGuard<'a, K, V>(K, V, &'a mut HashMap<K, V>)
|
||||
struct InsertGuard<'a, K, V>(K, V, &'a mut FxHashMap<K, V>)
|
||||
where
|
||||
K: Hash + Eq + Copy,
|
||||
V: Copy;
|
||||
|
|
@ -203,8 +200,8 @@ fn horizontal_edges_contained(
|
|||
poly: &Polygon,
|
||||
a: Point2,
|
||||
b: Point2,
|
||||
cache: &mut HashMap<Point2, bool>,
|
||||
edge_cache: &mut HashMap<(u32, (u32, u32)), bool>,
|
||||
cache: &mut FxHashMap<Point2, bool>,
|
||||
edge_cache: &mut FxHashMap<(u32, (u32, u32)), bool>,
|
||||
) -> bool {
|
||||
assert_ne!(a.x, b.x);
|
||||
|
||||
|
|
@ -277,8 +274,8 @@ fn vertical_edges_contain(
|
|||
poly: &Polygon,
|
||||
a: Point2,
|
||||
b: Point2,
|
||||
cache: &mut HashMap<Point2, bool>,
|
||||
edge_cache: &mut HashMap<(u32, (u32, u32)), bool>,
|
||||
cache: &mut FxHashMap<Point2, bool>,
|
||||
edge_cache: &mut FxHashMap<(u32, (u32, u32)), bool>,
|
||||
) -> bool {
|
||||
assert_ne!(a.y, b.y);
|
||||
|
||||
|
|
@ -353,9 +350,9 @@ pub fn part2(input: Parsed) {
|
|||
|
||||
let mut max_area = 0;
|
||||
|
||||
let mut contains_cache = HashMap::new();
|
||||
let mut h_edge_cache = HashMap::new();
|
||||
let mut v_edge_cache = HashMap::new();
|
||||
let mut contains_cache = FxHashMap::default();
|
||||
let mut h_edge_cache = FxHashMap::default();
|
||||
let mut v_edge_cache = FxHashMap::default();
|
||||
|
||||
for (ia, &a) in poly.points().iter().enumerate() {
|
||||
for &b in poly.points().iter().skip(ia + 1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue