one_has_height_1
All checks were successful
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo clippy (1.65) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo test (1.65) Build done.

This commit is contained in:
AF 2023-10-15 12:45:46 +00:00
parent 16fbbbd16d
commit edbff39ae2
2 changed files with 55 additions and 26 deletions

View File

@ -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<u64>, DefaultComparator, Infallible>;
type Trees = TreeContext2<
'static,
TestContextPlain,
AtomicObject<u64>,
DefaultComparator,
WrappedExtra<BalancingError, Infallible>,
>;
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);
}
}

View File

@ -26,32 +26,32 @@ impl<Cl: Clone, T> Clone for TreeContext<Cl, T> {
}
}
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<R, E> {
Resolution(R),
Extra(E),
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a>
From<ResolutionFailure<'a, Ctx, Node<'a, Ctx, A>>> for TreeContextError<'a, Ctx, A, E>
pub type TreeContextError2<'a, Ctx, A, E> =
TreeContextError<ResolutionFailure<'a, Ctx, Node<'a, Ctx, A>>, E>;
impl<L, P, E> From<ResolutionError<L, TreeParseError<P>>>
for TreeContextError<ResolutionError<L, TreeParseError<P>>, E>
{
fn from(value: ResolutionFailure<'a, Ctx, Node<'a, Ctx, A>>) -> Self {
fn from(value: ResolutionError<L, TreeParseError<P>>) -> Self {
Self::Resolution(value)
}
}
type TreeParseError2<'a, A> = TreeParseError<ParseErrorA<'a, A>>;
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From<TreeParseError2<'a, A>>
for TreeContextError<'a, Ctx, A, E>
impl<L, P, E> From<TreeParseError<P>>
for TreeContextError<ResolutionError<L, TreeParseError<P>>, E>
{
fn from(value: TreeParseError2<'a, A>) -> Self {
fn from(value: TreeParseError<P>) -> Self {
ResolutionError::Parse(value).into()
}
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From<HeightError>
for TreeContextError<'a, Ctx, A, E>
{
impl<L, P, E> From<HeightError> for TreeContextError<ResolutionError<L, TreeParseError<P>>, 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<A>,
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<W, E> {
Wrapped(W),
Extra(E),
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, W: 'a, E: 'a> From<WrappedExtra<W, E>>
for TreeContextError<'a, Ctx, A, WrappedExtra<W, E>>
{
impl<R, E, W> From<WrappedExtra<W, E>> for TreeContextError<R, WrappedExtra<W, E>> {
fn from(value: WrappedExtra<W, E>) -> Self {
Self::Extra(value)
}
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From<BalancingError>
for TreeContextError<'a, Ctx, A, WrappedExtra<BalancingError, E>>
{
impl<R, E> From<BalancingError> for TreeContextError<R, WrappedExtra<BalancingError, E>> {
fn from(value: BalancingError) -> Self {
WrappedExtra::Wrapped(value).into()
}
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From<BoundsError<A>>
for TreeContextError<'a, Ctx, A, WrappedExtra<BoundsError<A>, E>>
{
impl<R, A, E> From<BoundsError<A>> for TreeContextError<R, WrappedExtra<BoundsError<A>, E>> {
fn from(value: BoundsError<A>) -> Self {
WrappedExtra::Wrapped(value).into()
}