@@ -134,23 +134,43 @@ where
134134 Ok ( ( ) )
135135}
136136
137- /// How the blocks of a [`BitPackedArray`] are packed.
138- #[ derive( Clone , Debug ) ]
139- pub enum BitWidths {
137+ /// How the blocks of a [`BitPackedArray`] are packed, borrowing block offsets if present .
138+ #[ derive( Clone , Copy , Debug ) ]
139+ pub enum BitWidthsView < ' a > {
140140 /// Every block is packed at this bit width.
141141 Global ( u8 ) ,
142142 /// Byte boundaries of the packed blocks, from which each block's bit width is derived.
143- Blocked ( ArrayRef ) ,
143+ Blocked ( & ' a ArrayRef ) ,
144144}
145145
146- impl BitWidths {
146+ impl BitWidthsView < ' _ > {
147147 /// Returns `true` if every block is packed at one bit width.
148148 #[ inline]
149149 pub fn is_global ( & self ) -> bool {
150150 matches ! ( self , Self :: Global ( _) )
151151 }
152152}
153153
154+ /// How the blocks of a [`BitPackedArray`] are packed, owning block offsets if present.
155+ ///
156+ /// This is the owned form of [`BitWidthsView`], held by [`BitPackedDataParts`].
157+ #[ derive( Clone , Debug ) ]
158+ pub enum BitWidths {
159+ /// Every block is packed at this bit width.
160+ Global ( u8 ) ,
161+ /// Byte boundaries of the packed blocks, from which each block's bit width is derived.
162+ Blocked ( ArrayRef ) ,
163+ }
164+
165+ impl From < BitWidthsView < ' _ > > for BitWidths {
166+ fn from ( view : BitWidthsView < ' _ > ) -> Self {
167+ match view {
168+ BitWidthsView :: Global ( bit_width) => Self :: Global ( bit_width) ,
169+ BitWidthsView :: Blocked ( block_offsets) => Self :: Blocked ( block_offsets. clone ( ) ) ,
170+ }
171+ }
172+ }
173+
154174pub struct BitPackedDataParts {
155175 pub offset : u16 ,
156176 pub bit_widths : BitWidths ,
@@ -396,10 +416,10 @@ pub trait BitPackedArrayExt: BitPackedArraySlotsExt {
396416 /// How the blocks are packed: at one global bit width, or at the widths implied by the block
397417 /// offsets.
398418 #[ inline]
399- fn bit_widths ( & self ) -> BitWidths {
419+ fn bit_widths ( & self ) -> BitWidthsView < ' _ > {
400420 match ( self . global_bit_width , self . block_offsets ( ) ) {
401- ( Some ( bit_width) , None ) => BitWidths :: Global ( bit_width) ,
402- ( None , Some ( block_offsets) ) => BitWidths :: Blocked ( block_offsets. clone ( ) ) ,
421+ ( Some ( bit_width) , None ) => BitWidthsView :: Global ( bit_width) ,
422+ ( None , Some ( block_offsets) ) => BitWidthsView :: Blocked ( block_offsets) ,
403423 _ => vortex_panic ! (
404424 "BitPacked must have exactly one of a global bit width and block offsets"
405425 ) ,
0 commit comments