From: Ben Pfaff Date: Tue, 20 Oct 2026 02:32:56 +0000 (-0700) Subject: percentiles X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=271977c99a88cf9f0867f12e9885f52718dbdb57;p=pspp percentiles --- diff --git a/rust/pspp/src/percentiles.rs b/rust/pspp/src/percentiles.rs index 15e288f107..278004ed31 100644 --- a/rust/pspp/src/percentiles.rs +++ b/rust/pspp/src/percentiles.rs @@ -144,22 +144,20 @@ where where T: CumulativeFrequency, { - 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 } - }) + let obs = this.get(k)?; + let y = obs.y(); + let cc = obs.cc(); + let c = if k == 0 { cc } else { cc - this[k - 1].cc() }; + Some(Observation { y, c, cc }) } - match this.partition_point(|obs| obs.cc() <= cum_weight) { - 0 => (None, get(this, 0)), - k => (get(this, k - 1), get(this, k)), - } + let k = this.partition_point(|obs| obs.cc() <= cum_weight); + let a = k.checked_sub(1).and_then(|k| get(this, k)); + let b = get(this, k); + (a, b) } - let total_weight = self.last().map_or(0.0, |last| last.cc()); - let tcw = algorithm.target_cumulative_weight(total_weight, p); + let tcw = algorithm.target_cumulative_weight(self.last()?.cc(), p); algorithm.percentile(tcw, observations_around(self, tcw)) } }