[][src]Struct simple_tree::Tree

pub struct Tree<T: Clone> { /* fields omitted */ }

Stores all data and relationships between nodes

Methods

impl<T: Clone> Tree<T>[src]

pub fn new() -> Self[src]

Returns a new empty tree

pub fn is_valid(&self, node: NodeID) -> bool[src]

Check if a node id points to a valid, non-deleted node in the tree. Returns true if the node id is valid.

Arguments

  • node - the NodeID to check

pub fn delete(&mut self, node: NodeID) -> usize[src]

Mark a node in the tree, and all of its children as invalid. This allows the reuse of these indexes by other nodes created later. Returns the number of total nodes that were deleted.

pub fn add_root(&mut self, val: T) -> NodeID[src]

Add a root node and return its id

pub fn get(&self, node: NodeID) -> Option<&T>[src]

Returns the value for a node (if it exists)

pub fn get_mut(&mut self, node: NodeID) -> Option<&mut T>[src]

Returns the mutable value for a node (if it exists)

pub fn get_unchecked(&self, node: NodeID) -> &T[src]

Returns the value for a node, and panic if it doesn't exist

pub fn get_unchecked_mut(&mut self, node: NodeID) -> &mut T[src]

Returns the mutable value for a node, and panic if it doesn't exist

pub fn set(&mut self, node: NodeID, val: T)[src]

Set the value for a node (if it already exists)

pub fn add_child(&mut self, node: NodeID, val: T) -> Option<NodeID>[src]

Add a child to the node and return its id (if successful)

pub fn add_child_unchecked(&mut self, node: NodeID, val: T) -> NodeID[src]

Add a child to the node and return its id. Panics if node does not exist

pub fn children_ids_unchecked(&self, node: NodeID) -> &Vec<NodeID>[src]

Returns the children_ids for a node Panics if the node doesn't exist

pub fn root_ids(&self) -> &Vec<NodeID>[src]

Returns the root nodes of the tree

pub fn parent_id(&self, node: NodeID) -> Option<NodeID>[src]

Returns the parent id for the node

Important traits for DepthIter<'a, T>
pub fn iter_depth(&self) -> DepthIter<T>[src]

Returns a depth-first iterator This iterates a single node until a leaf is reached and then moves onto the next one

Important traits for BreadthIter<'a, T>
pub fn iter_breadth(&self) -> BreadthIter<T>[src]

Returns a breadth-first iterator This iterates an entire depth-level before moving onto the next deepest nodes

pub fn path(&self, node: NodeID) -> Vec<NodeID>[src]

Returns the node sequence from a root node to the given node

pub fn path_values_ref(&self, node: NodeID) -> Vec<&T>[src]

Returns references to values in the node sequence from a root node to the given node

pub fn path_values(&self, node: NodeID) -> Vec<T>[src]

Returns cloned values in the node sequence from a root node to the given node

Trait Implementations

impl<T: Clone> Clone for Tree<T>[src]

impl<T: Eq + Clone> Eq for Tree<T>[src]

impl<T: PartialEq + Clone> PartialEq<Tree<T>> for Tree<T>[src]

impl<T: Clone> StructuralEq for Tree<T>[src]

impl<T: Clone> StructuralPartialEq for Tree<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Tree<T> where
    T: RefUnwindSafe

impl<T> Send for Tree<T> where
    T: Send

impl<T> Sync for Tree<T> where
    T: Sync

impl<T> Unpin for Tree<T> where
    T: Unpin

impl<T> UnwindSafe for Tree<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.