pub mod simple;
pub mod moments;
pub mod histogram;
pub mod tdigest;
pub use histogram::{HistResult, Histogram};
pub use tdigest::{TDigest, TDigestResult, quantile_edges};
pub trait Mergeable {
fn merge(&mut self, other: &Self);
}
pub trait Accumulator: Mergeable {
type Item;
type Output;
fn empty() -> Self;
fn update(&mut self, x: Self::Item);
fn finalize(&self) -> Self::Output;
}
pub fn from_slice<A: Accumulator<Item = f64>>(xs: &[f64]) -> A {
let mut a = A::empty();
for &x in xs {
if !x.is_nan() { a.update(x); }
}
a
}
pub(crate) fn quantile_sorted(sorted: &[f64], q: f64) -> f64 {
let n = sorted.len();
if n == 0 { return f64::NAN; }
if n == 1 { return sorted[0]; }
let h = (n as f64 - 1.0) * q;
let lo = h.floor() as usize;
let hi = h.ceil() as usize;
let frac = h - lo as f64;
sorted[lo] + (sorted[hi] - sorted[lo]) * frac
}