From: Ben Pfaff Date: Tue, 20 Oct 2026 02:12:04 +0000 (-0700) Subject: work on percentiles X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4e55f9c0a436293649f2a605b8c269db52780aa;p=pspp work on percentiles --- 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)), } }