From b73f18960f5b542bc82bc579bfefff30d3f3f01a Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Sun, 10 Nov 2024 23:19:25 +0100 Subject: [PATCH] refactor: Empirical::add: Use `and_modify` --- src/distribution/empirical.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/distribution/empirical.rs b/src/distribution/empirical.rs index 0726fb00..a6522fd1 100644 --- a/src/distribution/empirical.rs +++ b/src/distribution/empirical.rs @@ -104,7 +104,10 @@ impl Empirical { self.var += (sum - 1.) * (data_point - self.mean) * (data_point - self.mean) / sum; self.mean += (data_point - self.mean) / sum; - *self.data.entry(map_key).or_insert(0) += 1; + self.data + .entry(map_key) + .and_modify(|c| *c += 1) + .or_insert(1); } pub fn remove(&mut self, data_point: f64) {