loosen tree bounds

This commit is contained in:
AF 2023-07-29 15:04:29 +00:00
parent fd2bae70ac
commit b7e3beacb6

View File

@ -55,18 +55,18 @@ impl<E: Display> Display for TreeParseError<E> {
impl<E: Error> Error for TreeParseError<E> {}
pub struct Node<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
pub struct Node<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> {
l: Tree<'a, Ctx, A>,
r: Tree<'a, Ctx, A>,
key: A,
}
pub struct Tree<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
pub struct Tree<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> {
node: Nullable<'a, Ctx, Node<'a, Ctx, A>>,
height: u64,
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Tree<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Tree<'a, Ctx, A> {
fn validate_height(&self) -> Result<(), HeightError> {
if let Nullable::Null(_) = self.node {
if self.height != 0 {
@ -85,7 +85,7 @@ pub struct NodeFactory<F>(F);
#[derive(Clone)]
pub struct TreeFactory<F>(NullableFactory<NodeFactory<F>>);
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Node<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Node<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) {
self.l.serialize(serializer);
self.r.serialize(serializer);
@ -93,14 +93,16 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Node<'a, Ct
}
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Tree<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Tree<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) {
self.height.serialize(serializer);
self.node.serialize(serializer);
}
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableBase<'a, Ctx> for Node<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx>
for Node<'a, Ctx, A>
{
type Fctr = NodeFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr {
@ -116,7 +118,9 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> for
}
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableBase<'a, Ctx> for Tree<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx>
for Tree<'a, Ctx, A>
{
type Fctr = TreeFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr {
@ -130,7 +134,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> for
}
}
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> FactoryBase<'a, Ctx> for NodeFactory<F> {
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for NodeFactory<F> {
type Mtbl = Node<'a, Ctx, F::Mtbl>;
type ParseError = TreeParseError<F::ParseError>;
@ -140,7 +144,7 @@ impl<F> ParseMode for NodeFactory<F> {
type Mode = RegularMode;
}
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> RegularFactory<'a, Ctx> for NodeFactory<F> {
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> RegularFactory<'a, Ctx> for NodeFactory<F> {
fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
let tree_factory = TreeFactory(NullableFactory::new(self.clone()));
let (l, inctx) = tree_factory.ideserialize(inctx)?;
@ -158,7 +162,7 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> RegularFactory<'a, Ctx> for Node
}
}
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> FactoryBase<'a, Ctx> for TreeFactory<F> {
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for TreeFactory<F> {
type Mtbl = Tree<'a, Ctx, F::Mtbl>;
type ParseError = TreeParseError<F::ParseError>;
@ -168,7 +172,7 @@ impl<F> ParseMode for TreeFactory<F> {
type Mode = InliningMode;
}
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> InlineableFactory<'a, Ctx> for TreeFactory<F> {
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> InlineableFactory<'a, Ctx> for TreeFactory<F> {
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
u64::a_extension_error(tail).into()
}
@ -182,7 +186,7 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> InlineableFactory<'a, Ctx> for T
}
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone> Clone for Node<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx> + Clone> Clone for Node<'a, Ctx, A> {
fn clone(&self) -> Self {
Self {
l: self.l.clone(),
@ -192,7 +196,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone> Clone for Node<'a, C
}
}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone> Clone for Tree<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx> + Clone> Clone for Tree<'a, Ctx, A> {
fn clone(&self) -> Self {
Self {
node: self.node.clone(),