Skip to content

Commit

Permalink
refactor: Empirical::add: Use and_modify
Browse files Browse the repository at this point in the history
  • Loading branch information
FreezyLemon authored and YeungOnion committed Dec 3, 2024
1 parent 6ad4291 commit b73f189
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/distribution/empirical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b73f189

Please sign in to comment.