Stub of swap_context
This commit is contained in:
parent
f63e012aea
commit
1f14f14e36
@ -6,3 +6,4 @@ pub mod base_context;
|
||||
pub mod directed_context;
|
||||
pub mod parent2node_clojure;
|
||||
pub mod relation_context;
|
||||
mod swap_context;
|
||||
|
||||
236
src/swap_context/context.rs
Normal file
236
src/swap_context/context.rs
Normal file
@ -0,0 +1,236 @@
|
||||
use crate::NodeRefContainer;
|
||||
use crate::base_context::BinaryTreeDirection;
|
||||
|
||||
pub unsafe trait BinaryTreeSwapContext: NodeRefContainer {
|
||||
fn swapNeighbors(
|
||||
&mut self,
|
||||
grandparent: Option<(Self::NodeRef, BinaryTreeDirection)>,
|
||||
parent: Self::NodeRef,
|
||||
parent2child: BinaryTreeDirection,
|
||||
child: Self::NodeRef,
|
||||
);
|
||||
|
||||
fn swapNeighbors_root_dyn(
|
||||
&mut self,
|
||||
parent: Self::NodeRef,
|
||||
parent2child: BinaryTreeDirection,
|
||||
child: Self::NodeRef,
|
||||
) {
|
||||
match parent2child {
|
||||
BinaryTreeDirection::LEFT => self.swapNeighbors_root_left(parent, child),
|
||||
BinaryTreeDirection::RIGHT => self.swapNeighbors_root_right(parent, child),
|
||||
}
|
||||
}
|
||||
|
||||
fn swapNeighbors_left_dyn(
|
||||
&mut self,
|
||||
grandparent: Self::NodeRef,
|
||||
parent: Self::NodeRef,
|
||||
parent2child: BinaryTreeDirection,
|
||||
child: Self::NodeRef,
|
||||
) {
|
||||
match parent2child {
|
||||
BinaryTreeDirection::LEFT => self.swapNeighbors_left_left(grandparent, parent, child),
|
||||
BinaryTreeDirection::RIGHT => self.swapNeighbors_left_right(grandparent, parent, child),
|
||||
}
|
||||
}
|
||||
|
||||
fn swapNeighbors_right_dyn(
|
||||
&mut self,
|
||||
grandparent: Self::NodeRef,
|
||||
parent: Self::NodeRef,
|
||||
parent2child: BinaryTreeDirection,
|
||||
child: Self::NodeRef,
|
||||
) {
|
||||
match parent2child {
|
||||
BinaryTreeDirection::LEFT => self.swapNeighbors_right_left(grandparent, parent, child),
|
||||
BinaryTreeDirection::RIGHT => {
|
||||
self.swapNeighbors_right_right(grandparent, parent, child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn swapNeighbors_dyn_left(
|
||||
&mut self,
|
||||
grandparent: Option<(Self::NodeRef, BinaryTreeDirection)>,
|
||||
parent: Self::NodeRef,
|
||||
child: Self::NodeRef,
|
||||
) {
|
||||
match grandparent {
|
||||
None => self.swapNeighbors_root_left(parent, child),
|
||||
Some((g, BinaryTreeDirection::LEFT)) => self.swapNeighbors_left_left(g, parent, child),
|
||||
Some((g, BinaryTreeDirection::RIGHT)) => {
|
||||
self.swapNeighbors_right_left(g, parent, child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn swapNeighbors_dyn_right(
|
||||
&mut self,
|
||||
grandparent: Option<(Self::NodeRef, BinaryTreeDirection)>,
|
||||
parent: Self::NodeRef,
|
||||
child: Self::NodeRef,
|
||||
) {
|
||||
match grandparent {
|
||||
None => self.swapNeighbors_root_right(parent, child),
|
||||
Some((g, BinaryTreeDirection::LEFT)) => self.swapNeighbors_left_right(g, parent, child),
|
||||
Some((g, BinaryTreeDirection::RIGHT)) => {
|
||||
self.swapNeighbors_right_right(g, parent, child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn swapNeighbors_root_left(&mut self, parent: Self::NodeRef, child: Self::NodeRef);
|
||||
|
||||
fn swapNeighbors_root_right(&mut self, parent: Self::NodeRef, child: Self::NodeRef);
|
||||
|
||||
fn swapNeighbors_left_left(
|
||||
&mut self,
|
||||
grandparent: Self::NodeRef,
|
||||
parent: Self::NodeRef,
|
||||
child: Self::NodeRef,
|
||||
);
|
||||
|
||||
fn swapNeighbors_left_right(
|
||||
&mut self,
|
||||
grandparent: Self::NodeRef,
|
||||
parent: Self::NodeRef,
|
||||
child: Self::NodeRef,
|
||||
);
|
||||
|
||||
fn swapNeighbors_right_left(
|
||||
&mut self,
|
||||
grandparent: Self::NodeRef,
|
||||
parent: Self::NodeRef,
|
||||
child: Self::NodeRef,
|
||||
);
|
||||
|
||||
fn swapNeighbors_right_right(
|
||||
&mut self,
|
||||
grandparent: Self::NodeRef,
|
||||
parent: Self::NodeRef,
|
||||
child: Self::NodeRef,
|
||||
);
|
||||
|
||||
fn swapDistant_dyn_left(
|
||||
&mut self,
|
||||
parent1: Option<(Self::NodeRef, BinaryTreeDirection)>,
|
||||
node1: Self::NodeRef,
|
||||
parent2: Self::NodeRef,
|
||||
node2: Self::NodeRef,
|
||||
) {
|
||||
match parent1 {
|
||||
None => self.swapDistant_root_left(node1, parent2, node2),
|
||||
Some((g, BinaryTreeDirection::LEFT)) => {
|
||||
self.swapDistant_left_left(g, node1, parent2, node2)
|
||||
}
|
||||
Some((g, BinaryTreeDirection::RIGHT)) => {
|
||||
self.swapDistant_right_left(g, node1, parent2, node2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn swapDistant_dyn_right(
|
||||
&mut self,
|
||||
parent1: Option<(Self::NodeRef, BinaryTreeDirection)>,
|
||||
node1: Self::NodeRef,
|
||||
parent2: Self::NodeRef,
|
||||
node2: Self::NodeRef,
|
||||
) {
|
||||
match parent1 {
|
||||
None => self.swapDistant_root_right(node1, parent2, node2),
|
||||
Some((g, BinaryTreeDirection::LEFT)) => {
|
||||
self.swapDistant_left_right(g, node1, parent2, node2)
|
||||
}
|
||||
Some((g, BinaryTreeDirection::RIGHT)) => {
|
||||
self.swapDistant_right_right(g, node1, parent2, node2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn swapDistant_root_dyn(
|
||||
&mut self,
|
||||
node1: Self::NodeRef,
|
||||
parent2: (Self::NodeRef, BinaryTreeDirection),
|
||||
node2: Self::NodeRef,
|
||||
) {
|
||||
match parent2.1 {
|
||||
BinaryTreeDirection::LEFT => self.swapDistant_root_left(node1, parent2.0, node2),
|
||||
BinaryTreeDirection::RIGHT => self.swapDistant_root_right(node1, parent2.0, node2),
|
||||
}
|
||||
}
|
||||
|
||||
fn swapDistant_left_dyn(
|
||||
&mut self,
|
||||
parent1: Self::NodeRef,
|
||||
node1: Self::NodeRef,
|
||||
parent2: (Self::NodeRef, BinaryTreeDirection),
|
||||
node2: Self::NodeRef,
|
||||
) {
|
||||
match parent2.1 {
|
||||
BinaryTreeDirection::LEFT => {
|
||||
self.swapDistant_left_left(parent1, node1, parent2.0, node2)
|
||||
}
|
||||
BinaryTreeDirection::RIGHT => {
|
||||
self.swapDistant_left_right(parent1, node1, parent2.0, node2)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn swapDistant_right_dyn(
|
||||
&mut self,
|
||||
parent1: Self::NodeRef,
|
||||
node1: Self::NodeRef,
|
||||
parent2: (Self::NodeRef, BinaryTreeDirection),
|
||||
node2: Self::NodeRef,
|
||||
) {
|
||||
match parent2.1 {
|
||||
BinaryTreeDirection::LEFT => {
|
||||
self.swapDistant_right_left(parent1, node1, parent2.0, node2)
|
||||
}
|
||||
BinaryTreeDirection::RIGHT => {
|
||||
self.swapDistant_right_right(parent1, node1, parent2.0, node2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn swapDistant_root_left(
|
||||
&mut self,
|
||||
node1: Self::NodeRef,
|
||||
parent2: Self::NodeRef,
|
||||
node2: Self::NodeRef,
|
||||
);
|
||||
fn swapDistant_root_right(
|
||||
&mut self,
|
||||
node1: Self::NodeRef,
|
||||
parent2: Self::NodeRef,
|
||||
node2: Self::NodeRef,
|
||||
);
|
||||
fn swapDistant_left_left(
|
||||
&mut self,
|
||||
parent1: Self::NodeRef,
|
||||
node1: Self::NodeRef,
|
||||
parent2: Self::NodeRef,
|
||||
node2: Self::NodeRef,
|
||||
);
|
||||
fn swapDistant_left_right(
|
||||
&mut self,
|
||||
parent1: Self::NodeRef,
|
||||
node1: Self::NodeRef,
|
||||
parent2: Self::NodeRef,
|
||||
node2: Self::NodeRef,
|
||||
);
|
||||
fn swapDistant_right_left(
|
||||
&mut self,
|
||||
parent1: Self::NodeRef,
|
||||
node1: Self::NodeRef,
|
||||
parent2: Self::NodeRef,
|
||||
node2: Self::NodeRef,
|
||||
);
|
||||
fn swapDistant_right_right(
|
||||
&mut self,
|
||||
parent1: Self::NodeRef,
|
||||
node1: Self::NodeRef,
|
||||
parent2: Self::NodeRef,
|
||||
node2: Self::NodeRef,
|
||||
);
|
||||
}
|
||||
1
src/swap_context/mod.rs
Normal file
1
src/swap_context/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
mod context;
|
||||
Loading…
Reference in New Issue
Block a user