From f38efb0ae08833e18d14c2042d970c118e4da056 Mon Sep 17 00:00:00 2001 From: timofey Date: Fri, 16 Jun 2023 09:49:46 +0000 Subject: [PATCH] `BinaryTreesTryJoin` --- src/flow/binary.rs | 9 +++++++++ src/flow/binary/avl.rs | 11 +++-------- src/flow/binary/bounds/bound.rs | 19 +++++++++---------- src/mrds/trees/avl.rs | 2 +- src/rstd/collections/avl/context.rs | 2 +- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/flow/binary.rs b/src/flow/binary.rs index 7a3a3e9..b6d722d 100644 --- a/src/flow/binary.rs +++ b/src/flow/binary.rs @@ -132,3 +132,12 @@ pub trait BinaryTreesHeight<'a>: BinaryTrees<'a> { fn leaf_height_error(&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>; +} diff --git a/src/flow/binary/avl.rs b/src/flow/binary/avl.rs index e7ff54d..cf57568 100644 --- a/src/flow/binary/avl.rs +++ b/src/flow/binary/avl.rs @@ -1,6 +1,6 @@ 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> { match self.refer(tree) { 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( &self, tl: Self::Tree, @@ -74,3 +67,5 @@ pub trait BinaryTreesAvl<'a>: BinaryTreesHeight<'a> { } } } + +impl<'a, BT: BinaryTreesHeight<'a> + BinaryTreesTryJoin<'a>> BinaryTreesAvl<'a> for BT {} diff --git a/src/flow/binary/bounds/bound.rs b/src/flow/binary/bounds/bound.rs index 70d9d42..8827ad2 100644 --- a/src/flow/binary/bounds/bound.rs +++ b/src/flow/binary/bounds/bound.rs @@ -1,7 +1,5 @@ -use crate::{ - flow::binary::{avl::*, *}, - func::context::*, -}; +use crate::flow::binary::*; +use crate::func::context::*; 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 { +impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesTryJoin<'a>> BinaryTreesTryJoin<'a> + for BoundTrees +{ fn try_join( &self, tl: Self::Tree, @@ -169,15 +169,14 @@ impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesAvl<'a>> BinaryTreesAvl<'a> fo self.0.bounds_bind( Bounds::join(boundsl.clone(), boundsr.clone(), &key, self.comparator()), |bounds| { - Self::fmap( - self.0.try_join(tl.bound, key, tr.bound), - |node| BoundNode2 { + Self::fmap(self.0.try_join(tl.bound, key, tr.bound), |node| { + BoundNode2 { boundsl, boundsr, bounds, node, - }, - ) + } + }) }, ) } diff --git a/src/mrds/trees/avl.rs b/src/mrds/trees/avl.rs index c8daf06..2ab4112 100644 --- a/src/mrds/trees/avl.rs +++ b/src/mrds/trees/avl.rs @@ -186,7 +186,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesHeight<'a> for AvlTs { } } -impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesAvl<'a> for AvlTs { +impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesTryJoin<'a> for AvlTs { fn try_join( &self, tl: Self::Tree, diff --git a/src/rstd/collections/avl/context.rs b/src/rstd/collections/avl/context.rs index 831e862..c046b78 100644 --- a/src/rstd/collections/avl/context.rs +++ b/src/rstd/collections/avl/context.rs @@ -112,7 +112,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator> - BinaryTreesAvl<'a> for BoundContext<'a, Ctx, A, C> + BinaryTreesTryJoin<'a> for BoundContext<'a, Ctx, A, C> { fn try_join( &self,