@@ -20,6 +20,7 @@ use vortex_array::ExecutionResult;
2020use vortex_array:: IntoArray ;
2121use vortex_array:: Precision ;
2222use vortex_array:: TypedArrayRef ;
23+ use vortex_array:: array_slots;
2324use vortex_array:: arrays:: Primitive ;
2425use vortex_array:: buffer:: BufferHandle ;
2526use vortex_array:: dtype:: DType ;
@@ -81,15 +82,14 @@ impl VTable for ALP {
8182 len : usize ,
8283 slots : & [ Option < ArrayRef > ] ,
8384 ) -> VortexResult < ( ) > {
85+ let slots = ALPSlotsView :: from_slots ( slots) ;
8486 validate_parts (
8587 dtype,
8688 len,
8789 data. exponents ,
88- slots[ ENCODED_SLOT ]
89- . as_ref ( )
90- . vortex_expect ( "ALPArray encoded slot" ) ,
90+ slots. encoded ,
9191 patches_from_slots (
92- slots,
92+ & slots,
9393 data. patch_offset ,
9494 data. patch_offset_within_chunk ,
9595 len,
@@ -170,16 +170,16 @@ impl VTable for ALP {
170170 }
171171
172172 fn slot_name ( _array : ArrayView < ' _ , Self > , idx : usize ) -> String {
173- SLOT_NAMES [ idx] . to_string ( )
173+ ALPSlots :: NAMES [ idx] . to_string ( )
174174 }
175175
176176 fn execute ( array : Array < Self > , ctx : & mut ExecutionCtx ) -> VortexResult < ExecutionResult > {
177- let array = require_child ! ( array, array. encoded( ) , ENCODED_SLOT => Primitive ) ;
177+ let array = require_child ! ( array, array. encoded( ) , ALPSlots :: ENCODED => Primitive ) ;
178178 require_patches ! (
179179 array,
180- PATCH_INDICES_SLOT ,
181- PATCH_VALUES_SLOT ,
182- PATCH_CHUNK_OFFSETS_SLOT
180+ ALPSlots :: PATCH_INDICES ,
181+ ALPSlots :: PATCH_VALUES ,
182+ ALPSlots :: PATCH_CHUNK_OFFSETS
183183 ) ;
184184
185185 Ok ( ExecutionResult :: done (
@@ -205,21 +205,17 @@ impl VTable for ALP {
205205 }
206206}
207207
208- /// The ALP-encoded values array.
209- pub ( super ) const ENCODED_SLOT : usize = 0 ;
210- /// The indices of exception values that could not be ALP-encoded.
211- pub ( super ) const PATCH_INDICES_SLOT : usize = 1 ;
212- /// The exception values that could not be ALP-encoded.
213- pub ( super ) const PATCH_VALUES_SLOT : usize = 2 ;
214- /// Chunk offsets for the patch indices/values.
215- pub ( super ) const PATCH_CHUNK_OFFSETS_SLOT : usize = 3 ;
216- pub ( super ) const NUM_SLOTS : usize = 4 ;
217- pub ( super ) const SLOT_NAMES : [ & str ; NUM_SLOTS ] = [
218- "encoded" ,
219- "patch_indices" ,
220- "patch_values" ,
221- "patch_chunk_offsets" ,
222- ] ;
208+ #[ array_slots( ALP ) ]
209+ pub struct ALPSlots {
210+ /// The ALP-encoded values array.
211+ pub encoded : ArrayRef ,
212+ /// The indices of exception values that could not be ALP-encoded.
213+ pub patch_indices : Option < ArrayRef > ,
214+ /// The exception values that could not be ALP-encoded.
215+ pub patch_values : Option < ArrayRef > ,
216+ /// Chunk offsets for the patch indices/values.
217+ pub patch_chunk_offsets : Option < ArrayRef > ,
218+ }
223219
224220#[ derive( Clone , Debug ) ]
225221pub struct ALPData {
@@ -439,20 +435,14 @@ impl ALPData {
439435 }
440436}
441437
442- pub trait ALPArrayExt : TypedArrayRef < ALP > {
443- fn encoded ( & self ) -> & ArrayRef {
444- self . as_ref ( ) . slots ( ) [ ENCODED_SLOT ]
445- . as_ref ( )
446- . vortex_expect ( "ALPArray encoded slot" )
447- }
448-
438+ pub trait ALPArrayExt : ALPArraySlotsExt {
449439 fn exponents ( & self ) -> Exponents {
450440 self . exponents
451441 }
452442
453443 fn patches ( & self ) -> Option < Patches > {
454444 patches_from_slots (
455- self . as_ref ( ) . slots ( ) ,
445+ & self . slots_view ( ) ,
456446 self . patch_offset ,
457447 self . patch_offset_within_chunk ,
458448 self . as_ref ( ) . len ( ) ,
@@ -461,12 +451,12 @@ pub trait ALPArrayExt: TypedArrayRef<ALP> {
461451}
462452
463453fn patches_from_slots (
464- slots : & [ Option < ArrayRef > ] ,
454+ slots : & ALPSlotsView ,
465455 patch_offset : Option < usize > ,
466456 patch_offset_within_chunk : Option < usize > ,
467457 len : usize ,
468458) -> Option < Patches > {
469- match ( & slots[ PATCH_INDICES_SLOT ] , & slots[ PATCH_VALUES_SLOT ] ) {
459+ match ( slots. patch_indices , slots. patch_values ) {
470460 ( Some ( indices) , Some ( values) ) => {
471461 let patch_offset = patch_offset. vortex_expect ( "has patch slots but no patch_offset" ) ;
472462 Some ( unsafe {
@@ -475,7 +465,7 @@ fn patches_from_slots(
475465 patch_offset,
476466 indices. clone ( ) ,
477467 values. clone ( ) ,
478- slots[ PATCH_CHUNK_OFFSETS_SLOT ] . clone ( ) ,
468+ slots. patch_chunk_offsets . cloned ( ) ,
479469 patch_offset_within_chunk,
480470 )
481471 } )
0 commit comments