diff --git a/src/rstd/collections/tree.rs b/src/rstd/collections/tree.rs index 7b86a99..ad18226 100644 --- a/src/rstd/collections/tree.rs +++ b/src/rstd/collections/tree.rs @@ -237,15 +237,23 @@ mod tests { use std::convert::Infallible; use crate::{ - flow::{binary::*, comparator::*}, + flow::{ + binary::{balancing::*, *}, + comparator::*, + }, rstd::atomic_object::*, testing::TestContextPlain, }; use super::context::*; - type Trees = - TreeContext2<'static, TestContextPlain, AtomicObject, DefaultComparator, Infallible>; + type Trees = TreeContext2< + 'static, + TestContextPlain, + AtomicObject, + DefaultComparator, + WrappedExtra, + >; fn new_trees() -> Trees { Trees::new((DefaultComparator.into(), u64::f())) @@ -256,4 +264,12 @@ mod tests { let trees = new_trees(); assert_eq!(trees.height(&trees.empty()), 0); } + + #[test] + fn one_has_height_1() { + let trees = BalancedTrees::new(new_trees()); + let tree = trees.empty(); + let tree = trees.clone().add_tree(tree, 0.into()).unwrap(); + assert_eq!(trees.height(&tree), 1); + } } diff --git a/src/rstd/collections/tree/context.rs b/src/rstd/collections/tree/context.rs index 1d66f6e..6578dd6 100644 --- a/src/rstd/collections/tree/context.rs +++ b/src/rstd/collections/tree/context.rs @@ -26,32 +26,32 @@ impl Clone for TreeContext { } } -pub enum TreeContextError<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> { - Resolution(ResolutionFailure<'a, Ctx, Node<'a, Ctx, A>>), +#[derive(Debug)] +pub enum TreeContextError { + Resolution(R), Extra(E), } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> - From>> for TreeContextError<'a, Ctx, A, E> +pub type TreeContextError2<'a, Ctx, A, E> = + TreeContextError>, E>; + +impl From>> + for TreeContextError>, E> { - fn from(value: ResolutionFailure<'a, Ctx, Node<'a, Ctx, A>>) -> Self { + fn from(value: ResolutionError>) -> Self { Self::Resolution(value) } } -type TreeParseError2<'a, A> = TreeParseError>; - -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From> - for TreeContextError<'a, Ctx, A, E> +impl From> + for TreeContextError>, E> { - fn from(value: TreeParseError2<'a, A>) -> Self { + fn from(value: TreeParseError

) -> Self { ResolutionError::Parse(value).into() } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From - for TreeContextError<'a, Ctx, A, E> -{ +impl From for TreeContextError>, E> { fn from(value: HeightError) -> Self { TreeParseError::HeightValue(value).into() } @@ -67,7 +67,7 @@ impl< E: 'a + Send, > FunctorContext<'a> for TreeContext2<'a, Ctx, A, C, E> { - type T = FallibleMonad<'a, Ctx, TreeContextError<'a, Ctx, A, E>>; + type T = FallibleMonad<'a, Ctx, TreeContextError2<'a, Ctx, A, E>>; } impl< @@ -181,6 +181,24 @@ impl< } } +impl< + 'a, + Ctx: Context<'a>, + A: Mentionable<'a, Ctx> + Clone, + C: 'a + Comparator, + E: 'a + Send, + > BinaryTreesTryJoin<'a> for TreeContext2<'a, Ctx, A, C, E> +{ + fn try_join( + &self, + tl: Self::Tree, + key: Self::Key, + tr: Self::Tree, + ) -> BTWrap<'a, Self, Self::Node> { + Self::pure(Node { l: tl, r: tr, key }) + } +} + impl< 'a, Ctx: Context<'a>, @@ -194,30 +212,25 @@ impl< } } +#[derive(Debug)] pub enum WrappedExtra { Wrapped(W), Extra(E), } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, W: 'a, E: 'a> From> - for TreeContextError<'a, Ctx, A, WrappedExtra> -{ +impl From> for TreeContextError> { fn from(value: WrappedExtra) -> Self { Self::Extra(value) } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From - for TreeContextError<'a, Ctx, A, WrappedExtra> -{ +impl From for TreeContextError> { fn from(value: BalancingError) -> Self { WrappedExtra::Wrapped(value).into() } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From> - for TreeContextError<'a, Ctx, A, WrappedExtra, E>> -{ +impl From> for TreeContextError, E>> { fn from(value: BoundsError) -> Self { WrappedExtra::Wrapped(value).into() }