pub struct WalkMutOwned<'r, TP: TreeProperties + 'r, D = (), A = ()> { /* private fields */ }
Expand description
Walk owned mutable tree up and down
Some algorithms need to remember how they reached the current node via WalkedDirection
as D
.
When walking manually it might be useful to be able to store additional data via A
.
Implementations§
source§impl<'r, TP, D, A> WalkMutOwned<'r, TP, D, A>where
TP: TreeProperties,
impl<'r, TP, D, A> WalkMutOwned<'r, TP, D, A>where
TP: TreeProperties,
sourcepub fn current_mut(
&mut self,
) -> NodeOrTree<Option<&mut Node<TP>>, &mut Node<TP>>
pub fn current_mut( &mut self, ) -> NodeOrTree<Option<&mut Node<TP>>, &mut Node<TP>>
Current mutable node or tree
If you need the result to outlive the destruction of the WalkMutOwned
value, see into_current_mut
.
sourcepub fn into_current_mut(
self,
) -> NodeOrTree<Option<&'r mut Node<TP>>, &'r mut Node<TP>>
pub fn into_current_mut( self, ) -> NodeOrTree<Option<&'r mut Node<TP>>, &'r mut Node<TP>>
Extract mutable node or tree
Also see current_mut
source§impl<'r, TP> WalkMutOwned<'r, TP, WalkedDirection, ()>where
TP: TreeProperties + 'r,
impl<'r, TP> WalkMutOwned<'r, TP, WalkedDirection, ()>where
TP: TreeProperties + 'r,
sourcepub fn delete_current(&mut self) -> Option<WalkedDirection>
pub fn delete_current(&mut self) -> Option<WalkedDirection>
Delete current node (or tree)
Afterwards the current node is the previous parent node, which was replaced by the sibling, or the (empty) tree when removing the last node.
Returns what up_with
would have returned.
source§impl<'r, TP, A> WalkMutOwned<'r, TP, WalkedDirection, A>where
TP: TreeProperties + 'r,
impl<'r, TP, A> WalkMutOwned<'r, TP, WalkedDirection, A>where
TP: TreeProperties + 'r,
sourcepub fn delete_current_with(&mut self) -> Option<(WalkedDirection, A)>
pub fn delete_current_with(&mut self) -> Option<(WalkedDirection, A)>
Delete current node (or tree)
Afterwards the current node is the previous parent node, which was replaced by the sibling, or the (empty) tree when removing the last node.
Returns what up_with
would have returned.
sourcepub fn compact_if_empty<F>(&mut self, is_empty: F)
pub fn compact_if_empty<F>(&mut self, is_empty: F)
Remove empty leaf nodes if possible
A node is considered “empty” if the passed function considers its value empty.
Calls this if the current value might just have become empty.
Empty leafs can only be removed if the parent node is empty too, or both siblings are empty leafs (then the parent becomes a leaf node).
- if current node isn’t empty nothing changes
- if current node is an empty leaf node:
- parent and sibling shouldn’t have both been empty, as previous
compact_if_empty
calls would have cleaned that up - if parent is empty: remove leaf and parent, replace parent with sibling.
current
points to sibling afterwards. - if sibling is an empty leaf: make parent a leaf,
current
points to parent afterwards. - otherwise no tree changes, but
current
points to parent afterwards.
- parent and sibling shouldn’t have both been empty, as previous
- if current node has an empty leaf child node, remove that child node and current node.
I.e. replace current node with other child;
current
points to that child afterwards. Other child node shouldn’t be an empty leaf, as previouscompact_if_empty
calls would have cleaned that up. - if current points to tree or root node, clear tree if it is an empty node
source§impl<'r, TP, D, A> WalkMutOwned<'r, TP, D, A>
impl<'r, TP, D, A> WalkMutOwned<'r, TP, D, A>
sourcepub fn down_root_with(&mut self, add: A) -> bool
pub fn down_root_with(&mut self, add: A) -> bool
Walk down from tree to root node (if at tree and not empty)
sourcepub fn down_left_with(&mut self, add: A) -> bool
pub fn down_left_with(&mut self, add: A) -> bool
Walk down to left node if present and not currently at tree
sourcepub fn down_right_with(&mut self, add: A) -> bool
pub fn down_right_with(&mut self, add: A) -> bool
Walk down to right node if present and not currently at tree
source§impl<'r, TP, D> WalkMutOwned<'r, TP, D, ()>
impl<'r, TP, D> WalkMutOwned<'r, TP, D, ()>
sourcepub fn down_root(&mut self) -> bool
pub fn down_root(&mut self) -> bool
Walk down from tree to root node (if at tree and not empty)
sourcepub fn down_left(&mut self) -> bool
pub fn down_left(&mut self) -> bool
Walk down to left node if present and not currently at tree
sourcepub fn down_right(&mut self) -> bool
pub fn down_right(&mut self) -> bool
Walk down to right node if present and not currently at tree
source§impl<'r, TP, D> WalkMutOwned<'r, TP, D>
impl<'r, TP, D> WalkMutOwned<'r, TP, D>
sourcepub fn path(&mut self, key: TP::Key) -> WalkMutOwnedPath<'r, '_, TP, D>
pub fn path(&mut self, key: TP::Key) -> WalkMutOwnedPath<'r, '_, TP, D>
Start iterator to walk to deepest node that is a prefix of the target key
While consuming the iterator the stack is updated with the position of the returned nodes.
When self
was in a mismatching subtree (i.e. not a prefix of the target key) before
the iterator won’t find anything.
sourcepub fn goto_insert(&mut self, key: &TP::Key) -> Option<InsertPosition>
pub fn goto_insert(&mut self, key: &TP::Key) -> Option<InsertPosition>
Walk to node where we’d have to insert key at
Returns None
if tree is empty.
source§impl<'r, TP, D> WalkMutOwned<'r, TP, D>
impl<'r, TP, D> WalkMutOwned<'r, TP, D>
source§impl<'r, TP> WalkMutOwned<'r, TP, WalkedDirection, ()>where
TP: TreeProperties + 'r,
impl<'r, TP> WalkMutOwned<'r, TP, WalkedDirection, ()>where
TP: TreeProperties + 'r,
sourcepub fn into_iter_pre_order(self) -> IterMutOwnedPreOrder<'r, TP> ⓘ
pub fn into_iter_pre_order(self) -> IterMutOwnedPreOrder<'r, TP> ⓘ
Convert into iterator traversing depth-first pre-order
sourcepub fn next_pre_order(&mut self) -> Option<&mut Node<TP>>
pub fn next_pre_order(&mut self) -> Option<&mut Node<TP>>
Tree traversal: depth-first pre-order
sourcepub fn into_iter_in_order(self) -> IterMutOwnedInOrder<'r, TP> ⓘ
pub fn into_iter_in_order(self) -> IterMutOwnedInOrder<'r, TP> ⓘ
Convert into iterator traversing depth-first in-order
sourcepub fn next_in_order(&mut self) -> Option<&mut Node<TP>>
pub fn next_in_order(&mut self) -> Option<&mut Node<TP>>
Tree traversal: depth-first in-order
sourcepub fn into_iter_post_order(self) -> IterMutOwnedPostOrder<'r, TP> ⓘ
pub fn into_iter_post_order(self) -> IterMutOwnedPostOrder<'r, TP> ⓘ
Convert into iterator traversing depth-first post-order
sourcepub fn next_post_order(&mut self) -> Option<&mut Node<TP>>
pub fn next_post_order(&mut self) -> Option<&mut Node<TP>>
Tree traversal: depth-first post-order
sourcepub fn into_iter_leafs(self) -> IterMutOwnedLeaf<'r, TP> ⓘ
pub fn into_iter_leafs(self) -> IterMutOwnedLeaf<'r, TP> ⓘ
Convert into iterator over all leafs
sourcepub fn into_iter_full_leafs(self) -> IterMutOwnedLeafFull<'r, TP> ⓘ
pub fn into_iter_full_leafs(self) -> IterMutOwnedLeafFull<'r, TP> ⓘ
Convert into iterator over all leafs and uncovered parts