|
1 | | -use vortex_mask::Mask; |
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// SPDX-FileCopyrightText: Copyright the Vortex contributors |
| 3 | + |
| 4 | +use vortex_buffer::{Buffer, BufferMut}; |
| 5 | +use vortex_mask::{Mask, MaskMut}; |
2 | 6 | use vortex_vector::VectorOps; |
3 | | -use vortex_vector::binaryview::{BinaryViewType, BinaryViewVector, BinaryViewVectorMut}; |
| 7 | +use vortex_vector::binaryview::{ |
| 8 | + BinaryView, BinaryViewType, BinaryViewVector, BinaryViewVectorMut, |
| 9 | +}; |
4 | 10 |
|
5 | | -use crate::filter::{Filter, MaskIndices}; |
| 11 | +use crate::filter::Filter; |
6 | 12 |
|
7 | | -macro_rules! delegate_filter_impl { |
8 | | - ($mask_ty:ty) => { |
9 | | - impl<T: BinaryViewType> Filter<$mask_ty> for &BinaryViewVector<T> { |
10 | | - type Output = BinaryViewVector<T>; |
| 13 | +impl<M, T: BinaryViewType> Filter<M> for &BinaryViewVector<T> |
| 14 | +where |
| 15 | + for<'a> &'a Mask: Filter<M, Output = Mask>, |
| 16 | + for<'a> &'a Buffer<BinaryView>: Filter<M, Output = Buffer<BinaryView>>, |
| 17 | +{ |
| 18 | + type Output = BinaryViewVector<T>; |
11 | 19 |
|
12 | | - fn filter(self, selection: &$mask_ty) -> Self::Output { |
13 | | - let views = self.views().filter(selection); |
14 | | - let validity = self.validity().filter(selection); |
| 20 | + fn filter(self, selection: &M) -> Self::Output { |
| 21 | + let views = self.views().filter(selection); |
| 22 | + let validity = self.validity().filter(selection); |
15 | 23 |
|
16 | | - // SAFETY: we filter the views and validity using the same mask |
17 | | - unsafe { |
18 | | - BinaryViewVector::<T>::new_unchecked(views, self.buffers().clone(), validity) |
19 | | - } |
20 | | - } |
21 | | - } |
| 24 | + // SAFETY: we filter the views and validity using the same mask |
| 25 | + unsafe { BinaryViewVector::<T>::new_unchecked(views, self.buffers().clone(), validity) } |
| 26 | + } |
| 27 | +} |
22 | 28 |
|
23 | | - impl<T: BinaryViewType> Filter<$mask_ty> for &mut BinaryViewVectorMut<T> { |
24 | | - type Output = (); |
| 29 | +impl<M, T: BinaryViewType> Filter<M> for &mut BinaryViewVectorMut<T> |
| 30 | +where |
| 31 | + for<'a> &'a mut MaskMut: Filter<M, Output = ()>, |
| 32 | + for<'a> &'a mut BufferMut<BinaryView>: Filter<M, Output = ()>, |
| 33 | +{ |
| 34 | + type Output = (); |
25 | 35 |
|
26 | | - fn filter(self, selection: &$mask_ty) -> Self::Output { |
27 | | - // SAFETY: views and validity filtered by the same mask will have |
28 | | - // same resultant length. |
29 | | - unsafe { |
30 | | - self.views_mut().filter(selection); |
31 | | - self.validity_mut().filter(selection); |
32 | | - } |
33 | | - } |
| 36 | + fn filter(self, selection: &M) -> Self::Output { |
| 37 | + // SAFETY: views and validity filtered by the same mask will have |
| 38 | + // same resultant length. |
| 39 | + unsafe { |
| 40 | + self.views_mut().filter(selection); |
| 41 | + self.validity_mut().filter(selection); |
34 | 42 | } |
35 | | - }; |
| 43 | + } |
36 | 44 | } |
37 | | - |
38 | | -delegate_filter_impl!(Mask); |
39 | | -delegate_filter_impl!(MaskIndices<'_>); |
|
0 commit comments