From bfbfab11a7f25842a6a5394ec517913ee80f074b Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Tue, 7 May 2024 18:08:29 +0100 Subject: [PATCH] fix clippy --- vortex-array/src/array/chunked/stats.rs | 5 +- vortex-array/src/stats/statsset.rs | 90 +++++++++++-------------- 2 files changed, 41 insertions(+), 54 deletions(-) diff --git a/vortex-array/src/array/chunked/stats.rs b/vortex-array/src/array/chunked/stats.rs index 7b831e018e..0b05091a77 100644 --- a/vortex-array/src/array/chunked/stats.rs +++ b/vortex-array/src/array/chunked/stats.rs @@ -1,8 +1,8 @@ use vortex_error::VortexResult; use crate::array::chunked::ChunkedArray; -use crate::stats::{ArrayStatisticsCompute, Stat, StatsSet}; use crate::stats::ArrayStatistics; +use crate::stats::{ArrayStatisticsCompute, Stat, StatsSet}; impl ArrayStatisticsCompute for ChunkedArray<'_> { fn compute_statistics(&self, stat: Stat) -> VortexResult { @@ -17,6 +17,7 @@ impl ArrayStatisticsCompute for ChunkedArray<'_> { .reduce(|mut acc, x| { acc.merge(&x); acc - }).unwrap_or_default()) + }) + .unwrap_or_default()) } } diff --git a/vortex-array/src/stats/statsset.rs b/vortex-array/src/stats/statsset.rs index 14d944ec35..ccb1e1071b 100644 --- a/vortex-array/src/stats/statsset.rs +++ b/vortex-array/src/stats/statsset.rs @@ -3,7 +3,6 @@ use std::collections::HashMap; use enum_iterator::all; use itertools::Itertools; - use vortex_error::VortexError; use vortex_scalar::{ListScalarVec, Scalar}; @@ -35,7 +34,7 @@ impl StatsSet { self.values.get(&stat) } - fn get_as TryFrom<&'a Scalar, Error=VortexError>>(&self, stat: Stat) -> Option { + fn get_as TryFrom<&'a Scalar, Error = VortexError>>(&self, stat: Stat) -> Option { self.get(stat).map(|v| T::try_from(v).unwrap()) } @@ -71,17 +70,14 @@ impl StatsSet { } fn merge_ordered bool>(&mut self, stat: Stat, other: &Self, cmp: F) { - match self.values.entry(stat) { - Entry::Occupied(mut e) => { - if let Some(ov) = other.get(stat) { - if cmp(ov, e.get()) { - e.insert(ov.clone()); - } - } else { - e.remove(); + if let Entry::Occupied(mut e) = self.values.entry(stat) { + if let Some(ov) = other.get(stat) { + if cmp(ov, e.get()) { + e.insert(ov.clone()); } + } else { + e.remove(); } - _ => {} } } @@ -129,16 +125,13 @@ impl StatsSet { } fn merge_scalar_stat(&mut self, other: &Self, stat: Stat) { - match self.values.entry(stat) { - Entry::Occupied(mut e) => { - if let Some(other_value) = other.get_as::(stat) { - let self_value: usize = e.get().try_into().unwrap(); - e.insert((self_value + other_value).into()); - } else { - e.remove(); - } + if let Entry::Occupied(mut e) = self.values.entry(stat) { + if let Some(other_value) = other.get_as::(stat) { + let self_value: usize = e.get().try_into().unwrap(); + e.insert((self_value + other_value).into()); + } else { + e.remove(); } - _ => {} } } @@ -151,49 +144,43 @@ impl StatsSet { } fn merge_freq_stat(&mut self, other: &Self, stat: Stat) { - match self.values.entry(stat) { - Entry::Occupied(mut e) => { - if let Some(other_value) = other.get_as::>(stat) { - // TODO(robert): Avoid the copy here. We could e.get_mut() but need to figure out casting - let self_value: ListScalarVec = e.get().try_into().unwrap(); - e.insert( - ListScalarVec( - self_value - .0 - .iter() - .zip_eq(other_value.0.iter()) - .map(|(s, o)| *s + *o) - .collect::>(), - ) - .into(), - ); - } else { - e.remove(); - } + if let Entry::Occupied(mut e) = self.values.entry(stat) { + if let Some(other_value) = other.get_as::>(stat) { + // TODO(robert): Avoid the copy here. We could e.get_mut() but need to figure out casting + let self_value: ListScalarVec = e.get().try_into().unwrap(); + e.insert( + ListScalarVec( + self_value + .0 + .iter() + .zip_eq(other_value.0.iter()) + .map(|(s, o)| *s + *o) + .collect::>(), + ) + .into(), + ); + } else { + e.remove(); } - _ => {} } } /// Merged run count is an upper bound where we assume run is interrupted at the boundary fn merge_run_count(&mut self, other: &Self) { - match self.values.entry(Stat::RunCount) { - Entry::Occupied(mut e) => { - if let Some(other_value) = other.get_as::(Stat::RunCount) { - let self_value: usize = e.get().try_into().unwrap(); - e.insert((self_value + other_value + 1).into()); - } else { - e.remove(); - } + if let Entry::Occupied(mut e) = self.values.entry(Stat::RunCount) { + if let Some(other_value) = other.get_as::(Stat::RunCount) { + let self_value: usize = e.get().try_into().unwrap(); + e.insert((self_value + other_value + 1).into()); + } else { + e.remove(); } - _ => {} } } } impl Extend<(Stat, Scalar)> for StatsSet { #[inline] - fn extend>(&mut self, iter: T) { + fn extend>(&mut self, iter: T) { self.values.extend(iter) } } @@ -225,11 +212,10 @@ mod test { assert_eq!(first.get(Stat::Min), None); } - #[test] fn merge_mins() { let mut first = StatsSet::of(Stat::Min, 37.into()); first.merge(&StatsSet::of(Stat::Min, 42.into())); assert_eq!(first.get(Stat::Min).cloned(), Some(37.into())); } -} \ No newline at end of file +}