From c4c279cd2716bebde1004d9589e7fd14adf101b9 Mon Sep 17 00:00:00 2001 From: timofey Date: Fri, 16 Jun 2023 09:44:12 +0000 Subject: [PATCH] `BinaryTreesHeight` --- src/flow/binary.rs | 6 ++++++ src/flow/binary/avl.rs | 6 +----- src/flow/binary/bounds/bound.rs | 6 +++++- src/mrds/trees/avl.rs | 4 +++- src/rstd/collections/avl/context.rs | 6 +++++- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/flow/binary.rs b/src/flow/binary.rs index 91eecb7..7a3a3e9 100644 --- a/src/flow/binary.rs +++ b/src/flow/binary.rs @@ -126,3 +126,9 @@ pub trait BinaryTreesMutable<'a>: BinaryTreesEmpty<'a> { }) } } + +pub trait BinaryTreesHeight<'a>: BinaryTrees<'a> { + fn height(&self, tree: &Self::Tree) -> u64; + + fn leaf_height_error(&self, height: u64) -> BTWrap<'a, Self, T>; +} diff --git a/src/flow/binary/avl.rs b/src/flow/binary/avl.rs index 1924563..ad287d7 100644 --- a/src/flow/binary/avl.rs +++ b/src/flow/binary/avl.rs @@ -1,10 +1,6 @@ use super::*; -pub trait BinaryTreesAvl<'a>: BinaryTrees<'a> { - fn height(&self, tree: &Self::Tree) -> u64; - - fn leaf_height_error(&self, height: u64) -> BTWrap<'a, Self, T>; - +pub trait BinaryTreesAvl<'a>: BinaryTreesHeight<'a> { fn assume_node(&self, tree: &Self::Tree) -> BTWrap<'a, Self, Self::Node> { match self.refer(tree) { Some(reference) => self.resolve(&reference), diff --git a/src/flow/binary/bounds/bound.rs b/src/flow/binary/bounds/bound.rs index 8eef341..37b71d7 100644 --- a/src/flow/binary/bounds/bound.rs +++ b/src/flow/binary/bounds/bound.rs @@ -146,7 +146,9 @@ impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesEmpty<'a>> BinaryTreesEmpty<'a } } -impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesAvl<'a>> BinaryTreesAvl<'a> for BoundTrees { +impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesHeight<'a>> BinaryTreesHeight<'a> + for BoundTrees +{ fn height(&self, tree: &Self::Tree) -> u64 { self.0.height(&tree.bound) } @@ -154,7 +156,9 @@ impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesAvl<'a>> BinaryTreesAvl<'a> fo fn leaf_height_error(&self, height: u64) -> BTWrap<'a, Self, T> { self.0.leaf_height_error(height) } +} +impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesAvl<'a>> BinaryTreesAvl<'a> for BoundTrees { fn join_key_unbalanced( &self, tl: Self::Tree, diff --git a/src/mrds/trees/avl.rs b/src/mrds/trees/avl.rs index d717083..4270243 100644 --- a/src/mrds/trees/avl.rs +++ b/src/mrds/trees/avl.rs @@ -176,7 +176,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesMutable<'a> for AvlTs { } } -impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesAvl<'a> for AvlTs { +impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesHeight<'a> for AvlTs { fn height(&self, tree: &Self::Tree) -> u64 { tree.height } @@ -184,7 +184,9 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesAvl<'a> for AvlTs { fn leaf_height_error(&self, height: u64) -> BTWrap<'a, Self, T> { panic!("leaf height error: {height}.") } +} +impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesAvl<'a> for AvlTs { fn join_key_unbalanced( &self, tl: Self::Tree, diff --git a/src/rstd/collections/avl/context.rs b/src/rstd/collections/avl/context.rs index 95c180c..18bf278 100644 --- a/src/rstd/collections/avl/context.rs +++ b/src/rstd/collections/avl/context.rs @@ -98,7 +98,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> + BinaryTreesHeight<'a> for BoundContext<'a, Ctx, A, C> { fn height(&self, tree: &Self::Tree) -> u64 { tree.height() @@ -109,7 +109,11 @@ 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> +{ fn join_key_unbalanced( &self, tl: Self::Tree,