File tree Expand file tree Collapse file tree 5 files changed +24
-13
lines changed
vortex-compute/src/filter Expand file tree Collapse file tree 5 files changed +24
-13
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,14 @@ use crate::filter::Filter;
1010// TODO(ngates): we need more experimentation to determine the best threshold here.
1111const FILTER_SLICES_DENSITY_THRESHOLD : f64 = 0.8 ;
1212
13- impl Filter for BitBuffer {
14- fn filter ( & self , mask : & Mask ) -> Self {
13+ impl Filter for & BitBuffer {
14+ type Output = BitBuffer ;
15+
16+ fn filter ( self , mask : & Mask ) -> BitBuffer {
1517 assert_eq ! ( mask. len( ) , self . len( ) ) ;
1618 match mask {
1719 Mask :: AllTrue ( _) => self . clone ( ) ,
18- Mask :: AllFalse ( _) => Self :: empty ( ) ,
20+ Mask :: AllFalse ( _) => BitBuffer :: empty ( ) ,
1921 Mask :: Values ( v) => match v. threshold_iter ( FILTER_SLICES_DENSITY_THRESHOLD ) {
2022 MaskIter :: Indices ( indices) => filter_indices ( self , indices) ,
2123 MaskIter :: Slices ( slices) => filter_slices ( self , mask. true_count ( ) , slices) ,
Original file line number Diff line number Diff line change @@ -7,14 +7,16 @@ use vortex_vector::bool::BoolVector;
77
88use crate :: filter:: Filter ;
99
10- impl Filter for BoolVector {
11- fn filter ( & self , mask : & Mask ) -> Self {
10+ impl Filter for & BoolVector {
11+ type Output = BoolVector ;
12+
13+ fn filter ( self , mask : & Mask ) -> BoolVector {
1214 let filtered_bits = self . bits ( ) . filter ( mask) ;
1315 let filtered_validity = self . validity ( ) . filter ( mask) ;
1416
1517 // SAFETY: We filter the bits and validity with the same mask, and since they came from an
1618 // existing and valid `BoolVector`, we know that the filtered output must have the same
1719 // length.
18- unsafe { Self :: new_unchecked ( filtered_bits, filtered_validity) }
20+ unsafe { BoolVector :: new_unchecked ( filtered_bits, filtered_validity) }
1921 }
2022}
Original file line number Diff line number Diff line change @@ -9,12 +9,14 @@ use crate::filter::Filter;
99// This is modeled after the constant with the equivalent name in arrow-rs.
1010const FILTER_SLICES_SELECTIVITY_THRESHOLD : f64 = 0.8 ;
1111
12- impl < T : Copy > Filter for Buffer < T > {
13- fn filter ( & self , mask : & Mask ) -> Self {
12+ impl < T : Copy > Filter for & Buffer < T > {
13+ type Output = Buffer < T > ;
14+
15+ fn filter ( self , mask : & Mask ) -> Buffer < T > {
1416 assert_eq ! ( mask. len( ) , self . len( ) ) ;
1517 match mask {
1618 Mask :: AllTrue ( _) => self . clone ( ) ,
17- Mask :: AllFalse ( _) => Self :: empty ( ) ,
19+ Mask :: AllFalse ( _) => Buffer :: empty ( ) ,
1820 Mask :: Values ( v) => match v. threshold_iter ( FILTER_SLICES_SELECTIVITY_THRESHOLD ) {
1921 MaskIter :: Indices ( indices) => filter_indices ( self . as_slice ( ) , indices) ,
2022 MaskIter :: Slices ( slices) => {
Original file line number Diff line number Diff line change @@ -5,16 +5,18 @@ use vortex_mask::Mask;
55
66use crate :: filter:: Filter ;
77
8- impl Filter for Mask {
9- fn filter ( & self , mask : & Mask ) -> Self {
8+ impl Filter for & Mask {
9+ type Output = Mask ;
10+
11+ fn filter ( self , mask : & Mask ) -> Mask {
1012 assert_eq ! ( self . len( ) , mask. len( ) ) ;
1113
1214 match ( self , mask) {
1315 ( Mask :: AllTrue ( _) , _) => Mask :: AllTrue ( mask. true_count ( ) ) ,
1416 ( Mask :: AllFalse ( _) , _) => Mask :: AllFalse ( mask. true_count ( ) ) ,
1517
1618 ( Mask :: Values ( _) , Mask :: AllTrue ( _) ) => self . clone ( ) ,
17- ( Mask :: Values ( _) , Mask :: AllFalse ( _) ) => Self :: new_true ( 0 ) ,
19+ ( Mask :: Values ( _) , Mask :: AllFalse ( _) ) => Mask :: new_true ( 0 ) ,
1820 ( Mask :: Values ( v1) , Mask :: Values ( _) ) => Mask :: from ( v1. bit_buffer ( ) . filter ( mask) ) ,
1921 }
2022 }
Original file line number Diff line number Diff line change @@ -12,12 +12,15 @@ use vortex_mask::Mask;
1212
1313/// Function for filtering based on a selection mask.
1414pub trait Filter {
15+ /// The result type after performing the operation.
16+ type Output ;
17+
1518 /// Filters the vector using the provided mask, returning a new value.
1619 ///
1720 /// The result value will have length equal to the true count of the provided mask.
1821 ///
1922 /// # Panics
2023 ///
2124 /// If the length of the mask does not equal the length of the value being filtered.
22- fn filter ( & self , mask : & Mask ) -> Self ;
25+ fn filter ( self , mask : & Mask ) -> Self :: Output ;
2326}
You can’t perform that action at this time.
0 commit comments