#[cfg(feature = "serde1")] use serde::{Serialize, Deserialize};
use super::{Estimate, Merge};
fn min(a: f64, b: f64) -> f64 {
a.min(b)
}
fn max(a: f64, b: f64) -> f64 {
a.max(b)
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct Min {
x: f64,
}
impl Min {
#[inline]
pub fn from_value(x: f64) -> Min {
Min { x }
}
#[inline]
pub fn new() -> Min {
Min::from_value(::core::f64::INFINITY)
}
#[inline]
pub fn min(&self) -> f64 {
self.x
}
}
impl core::default::Default for Min {
fn default() -> Min {
Min::new()
}
}
impl_from_iterator!(Min);
impl_from_par_iterator!(Min);
impl Estimate for Min {
#[inline]
fn add(&mut self, x: f64) {
self.x = min(self.x, x);
}
#[inline]
fn estimate(&self) -> f64 {
self.min()
}
}
impl Merge for Min {
#[inline]
fn merge(&mut self, other: &Min) {
self.add(other.x);
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct Max {
x: f64,
}
impl Max {
#[inline]
pub fn from_value(x: f64) -> Max {
Max { x }
}
#[inline]
pub fn new() -> Max {
Max::from_value(::core::f64::NEG_INFINITY)
}
#[inline]
pub fn max(&self) -> f64 {
self.x
}
}
impl core::default::Default for Max {
fn default() -> Max {
Max::new()
}
}
impl_from_iterator!(Max);
impl_from_par_iterator!(Max);
impl Estimate for Max {
#[inline]
fn add(&mut self, x: f64) {
self.x = max(self.x, x);
}
#[inline]
fn estimate(&self) -> f64 {
self.max()
}
}
impl Merge for Max {
#[inline]
fn merge(&mut self, other: &Max) {
self.add(other.x);
}
}