@@ -8,46 +8,27 @@ use vortex_array::arrays::PrimitiveArray;
88use vortex_array:: builders:: { ArrayBuilder , PrimitiveBuilder , UninitRange } ;
99use vortex_array:: patches:: Patches ;
1010use vortex_dtype:: {
11- IntegerPType , NativePType , PhysicalPType , match_each_integer_ptype,
12- match_each_unsigned_integer_ptype,
11+ IntegerPType , NativePType , match_each_integer_ptype, match_each_unsigned_integer_ptype,
1312} ;
1413use vortex_error:: VortexExpect ;
1514use vortex_mask:: Mask ;
1615use vortex_scalar:: Scalar ;
1716
1817use crate :: BitPackedArray ;
19- use crate :: unpack_iter:: { BitPacked , UnpackStrategy } ;
20-
21- /// BitPacking strategy - uses plain bitpacking without reference value
22- pub struct BitPackingStrategy ;
23-
24- impl < T : PhysicalPType < Physical : BitPacking > > UnpackStrategy < T > for BitPackingStrategy {
25- #[ inline( always) ]
26- unsafe fn unpack_chunk (
27- & self ,
28- bit_width : usize ,
29- chunk : & [ T :: Physical ] ,
30- dst : & mut [ T :: Physical ] ,
31- ) {
32- // SAFETY: Caller must ensure [`BitPacking::unchecked_unpack`] safety requirements hold.
33- unsafe {
34- BitPacking :: unchecked_unpack ( bit_width, chunk, dst) ;
35- }
36- }
37- }
18+ use crate :: unpack_iter:: BitPacked ;
3819
39- pub fn unpack ( array : & BitPackedArray ) -> PrimitiveArray {
40- match_each_integer_ptype ! ( array. ptype( ) , |P | { unpack_primitive :: <P >( array) } )
20+ pub fn unpack_array ( array : & BitPackedArray ) -> PrimitiveArray {
21+ match_each_integer_ptype ! ( array. ptype( ) , |P | { unpack_primitive_array :: <P >( array) } )
4122}
4223
43- pub fn unpack_primitive < T : BitPacked > ( array : & BitPackedArray ) -> PrimitiveArray {
24+ pub fn unpack_primitive_array < T : BitPacked > ( array : & BitPackedArray ) -> PrimitiveArray {
4425 let mut builder = PrimitiveBuilder :: with_capacity ( array. dtype ( ) . nullability ( ) , array. len ( ) ) ;
45- unpack_into :: < T > ( array, & mut builder) ;
26+ unpack_into_primitive_builder :: < T > ( array, & mut builder) ;
4627 assert_eq ! ( builder. len( ) , array. len( ) ) ;
4728 builder. finish_into_primitive ( )
4829}
4930
50- pub ( crate ) fn unpack_into < T : BitPacked > (
31+ pub ( crate ) fn unpack_into_primitive_builder < T : BitPacked > (
5132 array : & BitPackedArray ,
5233 // TODO(ngates): do we want to use fastlanes alignment for this buffer?
5334 builder : & mut PrimitiveBuilder < T > ,
@@ -65,25 +46,28 @@ pub(crate) fn unpack_into<T: BitPacked>(
6546 uninit_range. append_mask ( array. validity_mask ( ) ) ;
6647 }
6748
49+ // SAFETY: `decode_into` will initialize all values in this range.
50+ let uninit_slice = unsafe { uninit_range. slice_uninit_mut ( 0 , array. len ( ) ) } ;
51+
6852 let mut bit_packed_iter = array. unpacked_chunks ( ) ;
69- bit_packed_iter. decode_into ( & mut uninit_range ) ;
53+ bit_packed_iter. decode_into ( uninit_slice ) ;
7054
7155 if let Some ( patches) = array. patches ( ) {
72- apply_patches ( & mut uninit_range, patches) ;
56+ apply_patches_to_uninit_range ( & mut uninit_range, patches) ;
7357 } ;
7458
7559 // SAFETY: We have set a correct validity mask via `append_mask` with `array.len()` values and
76- // initialized the same number of values needed via calls to `copy_from_slice `.
60+ // initialized the same number of values needed via `decode_into `.
7761 unsafe {
7862 uninit_range. finish ( ) ;
7963 }
8064}
8165
82- pub fn apply_patches < T : NativePType > ( dst : & mut UninitRange < T > , patches : & Patches ) {
83- apply_patches_fn ( dst, patches, |x| x)
66+ pub fn apply_patches_to_uninit_range < T : NativePType > ( dst : & mut UninitRange < T > , patches : & Patches ) {
67+ apply_patches_to_uninit_range_fn ( dst, patches, |x| x)
8468}
8569
86- pub fn apply_patches_fn < T : NativePType , F : Fn ( T ) -> T > (
70+ pub fn apply_patches_to_uninit_range_fn < T : NativePType , F : Fn ( T ) -> T > (
8771 dst : & mut UninitRange < T > ,
8872 patches : & Patches ,
8973 f : F ,
@@ -96,7 +80,7 @@ pub fn apply_patches_fn<T: NativePType, F: Fn(T) -> T>(
9680 let values = values. as_slice :: < T > ( ) ;
9781
9882 match_each_unsigned_integer_ptype ! ( indices. ptype( ) , |P | {
99- insert_values_and_validity_at_indices (
83+ insert_values_and_validity_at_indices_to_uninit_range (
10084 dst,
10185 indices. as_slice:: <P >( ) ,
10286 values,
@@ -107,7 +91,11 @@ pub fn apply_patches_fn<T: NativePType, F: Fn(T) -> T>(
10791 } ) ;
10892}
10993
110- fn insert_values_and_validity_at_indices < T : NativePType , IndexT : IntegerPType , F : Fn ( T ) -> T > (
94+ fn insert_values_and_validity_at_indices_to_uninit_range <
95+ T : NativePType ,
96+ IndexT : IntegerPType ,
97+ F : Fn ( T ) -> T ,
98+ > (
11199 dst : & mut UninitRange < T > ,
112100 indices : & [ IndexT ] ,
113101 values : & [ T ] ,
@@ -223,23 +211,23 @@ mod tests {
223211 fn test_all_zeros ( ) {
224212 let zeros = buffer ! [ 0u16 , 0 , 0 , 0 ] . into_array ( ) . to_primitive ( ) ;
225213 let bitpacked = bitpack_encode ( & zeros, 0 , None ) . unwrap ( ) ;
226- let actual = unpack ( & bitpacked) ;
214+ let actual = unpack_array ( & bitpacked) ;
227215 assert_arrays_eq ! ( actual, PrimitiveArray :: from_iter( [ 0u16 , 0 , 0 , 0 ] ) ) ;
228216 }
229217
230218 #[ test]
231219 fn test_simple_patches ( ) {
232220 let zeros = buffer ! [ 0u16 , 1 , 0 , 1 ] . into_array ( ) . to_primitive ( ) ;
233221 let bitpacked = bitpack_encode ( & zeros, 0 , None ) . unwrap ( ) ;
234- let actual = unpack ( & bitpacked) ;
222+ let actual = unpack_array ( & bitpacked) ;
235223 assert_arrays_eq ! ( actual, PrimitiveArray :: from_iter( [ 0u16 , 1 , 0 , 1 ] ) ) ;
236224 }
237225
238226 #[ test]
239227 fn test_one_full_chunk ( ) {
240228 let zeros = BufferMut :: from_iter ( 0u16 ..1024 ) . into_array ( ) . to_primitive ( ) ;
241229 let bitpacked = bitpack_encode ( & zeros, 10 , None ) . unwrap ( ) ;
242- let actual = unpack ( & bitpacked) ;
230+ let actual = unpack_array ( & bitpacked) ;
243231 assert_arrays_eq ! ( actual, PrimitiveArray :: from_iter( 0u16 ..1024 ) ) ;
244232 }
245233
@@ -250,7 +238,7 @@ mod tests {
250238 . to_primitive ( ) ;
251239 let bitpacked = bitpack_encode ( & zeros, 10 , None ) . unwrap ( ) ;
252240 assert ! ( bitpacked. patches( ) . is_some( ) ) ;
253- let actual = unpack ( & bitpacked) ;
241+ let actual = unpack_array ( & bitpacked) ;
254242 assert_arrays_eq ! (
255243 actual,
256244 PrimitiveArray :: from_iter( ( 5u16 ..1029 ) . chain( 5u16 ..1029 ) . chain( 5u16 ..1029 ) )
@@ -262,7 +250,7 @@ mod tests {
262250 let zeros = BufferMut :: from_iter ( 0u16 ..1025 ) . into_array ( ) . to_primitive ( ) ;
263251 let bitpacked = bitpack_encode ( & zeros, 11 , None ) . unwrap ( ) ;
264252 assert ! ( bitpacked. patches( ) . is_none( ) ) ;
265- let actual = unpack ( & bitpacked) ;
253+ let actual = unpack_array ( & bitpacked) ;
266254 assert_arrays_eq ! ( actual, PrimitiveArray :: from_iter( 0u16 ..1025 ) ) ;
267255 }
268256
@@ -274,7 +262,7 @@ mod tests {
274262 let bitpacked = bitpack_encode ( & zeros, 10 , None ) . unwrap ( ) ;
275263 assert_eq ! ( bitpacked. len( ) , 1025 ) ;
276264 assert ! ( bitpacked. patches( ) . is_some( ) ) ;
277- let actual = unpack ( & bitpacked) ;
265+ let actual = unpack_array ( & bitpacked) ;
278266 assert_arrays_eq ! ( actual, PrimitiveArray :: from_iter( 512u16 ..1537 ) ) ;
279267 }
280268
@@ -287,7 +275,7 @@ mod tests {
287275 assert_eq ! ( bitpacked. len( ) , 1025 ) ;
288276 assert ! ( bitpacked. patches( ) . is_some( ) ) ;
289277 let bitpacked = bitpacked. slice ( 1023 ..1025 ) ;
290- let actual = unpack ( bitpacked. as_ :: < BitPackedVTable > ( ) ) ;
278+ let actual = unpack_array ( bitpacked. as_ :: < BitPackedVTable > ( ) ) ;
291279 assert_arrays_eq ! ( actual, PrimitiveArray :: from_iter( [ 1535u16 , 1536 ] ) ) ;
292280 }
293281
@@ -300,7 +288,7 @@ mod tests {
300288 assert_eq ! ( bitpacked. len( ) , 2229 ) ;
301289 assert ! ( bitpacked. patches( ) . is_some( ) ) ;
302290 let bitpacked = bitpacked. slice ( 1023 ..2049 ) ;
303- let actual = unpack ( bitpacked. as_ :: < BitPackedVTable > ( ) ) ;
291+ let actual = unpack_array ( bitpacked. as_ :: < BitPackedVTable > ( ) ) ;
304292 assert_arrays_eq ! (
305293 actual,
306294 PrimitiveArray :: from_iter( ( 1023u16 ..2049 ) . map( |x| x + 512 ) )
@@ -313,7 +301,7 @@ mod tests {
313301 let bitpacked = bitpack_encode ( & empty, 0 , None ) . unwrap ( ) ;
314302
315303 let mut builder = PrimitiveBuilder :: < u32 > :: new ( Nullability :: NonNullable ) ;
316- unpack_into ( & bitpacked, & mut builder) ;
304+ unpack_into_primitive_builder ( & bitpacked, & mut builder) ;
317305
318306 let result = builder. finish_into_primitive ( ) ;
319307 assert_eq ! (
@@ -336,7 +324,7 @@ mod tests {
336324
337325 // Unpack into a new builder.
338326 let mut builder = PrimitiveBuilder :: < u32 > :: with_capacity ( Nullability :: Nullable , 5 ) ;
339- unpack_into ( & bitpacked, & mut builder) ;
327+ unpack_into_primitive_builder ( & bitpacked, & mut builder) ;
340328
341329 let result = builder. finish_into_primitive ( ) ;
342330
@@ -367,7 +355,7 @@ mod tests {
367355
368356 // Unpack into a new builder.
369357 let mut builder = PrimitiveBuilder :: < u32 > :: with_capacity ( Nullability :: NonNullable , 100 ) ;
370- unpack_into ( & bitpacked, & mut builder) ;
358+ unpack_into_primitive_builder ( & bitpacked, & mut builder) ;
371359
372360 let result = builder. finish_into_primitive ( ) ;
373361
0 commit comments