one_has_height_1
This commit is contained in:
parent
16fbbbd16d
commit
edbff39ae2
@ -237,15 +237,23 @@ mod tests {
|
|||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
flow::{binary::*, comparator::*},
|
flow::{
|
||||||
|
binary::{balancing::*, *},
|
||||||
|
comparator::*,
|
||||||
|
},
|
||||||
rstd::atomic_object::*,
|
rstd::atomic_object::*,
|
||||||
testing::TestContextPlain,
|
testing::TestContextPlain,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::context::*;
|
use super::context::*;
|
||||||
|
|
||||||
type Trees =
|
type Trees = TreeContext2<
|
||||||
TreeContext2<'static, TestContextPlain, AtomicObject<u64>, DefaultComparator, Infallible>;
|
'static,
|
||||||
|
TestContextPlain,
|
||||||
|
AtomicObject<u64>,
|
||||||
|
DefaultComparator,
|
||||||
|
WrappedExtra<BalancingError, Infallible>,
|
||||||
|
>;
|
||||||
|
|
||||||
fn new_trees() -> Trees {
|
fn new_trees() -> Trees {
|
||||||
Trees::new((DefaultComparator.into(), u64::f()))
|
Trees::new((DefaultComparator.into(), u64::f()))
|
||||||
@ -256,4 +264,12 @@ mod tests {
|
|||||||
let trees = new_trees();
|
let trees = new_trees();
|
||||||
assert_eq!(trees.height(&trees.empty()), 0);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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> {
|
#[derive(Debug)]
|
||||||
Resolution(ResolutionFailure<'a, Ctx, Node<'a, Ctx, A>>),
|
pub enum TreeContextError<R, E> {
|
||||||
|
Resolution(R),
|
||||||
Extra(E),
|
Extra(E),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a>
|
pub type TreeContextError2<'a, Ctx, A, E> =
|
||||||
From<ResolutionFailure<'a, Ctx, Node<'a, Ctx, A>>> for TreeContextError<'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)
|
Self::Resolution(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type TreeParseError2<'a, A> = TreeParseError<ParseErrorA<'a, A>>;
|
impl<L, P, E> From<TreeParseError<P>>
|
||||||
|
for TreeContextError<ResolutionError<L, TreeParseError<P>>, E>
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From<TreeParseError2<'a, A>>
|
|
||||||
for TreeContextError<'a, Ctx, A, E>
|
|
||||||
{
|
{
|
||||||
fn from(value: TreeParseError2<'a, A>) -> Self {
|
fn from(value: TreeParseError<P>) -> Self {
|
||||||
ResolutionError::Parse(value).into()
|
ResolutionError::Parse(value).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From<HeightError>
|
impl<L, P, E> From<HeightError> for TreeContextError<ResolutionError<L, TreeParseError<P>>, E> {
|
||||||
for TreeContextError<'a, Ctx, A, E>
|
|
||||||
{
|
|
||||||
fn from(value: HeightError) -> Self {
|
fn from(value: HeightError) -> Self {
|
||||||
TreeParseError::HeightValue(value).into()
|
TreeParseError::HeightValue(value).into()
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ impl<
|
|||||||
E: 'a + Send,
|
E: 'a + Send,
|
||||||
> FunctorContext<'a> for TreeContext2<'a, Ctx, A, C, E>
|
> 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<
|
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<
|
impl<
|
||||||
'a,
|
'a,
|
||||||
Ctx: Context<'a>,
|
Ctx: Context<'a>,
|
||||||
@ -194,30 +212,25 @@ impl<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum WrappedExtra<W, E> {
|
pub enum WrappedExtra<W, E> {
|
||||||
Wrapped(W),
|
Wrapped(W),
|
||||||
Extra(E),
|
Extra(E),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, W: 'a, E: 'a> From<WrappedExtra<W, E>>
|
impl<R, E, W> From<WrappedExtra<W, E>> for TreeContextError<R, WrappedExtra<W, E>> {
|
||||||
for TreeContextError<'a, Ctx, A, WrappedExtra<W, E>>
|
|
||||||
{
|
|
||||||
fn from(value: WrappedExtra<W, E>) -> Self {
|
fn from(value: WrappedExtra<W, E>) -> Self {
|
||||||
Self::Extra(value)
|
Self::Extra(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From<BalancingError>
|
impl<R, E> From<BalancingError> for TreeContextError<R, WrappedExtra<BalancingError, E>> {
|
||||||
for TreeContextError<'a, Ctx, A, WrappedExtra<BalancingError, E>>
|
|
||||||
{
|
|
||||||
fn from(value: BalancingError) -> Self {
|
fn from(value: BalancingError) -> Self {
|
||||||
WrappedExtra::Wrapped(value).into()
|
WrappedExtra::Wrapped(value).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From<BoundsError<A>>
|
impl<R, A, E> From<BoundsError<A>> for TreeContextError<R, WrappedExtra<BoundsError<A>, E>> {
|
||||||
for TreeContextError<'a, Ctx, A, WrappedExtra<BoundsError<A>, E>>
|
|
||||||
{
|
|
||||||
fn from(value: BoundsError<A>) -> Self {
|
fn from(value: BoundsError<A>) -> Self {
|
||||||
WrappedExtra::Wrapped(value).into()
|
WrappedExtra::Wrapped(value).into()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user