Skip to content

Commit

Permalink
semantic conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
jdcasale committed May 8, 2024
1 parent a1ab23b commit 21b67d4
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions vortex-array/src/stats/statsset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,20 @@ 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::<Vec<u64>>(stat) {
// TODO(robert): Avoid the copy here. We could e.get_mut() but need to figure out casting
let self_value: Vec<u64> = e.get().try_into().unwrap();
e.insert(
self_value
.iter()
.zip_eq(other_value.iter())
.map(|(s, o)| *s + *o)
.collect::<Vec<_>>()
.into(),
);
}
}
Entry::Vacant(e) => {
if let Some(other_value) = other.get(stat) {
e.insert(other_value.clone());
}
if let Entry::Occupied(mut e) = self.values.entry(stat) {
if let Some(other_value) = other.get_as::<Vec<u64>>(stat) {
// TODO(robert): Avoid the copy here. We could e.get_mut() but need to figure out casting
let self_value: Vec<u64> = e.get().try_into().unwrap();
e.insert(
self_value
.iter()
.zip_eq(other_value.iter())
.map(|(s, o)| *s + *o)
.collect::<Vec<_>>()
.into(),
);
} else {
e.remove();
}
}
}
Expand Down Expand Up @@ -211,7 +206,6 @@ impl IntoIterator for StatsSet {
#[cfg(test)]
mod test {
use itertools::Itertools;
use vortex_scalar::ListScalarVec;

use crate::stats::{Stat, StatsSet};

Expand Down Expand Up @@ -281,7 +275,7 @@ mod test {
#[test]
fn merge_into_freq() {
let vec = (0..255).collect_vec();
let mut first = StatsSet::of(Stat::BitWidthFreq, ListScalarVec(vec.clone()).into());
let mut first = StatsSet::of(Stat::BitWidthFreq, vec.clone().into());
first.merge(&StatsSet::new());
assert_eq!(first.get(Stat::BitWidthFreq), None);
}
Expand All @@ -290,25 +284,19 @@ mod test {
fn merge_from_freq() {
let vec = (0..255).collect_vec();
let mut first = StatsSet::new();
first.merge(&StatsSet::of(
Stat::BitWidthFreq,
ListScalarVec(vec.clone()).into(),
));
first.merge(&StatsSet::of(Stat::BitWidthFreq, vec.clone().into()));
assert_eq!(first.get(Stat::BitWidthFreq), None);
}

#[test]
fn merge_freqs() {
let vec_in = vec![5u64; 256];
let vec_out = vec![10u64; 256];
let mut first = StatsSet::of(Stat::BitWidthFreq, ListScalarVec(vec_in.clone()).into());
first.merge(&StatsSet::of(
Stat::BitWidthFreq,
ListScalarVec(vec_in.clone()).into(),
));
let mut first = StatsSet::of(Stat::BitWidthFreq, vec_in.clone().into());
first.merge(&StatsSet::of(Stat::BitWidthFreq, vec_in.clone().into()));
assert_eq!(
first.get(Stat::BitWidthFreq).cloned(),
Some(ListScalarVec(vec_out.clone()).into())
Some(vec_out.clone().into())
);
}

Expand Down

0 comments on commit 21b67d4

Please sign in to comment.