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
impl PatternTreeNode
sourcefn into_ref(self) -> Rc<RefCell<PatternTreeNode>>
fn into_ref(self) -> Rc<RefCell<PatternTreeNode>>
helper for getting a reference to a node
sourcefn get_node(&self, colour: &Colour) -> Option<Rc<RefCell<PatternTreeNode>>>
fn get_node(&self, colour: &Colour) -> Option<Rc<RefCell<PatternTreeNode>>>
Helper to map a given colour to its child node if that exists
sourcefn upsert_node(&mut self, colour: &Colour) -> Rc<RefCell<PatternTreeNode>>
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
sourcefn insert(&mut self, colours: impl Iterator<Item = Colour>)
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
sourcefn matches(&self, design: &Vec<Colour>) -> bool
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
sourcefn count_matches(&self, designs: &Vec<Vec<Colour>>) -> usize
fn count_matches(&self, designs: &Vec<Vec<Colour>>) -> usize
Solves part 1 by counting the designs that the pattern tree can match
sourcefn combinations(&self, design: &Vec<Colour>) -> usize
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.
sourcefn sum_combinations(&self, designs: &Vec<Vec<Colour>>) -> usize
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
impl Clone for PatternTreeNode
source§fn clone(&self) -> PatternTreeNode
fn clone(&self) -> PatternTreeNode
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PatternTreeNode
impl Debug for PatternTreeNode
source§impl PartialEq for PatternTreeNode
impl PartialEq for PatternTreeNode
impl Eq for PatternTreeNode
impl StructuralPartialEq for PatternTreeNode
Auto Trait Implementations§
impl Freeze for PatternTreeNode
impl !RefUnwindSafe for PatternTreeNode
impl !Send for PatternTreeNode
impl !Sync for PatternTreeNode
impl Unpin for PatternTreeNode
impl !UnwindSafe for PatternTreeNode
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.