day 8 part 1 fixed, regex is slow af to compile... dont do that in a loop.
This commit is contained in:
parent
e4ab3fb81e
commit
cab03a2ed5
3 changed files with 45 additions and 5 deletions
35
Cargo.lock
generated
35
Cargo.lock
generated
|
@ -78,6 +78,7 @@ dependencies = [
|
||||||
"reqwest-retry",
|
"reqwest-retry",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"static_init",
|
||||||
"tiktoken-rs",
|
"tiktoken-rs",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
@ -260,6 +261,12 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg_aliases"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.31"
|
version = "0.4.31"
|
||||||
|
@ -1571,6 +1578,34 @@ dependencies = [
|
||||||
"windows-sys 0.48.0",
|
"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]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
|
|
|
@ -27,6 +27,7 @@ tokio = { version = "1", features = ["full"] }
|
||||||
itertools = "0.12"
|
itertools = "0.12"
|
||||||
derive_builder = "0.12.0"
|
derive_builder = "0.12.0"
|
||||||
rayon = "1.8.0"
|
rayon = "1.8.0"
|
||||||
|
static_init = "1.0.3"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
part2 = []
|
part2 = []
|
||||||
|
|
|
@ -2,12 +2,16 @@ use aoc23::prelude::*;
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::{collections::HashMap, str::FromStr, time::Instant};
|
use std::{collections::HashMap, time::Instant};
|
||||||
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::error::Error;
|
use static_init::dynamic;
|
||||||
|
|
||||||
|
#[dynamic]
|
||||||
|
static RE_PARSE_NODE: Regex =
|
||||||
|
Regex::new(r"(?<id>\w{3}).*?(?<left>\w{3}).*?(?<right>\w{3})").expect("re_parse_node invalid");
|
||||||
|
|
||||||
#[derive(Debug, Builder, Clone)]
|
#[derive(Debug, Builder, Clone)]
|
||||||
struct Node<'a> {
|
struct Node<'a> {
|
||||||
|
@ -18,9 +22,9 @@ struct Node<'a> {
|
||||||
|
|
||||||
impl<'a> Node<'a> {
|
impl<'a> Node<'a> {
|
||||||
fn new(s: &'a str) -> Result<Self> {
|
fn new(s: &'a str) -> Result<Self> {
|
||||||
let re = Regex::new(r"(?<id>\w{3}).*?(?<left>\w{3}).*?(?<right>\w{3})")?
|
// let re = Regex::new(r"(?`<id>`\w{3}) = ((?`<left>`\w{3}), (?`<right>`\w{3}))")?
|
||||||
.captures(s)
|
// let re = Regex::new(r"(?`<id>`\w{3})._?(?`<left>`\w{3})._?(?`<right>`\w{3})")?
|
||||||
.expect("No match for regex");
|
let re = RE_PARSE_NODE.captures(s).expect("No match for regex");
|
||||||
Ok(NodeBuilder::default()
|
Ok(NodeBuilder::default()
|
||||||
.id(re.name("id").expect("no id").as_str())
|
.id(re.name("id").expect("no id").as_str())
|
||||||
.left(re.name("left").expect("no left").as_str())
|
.left(re.name("left").expect("no left").as_str())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue