Skip to content

Commit

Permalink
day19: ahash -> fxhash, Vec -> ArrayVec
Browse files Browse the repository at this point in the history
  • Loading branch information
pedantic79 committed Jan 3, 2024
1 parent b29d287 commit 81508a4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/day19.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use std::ops::Range;

use ahash::{HashMap, HashMapExt};
use ahash::HashMapExt;
use aoc_runner_derive::{aoc, aoc_generator};
use arrayvec::ArrayVec;
use nom::{
branch::alt,
bytes::complete::{tag, take_until1, take_while1},
character::complete::{newline, one_of},
combinator::{map, value},
multi::separated_list0,
IResult,
};
use rustc_hash::FxHashMap as HashMap;

use crate::common::nom::{fold_separated_list0, nom_lines, nom_usize, process_input};

Expand Down Expand Up @@ -107,7 +108,7 @@ fn parse_jump(s: &str) -> IResult<&str, Jump> {

#[derive(Debug)]
pub struct Workflow {
rules: Vec<(usize, char, usize, Jump)>,
rules: ArrayVec<(usize, char, usize, Jump), 4>,
default: Jump,
}

Expand All @@ -127,10 +128,17 @@ fn parse_rule(s: &str) -> IResult<&str, (usize, char, usize, Jump)> {
Ok((s, (xmas, op, n, jump)))
}

fn parse_arrayvec_parse_rule(s: &str) -> IResult<&str, ArrayVec<(usize, char, usize, Jump), 4>> {
fold_separated_list0(tag(","), parse_rule, ArrayVec::new, |mut v, x| {
v.push(x);
v
})(s)
}

fn parse_workflow(s: &str) -> IResult<&str, (String, Workflow)> {
let (s, name) = take_until1("{")(s)?;
let (s, _) = tag("{")(s)?;
let (s, rules) = separated_list0(tag(","), parse_rule)(s)?;
let (s, rules) = parse_arrayvec_parse_rule(s)?;
let (s, _) = tag(",")(s)?;
let (s, default) = parse_jump(s)?;
let (s, _) = tag("}")(s)?;
Expand Down

0 comments on commit 81508a4

Please sign in to comment.