@@ -24,11 +24,16 @@ use crate::unpack_iter::BitPacked;
2424
2525/// Unpacks a bit-packed array into a primitive vector.
2626pub fn unpack_to_primitive_vector ( array : & BitPackedArray ) -> PrimitiveVectorMut {
27- match_each_integer_ptype ! ( array. ptype( ) , |P | { unpack_to_pvector:: <P >( array) . into( ) } )
27+ match_each_integer_ptype ! ( array. ptype( ) , |P | {
28+ unpack_to_pvector:: <P , fn ( P ) -> P >( array, std:: convert:: identity) . into( )
29+ } )
2830}
2931
3032/// Unpacks a bit-packed array into a generic [`PVectorMut`].
31- pub fn unpack_to_pvector < P : BitPacked > ( array : & BitPackedArray ) -> PVectorMut < P > {
33+ pub fn unpack_to_pvector < P : BitPacked , F : FnMut ( P ) -> P > (
34+ array : & BitPackedArray ,
35+ map_fn : F ,
36+ ) -> PVectorMut < P > {
3237 if array. is_empty ( ) {
3338 return PVectorMut :: with_capacity ( 0 ) ;
3439 }
@@ -71,6 +76,7 @@ pub fn unpack_to_pvector<P: BitPacked>(array: &BitPackedArray) -> PVectorMut<P>
7176 patch_offset,
7277 patch_values_slice,
7378 patches_validity,
79+ map_fn,
7480 )
7581 } ;
7682 } ) ;
@@ -87,16 +93,18 @@ pub fn unpack_to_pvector<P: BitPacked>(array: &BitPackedArray) -> PVectorMut<P>
8793/// - `patch_indices` must be sorted in ascending order.
8894/// - `patch_indices` and `patch_values` must have the same length.
8995/// - `buffer` and `validity` must have the same length.
90- unsafe fn apply_patches_inner < P , I > (
96+ unsafe fn apply_patches_inner < P , I , F > (
9197 buffer : & mut [ P ] ,
9298 validity : & mut MaskMut ,
9399 patch_indices : & [ I ] ,
94100 patch_offset : usize ,
95101 patch_values : & [ P ] ,
96102 patches_validity : & Validity ,
103+ map_fn : F ,
97104) where
98105 P : NativePType ,
99106 I : UnsignedPType ,
107+ F : FnMut ( P ) -> P ,
100108{
101109 debug_assert ! ( !patch_indices. is_empty( ) ) ;
102110 debug_assert_eq ! ( patch_indices. len( ) , patch_values. len( ) ) ;
@@ -106,13 +114,15 @@ unsafe fn apply_patches_inner<P, I>(
106114
107115 match patches_validity {
108116 Validity :: NonNullable | Validity :: AllValid => {
109- for ( & i, & value) in patch_indices. iter ( ) . zip_eq ( patch_values) {
117+ let mapped_values = patch_values. iter ( ) . copied ( ) . map ( map_fn) ;
118+
119+ for ( & i, mapped_value) in patch_indices. iter ( ) . zip_eq ( mapped_values) {
110120 let index = i. as_ ( ) - patch_offset;
111121
112122 // SAFETY: `index` is valid because caller guarantees all patch indices are within
113123 // bounds after offset adjustment.
114124 unsafe { validity. set_unchecked ( index) } ;
115- buffer[ index] = value ;
125+ buffer[ index] = mapped_value ;
116126 }
117127 }
118128 _ => vortex_panic ! ( "BitPackedArray somehow had nullable patch values" ) ,
0 commit comments