mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 23:29:58 -07:00
computer: big refactor
This commit is contained in:
@@ -1,5 +1,25 @@
|
||||
use std::ops::{Add, Div};
|
||||
|
||||
/// Extension trait for Option to provide shorter unwrap methods
|
||||
pub trait OptionExt<T> {
|
||||
/// Shorthand for `.as_ref().unwrap()`
|
||||
fn u(&self) -> &T;
|
||||
/// Shorthand for `.as_mut().unwrap()`
|
||||
fn um(&mut self) -> &mut T;
|
||||
}
|
||||
|
||||
impl<T> OptionExt<T> for Option<T> {
|
||||
#[inline]
|
||||
fn u(&self) -> &T {
|
||||
self.as_ref().unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn um(&mut self) -> &mut T {
|
||||
self.as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_percentile<T>(sorted: &[T], percentile: f64) -> T
|
||||
where
|
||||
T: Clone + Div<usize, Output = T> + Add<T, Output = T>,
|
||||
|
||||
Reference in New Issue
Block a user