Skip to content

Commit

Permalink
try?
Browse files Browse the repository at this point in the history
  • Loading branch information
Icerath committed Dec 24, 2024
1 parent 97eea32 commit 808cca4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/day23.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![expect(clippy::cast_possible_truncation, static_mut_refs)]
use std::hint::{assert_unchecked, unreachable_unchecked};
use std::{
hint::{assert_unchecked, unreachable_unchecked},
simd::{u8x32, Simd},
};
use tinyvec::ArrayVec;

#[inline(always)]
Expand Down Expand Up @@ -82,6 +85,20 @@ static mut NODES: [ArrayVec<[u16; MAX_CONNECTIONS]>; 26 * 26] =
unsafe fn parse(mut input: &[u8]) {
NODES.fill(ArrayVec::from_array_empty([0; MAX_CONNECTIONS]));

while input.len() >= 32 {
let block = u8x32::from_array(input[..32].try_into().unwrap());
let block = block - Simd::splat(b'a');
for i in 0..5 {
let lhs = 26 * block[i * 6] as u16 + block[i * 6 + 1] as u16;
let rhs = 26 * block[i * 6 + 3] as u16 + block[i * 6 + 4] as u16;

let None = NODES[lhs as usize].try_push(rhs) else { unreachable_unchecked() };
let None = NODES[rhs as usize].try_push(lhs) else { unreachable_unchecked() };
}

input = &input[30..];
}

while !input.is_empty() {
assert_unchecked(input.len() >= 6);
let lhs = 26 * (input[0] - b'a') as u16 + (input[1] - b'a') as u16;
Expand Down

0 comments on commit 808cca4

Please sign in to comment.