Struct easy_tree::Tree

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

A tree structure containing nodes.

Implementations§

source§

impl<T> Tree<T>

source

pub fn new() -> Self

Creates a new empty tree.

source

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

Adds a new node with the given data to the tree and returns its index. The nodes added with this method will be disconnected from the tree, so use it only for the root node. For adding children, use the add_child method.

source

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

Adds a child node with the given data to the specified parent node and returns the child’s index.

source

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

Adds a child node with the given data to the root node and returns the child’s index.

source

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

Returns a reference to the data of the node at the given index, or None if the index is out of bounds.

source

pub fn get_unchecked(&self, index: usize) -> &T

Returns a reference to the data of the node at the given index without bounds checking.

source

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

Returns a mutable reference to the data of the node at the given index, or None if the index is out of bounds.

source

pub fn get_unchecked_mut(&mut self, index: usize) -> &mut T

Returns a mutable reference to the data of the node at the given index without bounds checking.

source

pub fn parent_index_unchecked(&self, index: usize) -> Option<usize>

Returns the index of the parent node of the node at the given index, or None if the node has no parent.

source

pub fn children(&self, index: usize) -> &[usize]

Returns a slice of the indices of the children of the node at the given index.

source

pub fn traverse<'a, S>( &'a self, before_processing_children: impl FnMut(usize, &'a T, &mut S), after_processing_the_subtree: impl FnMut(usize, &'a T, &mut S), s: &mut S )

Walks the tree recursively, applying the given functions before and after processing the children of each node.

source

pub fn iter(&self) -> impl Iterator<Item = (usize, &T)>

Returns an iterator over the indices and data of the nodes in the tree.

source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (usize, &mut T)>

Returns a mutable iterator over the indices and data of the nodes in the tree.

source

pub fn is_empty(&self) -> bool

Returns true if the tree contains no nodes.

source

pub fn len(&self) -> usize

Returns the number of nodes in the tree.

source

pub fn clear(&mut self)

Removes all nodes from the tree.

source§

impl<T: Send + Sync> Tree<T>

source

pub fn par_iter(&self) -> impl ParallelIterator<Item = (usize, &T)>

Returns a parallel iterator over the indices and data of the nodes in the tree.

source

pub fn par_iter_mut(&mut self) -> impl ParallelIterator<Item = (usize, &mut T)>

Returns a mutable parallel iterator over the indices and data of the nodes in the tree.

Trait Implementations§

source§

impl<T: Clone> Clone for Tree<T>

source§

fn clone(&self) -> Tree<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Default for Tree<T>

source§

fn default() -> Self

Returns the “default value” for a type. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.