Reducing fixed context wrappers with macros
This commit is contained in:
parent
cbebfec06d
commit
6ce69a3ad5
@ -1,8 +1,18 @@
|
||||
use crate::NodeRefContainer;
|
||||
use crate::context::{BinaryTreeChildrenSetterContext, BinaryTreeChildrenGetterContext, BinaryTreeParentSetterContext, BinaryTreeParentGetterContext};
|
||||
use crate::directed::context::{
|
||||
DirectedBinaryTreeChildrenSetterContext, DirectedBinaryTreeChildrenGetterContext,
|
||||
use crate::context::{
|
||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext,
|
||||
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext,
|
||||
};
|
||||
use crate::directed::context::{
|
||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||
};
|
||||
|
||||
macro_rules! _mut_switch {
|
||||
($macro:tt $excl_mark:tt ( $($args:tt)+) ) => {
|
||||
$macro$excl_mark($($args)+);
|
||||
$macro$excl_mark($($args)+ mut);
|
||||
};
|
||||
}
|
||||
|
||||
pub struct LeftDirectedBinaryTreeWalker<CtxRef> {
|
||||
ctx: CtxRef,
|
||||
@ -12,175 +22,69 @@ pub struct RightDirectedBinaryTreeWalker<CtxRef> {
|
||||
ctx: CtxRef,
|
||||
}
|
||||
|
||||
impl<'ctx, Ctx: NodeRefContainer> LeftDirectedBinaryTreeWalker<&'ctx Ctx> {
|
||||
pub fn wrap(ctx: &'ctx Ctx) -> Self {
|
||||
macro_rules! _constructor {
|
||||
($name:ident $($mut:tt)?) => {
|
||||
impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx $($mut)? Ctx> {
|
||||
pub fn wrap(ctx: &'ctx $($mut)? Ctx) -> Self {
|
||||
return Self { ctx };
|
||||
}
|
||||
}
|
||||
impl<'ctx, Ctx: NodeRefContainer> LeftDirectedBinaryTreeWalker<&'ctx mut Ctx> {
|
||||
pub fn wrap(ctx: &'ctx mut Ctx) -> Self {
|
||||
return Self { ctx };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<'ctx, Ctx: NodeRefContainer> RightDirectedBinaryTreeWalker<&'ctx Ctx> {
|
||||
pub fn wrap(ctx: &'ctx Ctx) -> Self {
|
||||
return Self { ctx };
|
||||
_mut_switch!(_constructor!(LeftDirectedBinaryTreeWalker));
|
||||
_mut_switch!(_constructor!(RightDirectedBinaryTreeWalker));
|
||||
|
||||
macro_rules! _node_ref {
|
||||
($name:ident $($mut:tt)?) => {
|
||||
impl<Ctx: NodeRefContainer> NodeRefContainer for $name<& $($mut)? Ctx> {
|
||||
type NodeRef = Ctx::NodeRef;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<'ctx, Ctx: NodeRefContainer> RightDirectedBinaryTreeWalker<&'ctx mut Ctx> {
|
||||
pub fn wrap(ctx: &'ctx mut Ctx) -> Self {
|
||||
return Self { ctx };
|
||||
}
|
||||
}
|
||||
_mut_switch!(_node_ref!(LeftDirectedBinaryTreeWalker));
|
||||
_mut_switch!(_node_ref!(RightDirectedBinaryTreeWalker));
|
||||
|
||||
impl<Ctx: NodeRefContainer> NodeRefContainer for LeftDirectedBinaryTreeWalker<&Ctx> {
|
||||
type NodeRef = Ctx::NodeRef;
|
||||
}
|
||||
|
||||
impl<Ctx: NodeRefContainer> NodeRefContainer for LeftDirectedBinaryTreeWalker<&mut Ctx> {
|
||||
type NodeRef = Ctx::NodeRef;
|
||||
}
|
||||
|
||||
impl<Ctx: NodeRefContainer> NodeRefContainer for RightDirectedBinaryTreeWalker<&Ctx> {
|
||||
type NodeRef = Ctx::NodeRef;
|
||||
}
|
||||
|
||||
impl<Ctx: NodeRefContainer> NodeRefContainer for RightDirectedBinaryTreeWalker<&mut Ctx> {
|
||||
type NodeRef = Ctx::NodeRef;
|
||||
}
|
||||
|
||||
impl<Ctx: BinaryTreeParentGetterContext> BinaryTreeParentGetterContext for LeftDirectedBinaryTreeWalker<&Ctx> {
|
||||
macro_rules! _parent_get {
|
||||
($name:ident $($mut:tt)?) => {
|
||||
impl<Ctx: BinaryTreeParentGetterContext> BinaryTreeParentGetterContext
|
||||
for $name<& $($mut)? Ctx>
|
||||
{
|
||||
fn getParent(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getParent(node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx: BinaryTreeParentGetterContext> BinaryTreeParentGetterContext for LeftDirectedBinaryTreeWalker<&mut Ctx> {
|
||||
fn getParent(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getParent(node);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<Ctx: BinaryTreeParentGetterContext> BinaryTreeParentGetterContext for RightDirectedBinaryTreeWalker<&Ctx> {
|
||||
fn getParent(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getParent(node);
|
||||
}
|
||||
}
|
||||
_mut_switch!(_parent_get!(LeftDirectedBinaryTreeWalker));
|
||||
_mut_switch!(_parent_get!(RightDirectedBinaryTreeWalker));
|
||||
|
||||
impl<Ctx: BinaryTreeParentGetterContext> BinaryTreeParentGetterContext for RightDirectedBinaryTreeWalker<&mut Ctx> {
|
||||
fn getParent(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getParent(node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx: BinaryTreeChildrenGetterContext> DirectedBinaryTreeChildrenGetterContext
|
||||
for LeftDirectedBinaryTreeWalker<&Ctx>
|
||||
{
|
||||
macro_rules! _children_get {
|
||||
($name:ident $fwd:ident $op:ident $($mut:tt)? ) => {
|
||||
impl<Ctx: BinaryTreeChildrenGetterContext> DirectedBinaryTreeChildrenGetterContext
|
||||
for $name <& $($mut)? Ctx>
|
||||
{
|
||||
fn getForwardChild(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getLeftChild(node);
|
||||
return self.ctx.$fwd(node);
|
||||
}
|
||||
|
||||
fn getOppositeChild(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getRightChild(node);
|
||||
return self.ctx.$op(node);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<Ctx: BinaryTreeChildrenGetterContext> DirectedBinaryTreeChildrenGetterContext
|
||||
for LeftDirectedBinaryTreeWalker<&mut Ctx>
|
||||
{
|
||||
fn getForwardChild(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getLeftChild(node);
|
||||
}
|
||||
_mut_switch!(_children_get!(LeftDirectedBinaryTreeWalker getLeftChild getRightChild));
|
||||
_mut_switch!(_children_get!(RightDirectedBinaryTreeWalker getRightChild getLeftChild));
|
||||
|
||||
fn getOppositeChild(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getRightChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx: BinaryTreeChildrenGetterContext> DirectedBinaryTreeChildrenGetterContext
|
||||
for RightDirectedBinaryTreeWalker<&Ctx>
|
||||
{
|
||||
fn getForwardChild(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getRightChild(node);
|
||||
}
|
||||
|
||||
fn getOppositeChild(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getLeftChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx: BinaryTreeChildrenGetterContext> DirectedBinaryTreeChildrenGetterContext
|
||||
for RightDirectedBinaryTreeWalker<&mut Ctx>
|
||||
{
|
||||
fn getForwardChild(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getRightChild(node);
|
||||
}
|
||||
|
||||
fn getOppositeChild(&self, node: Self::NodeRef) -> Option<Self::NodeRef> {
|
||||
return self.ctx.getLeftChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<Ctx: BinaryTreeChildrenSetterContext> DirectedBinaryTreeChildrenSetterContext
|
||||
for LeftDirectedBinaryTreeWalker<&mut Ctx>
|
||||
{
|
||||
fn xSetForwardChild(&mut self, node: Self::NodeRef, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.xSetLeftChild(node, newChild)
|
||||
}
|
||||
|
||||
fn xSetOppositeChild(&mut self, node: Self::NodeRef, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.xSetRightChild(node, newChild)
|
||||
}
|
||||
|
||||
fn setForwardChild(&mut self, node: Self::NodeRef, newChild: Self::NodeRef) {
|
||||
self.ctx.setLeftChild(node, newChild)
|
||||
}
|
||||
|
||||
fn setOppositeChild(&mut self, node: Self::NodeRef, newChild: Self::NodeRef) {
|
||||
self.ctx.setRightChild(node, newChild)
|
||||
}
|
||||
|
||||
fn clearForwardChild(&mut self, node: Self::NodeRef) {
|
||||
self.ctx.clearLeftChild(node)
|
||||
}
|
||||
|
||||
fn clearOppositeChild(&mut self, node: Self::NodeRef) {
|
||||
self.ctx.clearRightChild(node)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<Ctx: BinaryTreeChildrenSetterContext> DirectedBinaryTreeChildrenSetterContext
|
||||
for RightDirectedBinaryTreeWalker<&mut Ctx>
|
||||
{
|
||||
fn xSetForwardChild(&mut self, node: Self::NodeRef, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.xSetRightChild(node, newChild)
|
||||
}
|
||||
|
||||
fn xSetOppositeChild(&mut self, node: Self::NodeRef, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.xSetLeftChild(node, newChild)
|
||||
}
|
||||
|
||||
fn setForwardChild(&mut self, node: Self::NodeRef, newChild: Self::NodeRef) {
|
||||
self.ctx.setRightChild(node, newChild)
|
||||
}
|
||||
|
||||
fn setOppositeChild(&mut self, node: Self::NodeRef, newChild: Self::NodeRef) {
|
||||
self.ctx.setLeftChild(node, newChild)
|
||||
}
|
||||
|
||||
fn clearForwardChild(&mut self, node: Self::NodeRef) {
|
||||
self.ctx.clearRightChild(node)
|
||||
}
|
||||
|
||||
fn clearOppositeChild(&mut self, node: Self::NodeRef) {
|
||||
self.ctx.clearLeftChild(node)
|
||||
}
|
||||
}
|
||||
unsafe impl<Ctx: BinaryTreeParentSetterContext> BinaryTreeParentSetterContext
|
||||
for LeftDirectedBinaryTreeWalker<&mut Ctx>
|
||||
{
|
||||
macro_rules! _parent_set {
|
||||
($name:ident) => {
|
||||
unsafe impl<Ctx: BinaryTreeParentSetterContext> BinaryTreeParentSetterContext
|
||||
for $name <&mut Ctx>
|
||||
{
|
||||
fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option<Self::NodeRef>) {
|
||||
self.ctx.xSetParent(node, newParent);
|
||||
}
|
||||
@ -192,20 +96,54 @@ unsafe impl<Ctx: BinaryTreeParentSetterContext> BinaryTreeParentSetterContext
|
||||
fn clearParent(&mut self, node: Self::NodeRef) {
|
||||
self.ctx.clearParent(node)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
_parent_set!(LeftDirectedBinaryTreeWalker);
|
||||
_parent_set!(RightDirectedBinaryTreeWalker);
|
||||
|
||||
unsafe impl<Ctx: BinaryTreeParentSetterContext> BinaryTreeParentSetterContext
|
||||
for RightDirectedBinaryTreeWalker<&mut Ctx>
|
||||
{
|
||||
fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option<Self::NodeRef>) {
|
||||
self.ctx.xSetParent(node, newParent);
|
||||
macro_rules! _children_set {
|
||||
(
|
||||
$name:ident
|
||||
$fwd_xset:ident $fwd_set:ident $fwd_clear:ident
|
||||
$op_xset:ident $op_set:ident $op_clear:ident
|
||||
) => {
|
||||
unsafe impl<Ctx: BinaryTreeChildrenSetterContext> DirectedBinaryTreeChildrenSetterContext
|
||||
for $name<&mut Ctx>
|
||||
{
|
||||
fn xSetForwardChild(&mut self, node: Self::NodeRef, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.$fwd_xset(node, newChild)
|
||||
}
|
||||
|
||||
fn setParent(&mut self, node: Self::NodeRef, newParent: Self::NodeRef) {
|
||||
self.ctx.setParent(node, newParent);
|
||||
fn xSetOppositeChild(&mut self, node: Self::NodeRef, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.$op_xset(node, newChild)
|
||||
}
|
||||
|
||||
fn clearParent(&mut self, node: Self::NodeRef) {
|
||||
self.ctx.clearParent(node)
|
||||
fn setForwardChild(&mut self, node: Self::NodeRef, newChild: Self::NodeRef) {
|
||||
self.ctx.$fwd_set(node, newChild)
|
||||
}
|
||||
|
||||
fn setOppositeChild(&mut self, node: Self::NodeRef, newChild: Self::NodeRef) {
|
||||
self.ctx.$op_set(node, newChild)
|
||||
}
|
||||
|
||||
fn clearForwardChild(&mut self, node: Self::NodeRef) {
|
||||
self.ctx.$fwd_clear(node)
|
||||
}
|
||||
|
||||
fn clearOppositeChild(&mut self, node: Self::NodeRef) {
|
||||
self.ctx.$op_clear(node)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
_children_set!(
|
||||
LeftDirectedBinaryTreeWalker
|
||||
xSetLeftChild setLeftChild clearLeftChild
|
||||
xSetRightChild setRightChild clearRightChild
|
||||
);
|
||||
_children_set!(
|
||||
RightDirectedBinaryTreeWalker
|
||||
xSetRightChild setRightChild clearRightChild
|
||||
xSetLeftChild setLeftChild clearLeftChild
|
||||
);
|
||||
|
||||
@ -1,62 +1,45 @@
|
||||
use crate::NodeRefContainer;
|
||||
use crate::context::{
|
||||
BinaryTreeChildrenSetterContext, BinaryTreeChildrenGetterContext, BinaryTreeRootGetter, BinaryTreeRootSetter,
|
||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeRootGetter,
|
||||
BinaryTreeRootSetter,
|
||||
};
|
||||
use crate::directed::{
|
||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||
};
|
||||
use crate::directed::{DirectedBinaryTreeChildrenSetterContext, DirectedBinaryTreeChildrenGetterContext};
|
||||
use crate::parent2node::clojure::{Parent2NodeGetterClojure, Parent2NodeSetterClojure};
|
||||
|
||||
struct Parent2LeftChildContextWrapper<CtxRef, NodeRef> {
|
||||
ctx: CtxRef,
|
||||
node: NodeRef,
|
||||
macro_rules! _mut_switch {
|
||||
($macro:tt $excl_mark:tt ( $($args:tt)+) ) => {
|
||||
$macro$excl_mark($($args)+);
|
||||
$macro$excl_mark($($args)+ mut);
|
||||
};
|
||||
}
|
||||
|
||||
struct Parent2RightChildContextWrapper<CtxRef, NodeRef> {
|
||||
macro_rules! _struct {
|
||||
($name:ident) => {
|
||||
struct $name<CtxRef, NodeRef> {
|
||||
ctx: CtxRef,
|
||||
node: NodeRef,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
struct Root2NodeContextWrapper<NodeRef> {
|
||||
ctx: NodeRef,
|
||||
}
|
||||
_struct!(Parent2LeftChildContextWrapper);
|
||||
_struct!(Parent2RightChildContextWrapper);
|
||||
_struct!(Parent2ForwardChildContextWrapper);
|
||||
_struct!(Parent2OppositeChildContextWrapper);
|
||||
|
||||
struct Parent2ForwardChildContextWrapper<CtxRef, NodeRef> {
|
||||
ctx: CtxRef,
|
||||
node: NodeRef,
|
||||
}
|
||||
|
||||
struct Parent2OppositeChildContextWrapper<CtxRef, NodeRef> {
|
||||
ctx: CtxRef,
|
||||
node: NodeRef,
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer> Parent2LeftChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef> {
|
||||
fn wrap(ctx: &'ctx CtxRef, node: CtxRef::NodeRef) -> Self {
|
||||
macro_rules! _constructor {
|
||||
($name:ident $($mut:tt)?) => {
|
||||
impl<'ctx, Ctx: NodeRefContainer> $name <&'ctx $($mut)? Ctx, Ctx::NodeRef> {
|
||||
pub fn wrap(ctx: &'ctx $($mut)? Ctx, node: Ctx::NodeRef) -> Self {
|
||||
return Self { ctx, node };
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer>
|
||||
Parent2LeftChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn wrap(ctx: &'ctx mut CtxRef, node: CtxRef::NodeRef) -> Self {
|
||||
return Self { ctx, node };
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer>
|
||||
Parent2RightChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn wrap(ctx: &'ctx CtxRef, node: CtxRef::NodeRef) -> Self {
|
||||
return Self { ctx, node };
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer>
|
||||
Parent2RightChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn wrap(ctx: &'ctx mut CtxRef, node: CtxRef::NodeRef) -> Self {
|
||||
return Self { ctx, node };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer + BinaryTreeRootGetter> Root2NodeContextWrapper<&'ctx CtxRef> {
|
||||
@ -71,60 +54,17 @@ impl<'ctx, CtxRef: NodeRefContainer> Root2NodeContextWrapper<&'ctx mut CtxRef> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer>
|
||||
Parent2ForwardChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn wrap(ctx: &'ctx CtxRef, node: CtxRef::NodeRef) -> Self {
|
||||
return Self { ctx, node };
|
||||
_mut_switch!(_constructor!(Parent2LeftChildContextWrapper));
|
||||
_mut_switch!(_constructor!(Parent2RightChildContextWrapper));
|
||||
_mut_switch!(_constructor!(Parent2ForwardChildContextWrapper));
|
||||
_mut_switch!(_constructor!(Parent2OppositeChildContextWrapper));
|
||||
|
||||
macro_rules! _node_ref {
|
||||
($name:ident $($mut:tt)?) => {
|
||||
impl<Ctx: NodeRefContainer> NodeRefContainer for $name<& $($mut)? Ctx, Ctx::NodeRef> {
|
||||
type NodeRef = Ctx::NodeRef;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer>
|
||||
Parent2ForwardChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn wrap(ctx: &'ctx mut CtxRef, node: CtxRef::NodeRef) -> Self {
|
||||
return Self { ctx, node };
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer>
|
||||
Parent2OppositeChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn wrap(ctx: &'ctx CtxRef, node: CtxRef::NodeRef) -> Self {
|
||||
return Self { ctx, node };
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer>
|
||||
Parent2OppositeChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn wrap(ctx: &'ctx mut CtxRef, node: CtxRef::NodeRef) -> Self {
|
||||
return Self { ctx, node };
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer
|
||||
for Parent2LeftChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
type NodeRef = CtxRef::NodeRef;
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer
|
||||
for Parent2LeftChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
type NodeRef = CtxRef::NodeRef;
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer
|
||||
for Parent2RightChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
type NodeRef = CtxRef::NodeRef;
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer
|
||||
for Parent2RightChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
type NodeRef = CtxRef::NodeRef;
|
||||
};
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer for Root2NodeContextWrapper<&'ctx CtxRef> {
|
||||
@ -137,60 +77,21 @@ impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer
|
||||
type NodeRef = CtxRef::NodeRef;
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer
|
||||
for Parent2ForwardChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
type NodeRef = CtxRef::NodeRef;
|
||||
}
|
||||
_mut_switch!(_node_ref!(Parent2LeftChildContextWrapper));
|
||||
_mut_switch!(_node_ref!(Parent2RightChildContextWrapper));
|
||||
_mut_switch!(_node_ref!(Parent2ForwardChildContextWrapper));
|
||||
_mut_switch!(_node_ref!(Parent2OppositeChildContextWrapper));
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer
|
||||
for Parent2ForwardChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
type NodeRef = CtxRef::NodeRef;
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer
|
||||
for Parent2OppositeChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
type NodeRef = CtxRef::NodeRef;
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer
|
||||
for Parent2OppositeChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
type NodeRef = CtxRef::NodeRef;
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure
|
||||
for Parent2LeftChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
macro_rules! _get_child {
|
||||
($name:ident $fn:ident $($mut:tt)? ) => {
|
||||
impl<'ctx, CtxRef: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure
|
||||
for $name <&'ctx $($mut)? CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn getChild(&self) -> Self::NodeRef {
|
||||
return self.ctx.getLeftChild(self.node);
|
||||
return self.ctx.$fn(self.node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure
|
||||
for Parent2LeftChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn getChild(&self) -> Self::NodeRef {
|
||||
return self.ctx.getLeftChild(self.node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure
|
||||
for Parent2RightChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn getChild(&self) -> Self::NodeRef {
|
||||
return self.ctx.getRightChild(self.node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure
|
||||
for Parent2RightChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn getChild(&self) -> Self::NodeRef {
|
||||
return self.ctx.getRightChild(self.node);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: BinaryTreeRootGetter> Parent2NodeGetterClojure
|
||||
@ -209,70 +110,29 @@ impl<'ctx, CtxRef: BinaryTreeRootGetter> Parent2NodeGetterClojure
|
||||
}
|
||||
}
|
||||
|
||||
_mut_switch!(_get_child!(Parent2LeftChildContextWrapper getLeftChild));
|
||||
_mut_switch!(_get_child!(Parent2RightChildContextWrapper getRightChild));
|
||||
_mut_switch!(_get_child!(Parent2ForwardChildContextWrapper getForwardChild));
|
||||
_mut_switch!(_get_child!(Parent2OppositeChildContextWrapper getOppositeChild));
|
||||
|
||||
|
||||
impl<'ctx, CtxRef: DirectedBinaryTreeChildrenGetterContext> Parent2NodeGetterClojure
|
||||
for Parent2ForwardChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn getChild(&self) -> Self::NodeRef {
|
||||
return self.ctx.getForwardChild(self.node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: DirectedBinaryTreeChildrenGetterContext> Parent2NodeGetterClojure
|
||||
for Parent2ForwardChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn getChild(&self) -> Self::NodeRef {
|
||||
return self.ctx.getForwardChild(self.node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: DirectedBinaryTreeChildrenGetterContext> Parent2NodeGetterClojure
|
||||
for Parent2OppositeChildContextWrapper<&'ctx CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn getChild(&self) -> Self::NodeRef {
|
||||
return self.ctx.getOppositeChild(self.node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: DirectedBinaryTreeChildrenGetterContext> Parent2NodeGetterClojure
|
||||
for Parent2OppositeChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn getChild(&self) -> Self::NodeRef {
|
||||
return self.ctx.getOppositeChild(self.node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: BinaryTreeChildrenSetterContext> Parent2NodeSetterClojure
|
||||
for Parent2LeftChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
macro_rules! _set_child {
|
||||
($name:ident $xset:ident $set:ident $clear:ident) => {
|
||||
impl<'ctx, CtxRef: BinaryTreeChildrenSetterContext> Parent2NodeSetterClojure
|
||||
for $name<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn xSetChild(&mut self, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.xSetLeftChild(self.node, newChild);
|
||||
self.ctx.$xset(self.node, newChild);
|
||||
}
|
||||
|
||||
fn setChild(&mut self, newChild: Self::NodeRef) {
|
||||
self.ctx.setLeftChild(self.node, newChild);
|
||||
self.ctx.$set(self.node, newChild);
|
||||
}
|
||||
|
||||
fn clearChild(&mut self) {
|
||||
self.ctx.clearLeftChild(self.node);
|
||||
self.ctx.$clear(self.node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: BinaryTreeChildrenSetterContext> Parent2NodeSetterClojure
|
||||
for Parent2RightChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn xSetChild(&mut self, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.xSetRightChild(self.node, newChild);
|
||||
}
|
||||
|
||||
fn setChild(&mut self, newChild: Self::NodeRef) {
|
||||
self.ctx.setRightChild(self.node, newChild);
|
||||
}
|
||||
|
||||
fn clearChild(&mut self) {
|
||||
self.ctx.clearRightChild(self.node);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: BinaryTreeRootSetter> Parent2NodeSetterClojure
|
||||
@ -291,36 +151,7 @@ impl<'ctx, CtxRef: BinaryTreeRootSetter> Parent2NodeSetterClojure
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'ctx, CtxRef: DirectedBinaryTreeChildrenSetterContext> Parent2NodeSetterClojure
|
||||
for Parent2ForwardChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn xSetChild(&mut self, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.xSetLeftChild(self.node, newChild);
|
||||
}
|
||||
|
||||
fn setChild(&mut self, newChild: Self::NodeRef) {
|
||||
self.ctx.setLeftChild(self.node, newChild);
|
||||
}
|
||||
|
||||
fn clearChild(&mut self) {
|
||||
self.ctx.clearLeftChild(self.node);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx, CtxRef: DirectedBinaryTreeChildrenSetterContext> Parent2NodeSetterClojure
|
||||
for Parent2OppositeChildContextWrapper<&'ctx mut CtxRef, CtxRef::NodeRef>
|
||||
{
|
||||
fn xSetChild(&mut self, newChild: Option<Self::NodeRef>) {
|
||||
self.ctx.xSetRightChild(self.node, newChild);
|
||||
}
|
||||
|
||||
fn setChild(&mut self, newChild: Self::NodeRef) {
|
||||
self.ctx.setRightChild(self.node, newChild);
|
||||
}
|
||||
|
||||
fn clearChild(&mut self) {
|
||||
self.ctx.clearRightChild(self.node);
|
||||
}
|
||||
}
|
||||
|
||||
_set_child!(Parent2LeftChildContextWrapper xSetLeftChild setLeftChild clearLeftChild);
|
||||
_set_child!(Parent2RightChildContextWrapper xSetRightChild setRightChild clearRightChild);
|
||||
_set_child!(Parent2ForwardChildContextWrapper xSetForwardChild setForwardChild clearForwardChild);
|
||||
_set_child!(Parent2OppositeChildContextWrapper xSetOppositeChild setOppositeChild clearOppositeChild);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user