From 1c589acd85c8867b6b5dd09629c5929ccdf596b4 Mon Sep 17 00:00:00 2001 From: timofey Date: Fri, 16 Jun 2023 09:06:33 +0000 Subject: [PATCH] `BinaryTreesAvl` for `BoundTrees` --- src/flow/binary/bounds/bound.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/flow/binary/bounds/bound.rs b/src/flow/binary/bounds/bound.rs index 5c71d95..a18b6b0 100644 --- a/src/flow/binary/bounds/bound.rs +++ b/src/flow/binary/bounds/bound.rs @@ -129,3 +129,34 @@ impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesEmpty<'a>> BinaryTreesEmpty<'a } } } + +impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesAvl<'a>> BinaryTreesAvl<'a> for BoundTrees { + fn height(&self, tree: &Self::Tree) -> u64 { + self.0.height(&tree.bound) + } + + fn leaf_height_error(&self, height: u64) -> BTWrap<'a, Self, T> { + self.0.leaf_height_error(height) + } + + fn join_key_unbalanced( + &self, + tl: Self::Tree, + key: Self::Key, + tr: Self::Tree, + ) -> BTWrap<'a, Self, Self::Node> { + let (boundsl, boundsr) = (tl.bounds, tr.bounds); + match Bounds::join(boundsl.clone(), boundsr.clone(), &key, self.comparator()) { + Ok(bounds) => Self::fmap( + self.0.join_key_unbalanced(tl.bound, key, tr.bound), + |node| BoundNode2 { + boundsl, + boundsr, + bounds, + node, + }, + ), + Err(e) => self.0.bounds_error(e), + } + } +}