pub struct IndexTree<T> { /* private fields */ }
Expand description

A tree structure implemented using a single Vec and numerical identifiers (indices in the vector) instead of reference counted pointers like.

Implementations§

source§

impl<T> IndexTree<T>

source

pub fn new_root(data: T) -> IndexTree<T>

Creates a new empty Tree

source

pub fn count(&self) -> usize

Counts the number of nodes

source

pub fn get(&self, id: usize) -> Option<&Node<T>>

Returns a reference to the node with the given id if in the tree.

source

pub fn get_mut(&mut self, id: usize) -> Option<&mut Node<T>>

Returns a mutable reference to the node with the given id if in the tree.

source

pub fn add_child(&mut self, parent_id: usize, data: T) -> usize

Appends a new child to the node with parent_id, after existing children.

source

pub fn children(&self, id: usize) -> Children<'_, T>

Returns an iterator of IDs of a given node’s children.

source

pub fn find_child<F>(&self, parent_id: usize, f: F) -> Option<usize>
where F: Fn(&T) -> bool,

Finds the child specified by the predicate.

source

pub fn descendants(&self, id: usize) -> Descendants<'_, T>

An iterator of the IDs of a given node and its descendants, as a pre-order depth-first search where children are visited in insertion order.

Trait Implementations§

source§

impl<T> Index<usize> for IndexTree<T>

§

type Output = Node<T>

The returned type after indexing.
source§

fn index(&self, id: usize) -> &Node<T>

Performs the indexing (container[index]) operation. Read more
source§

impl<T> IndexMut<usize> for IndexTree<T>

source§

fn index_mut(&mut self, id: usize) -> &mut Node<T>

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for IndexTree<T>
where T: RefUnwindSafe,

§

impl<T> Send for IndexTree<T>
where T: Send,

§

impl<T> Sync for IndexTree<T>
where T: Sync,

§

impl<T> Unpin for IndexTree<T>
where T: Unpin,

§

impl<T> UnwindSafe for IndexTree<T>
where T: UnwindSafe,

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

source§

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

§

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>,

§

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.