use core;
use super::reduce::Reduce;
fn min(a: f64, b: f64) -> f64 {
a.min(b)
}
fn max(a: f64, b: f64) -> f64 {
a.max(b)
}
#[derive(Debug, Clone)]
pub struct Min {
r: Reduce<fn(f64, f64) -> f64>,
}
impl Min {
#[inline]
pub fn from_value(x: f64) -> Min {
Min {
r: Reduce::from_value_and_fn(x, min),
}
}
#[inline]
pub fn new() -> Min {
Min::from_value(::core::f64::INFINITY)
}
#[inline]
pub fn add(&mut self, x: f64) {
self.r.add(x);
}
#[inline]
pub fn min(&self) -> f64 {
self.r.reduction()
}
#[inline]
pub fn merge(&mut self, other: &Min) {
self.r.merge(&other.r);
}
}
impl core::iter::FromIterator<f64> for Min {
fn from_iter<T>(iter: T) -> Min
where T: IntoIterator<Item=f64>
{
let mut a = Min::new();
for i in iter {
a.add(i);
}
a
}
}
#[derive(Debug, Clone)]
pub struct Max {
r: Reduce<fn(f64, f64) -> f64>,
}
impl Max {
#[inline]
pub fn from_value(x: f64) -> Max {
Max {
r: Reduce::from_value_and_fn(x, max),
}
}
#[inline]
pub fn new() -> Max {
Max::from_value(::core::f64::NEG_INFINITY)
}
#[inline]
pub fn add(&mut self, x: f64) {
self.r.add(x);
}
#[inline]
pub fn max(&self) -> f64 {
self.r.reduction()
}
#[inline]
pub fn merge(&mut self, other: &Max) {
self.r.merge(&other.r);
}
}
impl core::iter::FromIterator<f64> for Max {
fn from_iter<T>(iter: T) -> Max
where T: IntoIterator<Item=f64>
{
let mut a = Max::new();
for i in iter {
a.add(i);
}
a
}
}