Direction dispatcher
This commit is contained in:
parent
03b6925b0c
commit
58be1f0023
@ -1,4 +1,4 @@
|
|||||||
use crate::NodeRefContainer;
|
use crate::{NodeRef, NodeRefContainer};
|
||||||
|
|
||||||
pub enum BinaryTreeDirection {
|
pub enum BinaryTreeDirection {
|
||||||
LEFT,
|
LEFT,
|
||||||
@ -62,3 +62,7 @@ pub unsafe trait BinaryTreeParentSetterContext: NodeRefContainer {
|
|||||||
|
|
||||||
fn clearParent(&mut self, node: Self::NodeRef);
|
fn clearParent(&mut self, node: Self::NodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait BinaryTreeDirectionDispatcherClojure: NodeRefContainer {
|
||||||
|
fn determineDirection(&self, node: Self::NodeRef) -> Option<BinaryTreeDirection>;
|
||||||
|
}
|
||||||
@ -30,3 +30,7 @@ pub unsafe trait DirectedBinaryTreeChildrenSetterContext: NodeRefContainer {
|
|||||||
fn clearForwardChild(&mut self, node: Self::NodeRef);
|
fn clearForwardChild(&mut self, node: Self::NodeRef);
|
||||||
fn clearOppositeChild(&mut self, node: Self::NodeRef);
|
fn clearOppositeChild(&mut self, node: Self::NodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait DirectedBinaryTreeDirectionDispatcherClojure: NodeRefContainer {
|
||||||
|
fn determineDirection(&self, node: Self::NodeRef) -> Option<DirectedBinaryTreeDirection>;
|
||||||
|
}
|
||||||
@ -1,12 +1,16 @@
|
|||||||
use crate::NodeRefContainer;
|
use crate::NodeRefContainer;
|
||||||
use crate::base_context::{
|
use crate::base_context::{
|
||||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeDirection,
|
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeDirection,
|
||||||
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext,
|
BinaryTreeDirectionDispatcherClojure, BinaryTreeParentGetterContext,
|
||||||
|
BinaryTreeParentSetterContext,
|
||||||
};
|
};
|
||||||
use crate::base_context::{BinaryTreeRootGetter, BinaryTreeRootSetter};
|
use crate::base_context::{BinaryTreeRootGetter, BinaryTreeRootSetter};
|
||||||
use crate::directed_context::context::{
|
use crate::directed_context::context::{
|
||||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||||
};
|
};
|
||||||
|
use crate::directed_context::{
|
||||||
|
DirectedBinaryTreeDirection, DirectedBinaryTreeDirectionDispatcherClojure,
|
||||||
|
};
|
||||||
use crate::relation_context::{
|
use crate::relation_context::{
|
||||||
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
||||||
DirectedBinaryTreeRelationSetterContext,
|
DirectedBinaryTreeRelationSetterContext,
|
||||||
@ -188,3 +192,21 @@ unsafe impl<Ctx: BinaryTreeRelationSetterContext> DirectedBinaryTreeRelationSett
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<Ctx: BinaryTreeDirectionDispatcherClojure> DirectedBinaryTreeDirectionDispatcherClojure
|
||||||
|
for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx>
|
||||||
|
{
|
||||||
|
fn determineDirection(&self, node: Self::NodeRef) -> Option<DirectedBinaryTreeDirection> {
|
||||||
|
match self.ctx.determineDirection(node) {
|
||||||
|
None => return None,
|
||||||
|
Some(BinaryTreeDirection::LEFT) => match self.dir {
|
||||||
|
BinaryTreeDirection::LEFT => return Some(DirectedBinaryTreeDirection::FORWARD),
|
||||||
|
BinaryTreeDirection::RIGHT => return Some(DirectedBinaryTreeDirection::OPPOSITE),
|
||||||
|
},
|
||||||
|
Some(BinaryTreeDirection::RIGHT) => match self.dir {
|
||||||
|
BinaryTreeDirection::LEFT => return Some(DirectedBinaryTreeDirection::OPPOSITE),
|
||||||
|
BinaryTreeDirection::RIGHT => return Some(DirectedBinaryTreeDirection::FORWARD),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
use crate::NodeRefContainer;
|
use crate::NodeRefContainer;
|
||||||
use crate::base_context::{
|
use crate::base_context::{
|
||||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext,
|
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeDirection,
|
||||||
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter,
|
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter,
|
||||||
BinaryTreeRootSetter,
|
BinaryTreeRootSetter, BinaryTreeDirectionDispatcherClojure
|
||||||
};
|
};
|
||||||
use crate::directed_context::{
|
use crate::directed_context::{
|
||||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||||
|
DirectedBinaryTreeDirectionDispatcherClojure, DirectedBinaryTreeDirection
|
||||||
};
|
};
|
||||||
use crate::relation_context::{
|
use crate::relation_context::{
|
||||||
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
||||||
@ -23,17 +24,33 @@ pub struct FixedRightDirectedBinaryTreeContextFromContext<CtxRef> {
|
|||||||
ctx: CtxRef,
|
ctx: CtxRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
_mut_switch!(_ctx_wrapper_constructor!(FixedLeftDirectedBinaryTreeContextFromContext));
|
_mut_switch!(_ctx_wrapper_constructor!(
|
||||||
_mut_switch!(_ctx_wrapper_constructor!(FixedRightDirectedBinaryTreeContextFromContext));
|
FixedLeftDirectedBinaryTreeContextFromContext
|
||||||
|
));
|
||||||
|
_mut_switch!(_ctx_wrapper_constructor!(
|
||||||
|
FixedRightDirectedBinaryTreeContextFromContext
|
||||||
|
));
|
||||||
|
|
||||||
_mut_switch!(_delegate_node_ref!(FixedLeftDirectedBinaryTreeContextFromContext));
|
_mut_switch!(_delegate_node_ref!(
|
||||||
_mut_switch!(_delegate_node_ref!(FixedRightDirectedBinaryTreeContextFromContext));
|
FixedLeftDirectedBinaryTreeContextFromContext
|
||||||
|
));
|
||||||
|
_mut_switch!(_delegate_node_ref!(
|
||||||
|
FixedRightDirectedBinaryTreeContextFromContext
|
||||||
|
));
|
||||||
|
|
||||||
_mut_switch!(_delegate_root_getter!(FixedLeftDirectedBinaryTreeContextFromContext));
|
_mut_switch!(_delegate_root_getter!(
|
||||||
_mut_switch!(_delegate_root_getter!(FixedRightDirectedBinaryTreeContextFromContext));
|
FixedLeftDirectedBinaryTreeContextFromContext
|
||||||
|
));
|
||||||
|
_mut_switch!(_delegate_root_getter!(
|
||||||
|
FixedRightDirectedBinaryTreeContextFromContext
|
||||||
|
));
|
||||||
|
|
||||||
_mut_switch!(_delegate_parent_getter!(FixedLeftDirectedBinaryTreeContextFromContext));
|
_mut_switch!(_delegate_parent_getter!(
|
||||||
_mut_switch!(_delegate_parent_getter!(FixedRightDirectedBinaryTreeContextFromContext));
|
FixedLeftDirectedBinaryTreeContextFromContext
|
||||||
|
));
|
||||||
|
_mut_switch!(_delegate_parent_getter!(
|
||||||
|
FixedRightDirectedBinaryTreeContextFromContext
|
||||||
|
));
|
||||||
|
|
||||||
macro_rules! _children_get {
|
macro_rules! _children_get {
|
||||||
($name:ident $fwd:ident $op:ident $($mut:tt)? ) => {
|
($name:ident $fwd:ident $op:ident $($mut:tt)? ) => {
|
||||||
@ -166,3 +183,27 @@ _relation_set!(
|
|||||||
xSetRightRelation setRightRelation clearRightChild
|
xSetRightRelation setRightRelation clearRightChild
|
||||||
xSetLeftRelation setLeftRelation clearLeftChild
|
xSetLeftRelation setLeftRelation clearLeftChild
|
||||||
);
|
);
|
||||||
|
|
||||||
|
macro_rules! _direction_selector {
|
||||||
|
($name:ident $left:ident $right:ident $($mut:tt)?) => {
|
||||||
|
impl<Ctx: BinaryTreeDirectionDispatcherClojure> DirectedBinaryTreeDirectionDispatcherClojure
|
||||||
|
for $name<& $($mut)? Ctx>
|
||||||
|
{
|
||||||
|
fn determineDirection(&self, node: Self::NodeRef) -> Option<DirectedBinaryTreeDirection> {
|
||||||
|
match self.ctx.determineDirection(node) {
|
||||||
|
None => return None,
|
||||||
|
Some(BinaryTreeDirection::LEFT) => return Some(DirectedBinaryTreeDirection::$left),
|
||||||
|
Some(BinaryTreeDirection::RIGHT) => return Some(DirectedBinaryTreeDirection::$right)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
_mut_switch!(_direction_selector!(
|
||||||
|
FixedLeftDirectedBinaryTreeContextFromContext
|
||||||
|
FORWARD OPPOSITE
|
||||||
|
));
|
||||||
|
_mut_switch!(_direction_selector!(
|
||||||
|
FixedRightDirectedBinaryTreeContextFromContext
|
||||||
|
OPPOSITE FORWARD
|
||||||
|
));
|
||||||
|
|||||||
@ -1,12 +1,6 @@
|
|||||||
use crate::NodeRefContainer;
|
use crate::NodeRefContainer;
|
||||||
use crate::base_context::{
|
use crate::base_context::{BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeDirection, BinaryTreeDirectionDispatcherClojure, BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter, BinaryTreeRootSetter};
|
||||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext,
|
use crate::directed_context::{DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext, DirectedBinaryTreeDirection, DirectedBinaryTreeDirectionDispatcherClojure};
|
||||||
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter,
|
|
||||||
BinaryTreeRootSetter,
|
|
||||||
};
|
|
||||||
use crate::directed_context::{
|
|
||||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
|
||||||
};
|
|
||||||
use crate::relation_context::{
|
use crate::relation_context::{
|
||||||
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
||||||
DirectedBinaryTreeRelationSetterContext,
|
DirectedBinaryTreeRelationSetterContext,
|
||||||
@ -123,3 +117,23 @@ unsafe impl<Ctx: BinaryTreeParentSetterContext + DirectedBinaryTreeChildrenSette
|
|||||||
self.ctx.clearOppositeChild(parent);
|
self.ctx.clearOppositeChild(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! _direction_selector {
|
||||||
|
($name:ident $ctx:ident $enum:ident $($mut:tt)?) => {
|
||||||
|
impl<Ctx: $ctx> $ctx
|
||||||
|
for $name<& $($mut)? Ctx>
|
||||||
|
{
|
||||||
|
fn determineDirection(&self, node: Self::NodeRef) -> Option<$enum> {
|
||||||
|
return self.ctx.determineDirection(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
_mut_switch!(_direction_selector!(
|
||||||
|
BinaryTreeRelationContextFromBaseContextConverter
|
||||||
|
BinaryTreeDirectionDispatcherClojure BinaryTreeDirection
|
||||||
|
));
|
||||||
|
_mut_switch!(_direction_selector!(
|
||||||
|
DirectedBinaryTreeRelationContextFromBaseContextConverter
|
||||||
|
DirectedBinaryTreeDirectionDispatcherClojure DirectedBinaryTreeDirection
|
||||||
|
));
|
||||||
Loading…
Reference in New Issue
Block a user