diff --git a/src/rstd/collections/avl.rs b/src/rstd/collections/avl.rs index 094abd2..214771e 100644 --- a/src/rstd/collections/avl.rs +++ b/src/rstd/collections/avl.rs @@ -1,6 +1,5 @@ pub mod binary; pub mod bounds; -pub mod context; use std::{error::Error, fmt::Display, rc::Rc}; diff --git a/src/rstd/collections/avl/context.rs b/src/rstd/collections/avl/context.rs deleted file mode 100644 index eb2afb9..0000000 --- a/src/rstd/collections/avl/context.rs +++ /dev/null @@ -1,132 +0,0 @@ -use crate::flow::{ - binary::{avl::BinaryTreesAvl, *}, - comparator::*, -}; -use crate::func::{context::*, *}; -use crate::rstd::fallible::*; - -use super::{bounds::*, *}; - -pub struct BoundContext<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, C: 'a + Comparator> { - factory: A::Fctr, - comparator: Rc, -} - -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, C: 'a + Comparator> Clone - for BoundContext<'a, Ctx, A, C> -{ - fn clone(&self) -> Self { - Self { - factory: self.factory.clone(), - comparator: self.comparator.clone(), - } - } -} - -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator> - FunctorContext<'a> for BoundContext<'a, Ctx, A, C> -{ - type T = FallibleMonad<'a, Ctx, BoundResolutionError<'a, Ctx, A>>; -} - -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator> BinaryTrees<'a> - for BoundContext<'a, Ctx, A, C> -{ - type Node = BoundNode<'a, Ctx, A>; - type Reference = BoundReference<'a, Ctx, A>; - type Tree = BoundTree<'a, Ctx, A>; - type Key = A; - type Comparator = C; - - type _Tm = Self::T; - - fn comparator(&self) -> &Self::Comparator { - &self.comparator - } - - fn split(&self, node: &Self::Node) -> Split<'a, Self> { - node.split() - } - - fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node> { - Ctx::stuff(reference.resolve(self.comparator.clone())) - } - - fn equal(&self, rl: &Self::Reference, rr: &Self::Reference) -> bool { - BoundReference::equal(rl, rr, self.comparator.as_ref()) - } - - fn refer(&self, tree: &Self::Tree) -> Option { - tree.reference() - } -} - -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator> - BinaryTreesTreeOf<'a> for BoundContext<'a, Ctx, A, C> -{ - fn tree_of(&self, node: Self::Node) -> BTWrap<'a, Self, Self::Tree> { - match node.into_tree() { - Ok(tree) => Self::pure(tree), - Err(e) => Self::fail(ResolutionError::Parse(e)), - } - } -} - -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator> - BinaryTreesEmpty<'a> for BoundContext<'a, Ctx, A, C> -{ - fn empty(&self) -> Self::Tree { - BoundTree::empty(self.factory.clone()) - } - - fn split_key_empty( - &self, - tree: Self::Tree, - key: Self::Key, - ) -> BTWrap<'a, Self, KeySplit<'a, Self>> { - Ctx::stuff(tree.split_empty_res(key, self.factory.clone(), self.comparator.clone())) - } -} - -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator> - BinaryTreesMutable<'a> for BoundContext<'a, Ctx, A, C> -{ - fn join_key( - self, - tl: Self::Tree, - key: Self::Key, - tr: Self::Tree, - ) -> BTWrap<'a, Self, Self::Node> { - self.join_key_balanced(tl, key, tr) - } -} - -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator> - BinaryTreesHeight<'a> for BoundContext<'a, Ctx, A, C> -{ - fn height(&self, tree: &Self::Tree) -> u64 { - tree.height() - } - - fn leaf_height_error(&self, height: u64) -> BTWrap<'a, Self, T> { - as Fail<_>>::fail(ResolutionError::Parse(BoundError::Avl( - AvlError::LeafHeight(height), - ))) - } -} - -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator> - BinaryTreesTryJoin<'a> for BoundContext<'a, Ctx, A, C> -{ - fn try_join( - &self, - tl: Self::Tree, - key: Self::Key, - tr: Self::Tree, - ) -> BTWrap<'a, Self, Self::Node> { - match BoundNode::new(tl, tr, key, self.comparator.as_ref()) { - Ok(n) => as Pure>::pure(n), - Err(e) => as Fail<_>>::fail(ResolutionError::Parse(e)), - } - } -}