PartialOrd
-> Ord
This commit is contained in:
parent
a89fd3416c
commit
634393ba4a
@ -19,17 +19,15 @@ pub trait Comparator<A> {
|
||||
fn pick_smaller(&self, kl: &A, kr: &A) -> Comparison;
|
||||
}
|
||||
|
||||
/// Implementation of a [Comparator] relying on [`PartialOrd`].
|
||||
/// Implementation of a [Comparator] relying on [`Ord`].
|
||||
pub struct DefaultComparator;
|
||||
|
||||
impl<A: PartialOrd> Comparator<A> for DefaultComparator {
|
||||
impl<A: Ord> Comparator<A> for DefaultComparator {
|
||||
fn pick_smaller(&self, kl: &A, kr: &A) -> Comparison {
|
||||
if kl < kr {
|
||||
Comparison::L
|
||||
} else if kr < kl {
|
||||
Comparison::R
|
||||
} else {
|
||||
Comparison::E
|
||||
match kl.cmp(kr) {
|
||||
std::cmp::Ordering::Less => Comparison::L,
|
||||
std::cmp::Ordering::Equal => Comparison::E,
|
||||
std::cmp::Ordering::Greater => Comparison::R,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ impl<'a, A: 'a> FunctorContext<'a> for AvlTs<A> {
|
||||
type T = instances::solo::SoloInstance;
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTrees<'a> for AvlTs<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTrees<'a> for AvlTs<A> {
|
||||
type Node = AvlN<A>;
|
||||
|
||||
type Reference = AvlR<A>;
|
||||
@ -137,7 +137,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTrees<'a> for AvlTs<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesTreeOf<'a> for AvlTs<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesTreeOf<'a> for AvlTs<A> {
|
||||
fn tree_of(&self, node: Self::Node) -> BTWrap<'a, Self, Self::Tree> {
|
||||
AvlT {
|
||||
height: std::cmp::max(node.l.height, node.r.height)
|
||||
@ -148,7 +148,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesTreeOf<'a> for AvlTs<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesEmpty<'a> for AvlTs<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesEmpty<'a> for AvlTs<A> {
|
||||
fn empty(&self) -> Self::Tree {
|
||||
AvlT {
|
||||
reference: None,
|
||||
@ -165,7 +165,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesEmpty<'a> for AvlTs<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesMutable<'a> for AvlTs<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesMutable<'a> for AvlTs<A> {
|
||||
fn join_key(
|
||||
self,
|
||||
tl: Self::Tree,
|
||||
@ -176,7 +176,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesMutable<'a> for AvlTs<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesHeight<'a> for AvlTs<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesHeight<'a> for AvlTs<A> {
|
||||
fn height(&self, tree: &Self::Tree) -> u64 {
|
||||
tree.height
|
||||
}
|
||||
@ -186,7 +186,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesHeight<'a> for AvlTs<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesTryJoin<'a> for AvlTs<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesTryJoin<'a> for AvlTs<A> {
|
||||
fn try_join(
|
||||
&self,
|
||||
tl: Self::Tree,
|
||||
@ -197,7 +197,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesTryJoin<'a> for AvlTs<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesBindable<'a> for AvlTs<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesBindable<'a> for AvlTs<A> {
|
||||
fn bounds_error<T: 'a>(&self, _error: bounds::BoundsError<Self::Key>) -> BTWrap<'a, Self, T> {
|
||||
panic!("bounds violated.");
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ impl<'a, A: 'a> FunctorContext<'a> for Trees<A> {
|
||||
type T = instances::solo::SoloInstance;
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTrees<'a> for Trees<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTrees<'a> for Trees<A> {
|
||||
type Node = Node<A>;
|
||||
|
||||
type Reference = Reference<A>;
|
||||
@ -114,7 +114,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTrees<'a> for Trees<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesHeight<'a> for Trees<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesHeight<'a> for Trees<A> {
|
||||
fn height(&self, tree: &Self::Tree) -> u64 {
|
||||
tree.height
|
||||
}
|
||||
@ -124,7 +124,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesHeight<'a> for Trees<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesEmpty<'a> for Trees<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesEmpty<'a> for Trees<A> {
|
||||
fn empty(&self) -> Self::Tree {
|
||||
Tree {
|
||||
reference: None,
|
||||
@ -141,7 +141,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesEmpty<'a> for Trees<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesTryJoin<'a> for Trees<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesTryJoin<'a> for Trees<A> {
|
||||
fn try_join(
|
||||
&self,
|
||||
tl: Self::Tree,
|
||||
@ -152,7 +152,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesTryJoin<'a> for Trees<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesUnbalanced<'a> for Trees<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesUnbalanced<'a> for Trees<A> {
|
||||
fn tree_of_with_height(&self, node: Self::Node, height: u64) -> BTWrap<'a, Self, Self::Tree> {
|
||||
Tree {
|
||||
reference: Some(Reference {
|
||||
@ -167,7 +167,7 @@ impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesUnbalanced<'a> for Trees<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A: 'a + PartialOrd + Clone> BinaryTreesBindable<'a> for Trees<A> {
|
||||
impl<'a, A: 'a + Ord + Clone> BinaryTreesBindable<'a> for Trees<A> {
|
||||
fn bounds_error<T: 'a>(&self, _error: bounds::BoundsError<Self::Key>) -> BTWrap<'a, Self, T> {
|
||||
panic!("bounds violated.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user