summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock41
-rw-r--r--Cargo.toml1
-rw-r--r--src/2021/19/mod.rs11
-rw-r--r--src/prelude.rs3
4 files changed, 50 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7071508..6420581 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6,6 +6,7 @@ version = 3
name = "advent-of-code"
version = "0.1.0"
dependencies = [
+ "ahash",
"anyhow",
"paw",
"priority-queue",
@@ -14,6 +15,17 @@ dependencies = [
]
[[package]]
+name = "ahash"
+version = "0.7.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
+dependencies = [
+ "getrandom",
+ "once_cell",
+ "version_check",
+]
+
+[[package]]
name = "aho-corasick"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -61,6 +73,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
name = "clap"
version = "2.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -77,6 +95,17 @@ dependencies = [
]
[[package]]
+name = "getrandom"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi",
+]
+
+[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -129,6 +158,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
+name = "once_cell"
+version = "1.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
+
+[[package]]
name = "paw"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -317,6 +352,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
+name = "wasi"
+version = "0.10.2+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
+
+[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index f6fd153..cccaac3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+ahash = "0.7.6"
anyhow = "1.0.51"
paw = "1.0.0"
priority-queue = "1.2.1"
diff --git a/src/2021/19/mod.rs b/src/2021/19/mod.rs
index 1257aa6..7468ccc 100644
--- a/src/2021/19/mod.rs
+++ b/src/2021/19/mod.rs
@@ -115,15 +115,16 @@ impl Scanner {
fn matches(&self, other: &HashSet<Point>) -> Option<(usize, Point)> {
for (i, beacons) in self.each_orientation().enumerate() {
let mut offsets = vec![];
- for beacon1 in beacons.clone() {
+ for beacon1 in &beacons {
for beacon2 in other {
- offsets.push(*beacon2 - beacon1);
+ offsets.push(*beacon2 - *beacon1);
}
}
for offset in offsets {
- let set1: HashSet<_> =
- beacons.iter().map(|beacon| *beacon + offset).collect();
- let matches = set1.intersection(other).count();
+ let matches = beacons
+ .iter()
+ .filter(|beacon| other.contains(&(**beacon + offset)))
+ .count();
if matches == 0 {
panic!("bug");
}
diff --git a/src/prelude.rs b/src/prelude.rs
index d9263f5..cd6b8f8 100644
--- a/src/prelude.rs
+++ b/src/prelude.rs
@@ -2,9 +2,10 @@ pub use crate::util::grid::{Col, Grid, Row};
pub use crate::util::parse;
pub use std::cmp::Ordering;
-pub use std::collections::{HashMap, HashSet, VecDeque};
+pub use std::collections::VecDeque;
pub use std::fs::File;
pub use std::io::{BufRead as _, Read as _};
+pub use ahash::{AHashMap as HashMap, AHashSet as HashSet};
pub use anyhow::{anyhow, bail, Context as _, Error, Result};
pub use regex::Regex;