Now node references is clone instead of copy (e.g. for Python's Py_IncRef) and node ref now is separate trait to forbid use of existing types
This commit is contained in:
parent
fbe424c276
commit
67917161f5
@ -11,14 +11,14 @@ fn goDown<Ctx: BinaryTreeChildrenGetterContext>(
|
||||
let mut p = root;
|
||||
match dir {
|
||||
BinaryTreeDirection::LEFT => loop {
|
||||
match ctx.getLeftChild(p) {
|
||||
match ctx.getLeftChild(p.clone()) {
|
||||
None => return p,
|
||||
Some(c) => p = c,
|
||||
}
|
||||
},
|
||||
|
||||
BinaryTreeDirection::RIGHT => loop {
|
||||
match ctx.getRightChild(p) {
|
||||
match ctx.getRightChild(p.clone()) {
|
||||
None => return p,
|
||||
Some(c) => p = c,
|
||||
}
|
||||
@ -34,14 +34,14 @@ fn goDownDirected<Ctx: DirectedBinaryTreeChildrenGetterContext>(
|
||||
let mut p = root;
|
||||
match dir {
|
||||
DirectedBinaryTreeDirection::FORWARD => loop {
|
||||
match ctx.getForwardChild(p) {
|
||||
match ctx.getForwardChild(p.clone()) {
|
||||
None => return p,
|
||||
Some(c) => p = c,
|
||||
}
|
||||
},
|
||||
|
||||
DirectedBinaryTreeDirection::OPPOSITE => loop {
|
||||
match ctx.getOppositeChild(p) {
|
||||
match ctx.getOppositeChild(p.clone()) {
|
||||
None => return p,
|
||||
Some(c) => p = c,
|
||||
}
|
||||
|
||||
@ -16,23 +16,23 @@ unsafe fn swapNeighbors<
|
||||
parent: Ctx::NodeRef,
|
||||
child: Ctx::NodeRef,
|
||||
) {
|
||||
ctx.xSetParent(child, grandparent);
|
||||
parentLocation.setChild(child);
|
||||
ctx.xSetForwardChild(parent, ctx.getForwardChild(child));
|
||||
ctx.xSetParent(child.clone(), grandparent);
|
||||
parentLocation.setChild(child.clone());
|
||||
ctx.xSetForwardChild(parent.clone(), ctx.getForwardChild(child.clone()));
|
||||
|
||||
let oppositeChild = ctx.getOppositeChild(parent);
|
||||
ctx.xSetOppositeChild(parent, ctx.getOppositeChild(child));
|
||||
ctx.xSetOppositeChild(child, oppositeChild);
|
||||
let oppositeChild = ctx.getOppositeChild(parent.clone());
|
||||
ctx.xSetOppositeChild(parent.clone(), ctx.getOppositeChild(child.clone()));
|
||||
ctx.xSetOppositeChild(child.clone(), oppositeChild);
|
||||
|
||||
if let Some(n) = ctx.getOppositeChild(child) {
|
||||
ctx.setParent(n, child)
|
||||
if let Some(n) = ctx.getOppositeChild(child.clone()) {
|
||||
ctx.setParent(n, child.clone())
|
||||
}
|
||||
if let Some(n) = ctx.getOppositeChild(parent) {
|
||||
ctx.setParent(n, parent)
|
||||
if let Some(n) = ctx.getOppositeChild(parent.clone()) {
|
||||
ctx.setParent(n, parent.clone())
|
||||
}
|
||||
if let Some(n) = ctx.getForwardChild(child) {
|
||||
ctx.setParent(n, parent)
|
||||
if let Some(n) = ctx.getForwardChild(child.clone()) {
|
||||
ctx.setParent(n, parent.clone())
|
||||
}
|
||||
ctx.setForwardChild(child, parent);
|
||||
ctx.setForwardChild(child.clone(), parent.clone());
|
||||
ctx.setParent(parent, child);
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
pub trait NodeRef: Sized + Clone {}
|
||||
|
||||
pub trait NodeRefContainer {
|
||||
type NodeRef: Sized + Copy;
|
||||
type NodeRef: NodeRef;
|
||||
}
|
||||
|
||||
pub trait BinaryTreeRootGetter: NodeRefContainer {
|
||||
|
||||
@ -82,10 +82,10 @@ macro_rules! _get_child {
|
||||
match self.dir {
|
||||
None => return self.ctx.getRoot(),
|
||||
Some($dir_enum_lbl::$d1_lbl) => unsafe {
|
||||
self.ctx.$d1_get (*self.node.node.deref())
|
||||
self.ctx.$d1_get ((*self.node.node.deref()).clone())
|
||||
},
|
||||
Some($dir_enum_lbl::$d2_lbl) => unsafe {
|
||||
self.ctx.$d2_get (*self.node.node.deref())
|
||||
self.ctx.$d2_get ((*self.node.node.deref()).clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -118,10 +118,10 @@ macro_rules! _set_child {
|
||||
match self.dir {
|
||||
None => self.ctx.xSetRoot(newChild),
|
||||
Some($dir_enum_lbl::$d1_lbl) => unsafe {
|
||||
self.ctx.$d1_xset (*self.node.node.deref(), newChild)
|
||||
self.ctx.$d1_xset ((*self.node.node.deref()).clone(), newChild)
|
||||
},
|
||||
Some($dir_enum_lbl::$d2_lbl) => unsafe {
|
||||
self.ctx.$d2_xset (*self.node.node.deref(), newChild)
|
||||
self.ctx.$d2_xset ((*self.node.node.deref()).clone(), newChild)
|
||||
}
|
||||
};
|
||||
return;
|
||||
@ -131,10 +131,10 @@ macro_rules! _set_child {
|
||||
match self.dir {
|
||||
None => self.ctx.setRoot(newChild),
|
||||
Some($dir_enum_lbl::$d1_lbl) => unsafe {
|
||||
self.ctx.$d1_set (*self.node.node.deref(), newChild)
|
||||
self.ctx.$d1_set ((*self.node.node.deref()).clone(), newChild)
|
||||
},
|
||||
Some($dir_enum_lbl::$d2_lbl) => unsafe {
|
||||
self.ctx.$d2_set (*self.node.node.deref(), newChild)
|
||||
self.ctx.$d2_set ((*self.node.node.deref()).clone(), newChild)
|
||||
}
|
||||
};
|
||||
return;
|
||||
@ -144,10 +144,10 @@ macro_rules! _set_child {
|
||||
match self.dir {
|
||||
None => self.ctx.clearRoot(),
|
||||
Some($dir_enum_lbl::$d1_lbl) => unsafe {
|
||||
self.ctx.$d1_clear (*self.node.node.deref())
|
||||
self.ctx.$d1_clear ((*self.node.node.deref()).clone())
|
||||
},
|
||||
Some($dir_enum_lbl::$d2_lbl) => unsafe {
|
||||
self.ctx.$d2_clear (*self.node.node.deref())
|
||||
self.ctx.$d2_clear ((*self.node.node.deref()).clone())
|
||||
}
|
||||
};
|
||||
return;
|
||||
|
||||
@ -100,7 +100,7 @@ macro_rules! _get_child {
|
||||
for $name <&'ctx $($mut)? Ctx, Ctx::NodeRef>
|
||||
{
|
||||
fn getChild(&self) -> Option<Self::NodeRef> {
|
||||
return self.ctx.$fn (self.node);
|
||||
return self.ctx.$fn (self.node.clone());
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -143,15 +143,15 @@ macro_rules! _set_child {
|
||||
($name:ident $ctx:ident $xset:ident $set:ident $clear:ident) => {
|
||||
impl<'ctx, Ctx: $ctx> Parent2NodeSetterClojure for $name<&'ctx mut Ctx, Ctx::NodeRef> {
|
||||
fn xSetChild(&mut self, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.$xset(self.node, newChild);
|
||||
self.ctx.$xset(self.node.clone(), newChild);
|
||||
}
|
||||
|
||||
fn setChild(&mut self, newChild: Self::NodeRef) {
|
||||
self.ctx.$set(self.node, newChild);
|
||||
self.ctx.$set(self.node.clone(), newChild);
|
||||
}
|
||||
|
||||
fn clearChild(&mut self) {
|
||||
self.ctx.$clear(self.node);
|
||||
self.ctx.$clear(self.node.clone());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user