binary-tree-core-0.rs/src/base_context.rs

69 lines
2.2 KiB
Rust

use crate::{NodeRef, NodeRefContainer};
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum BinaryTreeDirection {
LEFT,
RIGHT,
}
pub trait BinaryTreeRootGetter: NodeRefContainer {
fn getRoot(&self) -> Option<Self::NodeRef>;
}
pub trait BinaryTreeRootSetter: NodeRefContainer {
fn xSetRoot(&mut self, newRoot: Option<Self::NodeRef>) {
match newRoot {
None => self.clearRoot(),
Some(nn) => self.setRoot(nn),
}
}
fn setRoot(&mut self, newRoot: Self::NodeRef);
fn clearRoot(&mut self);
}
pub trait BinaryTreeChildrenGetterContext: NodeRefContainer {
fn getLeftChild(&self, node: Self::NodeRef) -> Option<Self::NodeRef>;
fn getRightChild(&self, node: Self::NodeRef) -> Option<Self::NodeRef>;
}
pub trait BinaryTreeParentGetterContext: NodeRefContainer {
fn getParent(&self, node: Self::NodeRef) -> Option<Self::NodeRef>;
}
pub unsafe trait BinaryTreeChildrenSetterContext: NodeRefContainer {
fn xSetLeftChild(&mut self, node: Self::NodeRef, newChild: Option<Self::NodeRef>) {
match newChild {
None => self.clearLeftChild(node),
Some(nn) => self.setLeftChild(node, nn),
}
}
fn xSetRightChild(&mut self, node: Self::NodeRef, newChild: Option<Self::NodeRef>) {
match newChild {
None => self.clearLeftChild(node),
Some(nn) => self.setRightChild(node, nn),
}
}
fn setLeftChild(&mut self, node: Self::NodeRef, newChild: Self::NodeRef);
fn setRightChild(&mut self, node: Self::NodeRef, newChild: Self::NodeRef);
fn clearLeftChild(&mut self, node: Self::NodeRef);
fn clearRightChild(&mut self, node: Self::NodeRef);
}
pub unsafe trait BinaryTreeParentSetterContext: NodeRefContainer {
fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option<Self::NodeRef>) {
match newParent {
None => self.clearParent(node),
Some(nn) => self.setParent(node, nn),
}
}
fn setParent(&mut self, node: Self::NodeRef, newParent: Self::NodeRef);
fn clearParent(&mut self, node: Self::NodeRef);
}
pub trait BinaryTreeDirectionDispatcherClojure: NodeRefContainer {
fn determineDirection(&self, node: Self::NodeRef) -> Option<BinaryTreeDirection>;
}