[][src]Struct treelike::example::LinTree

pub struct LinTree<'a, T> { /* fields omitted */ }

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.

Methods

impl<'a, T> LinTree<'a, T>[src]

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

Trait Implementations

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

type Content = &'a T

The content of the current node. Read more

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. Read more

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

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

fn left(self) -> Option<Self>[src]

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

fn right(self) -> Option<Self>[src]

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

fn first(self) -> Self::Content[src]

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

fn last(self) -> Self::Content[src]

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

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

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

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

like callback_dft but the parents content is visited before the children's. Read more

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

Like callback_bft but allows filtering, thereby disallowing some optimizations. Read more

Important traits for DFT<T, F>
fn iter_dft<F: FilterBuilder<Self>>(self, filter: F) -> DFT<Self, F>[src]

Important traits for DFTP<T, F>
fn iter_dft_pre<F: FilterBuilder<Self>>(self, filter: F) -> DFTP<Self, F>[src]

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

impl<'a, T: Debug> Debug for LinTree<'a, T>[src]

impl<'a, T> Copy for LinTree<'a, T>[src]

impl<'a, T> Clone for LinTree<'a, T>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

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

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

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

Blanket Implementations

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> Into<U> for T where
    U: From<T>, 
[src]

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

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.

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.