Struct Tree

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

An n-ary index-based tree.

Implementations§

Source§

impl<T> Tree<T>

Source

pub fn new() -> Tree<T>

Creates an empty tree.

Source

pub fn len(&self) -> usize

The number of nodes in the tree.

Source

pub fn is_empty(&self) -> bool

Returns true iff the tree is empty.

Source

pub fn root(&self) -> Option<&Node<T>>

Returns this tree’s root, or None if it is empty.

Source

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

Gets a node by it’s index.

Source

pub fn node_iter<'a>(&'a self, start: &'a Node<T>) -> NodeIter<'_, T>

Iterates a subtree starting from a given node. Order is not guaranteed.

Source

pub fn node_iter_with_skip<'a>( &'a self, start: &'a Node<T>, skip: Vec<usize>, ) -> NodeIter<'_, T>

Iterates a subtree, skipping indices contained in skip.

Source

pub fn iter(&self) -> NodeIter<'_, T>

Returns a node iterator starting from the tree’s root. Order is not guaranteed.

Source

pub fn insert(&mut self, item: T, parent_idx: Option<usize>) -> usize

Inserts a new value in this tree as a child of the parent_idx node.

Trait Implementations§

Source§

impl<T: Debug> Debug for Tree<T>

Source§

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

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

impl<T> Default for Tree<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<Idx: SliceIndex<[Node<T>]>, T> Index<Idx> for Tree<T>

Source§

type Output = <Idx as SliceIndex<[Node<T>]>>::Output

The returned type after indexing.
Source§

fn index(&self, index: Idx) -> &Self::Output

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

impl<Idx: SliceIndex<[Node<T>]>, T> IndexMut<Idx> for Tree<T>

Source§

fn index_mut(&mut self, index: Idx) -> &mut Self::Output

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

impl<'a, T> IntoIterator for &'a Tree<T>

Source§

type Item = &'a Node<T>

The type of the elements being iterated over.
Source§

type IntoIter = NodeIter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Tree<T>

§

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§

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

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V