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))
}
}