BinaryTreesEmpty
This commit is contained in:
parent
1e9258717a
commit
03b4a4764b
@ -34,9 +34,17 @@ pub trait BinaryTrees<'a>: FunctorContext<'a, T = Self::_Tm> + Clone {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait BinaryTreesMutable<'a>: BinaryTrees<'a> {
|
||||
pub trait BinaryTreesEmpty<'a>: BinaryTrees<'a> {
|
||||
fn empty(&self) -> Self::Tree;
|
||||
|
||||
fn split_key_empty(
|
||||
&self,
|
||||
tree: Self::Tree,
|
||||
key: Self::Key,
|
||||
) -> BTWrap<'a, Self, KeySplit<'a, Self>>;
|
||||
}
|
||||
|
||||
pub trait BinaryTreesMutable<'a>: BinaryTreesEmpty<'a> {
|
||||
fn join_key(
|
||||
self,
|
||||
tl: Self::Tree,
|
||||
@ -76,12 +84,6 @@ pub trait BinaryTreesMutable<'a>: BinaryTrees<'a> {
|
||||
})
|
||||
}
|
||||
|
||||
fn split_key_empty(
|
||||
&self,
|
||||
tree: Self::Tree,
|
||||
key: Self::Key,
|
||||
) -> BTWrap<'a, Self, KeySplit<'a, Self>>;
|
||||
|
||||
fn split_key_node(
|
||||
self,
|
||||
node: Self::Node,
|
||||
|
@ -146,7 +146,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTrees<'a> for AvlTs<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesMutable<'a> for AvlTs<A> {
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesEmpty<'a> for AvlTs<A> {
|
||||
fn empty(&self) -> Self::Tree {
|
||||
AvlT {
|
||||
reference: None,
|
||||
@ -154,15 +154,6 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesMutable<'a> for AvlTs<A> {
|
||||
}
|
||||
}
|
||||
|
||||
fn join_key(
|
||||
self,
|
||||
tl: Self::Tree,
|
||||
key: Self::Key,
|
||||
tr: Self::Tree,
|
||||
) -> BTWrap<'a, Self, Self::Node> {
|
||||
self.join_key_balanced(tl, key, tr)
|
||||
}
|
||||
|
||||
fn split_key_empty(
|
||||
&self,
|
||||
_tree: Self::Tree,
|
||||
@ -172,6 +163,17 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesMutable<'a> for AvlTs<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesMutable<'a> for AvlTs<A> {
|
||||
fn join_key(
|
||||
self,
|
||||
tl: Self::Tree,
|
||||
key: Self::Key,
|
||||
tr: Self::Tree,
|
||||
) -> BTWrap<'a, Self, Self::Node> {
|
||||
self.join_key_balanced(tl, key, tr)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesAvl<'a> for AvlTs<A> {
|
||||
fn height(&self, tree: &Self::Tree) -> u64 {
|
||||
tree.height
|
||||
|
@ -94,3 +94,38 @@ impl<'a, BT: BinaryTreesBindable<'a>> BinaryTrees<'a> for BoundTrees<BT> {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesEmpty<'a>> BinaryTreesEmpty<'a>
|
||||
for BoundTrees<BT>
|
||||
{
|
||||
fn empty(&self) -> Self::Tree {
|
||||
Bound {
|
||||
bound: self.0.empty(),
|
||||
bounds: Bounds::unbound(),
|
||||
}
|
||||
}
|
||||
|
||||
fn split_key_empty(
|
||||
&self,
|
||||
tree: Self::Tree,
|
||||
key: Self::Key,
|
||||
) -> BTWrap<'a, Self, KeySplit<'a, Self>> {
|
||||
match tree.bounds.split(&key, self.comparator()) {
|
||||
Ok((boundsl, boundsr)) => {
|
||||
Self::bind(self.0.split_key_empty(tree.bound, key), |(tl, tr)| {
|
||||
Self::pure((
|
||||
Bound {
|
||||
bound: tl,
|
||||
bounds: boundsl,
|
||||
},
|
||||
Bound {
|
||||
bound: tr,
|
||||
bounds: boundsr,
|
||||
},
|
||||
))
|
||||
})
|
||||
}
|
||||
Err(e) => self.0.bounds_error(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,21 +67,12 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A>>
|
||||
BinaryTreesMutable<'a> for BoundContext<'a, Ctx, A, C>
|
||||
BinaryTreesEmpty<'a> for BoundContext<'a, Ctx, A, C>
|
||||
{
|
||||
fn empty(&self) -> Self::Tree {
|
||||
BoundTree::empty(self.factory.clone())
|
||||
}
|
||||
|
||||
fn join_key(
|
||||
self,
|
||||
tl: Self::Tree,
|
||||
key: Self::Key,
|
||||
tr: Self::Tree,
|
||||
) -> BTWrap<'a, Self, Self::Node> {
|
||||
self.join_key_balanced(tl, key, tr)
|
||||
}
|
||||
|
||||
fn split_key_empty(
|
||||
&self,
|
||||
tree: Self::Tree,
|
||||
@ -91,6 +82,19 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A>>
|
||||
BinaryTreesMutable<'a> for BoundContext<'a, Ctx, A, C>
|
||||
{
|
||||
fn join_key(
|
||||
self,
|
||||
tl: Self::Tree,
|
||||
key: Self::Key,
|
||||
tr: Self::Tree,
|
||||
) -> BTWrap<'a, Self, Self::Node> {
|
||||
self.join_key_balanced(tl, key, tr)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A>>
|
||||
BinaryTreesAvl<'a> for BoundContext<'a, Ctx, A, C>
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user