BinaryTreesAvl::try_join
This commit is contained in:
parent
c4c279cd27
commit
d96a2c3920
@ -8,7 +8,7 @@ pub trait BinaryTreesAvl<'a>: BinaryTreesHeight<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn join_key_unbalanced(
|
fn try_join(
|
||||||
&self,
|
&self,
|
||||||
tl: Self::Tree,
|
tl: Self::Tree,
|
||||||
key: Self::Key,
|
key: Self::Key,
|
||||||
@ -33,7 +33,7 @@ pub trait BinaryTreesAvl<'a>: BinaryTreesHeight<'a> {
|
|||||||
) -> BTWrap<'a, Self, Self::Node> {
|
) -> BTWrap<'a, Self, Self::Node> {
|
||||||
let (hl, hr) = (self.height(&tl), self.height(&tr));
|
let (hl, hr) = (self.height(&tl), self.height(&tr));
|
||||||
match (hl.saturating_sub(hr), hr.saturating_sub(hl)) {
|
match (hl.saturating_sub(hr), hr.saturating_sub(hl)) {
|
||||||
(0, 0) | (0, 1) | (1, 0) => self.join_key_unbalanced(tl, key, tr),
|
(0, 0) | (0, 1) | (1, 0) => self.try_join(tl, key, tr),
|
||||||
(0, _) => Self::bind(self.assume_node(&tr), move |nr| {
|
(0, _) => Self::bind(self.assume_node(&tr), move |nr| {
|
||||||
let (trl, trr, kr) = self.split(&nr);
|
let (trl, trr, kr) = self.split(&nr);
|
||||||
let (rlh, rrh) = (self.height(&trl), self.height(&trr));
|
let (rlh, rrh) = (self.height(&trl), self.height(&trr));
|
||||||
|
@ -159,7 +159,7 @@ impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesHeight<'a>> BinaryTreesHeight<
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesAvl<'a>> BinaryTreesAvl<'a> for BoundTrees<BT> {
|
impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesAvl<'a>> BinaryTreesAvl<'a> for BoundTrees<BT> {
|
||||||
fn join_key_unbalanced(
|
fn try_join(
|
||||||
&self,
|
&self,
|
||||||
tl: Self::Tree,
|
tl: Self::Tree,
|
||||||
key: Self::Key,
|
key: Self::Key,
|
||||||
@ -170,7 +170,7 @@ impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesAvl<'a>> BinaryTreesAvl<'a> fo
|
|||||||
Bounds::join(boundsl.clone(), boundsr.clone(), &key, self.comparator()),
|
Bounds::join(boundsl.clone(), boundsr.clone(), &key, self.comparator()),
|
||||||
|bounds| {
|
|bounds| {
|
||||||
Self::fmap(
|
Self::fmap(
|
||||||
self.0.join_key_unbalanced(tl.bound, key, tr.bound),
|
self.0.try_join(tl.bound, key, tr.bound),
|
||||||
|node| BoundNode2 {
|
|node| BoundNode2 {
|
||||||
boundsl,
|
boundsl,
|
||||||
boundsr,
|
boundsr,
|
||||||
|
@ -187,7 +187,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesHeight<'a> for AvlTs<A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesAvl<'a> for AvlTs<A> {
|
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesAvl<'a> for AvlTs<A> {
|
||||||
fn join_key_unbalanced(
|
fn try_join(
|
||||||
&self,
|
&self,
|
||||||
tl: Self::Tree,
|
tl: Self::Tree,
|
||||||
key: Self::Key,
|
key: Self::Key,
|
||||||
|
@ -114,7 +114,7 @@ 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>>
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone, C: 'a + Comparator<A>>
|
||||||
BinaryTreesAvl<'a> for BoundContext<'a, Ctx, A, C>
|
BinaryTreesAvl<'a> for BoundContext<'a, Ctx, A, C>
|
||||||
{
|
{
|
||||||
fn join_key_unbalanced(
|
fn try_join(
|
||||||
&self,
|
&self,
|
||||||
tl: Self::Tree,
|
tl: Self::Tree,
|
||||||
key: Self::Key,
|
key: Self::Key,
|
||||||
|
Loading…
Reference in New Issue
Block a user