Skip to content

Commit 462f10a

Browse files
committed
add other Filter impls
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent e5c4ded commit 462f10a

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

vortex-compute/src/filter/buffer.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,48 @@ const FILTER_SLICES_SELECTIVITY_THRESHOLD: f64 = 0.8;
1212
impl<T: Copy> Filter for &Buffer<T> {
1313
type Output = Buffer<T>;
1414

15-
fn filter(self, mask: &Mask) -> Buffer<T> {
16-
assert_eq!(mask.len(), self.len());
17-
match mask {
15+
fn filter(self, selection_mask: &Mask) -> Buffer<T> {
16+
assert_eq!(
17+
selection_mask.len(),
18+
self.len(),
19+
"Selection mask length must equal the buffer length"
20+
);
21+
22+
match selection_mask {
1823
Mask::AllTrue(_) => self.clone(),
1924
Mask::AllFalse(_) => Buffer::empty(),
2025
Mask::Values(v) => match v.threshold_iter(FILTER_SLICES_SELECTIVITY_THRESHOLD) {
2126
MaskIter::Indices(indices) => filter_indices(self.as_slice(), indices),
2227
MaskIter::Slices(slices) => {
23-
filter_slices(self.as_slice(), mask.true_count(), slices)
28+
filter_slices(self.as_slice(), selection_mask.true_count(), slices)
2429
}
2530
},
2631
}
2732
}
2833
}
2934

35+
impl<T: Copy> Filter for Buffer<T> {
36+
type Output = Self;
37+
38+
fn filter(self, selection_mask: &Mask) -> Self {
39+
assert_eq!(
40+
selection_mask.len(),
41+
self.len(),
42+
"Selection mask length must equal the buffer length"
43+
);
44+
45+
// If we have exclusive access, we can perform the filter in place.
46+
match self.try_into_mut() {
47+
Ok(mut buffer_mut) => {
48+
(&mut buffer_mut).filter(selection_mask);
49+
buffer_mut.freeze()
50+
}
51+
// Otherwise, allocate a new buffer and fill it in (delegate to the `&Buffer` impl).
52+
Err(buffer) => (&buffer).filter(selection_mask),
53+
}
54+
}
55+
}
56+
3057
fn filter_indices<T: Copy>(values: &[T], indices: &[usize]) -> Buffer<T> {
3158
Buffer::<T>::from_trusted_len_iter(indices.iter().map(|&idx| values[idx]))
3259
}

vortex-compute/src/filter/buffer_mut.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use vortex_mask::Mask;
88

99
use crate::filter::Filter;
1010

11-
// TODO(connor): Implement `Filter` for more combinations of `Filter`
12-
1311
impl<T: Copy> Filter for &mut BufferMut<T> {
1412
type Output = ();
1513

vortex-compute/src/filter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ pub trait Filter {
2323
/// # Panics
2424
///
2525
/// If the length of the mask does not equal the length of the value being filtered.
26-
fn filter(self, mask: &Mask) -> Self::Output;
26+
fn filter(self, selection_mask: &Mask) -> Self::Output;
2727
}

0 commit comments

Comments
 (0)