diff --git a/Cargo.lock b/Cargo.lock index 5a94fa6..ace30be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,6 +78,7 @@ dependencies = [ "reqwest-retry", "serde", "serde_json", + "static_init", "tiktoken-rs", "tokio", ] @@ -260,6 +261,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chrono" version = "0.4.31" @@ -1571,6 +1578,34 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "static_init" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2a1c578e98c1c16fc3b8ec1328f7659a500737d7a0c6d625e73e830ff9c1f6" +dependencies = [ + "bitflags 1.3.2", + "cfg_aliases", + "libc", + "parking_lot 0.11.2", + "parking_lot_core 0.8.6", + "static_init_macro", + "winapi", +] + +[[package]] +name = "static_init_macro" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a2595fc3aa78f2d0e45dd425b22282dd863273761cc77780914b2cf3003acf" +dependencies = [ + "cfg_aliases", + "memchr", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "strsim" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index 64b77b0..20f1269 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ tokio = { version = "1", features = ["full"] } itertools = "0.12" derive_builder = "0.12.0" rayon = "1.8.0" +static_init = "1.0.3" [features] part2 = [] diff --git a/src/bin/day8.rs b/src/bin/day8.rs index 9fb40ce..c4eb7ae 100644 --- a/src/bin/day8.rs +++ b/src/bin/day8.rs @@ -2,12 +2,16 @@ use aoc23::prelude::*; use derive_builder::Builder; use itertools::Itertools; use rayon::prelude::*; -use std::{collections::HashMap, str::FromStr, time::Instant}; +use std::{collections::HashMap, time::Instant}; extern crate regex; use regex::Regex; -use std::error::Error; +use static_init::dynamic; + +#[dynamic] +static RE_PARSE_NODE: Regex = + Regex::new(r"(?\w{3}).*?(?\w{3}).*?(?\w{3})").expect("re_parse_node invalid"); #[derive(Debug, Builder, Clone)] struct Node<'a> { @@ -18,9 +22,9 @@ struct Node<'a> { impl<'a> Node<'a> { fn new(s: &'a str) -> Result { - let re = Regex::new(r"(?\w{3}).*?(?\w{3}).*?(?\w{3})")? - .captures(s) - .expect("No match for regex"); + // let re = Regex::new(r"(?``\w{3}) = ((?``\w{3}), (?``\w{3}))")? + // let re = Regex::new(r"(?``\w{3})._?(?``\w{3})._?(?``\w{3})")? + let re = RE_PARSE_NODE.captures(s).expect("No match for regex"); Ok(NodeBuilder::default() .id(re.name("id").expect("no id").as_str()) .left(re.name("left").expect("no left").as_str())