Added to parent2node clojure ability to set stored node as parent of other node
This commit is contained in:
parent
67917161f5
commit
2136192cf1
@ -2,7 +2,7 @@ use crate::context::BinaryTreeParentGetterContext;
|
||||
use crate::context::BinaryTreeParentSetterContext;
|
||||
use crate::directed::DirectedBinaryTreeChildrenGetterContext;
|
||||
use crate::directed::DirectedBinaryTreeChildrenSetterContext;
|
||||
use crate::parent2node::clojure::Parent2NodeSetterClojure;
|
||||
use crate::parent2node::clojure::{Parent2NodeSetterClojure, ParentProviderClojure};
|
||||
|
||||
unsafe fn swapNeighbors<
|
||||
Ctx: DirectedBinaryTreeChildrenGetterContext
|
||||
@ -11,13 +11,15 @@ unsafe fn swapNeighbors<
|
||||
+ BinaryTreeParentSetterContext,
|
||||
>(
|
||||
ctx: &mut Ctx,
|
||||
parentLocation: &mut impl Parent2NodeSetterClojure<NodeRef = Ctx::NodeRef>,
|
||||
grandparent: Option<Ctx::NodeRef>,
|
||||
grandparent: &mut (
|
||||
impl Parent2NodeSetterClojure<NodeRef = Ctx::NodeRef>
|
||||
+ ParentProviderClojure<NodeRef = Ctx::NodeRef>
|
||||
),
|
||||
parent: Ctx::NodeRef,
|
||||
child: Ctx::NodeRef,
|
||||
) {
|
||||
ctx.xSetParent(child.clone(), grandparent);
|
||||
parentLocation.setChild(child.clone());
|
||||
grandparent.setAsParentOf(child.clone());
|
||||
grandparent.setChild(child.clone());
|
||||
ctx.xSetForwardChild(parent.clone(), ctx.getForwardChild(child.clone()));
|
||||
|
||||
let oppositeChild = ctx.getOppositeChild(parent.clone());
|
||||
|
||||
@ -16,3 +16,7 @@ pub trait Parent2NodeSetterClojure: NodeRefContainer {
|
||||
|
||||
fn clearChild(&mut self);
|
||||
}
|
||||
|
||||
pub trait ParentProviderClojure: NodeRefContainer {
|
||||
fn setAsParentOf(&mut self, child: Self::NodeRef);
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use super::clojure::Parent2NodeSetterClojure;
|
||||
use super::clojure::{Parent2NodeSetterClojure, ParentProviderClojure};
|
||||
use crate::BinaryTreeDirection;
|
||||
use crate::NodeRefContainer;
|
||||
use crate::context::BinaryTreeRootGetter;
|
||||
use crate::context::{BinaryTreeParentSetterContext, BinaryTreeRootGetter};
|
||||
use crate::context::BinaryTreeRootSetter;
|
||||
use crate::context::{BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext};
|
||||
use crate::directed::{
|
||||
@ -124,7 +124,6 @@ macro_rules! _set_child {
|
||||
self.ctx.$d2_xset ((*self.node.node.deref()).clone(), newChild)
|
||||
}
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
fn setChild(&mut self, newChild: Self::NodeRef) {
|
||||
@ -137,7 +136,6 @@ macro_rules! _set_child {
|
||||
self.ctx.$d2_set ((*self.node.node.deref()).clone(), newChild)
|
||||
}
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
fn clearChild(&mut self) {
|
||||
@ -150,23 +148,54 @@ macro_rules! _set_child {
|
||||
self.ctx.$d2_clear ((*self.node.node.deref()).clone())
|
||||
}
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_set_child!(
|
||||
DynamicParent2NodeGetterClojureFromContext BinaryTreeChildrenSetterContext BinaryTreeDirection
|
||||
DynamicParent2NodeGetterClojureFromContext
|
||||
BinaryTreeChildrenSetterContext BinaryTreeDirection
|
||||
LEFT xSetLeftChild setLeftChild clearLeftChild
|
||||
RIGHT xSetRightChild setRightChild clearRightChild
|
||||
);
|
||||
_set_child!(
|
||||
DynamicParent2NodeGetterClojureFromDirectedContext DirectedBinaryTreeChildrenSetterContext DirectedBinaryTreeDirection
|
||||
DynamicParent2NodeGetterClojureFromDirectedContext
|
||||
DirectedBinaryTreeChildrenSetterContext DirectedBinaryTreeDirection
|
||||
FORWARD xSetForwardChild setForwardChild clearForwardChild
|
||||
OPPOSITE xSetOppositeChild setOppositeChild clearOppositeChild
|
||||
);
|
||||
|
||||
|
||||
macro_rules! _set_as_parent_of {
|
||||
($name:ident $dir_enum_lbl:ident $d1_lbl:ident $d2_lbl:ident) => {
|
||||
impl<'ctx, Ctx: BinaryTreeParentSetterContext> ParentProviderClojure
|
||||
for $name<&'ctx mut Ctx, Ctx::NodeRef>
|
||||
{
|
||||
fn setAsParentOf(&mut self, child: Self::NodeRef) {
|
||||
match self.dir {
|
||||
None => self.ctx.clearParent(child),
|
||||
Some($dir_enum_lbl::$d1_lbl) => unsafe {
|
||||
self.ctx.setParent(child, (*self.node.node.deref()).clone())
|
||||
},
|
||||
Some($dir_enum_lbl::$d2_lbl) => unsafe {
|
||||
self.ctx.setParent(child, (*self.node.node.deref()).clone())
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_set_as_parent_of!(
|
||||
DynamicParent2NodeGetterClojureFromContext
|
||||
BinaryTreeDirection LEFT RIGHT
|
||||
);
|
||||
_set_as_parent_of!(
|
||||
DynamicParent2NodeGetterClojureFromDirectedContext
|
||||
DirectedBinaryTreeDirection FORWARD OPPOSITE
|
||||
);
|
||||
|
||||
macro_rules! _drop {
|
||||
($name:ident $($mut:tt)?) => {
|
||||
impl<CtxRef, NodeRef> Drop for $name<CtxRef, NodeRef> {
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
use crate::NodeRefContainer;
|
||||
use crate::context::{
|
||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeRootGetter,
|
||||
BinaryTreeRootSetter,
|
||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext,
|
||||
BinaryTreeParentSetterContext, BinaryTreeRootGetter, BinaryTreeRootSetter,
|
||||
};
|
||||
use crate::directed::{
|
||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||
};
|
||||
use crate::parent2node::clojure::{Parent2NodeGetterClojure, Parent2NodeSetterClojure};
|
||||
use crate::parent2node::clojure::{
|
||||
Parent2NodeGetterClojure, Parent2NodeSetterClojure, ParentProviderClojure,
|
||||
};
|
||||
|
||||
macro_rules! _mut_switch {
|
||||
($macro:tt $excl_mark:tt ( $($args:tt)+) ) => {
|
||||
@ -189,3 +191,28 @@ _set_child!(
|
||||
FixedOppositeParent2NodeGetterClojureFromDirectedContext
|
||||
DirectedBinaryTreeChildrenSetterContext xSetOppositeChild setOppositeChild clearOppositeChild
|
||||
);
|
||||
|
||||
macro_rules! _set_as_parent_of {
|
||||
($name:ident) => {
|
||||
impl<'ctx, Ctx: BinaryTreeParentSetterContext> ParentProviderClojure
|
||||
for $name<&'ctx mut Ctx, Ctx::NodeRef>
|
||||
{
|
||||
fn setAsParentOf(&mut self, child: Self::NodeRef) {
|
||||
self.ctx.setParent(child, self.node.clone())
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<'ctx, Ctx: BinaryTreeParentSetterContext> ParentProviderClojure
|
||||
for FixedRootParent2NodeGetterClojureFromContext<&'ctx mut Ctx>
|
||||
{
|
||||
fn setAsParentOf(&mut self, child: Self::NodeRef) {
|
||||
self.ctx.clearParent(child)
|
||||
}
|
||||
}
|
||||
|
||||
_set_as_parent_of!(FixedLeftParent2NodeGetterClojureFromContext);
|
||||
_set_as_parent_of!(FixedRightParent2NodeGetterClojureFromContext);
|
||||
_set_as_parent_of!(FixedForwardParent2NodeGetterClojureFromDirectedContext);
|
||||
_set_as_parent_of!(FixedOppositeParent2NodeGetterClojureFromDirectedContext);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user