-
Notifications
You must be signed in to change notification settings - Fork 152
Closed
Description
I think it would be very useful to have the midpoint
function in num_traits
for implementing binary search.
I'm currently using:
pub trait Midpoint: Num {
fn midpoint(&self, rhs: &Self) -> Self;
}
impl<T> Midpoint for T
where
T: Num + Shr<u8, Output = T>,
for<'a> &'a T: BitXor<&'a T, Output = T> + BitAnd<&'a T, Output = T>,
{
fn midpoint(&self, rhs: &Self) -> Self {
((self ^ rhs) >> 1u8) + (self & rhs)
}
}
Metadata
Metadata
Assignees
Labels
No labels