Skip to main content

LinTree

Struct LinTree 

Source
pub struct LinTree<'a, T> { /* private fields */ }
Expand description

A tree whose nodes are stored in a backing slice.

The root node is at index 0 and the child nodes at index*2 + 1 and index*2 + 2.

Used in most examples, as it is easy to initialize.

Also shows a case where Treelike is implemented on the node itself, and not a reference to one. An important pitfall for that is that you may need to manually implement Copy and Clone as deriving them places Copy/Clone bounds on all type parameters (T in this case), even though that might not be necessary due to the content not being stored in-line, and therefore not being Copy/Cloned.

Implementations§

Source§

impl<'a, T> LinTree<'a, T>

Source

pub fn new(index: usize, slice: &'a [T]) -> Self

Trait Implementations§

Source§

impl<'a, T> Clone for LinTree<'a, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, T> Copy for LinTree<'a, T>

Source§

impl<'a, T: Debug> Debug for LinTree<'a, T>

Source§

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

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

impl<'a, T: Debug> Treelike for LinTree<'a, T>

Source§

fn callback_bft<CB: FnMut(Self::Content, usize)>(self, callback: CB)

This is also an example of overriding the Treelikes default implementations where necessary. LinTree can provide breadth-first traversal with a simple iteration

Source§

type Content = &'a T

The content of the current node. Read more
Source§

type ChildIterator = FlatMap<Zip<Chain<Once<usize>, Once<usize>>, Repeat<&'a [T]>>, Option<LinTree<'a, T>>, fn((usize, &'a [T])) -> Option<LinTree<'a, T>>>

You will have to specify the precise type you use for child iteration. This also implies that you have to move any closures into free standing functions. This is an Iterator over the children, not the contents of the children.
Source§

fn content(self) -> Self::Content

Has to produce this nodes Content.
Source§

fn children(self) -> Self::ChildIterator

Has to return an Iterator over all this nodes direct children. Read more
Source§

fn left(self) -> Option<Self>

Returns leftmost direct child of this Node. Mostly useful for binary trees.
Source§

fn right(self) -> Option<Self>

Returns rightmost direct child of this Node. Mostly useful for binary trees.
Source§

fn first(self) -> Self::Content

Recursively traverses the tree to the very first/leftmost node.
Source§

fn last(self) -> Self::Content

Recursively traverses the tree to the very last/rightmost node.
Source§

fn callback_dft<CB: FnMut(Self::Content, usize), F: FilterBuilder<Self>>( self, callback: CB, child_filter: F, )

Traverses the tree depth first, post order, i.e. children’s contents are visited before their parents. Read more
Source§

fn callback_dft_pre<CB: FnMut(Self::Content, usize), F: FilterBuilder<Self>>( self, callback: CB, child_filter: F, )

like callback_dft but the parents content is visited before the children’s.
Source§

fn callback_bft_filtered<CB: FnMut(Self::Content, usize), F: FilterBuilder<Self>>( self, callback: CB, filter: F, )

Like callback_bft but allows filtering, thereby disallowing some optimizations.
Source§

fn iter_dft<F: FilterBuilder<Self>>(self, filter: F) -> DFT<Self, F>

Source§

fn iter_dft_pre<F: FilterBuilder<Self>>(self, filter: F) -> DFTP<Self, F>

Source§

fn iter_bft<F: FilterBuilder<Self>>( self, filter: F, ) -> Chain<Once<Self::Content>, BFT<Self, F>>

Auto Trait Implementations§

§

impl<'a, T> Freeze for LinTree<'a, T>

§

impl<'a, T> RefUnwindSafe for LinTree<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for LinTree<'a, T>
where T: Sync,

§

impl<'a, T> Sync for LinTree<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for LinTree<'a, T>

§

impl<'a, T> UnsafeUnpin for LinTree<'a, T>

§

impl<'a, T> UnwindSafe for LinTree<'a, T>
where T: RefUnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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

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.