swapDistant & (x)setRelation
This commit is contained in:
parent
df0e32b7d5
commit
6e33460e63
@ -4,4 +4,4 @@ version = "0.0.0"
|
||||
edition = "2024"
|
||||
|
||||
[lints]
|
||||
rust = { nonstandard_style = "allow" }
|
||||
rust = { nonstandard_style = "allow", unsafe_op_in_unsafe_fn = "allow" }
|
||||
@ -1,2 +1,3 @@
|
||||
mod go_down;
|
||||
mod swap;
|
||||
mod set_relation;
|
||||
|
||||
24
src/algos/set_relation.rs
Normal file
24
src/algos/set_relation.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use crate::context::{BinaryTreeParentSetterContext, NodeRef};
|
||||
use crate::parent2node::clojure::{Parent2NodeSetterClojure, ParentProviderClojure};
|
||||
|
||||
pub unsafe fn setRelation<NodeRef: crate::context::NodeRef>(
|
||||
parent: &mut (
|
||||
impl Parent2NodeSetterClojure<NodeRef = NodeRef> + ParentProviderClojure<NodeRef = NodeRef>
|
||||
),
|
||||
child: NodeRef,
|
||||
) {
|
||||
parent.setChild(child.clone());
|
||||
parent.setAsParentOf(child);
|
||||
}
|
||||
|
||||
pub unsafe fn xSetRelation<NodeRef: crate::context::NodeRef>(
|
||||
parent: &mut (
|
||||
impl Parent2NodeSetterClojure<NodeRef = NodeRef> + ParentProviderClojure<NodeRef = NodeRef>
|
||||
),
|
||||
child: Option<NodeRef>,
|
||||
) {
|
||||
match child {
|
||||
None => parent.clearChild(),
|
||||
Some(c) => setRelation(parent, c),
|
||||
}
|
||||
}
|
||||
83
src/algos/swap/distant.rs
Normal file
83
src/algos/swap/distant.rs
Normal file
@ -0,0 +1,83 @@
|
||||
use crate::algos::set_relation::{setRelation, xSetRelation};
|
||||
use crate::context::BinaryTreeParentSetterContext;
|
||||
use crate::context::{
|
||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeParentGetterContext,
|
||||
};
|
||||
use crate::directed::{DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext};
|
||||
use crate::parent2node::clojure::{Parent2NodeSetterClojure, ParentProviderClojure};
|
||||
use crate::parent2node::fixed_wrapper::{
|
||||
FixedLeftParent2NodeGetterClojureFromContext as P2N_L,
|
||||
FixedRightParent2NodeGetterClojureFromContext as P2N_R,
|
||||
FixedForwardParent2NodeGetterClojureFromDirectedContext as P2N_F,
|
||||
FixedOppositeParent2NodeGetterClojureFromDirectedContext as P2N_O,
|
||||
};
|
||||
|
||||
unsafe fn swapDistant<
|
||||
Ctx: BinaryTreeChildrenGetterContext
|
||||
+ BinaryTreeChildrenSetterContext
|
||||
+ BinaryTreeParentGetterContext
|
||||
+ BinaryTreeParentSetterContext,
|
||||
>(
|
||||
ctx: &mut Ctx,
|
||||
parent1: &mut (
|
||||
impl Parent2NodeSetterClojure<NodeRef = Ctx::NodeRef>
|
||||
+ ParentProviderClojure<NodeRef = Ctx::NodeRef>
|
||||
),
|
||||
node1: Ctx::NodeRef,
|
||||
parent2: &mut (
|
||||
impl Parent2NodeSetterClojure<NodeRef = Ctx::NodeRef>
|
||||
+ ParentProviderClojure<NodeRef = Ctx::NodeRef>
|
||||
),
|
||||
node2: Ctx::NodeRef,
|
||||
) {
|
||||
setRelation(parent1, node2.clone());
|
||||
setRelation(parent2, node1.clone());
|
||||
|
||||
{
|
||||
let child1 = ctx.getLeftChild(node1.clone());
|
||||
let child2 = ctx.getLeftChild(node2.clone());
|
||||
xSetRelation(&mut P2N_L::wrap_mut(ctx, node2.clone()), child1);
|
||||
xSetRelation(&mut P2N_L::wrap_mut(ctx, node1.clone()), child2);
|
||||
}
|
||||
{
|
||||
let child1 = ctx.getRightChild(node1.clone());
|
||||
let child2 = ctx.getRightChild(node2.clone());
|
||||
xSetRelation(&mut P2N_R::wrap_mut(ctx, node2.clone()), child1);
|
||||
xSetRelation(&mut P2N_R::wrap_mut(ctx, node1.clone()), child2);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn swapDistantDirected<
|
||||
Ctx: DirectedBinaryTreeChildrenGetterContext
|
||||
+ DirectedBinaryTreeChildrenSetterContext
|
||||
+ BinaryTreeParentGetterContext
|
||||
+ BinaryTreeParentSetterContext,
|
||||
>(
|
||||
ctx: &mut Ctx,
|
||||
parent1: &mut (
|
||||
impl Parent2NodeSetterClojure<NodeRef = Ctx::NodeRef>
|
||||
+ ParentProviderClojure<NodeRef = Ctx::NodeRef>
|
||||
),
|
||||
node1: Ctx::NodeRef,
|
||||
parent2: &mut (
|
||||
impl Parent2NodeSetterClojure<NodeRef = Ctx::NodeRef>
|
||||
+ ParentProviderClojure<NodeRef = Ctx::NodeRef>
|
||||
),
|
||||
node2: Ctx::NodeRef,
|
||||
) {
|
||||
setRelation(parent1, node2.clone());
|
||||
setRelation(parent2, node1.clone());
|
||||
|
||||
{
|
||||
let child1 = ctx.getForwardChild(node1.clone());
|
||||
let child2 = ctx.getForwardChild(node2.clone());
|
||||
xSetRelation(&mut P2N_F::wrap_mut(ctx, node2.clone()), child1);
|
||||
xSetRelation(&mut P2N_F::wrap_mut(ctx, node1.clone()), child2);
|
||||
}
|
||||
{
|
||||
let child1 = ctx.getOppositeChild(node1.clone());
|
||||
let child2 = ctx.getOppositeChild(node2.clone());
|
||||
xSetRelation(&mut P2N_O::wrap_mut(ctx, node2.clone()), child1);
|
||||
xSetRelation(&mut P2N_O::wrap_mut(ctx, node1.clone()), child2);
|
||||
}
|
||||
}
|
||||
@ -1 +1,2 @@
|
||||
mod neighbors;
|
||||
mod distant;
|
||||
Loading…
Reference in New Issue
Block a user