advent_of_code_2024::day_19

Struct PatternTreeNode

source
struct PatternTreeNode {
    is_match: bool,
    w: Option<Rc<RefCell<PatternTreeNode>>>,
    u: Option<Rc<RefCell<PatternTreeNode>>>,
    b: Option<Rc<RefCell<PatternTreeNode>>>,
    r: Option<Rc<RefCell<PatternTreeNode>>>,
    g: Option<Rc<RefCell<PatternTreeNode>>>,
}
Expand description

A tree with branching factor of 5 for encoding the Set of all the possible patterns

Fields§

§is_match: bool§w: Option<Rc<RefCell<PatternTreeNode>>>§u: Option<Rc<RefCell<PatternTreeNode>>>§b: Option<Rc<RefCell<PatternTreeNode>>>§r: Option<Rc<RefCell<PatternTreeNode>>>§g: Option<Rc<RefCell<PatternTreeNode>>>

Implementations§

source§

impl PatternTreeNode

source

fn new() -> Self

Create an empty node

source

fn into_ref(self) -> Rc<RefCell<PatternTreeNode>>

helper for getting a reference to a node

source

fn get_node(&self, colour: &Colour) -> Option<Rc<RefCell<PatternTreeNode>>>

Helper to map a given colour to its child node if that exists

source

fn upsert_node(&mut self, colour: &Colour) -> Rc<RefCell<PatternTreeNode>>

Get a reference to the node for a colour, creating it if it doesn’t exist

source

fn insert(&mut self, colours: impl Iterator<Item = Colour>)

Recursively insert a pattern into the tree, creating the required nodes and marking the final node as terminating a pattern

source

fn matches(&self, design: &Vec<Colour>) -> bool

Does this tree match the design? he inner recursive function walks the tree matching the characters in the design, jumping back to the root node when patterns are matched

source

fn count_matches(&self, designs: &Vec<Vec<Colour>>) -> usize

Solves part 1 by counting the designs that the pattern tree can match

source

fn combinations(&self, design: &Vec<Colour>) -> usize

Similar to Self::matches, but doesn’t bail early when the root node matches the rest of the pattern, instead increments a count. Caches combinations that start at the root node for performance.

source

fn sum_combinations(&self, designs: &Vec<Vec<Colour>>) -> usize

Solves part, by calling Self::combinations for all designs and summing the result,

Trait Implementations§

source§

impl Clone for PatternTreeNode

source§

fn clone(&self) -> PatternTreeNode

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PatternTreeNode

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for PatternTreeNode

source§

fn eq(&self, other: &PatternTreeNode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for PatternTreeNode

source§

impl StructuralPartialEq for PatternTreeNode

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T