pub enum TreeNode<T: Terminal, F: Function> {
Terminal(T),
Function(F, Vec<TreeNode<T, F>>),
}Expand description
A node in a GP tree
Variants§
Implementations§
Source§impl<T: Terminal, F: Function> TreeNode<T, F>
impl<T: Terminal, F: Function> TreeNode<T, F>
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Check if this is a terminal node
Sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Check if this is a function node
Sourcepub fn depth(&self) -> usize
pub fn depth(&self) -> usize
Get the depth of this subtree.
Uses an explicit work stack rather than recursion so that pathologically deep trees cannot overflow the call stack (see the module note on deep trees).
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Get the number of nodes in this subtree.
Uses an explicit work stack rather than recursion (see the module note on deep trees).
Sourcepub fn get_subtree(&self, path: &[usize]) -> Option<&Self>
pub fn get_subtree(&self, path: &[usize]) -> Option<&Self>
Get a subtree at the given path
Sourcepub fn get_subtree_mut(&mut self, path: &[usize]) -> Option<&mut Self>
pub fn get_subtree_mut(&mut self, path: &[usize]) -> Option<&mut Self>
Get a mutable subtree at the given path
Sourcepub fn replace_subtree(&mut self, path: &[usize], new_subtree: Self) -> bool
pub fn replace_subtree(&mut self, path: &[usize], new_subtree: Self) -> bool
Replace a subtree at the given path
Sourcepub fn terminal_positions(&self) -> Vec<Vec<usize>>
pub fn terminal_positions(&self) -> Vec<Vec<usize>>
Get all terminal positions
Sourcepub fn function_positions(&self) -> Vec<Vec<usize>>
pub fn function_positions(&self) -> Vec<Vec<usize>>
Get all function positions
Trait Implementations§
Source§impl<'de, T: Terminal, F: Function> Deserialize<'de> for TreeNode<T, F>
impl<'de, T: Terminal, F: Function> Deserialize<'de> for TreeNode<T, F>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: Terminal, F: Function> Drop for TreeNode<T, F>
impl<T: Terminal, F: Function> Drop for TreeNode<T, F>
Source§fn drop(&mut self)
fn drop(&mut self)
Stack-safe teardown (EV-60).
The compiler-generated drop glue for a recursive enum like TreeNode
recurses one stack frame per level, so dropping a pathologically deep tree
would overflow the stack. This impl instead frees the subtree with an
explicit work stack. It takes each node’s children out with
std::mem::take (leaving an empty Vec behind) — which is permitted
under Drop, unlike moving a field out of self by value (E0509). Since
every node’s children Vec is emptied before that node is dropped,
the reentrant Drop::drop invoked when the node itself is freed always
finds an empty Vec and returns in O(1); no deep recursion occurs.
impl<T: PartialEq + Terminal, F: PartialEq + Function> StructuralPartialEq for TreeNode<T, F>
Auto Trait Implementations§
impl<T, F> Freeze for TreeNode<T, F>
impl<T, F> RefUnwindSafe for TreeNode<T, F>where
T: RefUnwindSafe,
F: RefUnwindSafe,
impl<T, F> Send for TreeNode<T, F>
impl<T, F> Sync for TreeNode<T, F>
impl<T, F> Unpin for TreeNode<T, F>
impl<T, F> UnsafeUnpin for TreeNode<T, F>where
T: UnsafeUnpin,
F: UnsafeUnpin,
impl<T, F> UnwindSafe for TreeNode<T, F>where
T: UnwindSafe,
F: UnwindSafe,
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Scalar for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.