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§
Trait Implementations§
impl<'a, T> Copy for LinTree<'a, T>
Source§impl<'a, T: Debug> Treelike for LinTree<'a, T>
impl<'a, T: Debug> Treelike for LinTree<'a, T>
Source§fn callback_bft<CB: FnMut(Self::Content, usize)>(self, callback: CB)
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 ChildIterator = FlatMap<Zip<Chain<Once<usize>, Once<usize>>, Repeat<&'a [T]>>, Option<LinTree<'a, T>>, fn((usize, &'a [T])) -> Option<LinTree<'a, T>>>
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 children(self) -> Self::ChildIterator
fn children(self) -> Self::ChildIterator
Has to return an Iterator over all this nodes direct children. Read more
Source§fn left(self) -> Option<Self>
fn left(self) -> Option<Self>
Returns leftmost direct child of this Node. Mostly useful for binary trees.
Source§fn right(self) -> Option<Self>
fn right(self) -> Option<Self>
Returns rightmost direct child of this Node. Mostly useful for binary trees.
Source§fn first(self) -> Self::Content
fn first(self) -> Self::Content
Recursively traverses the tree to the very first/leftmost node.
Source§fn last(self) -> Self::Content
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,
)
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,
)
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,
)
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.
fn iter_dft<F: FilterBuilder<Self>>(self, filter: F) -> DFT<Self, F> ⓘ
fn iter_dft_pre<F: FilterBuilder<Self>>(self, filter: F) -> DFTP<Self, F> ⓘ
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more