HeightError
This commit is contained in:
parent
a1d836ed54
commit
ee169f8bf4
@ -3,6 +3,8 @@ pub mod balancing;
|
|||||||
pub mod bound;
|
pub mod bound;
|
||||||
pub mod bounds;
|
pub mod bounds;
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
use crate::flow::comparator::*;
|
use crate::flow::comparator::*;
|
||||||
use crate::func::{context::*, *};
|
use crate::func::{context::*, *};
|
||||||
|
|
||||||
@ -132,10 +134,26 @@ pub trait BinaryTreesMutable<'a>: BinaryTreesEmpty<'a> + BinaryTreesTreeOf<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum HeightError {
|
||||||
|
LeafHeight(u64),
|
||||||
|
NodeHeight,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for HeightError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::NodeHeight => write!(f, "invalid node height: 0."),
|
||||||
|
Self::LeafHeight(height) => {
|
||||||
|
write!(f, "invalid leaf height: {height}!=0.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait BinaryTreesHeight<'a>: BinaryTrees<'a> {
|
pub trait BinaryTreesHeight<'a>: BinaryTrees<'a> {
|
||||||
fn height(&self, tree: &Self::Tree) -> u64;
|
fn height(&self, tree: &Self::Tree) -> u64;
|
||||||
fn leaf_height_error<T: 'a>(&self, height: u64) -> BTWrap<'a, Self, T>;
|
fn height_error<T: 'a>(&self, error: HeightError) -> BTWrap<'a, Self, T>;
|
||||||
fn node_height_error<T: 'a>(&self) -> BTWrap<'a, Self, T>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait BinaryTreesTryJoin<'a>: BinaryTrees<'a> {
|
pub trait BinaryTreesTryJoin<'a>: BinaryTrees<'a> {
|
||||||
|
@ -6,7 +6,7 @@ pub trait BinaryTreesAvl<'a>:
|
|||||||
fn assume_node(&self, tree: &Self::Tree) -> BTWrap<'a, Self, Self::Node> {
|
fn assume_node(&self, tree: &Self::Tree) -> BTWrap<'a, Self, Self::Node> {
|
||||||
match self.refer(tree) {
|
match self.refer(tree) {
|
||||||
Some(reference) => self.resolve(&reference),
|
Some(reference) => self.resolve(&reference),
|
||||||
None => self.leaf_height_error(self.height(tree)),
|
None => self.height_error(HeightError::LeafHeight(self.height(tree))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,12 +160,8 @@ impl<'a, BT: BinaryTreesUnbalanced<'a>> BinaryTreesHeight<'a> for BalancedTrees<
|
|||||||
self.0.height(tree)
|
self.0.height(tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn leaf_height_error<T: 'a>(&self, height: u64) -> BTWrap<'a, Self, T> {
|
fn height_error<T: 'a>(&self, error: HeightError) -> BTWrap<'a, Self, T> {
|
||||||
self.0.leaf_height_error(height)
|
self.0.height_error(error)
|
||||||
}
|
|
||||||
|
|
||||||
fn node_height_error<T: 'a>(&self) -> BTWrap<'a, Self, T> {
|
|
||||||
self.0.node_height_error()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,12 +169,8 @@ impl<'a, BT: BinaryTreesBindable<'a> + BinaryTreesHeight<'a>> BinaryTreesHeight<
|
|||||||
self.0.height(&tree.bound)
|
self.0.height(&tree.bound)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn leaf_height_error<T: 'a>(&self, height: u64) -> BTWrap<'a, Self, T> {
|
fn height_error<T: 'a>(&self, error: HeightError) -> BTWrap<'a, Self, T> {
|
||||||
self.0.leaf_height_error(height)
|
self.0.height_error(error)
|
||||||
}
|
|
||||||
|
|
||||||
fn node_height_error<T: 'a>(&self) -> BTWrap<'a, Self, T> {
|
|
||||||
self.0.node_height_error()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,12 +119,8 @@ impl<'a, A: 'a + Ord + Clone> BinaryTreesHeight<'a> for Trees<A> {
|
|||||||
tree.height
|
tree.height
|
||||||
}
|
}
|
||||||
|
|
||||||
fn leaf_height_error<T: 'a>(&self, height: u64) -> BTWrap<'a, Self, T> {
|
fn height_error<T: 'a>(&self, error: HeightError) -> BTWrap<'a, Self, T> {
|
||||||
panic!("leaf height error: {height}.")
|
panic!("{error}")
|
||||||
}
|
|
||||||
|
|
||||||
fn node_height_error<T: 'a>(&self) -> BTWrap<'a, Self, T> {
|
|
||||||
panic!("node with height 0.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user