Inline everything

This commit is contained in:
Vinzent Steinberg 2017-05-24 18:59:53 +02:00
parent 12c3fd76d1
commit c1af508205
4 changed files with 11 additions and 0 deletions

View File

@ -28,6 +28,7 @@ pub struct Average {
impl Average {
/// Create a new average estimator.
#[inline]
pub fn new() -> Average {
Average { avg: 0., n: 0 }
}

View File

@ -28,6 +28,7 @@ pub struct Min {
impl Min {
/// Create a new minium estimator from a given value.
#[inline]
pub fn from_value(x: f64) -> Min {
Min {
r: Reduce::from_value_and_fn(x, min),
@ -35,16 +36,19 @@ impl Min {
}
/// Create a new minimum estimator.
#[inline]
pub fn new() -> Min {
Min::from_value(::core::f64::INFINITY)
}
/// Add an element sampled from the population.
#[inline]
pub fn add(&mut self, x: f64) {
self.r.add(x);
}
/// Estimate the minium of the population.
#[inline]
pub fn min(&self) -> f64 {
self.r.reduction()
}
@ -65,6 +69,7 @@ impl Min {
/// min_left.merge(&min_right);
/// assert_eq!(min_total.min(), min_left.min());
/// ```
#[inline]
pub fn merge(&mut self, other: &Min) {
self.r.merge(&other.r);
}

View File

@ -14,21 +14,25 @@ impl<F> Reduce<F>
where F: Fn(f64, f64) -> f64
{
/// Create a new reduction estimator given an initial value and a reduction.
#[inline]
pub fn from_value_and_fn(x: f64, f: F) -> Reduce<F> {
Reduce { x: x, reduce: f }
}
/// Add an element sampled from the population.
#[inline]
pub fn add(&mut self, x: f64) {
self.x = (self.reduce)(self.x, x);
}
/// Estimate the reduction of the population.
#[inline]
pub fn reduction(&self) -> f64 {
self.x
}
/// Merge another sample into this one.
#[inline]
pub fn merge(&mut self, other: &Reduce<F>) {
self.add(other.x);
}

View File

@ -140,6 +140,7 @@ pub struct WeightedAverageWithError {
impl WeightedAverageWithError {
/// Create a new weighted and unweighted average estimator.
#[inline]
pub fn new() -> WeightedAverageWithError {
WeightedAverageWithError {
weight_sum_sq: 0.,