@@ -292,6 +292,63 @@ impl BinarySerializable for IPCodecParams {
292
292
}
293
293
}
294
294
295
+ /// Exposes the compact space compressed values as u64.
296
+ ///
297
+ /// This allows faster access to the values, as u64 is faster to work with than u128.
298
+ /// It also allows to handle u128 values like u64, via the `open_u64_lenient` as a uniform
299
+ /// access interface.
300
+ ///
301
+ /// When converting from the internal u64 to u128 `compact_to_u128` can be used.
302
+ pub struct CompactSpaceU64Accessor ( CompactSpaceDecompressor ) ;
303
+ impl CompactSpaceU64Accessor {
304
+ pub ( crate ) fn open ( data : OwnedBytes ) -> io:: Result < CompactSpaceU64Accessor > {
305
+ let decompressor = CompactSpaceU64Accessor ( CompactSpaceDecompressor :: open ( data) ?) ;
306
+ Ok ( decompressor)
307
+ }
308
+ /// Convert a compact space value to u128
309
+ pub fn compact_to_u128 ( & self , compact : u32 ) -> u128 {
310
+ self . 0 . compact_to_u128 ( compact)
311
+ }
312
+ }
313
+
314
+ impl ColumnValues < u64 > for CompactSpaceU64Accessor {
315
+ #[ inline]
316
+ fn get_val ( & self , doc : u32 ) -> u64 {
317
+ let compact = self . 0 . get_compact ( doc) ;
318
+ compact as u64
319
+ }
320
+
321
+ fn min_value ( & self ) -> u64 {
322
+ self . 0 . u128_to_compact ( self . 0 . min_value ( ) ) . unwrap ( ) as u64
323
+ }
324
+
325
+ fn max_value ( & self ) -> u64 {
326
+ self . 0 . u128_to_compact ( self . 0 . max_value ( ) ) . unwrap ( ) as u64
327
+ }
328
+
329
+ fn num_vals ( & self ) -> u32 {
330
+ self . 0 . params . num_vals
331
+ }
332
+
333
+ #[ inline]
334
+ fn iter ( & self ) -> Box < dyn Iterator < Item = u64 > + ' _ > {
335
+ Box :: new ( self . 0 . iter_compact ( ) . map ( |el| el as u64 ) )
336
+ }
337
+
338
+ #[ inline]
339
+ fn get_row_ids_for_value_range (
340
+ & self ,
341
+ value_range : RangeInclusive < u64 > ,
342
+ position_range : Range < u32 > ,
343
+ positions : & mut Vec < u32 > ,
344
+ ) {
345
+ let value_range = self . 0 . compact_to_u128 ( * value_range. start ( ) as u32 )
346
+ ..=self . 0 . compact_to_u128 ( * value_range. end ( ) as u32 ) ;
347
+ self . 0
348
+ . get_row_ids_for_value_range ( value_range, position_range, positions)
349
+ }
350
+ }
351
+
295
352
impl ColumnValues < u128 > for CompactSpaceDecompressor {
296
353
#[ inline]
297
354
fn get_val ( & self , doc : u32 ) -> u128 {
@@ -402,9 +459,14 @@ impl CompactSpaceDecompressor {
402
459
. map ( |compact| self . compact_to_u128 ( compact) )
403
460
}
404
461
462
+ #[ inline]
463
+ pub fn get_compact ( & self , idx : u32 ) -> u32 {
464
+ self . params . bit_unpacker . get ( idx, & self . data ) as u32
465
+ }
466
+
405
467
#[ inline]
406
468
pub fn get ( & self , idx : u32 ) -> u128 {
407
- let compact = self . params . bit_unpacker . get ( idx, & self . data ) as u32 ;
469
+ let compact = self . get_compact ( idx) ;
408
470
self . compact_to_u128 ( compact)
409
471
}
410
472
0 commit comments