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