From b17946b88e016534181d5da64aa30e515e31cd88 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Sat, 27 Dec 2025 00:41:13 +0300 Subject: [PATCH] Naming of context converters --- src/directed/{impls => }/dynamic_wrapper.rs | 24 +++---- src/directed/{impls => }/fixed_wrapper.rs | 28 ++++---- src/directed/impls/mod.rs | 2 - src/directed/mod.rs | 3 +- src/parent2node/dynamic_wrappers.rs | 24 +++---- src/parent2node/fixed_wrapper.rs | 80 ++++++++++----------- 6 files changed, 80 insertions(+), 81 deletions(-) rename src/directed/{impls => }/dynamic_wrapper.rs (86%) rename src/directed/{impls => }/fixed_wrapper.rs (79%) delete mode 100644 src/directed/impls/mod.rs diff --git a/src/directed/impls/dynamic_wrapper.rs b/src/directed/dynamic_wrapper.rs similarity index 86% rename from src/directed/impls/dynamic_wrapper.rs rename to src/directed/dynamic_wrapper.rs index fed70fc..1dd7ee6 100644 --- a/src/directed/impls/dynamic_wrapper.rs +++ b/src/directed/dynamic_wrapper.rs @@ -5,12 +5,12 @@ use crate::directed::context::{ }; use crate::direction::BinaryTreeDirection; -pub struct DynamicDirectedBinaryTreeWrapper { +pub struct DynamicDirectedBinaryTreeContextFromContext { ctx: CtxRef, dir: BinaryTreeDirection, } -impl<'ctx, Ctx: NodeRefContainer> DynamicDirectedBinaryTreeWrapper<&'ctx Ctx> { +impl<'ctx, Ctx: NodeRefContainer> DynamicDirectedBinaryTreeContextFromContext<&'ctx Ctx> { pub fn wrap(ctx: &'ctx Ctx, initialDirection: BinaryTreeDirection) -> Self { return Self { ctx, @@ -19,7 +19,7 @@ impl<'ctx, Ctx: NodeRefContainer> DynamicDirectedBinaryTreeWrapper<&'ctx Ctx> { } } -impl<'ctx, Ctx: NodeRefContainer> DynamicDirectedBinaryTreeWrapper<&'ctx mut Ctx> { +impl<'ctx, Ctx: NodeRefContainer> DynamicDirectedBinaryTreeContextFromContext<&'ctx mut Ctx> { pub fn wrap(ctx: &'ctx mut Ctx, initialDirection: BinaryTreeDirection) -> Self { return Self { ctx, @@ -28,34 +28,34 @@ impl<'ctx, Ctx: NodeRefContainer> DynamicDirectedBinaryTreeWrapper<&'ctx mut Ctx } } -impl DynamicDirectedBinaryTreeWrapper { +impl DynamicDirectedBinaryTreeContextFromContext { pub fn changeDirection(&mut self, newDirection: BinaryTreeDirection) { self.dir = newDirection } } -impl NodeRefContainer for DynamicDirectedBinaryTreeWrapper<&Ctx> { +impl NodeRefContainer for DynamicDirectedBinaryTreeContextFromContext<&Ctx> { type NodeRef = Ctx::NodeRef; } -impl NodeRefContainer for DynamicDirectedBinaryTreeWrapper<&mut Ctx> { +impl NodeRefContainer for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> { type NodeRef = Ctx::NodeRef; } -impl BinaryTreeParentGetterContext for DynamicDirectedBinaryTreeWrapper<&Ctx> { +impl BinaryTreeParentGetterContext for DynamicDirectedBinaryTreeContextFromContext<&Ctx> { fn getParent(&self, node: Self::NodeRef) -> Option { return self.ctx.getParent(node); } } -impl BinaryTreeParentGetterContext for DynamicDirectedBinaryTreeWrapper<&mut Ctx> { +impl BinaryTreeParentGetterContext for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> { fn getParent(&self, node: Self::NodeRef) -> Option { return self.ctx.getParent(node); } } impl DirectedBinaryTreeChildrenGetterContext - for DynamicDirectedBinaryTreeWrapper<&Ctx> + for DynamicDirectedBinaryTreeContextFromContext<&Ctx> { fn getForwardChild(&self, node: Self::NodeRef) -> Option { match self.dir { @@ -73,7 +73,7 @@ impl DirectedBinaryTreeChildrenGetterConte } impl DirectedBinaryTreeChildrenGetterContext - for DynamicDirectedBinaryTreeWrapper<&mut Ctx> + for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> { fn getForwardChild(&self, node: Self::NodeRef) -> Option { match self.dir { @@ -91,7 +91,7 @@ impl DirectedBinaryTreeChildrenGetterConte } unsafe impl DirectedBinaryTreeChildrenSetterContext - for DynamicDirectedBinaryTreeWrapper<&mut Ctx> + for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> { fn xSetForwardChild(&mut self, node: Self::NodeRef, newChild: Option) { match self.dir { @@ -137,7 +137,7 @@ unsafe impl DirectedBinaryTreeChildrenSett } unsafe impl BinaryTreeParentSetterContext - for DynamicDirectedBinaryTreeWrapper<&mut Ctx> + for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> { fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option) { self.ctx.xSetParent(node, newParent); diff --git a/src/directed/impls/fixed_wrapper.rs b/src/directed/fixed_wrapper.rs similarity index 79% rename from src/directed/impls/fixed_wrapper.rs rename to src/directed/fixed_wrapper.rs index f0e19bc..6f2f377 100644 --- a/src/directed/impls/fixed_wrapper.rs +++ b/src/directed/fixed_wrapper.rs @@ -14,11 +14,11 @@ macro_rules! _mut_switch { }; } -pub struct LeftDirectedBinaryTreeWalker { +pub struct FixedLeftDirectedBinaryTreeContextFromContext { ctx: CtxRef, } -pub struct RightDirectedBinaryTreeWalker { +pub struct FixedRightDirectedBinaryTreeContextFromContext { ctx: CtxRef, } @@ -32,8 +32,8 @@ macro_rules! _constructor { }; } -_mut_switch!(_constructor!(LeftDirectedBinaryTreeWalker)); -_mut_switch!(_constructor!(RightDirectedBinaryTreeWalker)); +_mut_switch!(_constructor!(FixedLeftDirectedBinaryTreeContextFromContext)); +_mut_switch!(_constructor!(FixedRightDirectedBinaryTreeContextFromContext)); macro_rules! _node_ref { ($name:ident $($mut:tt)?) => { @@ -43,8 +43,8 @@ macro_rules! _node_ref { }; } -_mut_switch!(_node_ref!(LeftDirectedBinaryTreeWalker)); -_mut_switch!(_node_ref!(RightDirectedBinaryTreeWalker)); +_mut_switch!(_node_ref!(FixedLeftDirectedBinaryTreeContextFromContext)); +_mut_switch!(_node_ref!(FixedRightDirectedBinaryTreeContextFromContext)); macro_rules! _parent_get { ($name:ident $($mut:tt)?) => { @@ -58,8 +58,8 @@ macro_rules! _parent_get { }; } -_mut_switch!(_parent_get!(LeftDirectedBinaryTreeWalker)); -_mut_switch!(_parent_get!(RightDirectedBinaryTreeWalker)); +_mut_switch!(_parent_get!(FixedLeftDirectedBinaryTreeContextFromContext)); +_mut_switch!(_parent_get!(FixedRightDirectedBinaryTreeContextFromContext)); macro_rules! _children_get { ($name:ident $fwd:ident $op:ident $($mut:tt)? ) => { @@ -77,8 +77,8 @@ macro_rules! _children_get { }; } -_mut_switch!(_children_get!(LeftDirectedBinaryTreeWalker getLeftChild getRightChild)); -_mut_switch!(_children_get!(RightDirectedBinaryTreeWalker getRightChild getLeftChild)); +_mut_switch!(_children_get!(FixedLeftDirectedBinaryTreeContextFromContext getLeftChild getRightChild)); +_mut_switch!(_children_get!(FixedRightDirectedBinaryTreeContextFromContext getRightChild getLeftChild)); macro_rules! _parent_set { ($name:ident) => { @@ -99,8 +99,8 @@ macro_rules! _parent_set { } }; } -_parent_set!(LeftDirectedBinaryTreeWalker); -_parent_set!(RightDirectedBinaryTreeWalker); +_parent_set!(FixedLeftDirectedBinaryTreeContextFromContext); +_parent_set!(FixedRightDirectedBinaryTreeContextFromContext); macro_rules! _children_set { ( @@ -138,12 +138,12 @@ macro_rules! _children_set { }; } _children_set!( - LeftDirectedBinaryTreeWalker + FixedLeftDirectedBinaryTreeContextFromContext xSetLeftChild setLeftChild clearLeftChild xSetRightChild setRightChild clearRightChild ); _children_set!( - RightDirectedBinaryTreeWalker + FixedRightDirectedBinaryTreeContextFromContext xSetRightChild setRightChild clearRightChild xSetLeftChild setLeftChild clearLeftChild ); diff --git a/src/directed/impls/mod.rs b/src/directed/impls/mod.rs deleted file mode 100644 index 99757bf..0000000 --- a/src/directed/impls/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod fixed_wrapper; -mod dynamic_wrapper; \ No newline at end of file diff --git a/src/directed/mod.rs b/src/directed/mod.rs index 4a0aa2e..cb175cb 100644 --- a/src/directed/mod.rs +++ b/src/directed/mod.rs @@ -1,5 +1,6 @@ mod context; -mod impls; +mod fixed_wrapper; +mod dynamic_wrapper; pub use context::DirectedBinaryTreeChildrenSetterContext; pub use context::DirectedBinaryTreeChildrenGetterContext; diff --git a/src/parent2node/dynamic_wrappers.rs b/src/parent2node/dynamic_wrappers.rs index 6649a8f..9e9845b 100644 --- a/src/parent2node/dynamic_wrappers.rs +++ b/src/parent2node/dynamic_wrappers.rs @@ -22,13 +22,13 @@ union _NodeOrNothing { node: ManuallyDrop, } -struct dyn_lr { +struct DynamicParent2NodeGetterClojureFromContext { dir: Option, ctx: CtxRef, node: _NodeOrNothing, } -struct dyn_dir { +struct DynamicParent2NodeGetterClojureFromDirectedContext { dir: Option, ctx: CtxRef, node: _NodeOrNothing, @@ -50,8 +50,8 @@ macro_rules! _constructor { }; } -_mut_switch!(_constructor!(dyn_lr BinaryTreeDirection)); -_mut_switch!(_constructor!(dyn_dir DirectedBinaryTreeDirection)); +_mut_switch!(_constructor!(DynamicParent2NodeGetterClojureFromContext BinaryTreeDirection)); +_mut_switch!(_constructor!(DynamicParent2NodeGetterClojureFromDirectedContext DirectedBinaryTreeDirection)); macro_rules! _node_ref { ($name:ident $($mut:tt)?) => { @@ -61,8 +61,8 @@ macro_rules! _node_ref { }; } -_mut_switch!(_node_ref!(dyn_lr)); -_mut_switch!(_node_ref!(dyn_dir)); +_mut_switch!(_node_ref!(DynamicParent2NodeGetterClojureFromContext)); +_mut_switch!(_node_ref!(DynamicParent2NodeGetterClojureFromDirectedContext)); macro_rules! _get_child { ( @@ -88,11 +88,11 @@ macro_rules! _get_child { } _mut_switch!(_get_child!( - dyn_lr BinaryTreeChildrenGetterContext + DynamicParent2NodeGetterClojureFromContext BinaryTreeChildrenGetterContext BinaryTreeDirection LEFT getLeftChild RIGHT getRightChild )); _mut_switch!(_get_child!( - dyn_dir DirectedBinaryTreeChildrenGetterContext + DynamicParent2NodeGetterClojureFromDirectedContext DirectedBinaryTreeChildrenGetterContext DirectedBinaryTreeDirection FORWARD getForwardChild OPPOSITE getOppositeChild )); @@ -137,12 +137,12 @@ macro_rules! _set_child { } _set_child!( - dyn_lr BinaryTreeChildrenSetterContext BinaryTreeDirection + DynamicParent2NodeGetterClojureFromContext BinaryTreeChildrenSetterContext BinaryTreeDirection LEFT xSetLeftChild setLeftChild clearLeftChild RIGHT xSetRightChild setRightChild clearRightChild ); _set_child!( - dyn_dir DirectedBinaryTreeChildrenSetterContext DirectedBinaryTreeDirection + DynamicParent2NodeGetterClojureFromDirectedContext DirectedBinaryTreeChildrenSetterContext DirectedBinaryTreeDirection FORWARD xSetForwardChild setForwardChild clearForwardChild OPPOSITE xSetOppositeChild setOppositeChild clearOppositeChild ); @@ -159,6 +159,6 @@ macro_rules! _drop { }; } -_drop!(dyn_lr); -_drop!(dyn_dir); +_drop!(DynamicParent2NodeGetterClojureFromContext); +_drop!(DynamicParent2NodeGetterClojureFromDirectedContext); diff --git a/src/parent2node/fixed_wrapper.rs b/src/parent2node/fixed_wrapper.rs index dc33e28..64d93d1 100644 --- a/src/parent2node/fixed_wrapper.rs +++ b/src/parent2node/fixed_wrapper.rs @@ -24,13 +24,13 @@ macro_rules! _struct { }; } -struct Root2NodeContextWrapper { +struct FixedRootParent2NodeGetterClojureFromContext { ctx: NodeRef, } -_struct!(Parent2LeftChildContextWrapper); -_struct!(Parent2RightChildContextWrapper); -_struct!(Parent2ForwardChildContextWrapper); -_struct!(Parent2OppositeChildContextWrapper); +_struct!(FixedLeftParent2NodeGetterClojureFromContext); +_struct!(FixedRightParent2NodeGetterClojureFromContext); +_struct!(FixedForwardParent2NodeGetterClojureFromDirectedContext); +_struct!(FixedOppositeParent2NodeGetterClojureFromDirectedContext); macro_rules! _constructor { ($name:ident $($mut:tt)?) => { @@ -42,22 +42,22 @@ macro_rules! _constructor { }; } -impl<'ctx, CtxRef: NodeRefContainer + BinaryTreeRootGetter> Root2NodeContextWrapper<&'ctx CtxRef> { - fn wrap(ctx: &'ctx CtxRef) -> Self { +impl<'ctx, Ctx: NodeRefContainer + BinaryTreeRootGetter> FixedRootParent2NodeGetterClojureFromContext<&'ctx Ctx> { + fn wrap(ctx: &'ctx Ctx) -> Self { return Self { ctx }; } } -impl<'ctx, CtxRef: NodeRefContainer> Root2NodeContextWrapper<&'ctx mut CtxRef> { - fn wrap(ctx: &'ctx mut CtxRef) -> Self { +impl<'ctx, Ctx: NodeRefContainer> FixedRootParent2NodeGetterClojureFromContext<&'ctx mut Ctx> { + fn wrap(ctx: &'ctx mut Ctx) -> Self { return Self { ctx }; } } -_mut_switch!(_constructor!(Parent2LeftChildContextWrapper)); -_mut_switch!(_constructor!(Parent2RightChildContextWrapper)); -_mut_switch!(_constructor!(Parent2ForwardChildContextWrapper)); -_mut_switch!(_constructor!(Parent2OppositeChildContextWrapper)); +_mut_switch!(_constructor!(FixedLeftParent2NodeGetterClojureFromContext)); +_mut_switch!(_constructor!(FixedRightParent2NodeGetterClojureFromContext)); +_mut_switch!(_constructor!(FixedForwardParent2NodeGetterClojureFromDirectedContext)); +_mut_switch!(_constructor!(FixedOppositeParent2NodeGetterClojureFromDirectedContext)); macro_rules! _node_ref { ($name:ident $($mut:tt)?) => { @@ -67,25 +67,25 @@ macro_rules! _node_ref { }; } -impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer for Root2NodeContextWrapper<&'ctx CtxRef> { - type NodeRef = CtxRef::NodeRef; +impl<'ctx, Ctx: NodeRefContainer> NodeRefContainer for FixedRootParent2NodeGetterClojureFromContext<&'ctx Ctx> { + type NodeRef = Ctx::NodeRef; } -impl<'ctx, CtxRef: NodeRefContainer> NodeRefContainer - for Root2NodeContextWrapper<&'ctx mut CtxRef> +impl<'ctx, Ctx: NodeRefContainer> NodeRefContainer + for FixedRootParent2NodeGetterClojureFromContext<&'ctx mut Ctx> { - type NodeRef = CtxRef::NodeRef; + type NodeRef = Ctx::NodeRef; } -_mut_switch!(_node_ref!(Parent2LeftChildContextWrapper)); -_mut_switch!(_node_ref!(Parent2RightChildContextWrapper)); -_mut_switch!(_node_ref!(Parent2ForwardChildContextWrapper)); -_mut_switch!(_node_ref!(Parent2OppositeChildContextWrapper)); +_mut_switch!(_node_ref!(FixedLeftParent2NodeGetterClojureFromContext)); +_mut_switch!(_node_ref!(FixedRightParent2NodeGetterClojureFromContext)); +_mut_switch!(_node_ref!(FixedForwardParent2NodeGetterClojureFromDirectedContext)); +_mut_switch!(_node_ref!(FixedOppositeParent2NodeGetterClojureFromDirectedContext)); macro_rules! _get_child { ($name:ident $fn:ident $($mut:tt)? ) => { - impl<'ctx, CtxRef: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure - for $name <&'ctx $($mut)? CtxRef, CtxRef::NodeRef> + impl<'ctx, Ctx: BinaryTreeChildrenGetterContext> Parent2NodeGetterClojure + for $name <&'ctx $($mut)? Ctx, Ctx::NodeRef> { fn getChild(&self) -> Self::NodeRef { return self.ctx.$fn(self.node); @@ -94,31 +94,31 @@ macro_rules! _get_child { }; } -impl<'ctx, CtxRef: BinaryTreeRootGetter> Parent2NodeGetterClojure - for Root2NodeContextWrapper<&'ctx CtxRef> +impl<'ctx, Ctx: BinaryTreeRootGetter> Parent2NodeGetterClojure + for FixedRootParent2NodeGetterClojureFromContext<&'ctx Ctx> { fn getChild(&self) -> Self::NodeRef { return self.ctx.getRoot(); } } -impl<'ctx, CtxRef: BinaryTreeRootGetter> Parent2NodeGetterClojure - for Root2NodeContextWrapper<&'ctx mut CtxRef> +impl<'ctx, Ctx: BinaryTreeRootGetter> Parent2NodeGetterClojure + for FixedRootParent2NodeGetterClojureFromContext<&'ctx mut Ctx> { fn getChild(&self) -> Self::NodeRef { return self.ctx.getRoot(); } } -_mut_switch!(_get_child!(Parent2LeftChildContextWrapper getLeftChild)); -_mut_switch!(_get_child!(Parent2RightChildContextWrapper getRightChild)); -_mut_switch!(_get_child!(Parent2ForwardChildContextWrapper getForwardChild)); -_mut_switch!(_get_child!(Parent2OppositeChildContextWrapper getOppositeChild)); +_mut_switch!(_get_child!(FixedLeftParent2NodeGetterClojureFromContext getLeftChild)); +_mut_switch!(_get_child!(FixedRightParent2NodeGetterClojureFromContext getRightChild)); +_mut_switch!(_get_child!(FixedForwardParent2NodeGetterClojureFromDirectedContext getForwardChild)); +_mut_switch!(_get_child!(FixedOppositeParent2NodeGetterClojureFromDirectedContext getOppositeChild)); macro_rules! _set_child { ($name:ident $xset:ident $set:ident $clear:ident) => { - impl<'ctx, CtxRef: BinaryTreeChildrenSetterContext> Parent2NodeSetterClojure - for $name<&'ctx mut CtxRef, CtxRef::NodeRef> + impl<'ctx, Ctx: BinaryTreeChildrenSetterContext> Parent2NodeSetterClojure + for $name<&'ctx mut Ctx, Ctx::NodeRef> { fn xSetChild(&mut self, newChild: Option) { self.ctx.$xset(self.node, newChild); @@ -135,8 +135,8 @@ macro_rules! _set_child { }; } -impl<'ctx, CtxRef: BinaryTreeRootSetter> Parent2NodeSetterClojure - for Root2NodeContextWrapper<&'ctx mut CtxRef> +impl<'ctx, Ctx: BinaryTreeRootSetter> Parent2NodeSetterClojure + for FixedRootParent2NodeGetterClojureFromContext<&'ctx mut Ctx> { fn xSetChild(&mut self, newChild: Option) { self.ctx.xSetRoot(newChild) @@ -151,7 +151,7 @@ impl<'ctx, CtxRef: BinaryTreeRootSetter> Parent2NodeSetterClojure } } -_set_child!(Parent2LeftChildContextWrapper xSetLeftChild setLeftChild clearLeftChild); -_set_child!(Parent2RightChildContextWrapper xSetRightChild setRightChild clearRightChild); -_set_child!(Parent2ForwardChildContextWrapper xSetForwardChild setForwardChild clearForwardChild); -_set_child!(Parent2OppositeChildContextWrapper xSetOppositeChild setOppositeChild clearOppositeChild); +_set_child!(FixedLeftParent2NodeGetterClojureFromContext xSetLeftChild setLeftChild clearLeftChild); +_set_child!(FixedRightParent2NodeGetterClojureFromContext xSetRightChild setRightChild clearRightChild); +_set_child!(FixedForwardParent2NodeGetterClojureFromDirectedContext xSetForwardChild setForwardChild clearForwardChild); +_set_child!(FixedOppositeParent2NodeGetterClojureFromDirectedContext xSetOppositeChild setOppositeChild clearOppositeChild);