BinaryTreesTryJoin

This commit is contained in:
AF 2023-06-16 09:49:46 +00:00
parent d96a2c3920
commit f38efb0ae0
5 changed files with 23 additions and 20 deletions

View File

@ -132,3 +132,12 @@ pub trait BinaryTreesHeight<'a>: BinaryTrees<'a> {
fn leaf_height_error<T: 'a>(&self, height: u64) -> BTWrap<'a, Self, T>; fn leaf_height_error<T: 'a>(&self, height: u64) -> BTWrap<'a, Self, T>;
} }
pub trait BinaryTreesTryJoin<'a>: BinaryTrees<'a> {
fn try_join(
&self,
tl: Self::Tree,
key: Self::Key,
tr: Self::Tree,
) -> BTWrap<'a, Self, Self::Node>;
}

View File

@ -1,6 +1,6 @@
use super::*; use super::*;
pub trait BinaryTreesAvl<'a>: BinaryTreesHeight<'a> { pub trait BinaryTreesAvl<'a>: BinaryTreesHeight<'a> + BinaryTreesTryJoin<'a> {
fn assume_node(&self, tree: &Self::Tree) -> BTWrap<'a, Self, Self::Node> { fn assume_node(&self, tree: &Self::Tree) -> BTWrap<'a, Self, Self::Node> {
match self.refer(tree) { match self.refer(tree) {
Some(reference) => self.resolve(&reference), Some(reference) => self.resolve(&reference),
@ -8,13 +8,6 @@ pub trait BinaryTreesAvl<'a>: BinaryTreesHeight<'a> {
} }
} }
fn try_join(
&self,
tl: Self::Tree,
key: Self::Key,
tr: Self::Tree,
) -> BTWrap<'a, Self, Self::Node>;
fn join_key_balanced_tree( fn join_key_balanced_tree(
&self, &self,
tl: Self::Tree, tl: Self::Tree,
@ -74,3 +67,5 @@ pub trait BinaryTreesAvl<'a>: BinaryTreesHeight<'a> {
} }
} }
} }
impl<'a, BT: BinaryTreesHeight<'a> + BinaryTreesTryJoin<'a>> BinaryTreesAvl<'a> for BT {}

View File

@ -1,7 +1,5 @@
use crate::{ use crate::flow::binary::*;
flow::binary::{avl::*, *}, use crate::func::context::*;
func::context::*,
};
use super::*; use super::*;
@ -158,7 +156,9 @@ impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesHeight<'a>> BinaryTreesHeight<
} }
} }
impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesAvl<'a>> BinaryTreesAvl<'a> for BoundTrees<BT> { impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesTryJoin<'a>> BinaryTreesTryJoin<'a>
for BoundTrees<BT>
{
fn try_join( fn try_join(
&self, &self,
tl: Self::Tree, tl: Self::Tree,
@ -169,15 +169,14 @@ impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesAvl<'a>> BinaryTreesAvl<'a> fo
self.0.bounds_bind( self.0.bounds_bind(
Bounds::join(boundsl.clone(), boundsr.clone(), &key, self.comparator()), Bounds::join(boundsl.clone(), boundsr.clone(), &key, self.comparator()),
|bounds| { |bounds| {
Self::fmap( Self::fmap(self.0.try_join(tl.bound, key, tr.bound), |node| {
self.0.try_join(tl.bound, key, tr.bound), BoundNode2 {
|node| BoundNode2 {
boundsl, boundsl,
boundsr, boundsr,
bounds, bounds,
node, node,
}, }
) })
}, },
) )
} }

View File

@ -186,7 +186,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesHeight<'a> for AvlTs<A> {
} }
} }
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesAvl<'a> for AvlTs<A> { impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesTryJoin<'a> for AvlTs<A> {
fn try_join( fn try_join(
&self, &self,
tl: Self::Tree, tl: Self::Tree,

View File

@ -112,7 +112,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A
} }
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A>> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A>>
BinaryTreesAvl<'a> for BoundContext<'a, Ctx, A, C> BinaryTreesTryJoin<'a> for BoundContext<'a, Ctx, A, C>
{ {
fn try_join( fn try_join(
&self, &self,