diff --git a/src/context.rs b/src/context.rs index 8d23329..10b0f9e 100644 --- a/src/context.rs +++ b/src/context.rs @@ -7,21 +7,26 @@ pub trait BinaryTreeRootGetter: NodeRefContainer { } pub trait BinaryTreeRootSetter: NodeRefContainer { - fn xSetRoot(&mut self, newRoot: Option); + fn xSetRoot(&mut self, newRoot: Option) { + match newRoot { + None => self.clearRoot(), + Some(nn) => self.setRoot(nn), + } + } fn setRoot(&mut self, newRoot: Self::NodeRef); fn clearRoot(&mut self); } -pub trait BinaryTreeDownWalker: NodeRefContainer { +pub trait BinaryTreeChildrenGetterContext: NodeRefContainer { fn getLeftChild(&self, node: Self::NodeRef) -> Option; fn getRightChild(&self, node: Self::NodeRef) -> Option; } -pub trait BinaryTreeUpWalker: NodeRefContainer { +pub trait BinaryTreeParentGetterContext: NodeRefContainer { fn getParent(&self, node: Self::NodeRef) -> Option; } -pub unsafe trait BinaryTreeDownBuilder: NodeRefContainer { +pub unsafe trait BinaryTreeChildrenSetterContext: NodeRefContainer { fn xSetLeftChild(&mut self, node: Self::NodeRef, newChild: Option) { match newChild { None => self.clearLeftChild(node), @@ -42,7 +47,7 @@ pub unsafe trait BinaryTreeDownBuilder: NodeRefContainer { fn clearRightChild(&mut self, node: Self::NodeRef); } -pub unsafe trait BinaryTreeBuilder: BinaryTreeDownBuilder { +pub unsafe trait BinaryTreeParentSetterContext: NodeRefContainer { fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option) { match newParent { None => self.clearParent(node), diff --git a/src/directed/context.rs b/src/directed/context.rs index 430892d..b21102e 100644 --- a/src/directed/context.rs +++ b/src/directed/context.rs @@ -1,11 +1,11 @@ use crate::NodeRefContainer; -pub trait DirectedBinaryTreeDownWalker: NodeRefContainer { +pub trait DirectedBinaryTreeChildrenGetterContext: NodeRefContainer { fn getForwardChild(&self, node: Self::NodeRef) -> Option; fn getOppositeChild(&self, node: Self::NodeRef) -> Option; } -pub unsafe trait DirectedBinaryTreeDownBuilder: NodeRefContainer { +pub unsafe trait DirectedBinaryTreeChildrenSetterContext: NodeRefContainer { fn xSetForwardChild(&mut self, node: Self::NodeRef, newChild: Option) { match newChild { None => self.clearForwardChild(node), @@ -24,17 +24,4 @@ pub unsafe trait DirectedBinaryTreeDownBuilder: NodeRefContainer { fn clearForwardChild(&mut self, node: Self::NodeRef); fn clearOppositeChild(&mut self, node: Self::NodeRef); -} - -pub unsafe trait DirectedBinaryTreeBuilder: DirectedBinaryTreeDownBuilder { - fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option) { - match newParent { - None => self.clearParent(node), - Some(nn) => self.setParent(node, nn), - } - } - - fn setParent(&mut self, node: Self::NodeRef, newParent: Self::NodeRef); - - fn clearParent(&mut self, node: Self::NodeRef); -} +} \ No newline at end of file diff --git a/src/directed/impls/dynamic_wrapper.rs b/src/directed/impls/dynamic_wrapper.rs index 48eca08..fed70fc 100644 --- a/src/directed/impls/dynamic_wrapper.rs +++ b/src/directed/impls/dynamic_wrapper.rs @@ -1,9 +1,7 @@ use crate::NodeRefContainer; -use crate::context::{ - BinaryTreeBuilder, BinaryTreeDownBuilder, BinaryTreeDownWalker, BinaryTreeUpWalker, -}; +use crate::context::{BinaryTreeChildrenSetterContext, BinaryTreeChildrenGetterContext, BinaryTreeParentSetterContext, BinaryTreeParentGetterContext}; use crate::directed::context::{ - DirectedBinaryTreeBuilder, DirectedBinaryTreeDownBuilder, DirectedBinaryTreeDownWalker, + DirectedBinaryTreeChildrenSetterContext, DirectedBinaryTreeChildrenGetterContext, }; use crate::direction::BinaryTreeDirection; @@ -44,19 +42,19 @@ impl NodeRefContainer for DynamicDirectedBinaryTreeWrappe type NodeRef = Ctx::NodeRef; } -impl BinaryTreeUpWalker for DynamicDirectedBinaryTreeWrapper<&Ctx> { +impl BinaryTreeParentGetterContext for DynamicDirectedBinaryTreeWrapper<&Ctx> { fn getParent(&self, node: Self::NodeRef) -> Option { return self.ctx.getParent(node); } } -impl BinaryTreeUpWalker for DynamicDirectedBinaryTreeWrapper<&mut Ctx> { +impl BinaryTreeParentGetterContext for DynamicDirectedBinaryTreeWrapper<&mut Ctx> { fn getParent(&self, node: Self::NodeRef) -> Option { return self.ctx.getParent(node); } } -impl DirectedBinaryTreeDownWalker +impl DirectedBinaryTreeChildrenGetterContext for DynamicDirectedBinaryTreeWrapper<&Ctx> { fn getForwardChild(&self, node: Self::NodeRef) -> Option { @@ -74,7 +72,7 @@ impl DirectedBinaryTreeDownWalker } } -impl DirectedBinaryTreeDownWalker +impl DirectedBinaryTreeChildrenGetterContext for DynamicDirectedBinaryTreeWrapper<&mut Ctx> { fn getForwardChild(&self, node: Self::NodeRef) -> Option { @@ -92,7 +90,7 @@ impl DirectedBinaryTreeDownWalker } } -unsafe impl DirectedBinaryTreeDownBuilder +unsafe impl DirectedBinaryTreeChildrenSetterContext for DynamicDirectedBinaryTreeWrapper<&mut Ctx> { fn xSetForwardChild(&mut self, node: Self::NodeRef, newChild: Option) { @@ -138,7 +136,7 @@ unsafe impl DirectedBinaryTreeDownBuilder } } -unsafe impl DirectedBinaryTreeBuilder +unsafe impl BinaryTreeParentSetterContext for DynamicDirectedBinaryTreeWrapper<&mut Ctx> { fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option) { diff --git a/src/directed/impls/fixed_wrapper.rs b/src/directed/impls/fixed_wrapper.rs index 0d1e2b1..8ede3e3 100644 --- a/src/directed/impls/fixed_wrapper.rs +++ b/src/directed/impls/fixed_wrapper.rs @@ -1,9 +1,7 @@ use crate::NodeRefContainer; -use crate::context::{ - BinaryTreeBuilder, BinaryTreeDownBuilder, BinaryTreeDownWalker, BinaryTreeUpWalker, -}; +use crate::context::{BinaryTreeChildrenSetterContext, BinaryTreeChildrenGetterContext, BinaryTreeParentSetterContext, BinaryTreeParentGetterContext}; use crate::directed::context::{ - DirectedBinaryTreeBuilder, DirectedBinaryTreeDownBuilder, DirectedBinaryTreeDownWalker, + DirectedBinaryTreeChildrenSetterContext, DirectedBinaryTreeChildrenGetterContext, }; pub struct LeftDirectedBinaryTreeWalker { @@ -53,31 +51,31 @@ impl NodeRefContainer for RightDirectedBinaryTreeWalker<& type NodeRef = Ctx::NodeRef; } -impl BinaryTreeUpWalker for LeftDirectedBinaryTreeWalker<&Ctx> { +impl BinaryTreeParentGetterContext for LeftDirectedBinaryTreeWalker<&Ctx> { fn getParent(&self, node: Self::NodeRef) -> Option { return self.ctx.getParent(node); } } -impl BinaryTreeUpWalker for LeftDirectedBinaryTreeWalker<&mut Ctx> { +impl BinaryTreeParentGetterContext for LeftDirectedBinaryTreeWalker<&mut Ctx> { fn getParent(&self, node: Self::NodeRef) -> Option { return self.ctx.getParent(node); } } -impl BinaryTreeUpWalker for RightDirectedBinaryTreeWalker<&Ctx> { +impl BinaryTreeParentGetterContext for RightDirectedBinaryTreeWalker<&Ctx> { fn getParent(&self, node: Self::NodeRef) -> Option { return self.ctx.getParent(node); } } -impl BinaryTreeUpWalker for RightDirectedBinaryTreeWalker<&mut Ctx> { +impl BinaryTreeParentGetterContext for RightDirectedBinaryTreeWalker<&mut Ctx> { fn getParent(&self, node: Self::NodeRef) -> Option { return self.ctx.getParent(node); } } -impl DirectedBinaryTreeDownWalker +impl DirectedBinaryTreeChildrenGetterContext for LeftDirectedBinaryTreeWalker<&Ctx> { fn getForwardChild(&self, node: Self::NodeRef) -> Option { @@ -89,7 +87,7 @@ impl DirectedBinaryTreeDownWalker } } -impl DirectedBinaryTreeDownWalker +impl DirectedBinaryTreeChildrenGetterContext for LeftDirectedBinaryTreeWalker<&mut Ctx> { fn getForwardChild(&self, node: Self::NodeRef) -> Option { @@ -101,7 +99,7 @@ impl DirectedBinaryTreeDownWalker } } -impl DirectedBinaryTreeDownWalker +impl DirectedBinaryTreeChildrenGetterContext for RightDirectedBinaryTreeWalker<&Ctx> { fn getForwardChild(&self, node: Self::NodeRef) -> Option { @@ -113,7 +111,7 @@ impl DirectedBinaryTreeDownWalker } } -impl DirectedBinaryTreeDownWalker +impl DirectedBinaryTreeChildrenGetterContext for RightDirectedBinaryTreeWalker<&mut Ctx> { fn getForwardChild(&self, node: Self::NodeRef) -> Option { @@ -125,7 +123,7 @@ impl DirectedBinaryTreeDownWalker } } -unsafe impl DirectedBinaryTreeDownBuilder +unsafe impl DirectedBinaryTreeChildrenSetterContext for LeftDirectedBinaryTreeWalker<&mut Ctx> { fn xSetForwardChild(&mut self, node: Self::NodeRef, newChild: Option) { @@ -153,7 +151,7 @@ unsafe impl DirectedBinaryTreeDownBuilder } } -unsafe impl DirectedBinaryTreeDownBuilder +unsafe impl DirectedBinaryTreeChildrenSetterContext for RightDirectedBinaryTreeWalker<&mut Ctx> { fn xSetForwardChild(&mut self, node: Self::NodeRef, newChild: Option) { @@ -180,7 +178,7 @@ unsafe impl DirectedBinaryTreeDownBuilder self.ctx.clearLeftChild(node) } } -unsafe impl DirectedBinaryTreeBuilder +unsafe impl BinaryTreeParentSetterContext for LeftDirectedBinaryTreeWalker<&mut Ctx> { fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option) { @@ -196,7 +194,7 @@ unsafe impl DirectedBinaryTreeBuilder } } -unsafe impl DirectedBinaryTreeBuilder +unsafe impl BinaryTreeParentSetterContext for RightDirectedBinaryTreeWalker<&mut Ctx> { fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option) { diff --git a/src/directed/mod.rs b/src/directed/mod.rs index a89da1e..4a0aa2e 100644 --- a/src/directed/mod.rs +++ b/src/directed/mod.rs @@ -1,6 +1,5 @@ mod context; mod impls; -pub use context::DirectedBinaryTreeBuilder; -pub use context::DirectedBinaryTreeDownBuilder; -pub use context::DirectedBinaryTreeDownWalker; +pub use context::DirectedBinaryTreeChildrenSetterContext; +pub use context::DirectedBinaryTreeChildrenGetterContext; diff --git a/src/parent2node/clojure.rs b/src/parent2node/clojure.rs index eb6eff8..2d0cf1f 100644 --- a/src/parent2node/clojure.rs +++ b/src/parent2node/clojure.rs @@ -1,10 +1,10 @@ use crate::NodeRefContainer; -pub trait Parent2NodeGetter: NodeRefContainer { +pub trait Parent2NodeGetterClojure: NodeRefContainer { fn getChild(&self) -> Self::NodeRef; } -pub trait Parent2NodeSetter: NodeRefContainer { +pub trait Parent2NodeSetterClojure: NodeRefContainer { fn xSetChild(&mut self, newChild: Option) { match newChild { None => self.clearChild(), diff --git a/src/parent2node/fixed_wrapper.rs b/src/parent2node/fixed_wrapper.rs index ddbfaff..76ff0ce 100644 --- a/src/parent2node/fixed_wrapper.rs +++ b/src/parent2node/fixed_wrapper.rs @@ -1,9 +1,9 @@ use crate::NodeRefContainer; use crate::context::{ - BinaryTreeDownBuilder, BinaryTreeDownWalker, BinaryTreeRootGetter, BinaryTreeRootSetter, + BinaryTreeChildrenSetterContext, BinaryTreeChildrenGetterContext, BinaryTreeRootGetter, BinaryTreeRootSetter, }; -use crate::directed::{DirectedBinaryTreeDownBuilder, DirectedBinaryTreeDownWalker}; -use crate::parent2node::clojure::{Parent2NodeGetter, Parent2NodeSetter}; +use crate::directed::{DirectedBinaryTreeChildrenSetterContext, DirectedBinaryTreeChildrenGetterContext}; +use crate::parent2node::clojure::{Parent2NodeGetterClojure, Parent2NodeSetterClojure}; struct Parent2LeftChildContextWrapper { ctx: CtxRef, @@ -161,7 +161,7 @@ impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer type NodeRef = CtxRef::NodeRef; } -impl<'ctx, CtxRef: BinaryTreeDownWalker> Parent2NodeGetter +impl<'ctx, CtxRef: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure for Parent2LeftChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef> { fn getChild(&self) -> Self::NodeRef { @@ -169,7 +169,7 @@ impl<'ctx, CtxRef: BinaryTreeDownWalker> Parent2NodeGetter } } -impl<'ctx, CtxRef: BinaryTreeDownWalker> Parent2NodeGetter +impl<'ctx, CtxRef: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure for Parent2LeftChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> { fn getChild(&self) -> Self::NodeRef { @@ -177,7 +177,7 @@ impl<'ctx, CtxRef: BinaryTreeDownWalker> Parent2NodeGetter } } -impl<'ctx, CtxRef: BinaryTreeDownWalker> Parent2NodeGetter +impl<'ctx, CtxRef: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure for Parent2RightChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef> { fn getChild(&self) -> Self::NodeRef { @@ -185,7 +185,7 @@ impl<'ctx, CtxRef: BinaryTreeDownWalker> Parent2NodeGetter } } -impl<'ctx, CtxRef: BinaryTreeDownWalker> Parent2NodeGetter +impl<'ctx, CtxRef: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure for Parent2RightChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> { fn getChild(&self) -> Self::NodeRef { @@ -193,7 +193,7 @@ impl<'ctx, CtxRef: BinaryTreeDownWalker> Parent2NodeGetter } } -impl<'ctx, CtxRef: BinaryTreeRootGetter> Parent2NodeGetter +impl<'ctx, CtxRef: BinaryTreeRootGetter> Parent2NodeGetterClojure for Root2NodeContextWrapper<&'ctx CtxRef> { fn getChild(&self) -> Self::NodeRef { @@ -201,7 +201,7 @@ impl<'ctx, CtxRef: BinaryTreeRootGetter> Parent2NodeGetter } } -impl<'ctx, CtxRef: BinaryTreeRootGetter> Parent2NodeGetter +impl<'ctx, CtxRef: BinaryTreeRootGetter> Parent2NodeGetterClojure for Root2NodeContextWrapper<&'ctx mut CtxRef> { fn getChild(&self) -> Self::NodeRef { @@ -211,7 +211,7 @@ impl<'ctx, CtxRef: BinaryTreeRootGetter> Parent2NodeGetter -impl<'ctx, CtxRef: DirectedBinaryTreeDownWalker> Parent2NodeGetter +impl<'ctx, CtxRef: DirectedBinaryTreeChildrenGetterContext> Parent2NodeGetterClojure for Parent2ForwardChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef> { fn getChild(&self) -> Self::NodeRef { @@ -219,7 +219,7 @@ for Parent2ForwardChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef> } } -impl<'ctx, CtxRef: DirectedBinaryTreeDownWalker> Parent2NodeGetter +impl<'ctx, CtxRef: DirectedBinaryTreeChildrenGetterContext> Parent2NodeGetterClojure for Parent2ForwardChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> { fn getChild(&self) -> Self::NodeRef { @@ -227,7 +227,7 @@ for Parent2ForwardChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> } } -impl<'ctx, CtxRef: DirectedBinaryTreeDownWalker> Parent2NodeGetter +impl<'ctx, CtxRef: DirectedBinaryTreeChildrenGetterContext> Parent2NodeGetterClojure for Parent2OppositeChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef> { fn getChild(&self) -> Self::NodeRef { @@ -235,7 +235,7 @@ for Parent2OppositeChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef> } } -impl<'ctx, CtxRef: DirectedBinaryTreeDownWalker> Parent2NodeGetter +impl<'ctx, CtxRef: DirectedBinaryTreeChildrenGetterContext> Parent2NodeGetterClojure for Parent2OppositeChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> { fn getChild(&self) -> Self::NodeRef { @@ -243,7 +243,7 @@ for Parent2OppositeChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> } } -impl<'ctx, CtxRef: BinaryTreeDownBuilder> Parent2NodeSetter +impl<'ctx, CtxRef: BinaryTreeChildrenSetterContext> Parent2NodeSetterClojure for Parent2LeftChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> { fn xSetChild(&mut self, newChild: Option) { @@ -259,7 +259,7 @@ impl<'ctx, CtxRef: BinaryTreeDownBuilder> Parent2NodeSetter } } -impl<'ctx, CtxRef: BinaryTreeDownBuilder> Parent2NodeSetter +impl<'ctx, CtxRef: BinaryTreeChildrenSetterContext> Parent2NodeSetterClojure for Parent2RightChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> { fn xSetChild(&mut self, newChild: Option) { @@ -275,7 +275,7 @@ impl<'ctx, CtxRef: BinaryTreeDownBuilder> Parent2NodeSetter } } -impl<'ctx, CtxRef: BinaryTreeRootSetter> Parent2NodeSetter +impl<'ctx, CtxRef: BinaryTreeRootSetter> Parent2NodeSetterClojure for Root2NodeContextWrapper<&'ctx mut CtxRef> { fn xSetChild(&mut self, newChild: Option) { @@ -292,7 +292,7 @@ impl<'ctx, CtxRef: BinaryTreeRootSetter> Parent2NodeSetter } -impl<'ctx, CtxRef: DirectedBinaryTreeDownBuilder> Parent2NodeSetter +impl<'ctx, CtxRef: DirectedBinaryTreeChildrenSetterContext> Parent2NodeSetterClojure for Parent2ForwardChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> { fn xSetChild(&mut self, newChild: Option) { @@ -308,7 +308,7 @@ for Parent2ForwardChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> } } -impl<'ctx, CtxRef: DirectedBinaryTreeDownBuilder> Parent2NodeSetter +impl<'ctx, CtxRef: DirectedBinaryTreeChildrenSetterContext> Parent2NodeSetterClojure for Parent2OppositeChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef> { fn xSetChild(&mut self, newChild: Option) {