remove BoundContext

This commit is contained in:
AF 2023-06-17 03:18:46 +00:00
parent 6765c056ab
commit b3a191ea5b
2 changed files with 0 additions and 133 deletions

View File

@ -1,6 +1,5 @@
pub mod binary; pub mod binary;
pub mod bounds; pub mod bounds;
pub mod context;
use std::{error::Error, fmt::Display, rc::Rc}; use std::{error::Error, fmt::Display, rc::Rc};

View File

@ -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<A>> {
factory: A::Fctr,
comparator: Rc<C>,
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, C: 'a + Comparator<A>> 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<A>>
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<A>> 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<Self::Reference> {
tree.reference()
}
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A>>
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<A>>
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<A>>
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<A>>
BinaryTreesHeight<'a> for BoundContext<'a, Ctx, A, C>
{
fn height(&self, tree: &Self::Tree) -> u64 {
tree.height()
}
fn leaf_height_error<T: 'a>(&self, height: u64) -> BTWrap<'a, Self, T> {
<FallibleMonad<'a, Ctx, _> as Fail<_>>::fail(ResolutionError::Parse(BoundError::Avl(
AvlError::LeafHeight(height),
)))
}
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A>>
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) => <FallibleMonad<'a, Ctx, _> as Pure>::pure(n),
Err(e) => <FallibleMonad<'a, Ctx, _> as Fail<_>>::fail(ResolutionError::Parse(e)),
}
}
}