Trait binary_tree::NodeMut [] [src]

pub trait NodeMut: Node + Sized {
    type NodePtr: Sized + DerefMut<Target=Self>;
    fn detach_left(&mut self) -> Option<Self::NodePtr>;
    fn detach_right(&mut self) -> Option<Self::NodePtr>;
    fn insert_left(&mut self, tree: Option<Self::NodePtr>) -> Option<Self::NodePtr>;
    fn insert_right(&mut self, tree: Option<Self::NodePtr>) -> Option<Self::NodePtr>;
    fn value_owned(self) -> Self::Value;

    fn rotate_left(&mut self) -> Result<()()> { ... }
    fn rotate_right(&mut self) -> Result<()()> { ... }
    fn walk_mut<FI, FS, FO>(&mut self, step_in: FI, stop: FS, step_out: FO) where FI: FnMut(&mut Self) -> WalkAction, FS: FnOnce(&mut Self), FO: FnMut(&mut Self, WalkAction) { ... }
    fn insert_before<F>(&mut self, new_node: Self::NodePtr, step_out: F) where F: FnMut(&mut Self, WalkAction) { ... }
    fn extract<FF, FE, FX>(&mut self, finder: FF, extractor: FE, exiter: FX) -> Option<Self::NodePtr> where FF: FnMut(&mut Self) -> WalkAction, FE: FnOnce(&mut Self, &mut Option<Self::NodePtr>), FX: FnMut(&mut Self, WalkAction) { ... }
    fn try_remove<F>(&mut self, step_out: F) -> Option<Self::NodePtr> where F: FnMut(&mut Self, WalkAction) { ... }
}

Mutating methods on a Binary Tree node.

Associated Types

type NodePtr: Sized + DerefMut<Target=Self>

Required Methods

fn detach_left(&mut self) -> Option<Self::NodePtr>

Try to detach the left sub-tree

fn detach_right(&mut self) -> Option<Self::NodePtr>

Try to detach the right sub-tree

fn insert_left(&mut self, tree: Option<Self::NodePtr>) -> Option<Self::NodePtr>

Replace the left subtree with tree and return the old one.

fn insert_right(&mut self, tree: Option<Self::NodePtr>) -> Option<Self::NodePtr>

Replace the right subtree with tree and return the old one.

fn value_owned(self) -> Self::Value

Consume a Node and return its value

Provided Methods

fn rotate_left(&mut self) -> Result<()()>

Try to rotate the tree left if right subtree exists

fn rotate_right(&mut self) -> Result<()()>

Try to rotate the tree right if left subtree exists

fn walk_mut<FI, FS, FO>(&mut self, step_in: FI, stop: FS, step_out: FO) where FI: FnMut(&mut Self) -> WalkAction, FS: FnOnce(&mut Self), FO: FnMut(&mut Self, WalkAction)

Walks down the tree by detaching subtrees, then up reattaching them back. step_in should guide the path taken, stop will be called on the node where either step_in returned Stop or it was not possible to proceed. Then step_out will be called for each node, except the final one, along the way.

fn insert_before<F>(&mut self, new_node: Self::NodePtr, step_out: F) where F: FnMut(&mut Self, WalkAction)

Insert new_node in-order before self. step_out will be invoked for all nodes in path from (excluding) the point of insertion, to (including) self, unless self is the point of insertion.

fn extract<FF, FE, FX>(&mut self, finder: FF, extractor: FE, exiter: FX) -> Option<Self::NodePtr> where FF: FnMut(&mut Self) -> WalkAction, FE: FnOnce(&mut Self, &mut Option<Self::NodePtr>), FX: FnMut(&mut Self, WalkAction)

Extract a node found by finder. This can be used in conjuction with try_remove to remove any node except the root. See CountTree::remove for an example implementation.

fn try_remove<F>(&mut self, step_out: F) -> Option<Self::NodePtr> where F: FnMut(&mut Self, WalkAction)

Replace this node with one of its descendant, returns None if it has no children.

Implementors