@@ -39,7 +39,6 @@ use crate::CompressorContext;
3939use crate :: GenerateStatsOptions ;
4040use crate :: Scheme ;
4141use crate :: SchemeExt ;
42- use crate :: SchemeId ;
4342use crate :: compress_patches;
4443use crate :: estimate_compression_ratio_with_sampling;
4544use crate :: schemes:: rle;
@@ -62,35 +61,14 @@ pub struct BitPackingScheme;
6261#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
6362pub struct SparseScheme ;
6463
65- impl SparseScheme {
66- /// Constant [`SchemeId`] for use in static exclusion rules.
67- pub const ID : SchemeId = SchemeId {
68- name : "vortex.int.sparse" ,
69- } ;
70- }
71-
7264/// Run-end encoding with end positions.
7365#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
7466pub struct RunEndScheme ;
7567
76- impl RunEndScheme {
77- /// Constant [`SchemeId`] for use in static exclusion rules.
78- pub const ID : SchemeId = SchemeId {
79- name : "vortex.int.runend" ,
80- } ;
81- }
82-
8368/// Sequence encoding for sequential patterns.
8469#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
8570pub struct SequenceScheme ;
8671
87- impl SequenceScheme {
88- /// Constant [`SchemeId`] for use in static exclusion rules.
89- pub const ID : SchemeId = SchemeId {
90- name : "vortex.int.sequence" ,
91- } ;
92- }
93-
9472/// Pco (pcodec) compression for integers.
9573#[ cfg( feature = "pco" ) ]
9674#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
@@ -158,7 +136,7 @@ impl Scheme for FORScheme {
158136 ctx : CompressorContext ,
159137 ) -> VortexResult < f64 > {
160138 // Only apply if we are not at the leaf.
161- if ctx. allowed_cascading == 0 {
139+ if ctx. finished_cascading ( ) {
162140 return Ok ( 0.0 ) ;
163141 }
164142
@@ -219,9 +197,8 @@ impl Scheme for FORScheme {
219197 // of bitpacking.
220198 // NOTE: we could delegate in the future if we had another downstream codec that performs
221199 // as well.
222- let mut leaf_ctx = ctx. clone ( ) ;
223- leaf_ctx. allowed_cascading = 0 ;
224- let mut biased_data = ArrayAndStats :: new ( biased. into_array ( ) , ctx. stats_options ) ;
200+ let leaf_ctx = ctx. clone ( ) . as_leaf ( ) ;
201+ let mut biased_data = ArrayAndStats :: new ( biased. into_array ( ) , ctx. stats_options ( ) ) ;
225202 let compressed = BitPackingScheme . compress ( compressor, & mut biased_data, leaf_ctx) ?;
226203
227204 let for_compressed = FoRArray :: try_new ( compressed, for_array. reference_scalar ( ) . clone ( ) ) ?;
@@ -246,18 +223,18 @@ impl Scheme for ZigZagScheme {
246223 1
247224 }
248225
249- fn descendant_exclusions ( & self ) -> & [ DescendantExclusion ] {
250- & [
226+ fn descendant_exclusions ( & self ) -> Vec < DescendantExclusion > {
227+ vec ! [
251228 DescendantExclusion {
252- excluded : DictScheme :: ID ,
229+ excluded: DictScheme . id ( ) ,
253230 children: ChildSelection :: All ,
254231 } ,
255232 DescendantExclusion {
256- excluded : RunEndScheme :: ID ,
233+ excluded: RunEndScheme . id ( ) ,
257234 children: ChildSelection :: All ,
258235 } ,
259236 DescendantExclusion {
260- excluded : SparseScheme :: ID ,
237+ excluded: SparseScheme . id ( ) ,
261238 children: ChildSelection :: All ,
262239 } ,
263240 ]
@@ -270,7 +247,7 @@ impl Scheme for ZigZagScheme {
270247 ctx : CompressorContext ,
271248 ) -> VortexResult < f64 > {
272249 // ZigZag is only useful when we cascade it with another encoding.
273- if ctx. allowed_cascading == 0 {
250+ if ctx. finished_cascading ( ) {
274251 return Ok ( 0.0 ) ;
275252 }
276253
@@ -302,7 +279,7 @@ impl Scheme for ZigZagScheme {
302279 let zag = zigzag_encode ( stats. source ( ) . clone ( ) ) ?;
303280 let encoded = zag. encoded ( ) . to_primitive ( ) ;
304281
305- let child_ctx = ctx. descend ( ) . with_scheme ( self . id ( ) , 0 ) ;
282+ let child_ctx = ctx. descend_with_scheme ( self . id ( ) , 0 ) ;
306283 let compressed = compressor. compress_canonical ( Canonical :: Primitive ( encoded) , child_ctx) ?;
307284
308285 tracing:: debug!( "zigzag output: {}" , compressed. encoding_id( ) ) ;
@@ -383,9 +360,9 @@ impl Scheme for SparseScheme {
383360 2
384361 }
385362
386- fn descendant_exclusions ( & self ) -> & [ DescendantExclusion ] {
387- & [ DescendantExclusion {
388- excluded : DictScheme :: ID ,
363+ fn descendant_exclusions ( & self ) -> Vec < DescendantExclusion > {
364+ vec ! [ DescendantExclusion {
365+ excluded: DictScheme . id ( ) ,
389366 children: ChildSelection :: All ,
390367 } ]
391368 }
@@ -397,7 +374,7 @@ impl Scheme for SparseScheme {
397374 ctx : CompressorContext ,
398375 ) -> VortexResult < f64 > {
399376 // Only use `SparseScheme` if we can cascade.
400- if ctx. allowed_cascading == 0 {
377+ if ctx. finished_cascading ( ) {
401378 return Ok ( 0.0 ) ;
402379 }
403380
@@ -446,7 +423,7 @@ impl Scheme for SparseScheme {
446423 data : & mut ArrayAndStats ,
447424 ctx : CompressorContext ,
448425 ) -> VortexResult < ArrayRef > {
449- assert ! ( ctx. allowed_cascading > 0 ) ;
426+ assert ! ( ! ctx. finished_cascading ( ) ) ;
450427
451428 let stats = data. integer_stats ( ) ;
452429
@@ -479,15 +456,15 @@ impl Scheme for SparseScheme {
479456 ) ?;
480457
481458 if let Some ( sparse) = sparse_encoded. as_opt :: < Sparse > ( ) {
482- let values_ctx = ctx. clone ( ) . descend ( ) . with_scheme ( self . id ( ) , 0 ) ;
459+ let values_ctx = ctx. clone ( ) . descend_with_scheme ( self . id ( ) , 0 ) ;
483460 let compressed_values = compressor. compress_canonical (
484461 Canonical :: Primitive ( sparse. patches ( ) . values ( ) . to_primitive ( ) ) ,
485462 values_ctx,
486463 ) ?;
487464
488465 let indices = sparse. patches ( ) . indices ( ) . to_primitive ( ) . narrow ( ) ?;
489466
490- let indices_ctx = ctx. descend ( ) . with_scheme ( self . id ( ) , 1 ) ;
467+ let indices_ctx = ctx. descend_with_scheme ( self . id ( ) , 1 ) ;
491468 let compressed_indices =
492469 compressor. compress_canonical ( Canonical :: Primitive ( indices) , indices_ctx) ?;
493470
@@ -517,21 +494,21 @@ impl Scheme for RunEndScheme {
517494 2
518495 }
519496
520- fn descendant_exclusions ( & self ) -> & [ DescendantExclusion ] {
521- & [ DescendantExclusion {
522- excluded : DictScheme :: ID ,
497+ fn descendant_exclusions ( & self ) -> Vec < DescendantExclusion > {
498+ vec ! [ DescendantExclusion {
499+ excluded: DictScheme . id ( ) ,
523500 children: ChildSelection :: All ,
524501 } ]
525502 }
526503
527- fn ancestor_exclusions ( & self ) -> & [ AncestorExclusion ] {
504+ fn ancestor_exclusions ( & self ) -> Vec < AncestorExclusion > {
528505 use vortex_compressor:: builtins:: FloatDictScheme ;
529506
530- & [
507+ vec ! [
531508 // Exclude from FloatDict values child (child 0). This replaces the old ALP
532509 // conditional propagation of float RLE exclusion to integer RunEnd.
533510 AncestorExclusion {
534- ancestor : FloatDictScheme :: ID ,
511+ ancestor: FloatDictScheme . id ( ) ,
535512 children: ChildSelection :: One ( 0 ) ,
536513 } ,
537514 ]
@@ -550,7 +527,7 @@ impl Scheme for RunEndScheme {
550527 return Ok ( 0.0 ) ;
551528 }
552529
553- if ctx. allowed_cascading == 0 {
530+ if ctx. finished_cascading ( ) {
554531 return Ok ( 0.0 ) ;
555532 }
556533
@@ -564,18 +541,18 @@ impl Scheme for RunEndScheme {
564541 data : & mut ArrayAndStats ,
565542 ctx : CompressorContext ,
566543 ) -> VortexResult < ArrayRef > {
567- assert ! ( ctx. allowed_cascading > 0 ) ;
544+ assert ! ( ! ctx. finished_cascading ( ) ) ;
568545
569546 let stats = data. integer_stats ( ) ;
570547
571548 // Run-end encode the ends.
572549 let ( ends, values) = runend_encode ( stats. source ( ) ) ;
573550
574- let values_ctx = ctx. clone ( ) . descend ( ) . with_scheme ( self . id ( ) , 0 ) ;
551+ let values_ctx = ctx. clone ( ) . descend_with_scheme ( self . id ( ) , 0 ) ;
575552 let compressed_values = compressor
576553 . compress_canonical ( Canonical :: Primitive ( values. to_primitive ( ) ) , values_ctx) ?;
577554
578- let ends_ctx = ctx. descend ( ) . with_scheme ( self . id ( ) , 1 ) ;
555+ let ends_ctx = ctx. descend_with_scheme ( self . id ( ) , 1 ) ;
579556 let compressed_ends =
580557 compressor. compress_canonical ( Canonical :: Primitive ( ends. to_primitive ( ) ) , ends_ctx) ?;
581558
@@ -601,24 +578,24 @@ impl Scheme for SequenceScheme {
601578 is_integer_primitive ( canonical)
602579 }
603580
604- fn ancestor_exclusions ( & self ) -> & [ AncestorExclusion ] {
581+ fn ancestor_exclusions ( & self ) -> Vec < AncestorExclusion > {
605582 use vortex_compressor:: builtins:: FloatDictScheme ;
606583 use vortex_compressor:: builtins:: StringDictScheme ;
607584
608- & [
585+ vec ! [
609586 // Exclude from IntDict codes.
610587 AncestorExclusion {
611- ancestor : DictScheme :: ID ,
588+ ancestor: DictScheme . id ( ) ,
612589 children: ChildSelection :: All ,
613590 } ,
614591 // Exclude from FloatDict codes (child 1).
615592 AncestorExclusion {
616- ancestor : FloatDictScheme :: ID ,
593+ ancestor: FloatDictScheme . id ( ) ,
617594 children: ChildSelection :: One ( 1 ) ,
618595 } ,
619596 // Exclude from StringDict codes (child 1).
620597 AncestorExclusion {
621- ancestor : StringDictScheme :: ID ,
598+ ancestor: StringDictScheme . id ( ) ,
622599 children: ChildSelection :: One ( 1 ) ,
623600 } ,
624601 ]
0 commit comments