From e4e55f9c0a436293649f2a605b8c269db52780aa Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 19 Oct 2026 19:12:04 -0700 Subject: [PATCH] work on percentiles --- rust/pspp/src/percentiles.rs | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/rust/pspp/src/percentiles.rs b/rust/pspp/src/percentiles.rs index 7a8d3ef63a..15e288f107 100644 --- a/rust/pspp/src/percentiles.rs +++ b/rust/pspp/src/percentiles.rs @@ -140,34 +140,21 @@ where where T: CumulativeFrequency, { - fn get(this: &[T], k: usize) -> Observation + fn get(this: &[T], k: usize) -> Option where T: CumulativeFrequency, { - let y = this[k].y(); - let cc = this[k].cc(); - let c = if k == 0 { cc } else { cc - this[k - 1].cc() }; - Observation { y, c, cc } + this.get(k).map(|obs| { + let y = obs.y(); + let cc = obs.cc(); + let c = if k == 0 { cc } else { cc - this[k - 1].cc() }; + Observation { y, c, cc } + }) } - match this - .partition_point(|obs| obs.cc() <= cum_weight) - .checked_sub(1) - { - Some(k) => { - if k + 1 >= this.len() { - (Some(get(this, k)), None) - } else { - (Some(get(this, k)), Some(get(this, k + 1))) - } - } - None => { - if this.is_empty() { - (None, None) - } else { - (None, Some(get(this, 0))) - } - } + match this.partition_point(|obs| obs.cc() <= cum_weight) { + 0 => (None, get(this, 0)), + k => (get(this, k - 1), get(this, k)), } } -- 2.47.3