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::context::BinaryTreeParentSetterContext;
|
||||||
use crate::directed::DirectedBinaryTreeChildrenGetterContext;
|
use crate::directed::DirectedBinaryTreeChildrenGetterContext;
|
||||||
use crate::directed::DirectedBinaryTreeChildrenSetterContext;
|
use crate::directed::DirectedBinaryTreeChildrenSetterContext;
|
||||||
use crate::parent2node::clojure::Parent2NodeSetterClojure;
|
use crate::parent2node::clojure::{Parent2NodeSetterClojure, ParentProviderClojure};
|
||||||
|
|
||||||
unsafe fn swapNeighbors<
|
unsafe fn swapNeighbors<
|
||||||
Ctx: DirectedBinaryTreeChildrenGetterContext
|
Ctx: DirectedBinaryTreeChildrenGetterContext
|
||||||
@ -11,13 +11,15 @@ unsafe fn swapNeighbors<
|
|||||||
+ BinaryTreeParentSetterContext,
|
+ BinaryTreeParentSetterContext,
|
||||||
>(
|
>(
|
||||||
ctx: &mut Ctx,
|
ctx: &mut Ctx,
|
||||||
parentLocation: &mut impl Parent2NodeSetterClojure<NodeRef = Ctx::NodeRef>,
|
grandparent: &mut (
|
||||||
grandparent: Option<Ctx::NodeRef>,
|
impl Parent2NodeSetterClojure<NodeRef = Ctx::NodeRef>
|
||||||
|
+ ParentProviderClojure<NodeRef = Ctx::NodeRef>
|
||||||
|
),
|
||||||
parent: Ctx::NodeRef,
|
parent: Ctx::NodeRef,
|
||||||
child: Ctx::NodeRef,
|
child: Ctx::NodeRef,
|
||||||
) {
|
) {
|
||||||
ctx.xSetParent(child.clone(), grandparent);
|
grandparent.setAsParentOf(child.clone());
|
||||||
parentLocation.setChild(child.clone());
|
grandparent.setChild(child.clone());
|
||||||
ctx.xSetForwardChild(parent.clone(), ctx.getForwardChild(child.clone()));
|
ctx.xSetForwardChild(parent.clone(), ctx.getForwardChild(child.clone()));
|
||||||
|
|
||||||
let oppositeChild = ctx.getOppositeChild(parent.clone());
|
let oppositeChild = ctx.getOppositeChild(parent.clone());
|
||||||
|
|||||||
@ -16,3 +16,7 @@ pub trait Parent2NodeSetterClojure: NodeRefContainer {
|
|||||||
|
|
||||||
fn clearChild(&mut self);
|
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::BinaryTreeDirection;
|
||||||
use crate::NodeRefContainer;
|
use crate::NodeRefContainer;
|
||||||
use crate::context::BinaryTreeRootGetter;
|
use crate::context::{BinaryTreeParentSetterContext, BinaryTreeRootGetter};
|
||||||
use crate::context::BinaryTreeRootSetter;
|
use crate::context::BinaryTreeRootSetter;
|
||||||
use crate::context::{BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext};
|
use crate::context::{BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext};
|
||||||
use crate::directed::{
|
use crate::directed::{
|
||||||
@ -124,7 +124,6 @@ macro_rules! _set_child {
|
|||||||
self.ctx.$d2_xset ((*self.node.node.deref()).clone(), newChild)
|
self.ctx.$d2_xset ((*self.node.node.deref()).clone(), newChild)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setChild(&mut self, newChild: Self::NodeRef) {
|
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)
|
self.ctx.$d2_set ((*self.node.node.deref()).clone(), newChild)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clearChild(&mut self) {
|
fn clearChild(&mut self) {
|
||||||
@ -150,23 +148,54 @@ macro_rules! _set_child {
|
|||||||
self.ctx.$d2_clear ((*self.node.node.deref()).clone())
|
self.ctx.$d2_clear ((*self.node.node.deref()).clone())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_set_child!(
|
_set_child!(
|
||||||
DynamicParent2NodeGetterClojureFromContext BinaryTreeChildrenSetterContext BinaryTreeDirection
|
DynamicParent2NodeGetterClojureFromContext
|
||||||
|
BinaryTreeChildrenSetterContext BinaryTreeDirection
|
||||||
LEFT xSetLeftChild setLeftChild clearLeftChild
|
LEFT xSetLeftChild setLeftChild clearLeftChild
|
||||||
RIGHT xSetRightChild setRightChild clearRightChild
|
RIGHT xSetRightChild setRightChild clearRightChild
|
||||||
);
|
);
|
||||||
_set_child!(
|
_set_child!(
|
||||||
DynamicParent2NodeGetterClojureFromDirectedContext DirectedBinaryTreeChildrenSetterContext DirectedBinaryTreeDirection
|
DynamicParent2NodeGetterClojureFromDirectedContext
|
||||||
|
DirectedBinaryTreeChildrenSetterContext DirectedBinaryTreeDirection
|
||||||
FORWARD xSetForwardChild setForwardChild clearForwardChild
|
FORWARD xSetForwardChild setForwardChild clearForwardChild
|
||||||
OPPOSITE xSetOppositeChild setOppositeChild clearOppositeChild
|
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 {
|
macro_rules! _drop {
|
||||||
($name:ident $($mut:tt)?) => {
|
($name:ident $($mut:tt)?) => {
|
||||||
impl<CtxRef, NodeRef> Drop for $name<CtxRef, NodeRef> {
|
impl<CtxRef, NodeRef> Drop for $name<CtxRef, NodeRef> {
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
use crate::NodeRefContainer;
|
use crate::NodeRefContainer;
|
||||||
use crate::context::{
|
use crate::context::{
|
||||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeRootGetter,
|
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext,
|
||||||
BinaryTreeRootSetter,
|
BinaryTreeParentSetterContext, BinaryTreeRootGetter, BinaryTreeRootSetter,
|
||||||
};
|
};
|
||||||
use crate::directed::{
|
use crate::directed::{
|
||||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||||
};
|
};
|
||||||
use crate::parent2node::clojure::{Parent2NodeGetterClojure, Parent2NodeSetterClojure};
|
use crate::parent2node::clojure::{
|
||||||
|
Parent2NodeGetterClojure, Parent2NodeSetterClojure, ParentProviderClojure,
|
||||||
|
};
|
||||||
|
|
||||||
macro_rules! _mut_switch {
|
macro_rules! _mut_switch {
|
||||||
($macro:tt $excl_mark:tt ( $($args:tt)+) ) => {
|
($macro:tt $excl_mark:tt ( $($args:tt)+) ) => {
|
||||||
@ -189,3 +191,28 @@ _set_child!(
|
|||||||
FixedOppositeParent2NodeGetterClojureFromDirectedContext
|
FixedOppositeParent2NodeGetterClojureFromDirectedContext
|
||||||
DirectedBinaryTreeChildrenSetterContext xSetOppositeChild setOppositeChild clearOppositeChild
|
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