Skip to content

Commit 311ade1

Browse files
committed
cleanup
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 2a1c374 commit 311ade1

17 files changed

Lines changed: 180 additions & 207 deletions

File tree

vortex-btrblocks/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn default_excluded() -> HashSet<SchemeId> {
8181
///
8282
/// ```rust
8383
/// use vortex_btrblocks::{BtrBlocksCompressorBuilder, Scheme, SchemeExt};
84-
/// use vortex_btrblocks::compressor::integer::DictScheme;
84+
/// use vortex_btrblocks::schemes::integer::DictScheme;
8585
///
8686
/// // Default compressor - all non-excluded schemes allowed.
8787
/// let compressor = BtrBlocksCompressorBuilder::default().build();

vortex-btrblocks/src/canonical_compressor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::CascadingCompressor;
2020
///
2121
/// ```rust
2222
/// use vortex_btrblocks::{BtrBlocksCompressor, BtrBlocksCompressorBuilder, Scheme, SchemeExt};
23-
/// use vortex_btrblocks::compressor::integer::DictScheme;
23+
/// use vortex_btrblocks::schemes::integer::DictScheme;
2424
///
2525
/// // Default compressor - all schemes allowed.
2626
/// let compressor = BtrBlocksCompressor::default();

vortex-btrblocks/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
//!
4242
//! ```rust
4343
//! use vortex_btrblocks::{BtrBlocksCompressor, BtrBlocksCompressorBuilder, Scheme, SchemeExt};
44-
//! use vortex_btrblocks::compressor::integer::DictScheme;
44+
//! use vortex_btrblocks::schemes::integer::DictScheme;
4545
//! use vortex_array::DynArray;
4646
//!
4747
//! // Default compressor with all schemes enabled.

vortex-btrblocks/src/schemes/decimal.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ impl Scheme for DecimalScheme {
7070
_ => return Ok(decimal.into_array()),
7171
};
7272

73-
let ctx = CompressorContext::default()
74-
.descend()
75-
.with_scheme(self.id(), 0);
73+
let ctx = CompressorContext::default().descend_with_scheme(self.id(), 0);
7674
let compressed = compressor.compress_canonical(Canonical::Primitive(prim), ctx)?;
7775

7876
DecimalBytePartsArray::try_new(compressed, decimal.decimal_dtype()).map(|d| d.into_array())

vortex-btrblocks/src/schemes/float.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl Scheme for ALPScheme {
122122
return Ok(0.0);
123123
}
124124

125-
if ctx.allowed_cascading == 0 {
125+
if ctx.finished_cascading() {
126126
// ALP does not compress on its own, we need to be able to cascade it with
127127
// an integer compressor.
128128
return Ok(0.0);
@@ -148,7 +148,7 @@ impl Scheme for ALPScheme {
148148
// to keep them linear for easy indexing.
149149
let compressed_alp_ints = compressor.compress_canonical(
150150
Canonical::Primitive(alp_ints),
151-
ctx.descend().with_scheme(self.id(), 0),
151+
ctx.descend_with_scheme(self.id(), 0),
152152
)?;
153153

154154
let patches = alp.patches().map(compress_patches).transpose()?;
@@ -220,9 +220,9 @@ impl Scheme for NullDominated {
220220
1
221221
}
222222

223-
fn descendant_exclusions(&self) -> &[DescendantExclusion] {
224-
&[DescendantExclusion {
225-
excluded: IntSparseScheme::ID,
223+
fn descendant_exclusions(&self) -> Vec<DescendantExclusion> {
224+
vec![DescendantExclusion {
225+
excluded: IntSparseScheme.id(),
226226
children: ChildSelection::All,
227227
}]
228228
}
@@ -234,7 +234,7 @@ impl Scheme for NullDominated {
234234
ctx: CompressorContext,
235235
) -> VortexResult<f64> {
236236
// Only use `SparseScheme` if we can cascade.
237-
if ctx.allowed_cascading == 0 {
237+
if ctx.finished_cascading() {
238238
return Ok(0.0);
239239
}
240240

@@ -260,7 +260,7 @@ impl Scheme for NullDominated {
260260
data: &mut ArrayAndStats,
261261
ctx: CompressorContext,
262262
) -> VortexResult<ArrayRef> {
263-
assert!(ctx.allowed_cascading > 0);
263+
assert!(!ctx.finished_cascading());
264264

265265
let stats = data.float_stats();
266266

@@ -271,7 +271,7 @@ impl Scheme for NullDominated {
271271
let indices = sparse.patches().indices().to_primitive().narrow()?;
272272
let compressed_indices = compressor.compress_canonical(
273273
Canonical::Primitive(indices.to_primitive()),
274-
ctx.descend().with_scheme(self.id(), 0),
274+
ctx.descend_with_scheme(self.id(), 0),
275275
)?;
276276

277277
SparseArray::try_new(

vortex-btrblocks/src/schemes/integer.rs

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use crate::CompressorContext;
3939
use crate::GenerateStatsOptions;
4040
use crate::Scheme;
4141
use crate::SchemeExt;
42-
use crate::SchemeId;
4342
use crate::compress_patches;
4443
use crate::estimate_compression_ratio_with_sampling;
4544
use crate::schemes::rle;
@@ -62,35 +61,14 @@ pub struct BitPackingScheme;
6261
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
6362
pub 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)]
7466
pub 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)]
8570
pub 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
]

vortex-btrblocks/src/schemes/rle.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ impl<C: RLEConfig> Scheme for RLEScheme<C> {
9292
3
9393
}
9494

95-
fn descendant_exclusions(&self) -> &[DescendantExclusion] {
96-
&[DescendantExclusion {
97-
excluded: IntDictScheme::ID,
95+
fn descendant_exclusions(&self) -> Vec<DescendantExclusion> {
96+
vec![DescendantExclusion {
97+
excluded: IntDictScheme.id(),
9898
children: ChildSelection::Many(&[1, 2]),
9999
}]
100100
}
@@ -106,7 +106,7 @@ impl<C: RLEConfig> Scheme for RLEScheme<C> {
106106
ctx: CompressorContext,
107107
) -> VortexResult<f64> {
108108
// RLE is only useful when we cascade it with another encoding.
109-
if ctx.allowed_cascading == 0 {
109+
if ctx.finished_cascading() {
110110
return Ok(0.0);
111111
}
112112

@@ -137,24 +137,24 @@ impl<C: RLEConfig> Scheme for RLEScheme<C> {
137137
let stats = data.get_or_insert_with::<C::Stats>(|| C::generate_stats(&array));
138138
let rle_array = RLEArray::encode(RLEStats::source(stats))?;
139139

140-
if ctx.allowed_cascading == 0 {
140+
if ctx.finished_cascading() {
141141
return Ok(rle_array.into_array());
142142
}
143143

144144
let compressed_values = C::compress_values(
145145
compressor,
146146
&rle_array.values().to_primitive(),
147-
ctx.clone().descend().with_scheme(self.id(), 0),
147+
ctx.clone().descend_with_scheme(self.id(), 0),
148148
)?;
149149

150150
let compressed_indices = compressor.compress_canonical(
151151
Canonical::Primitive(rle_array.indices().to_primitive().narrow()?),
152-
ctx.clone().descend().with_scheme(self.id(), 1),
152+
ctx.clone().descend_with_scheme(self.id(), 1),
153153
)?;
154154

155155
let compressed_offsets = compressor.compress_canonical(
156156
Canonical::Primitive(rle_array.values_idx_offsets().to_primitive().narrow()?),
157-
ctx.descend().with_scheme(self.id(), 2),
157+
ctx.descend_with_scheme(self.id(), 2),
158158
)?;
159159

160160
// SAFETY: Recursive compression doesn't affect the invariants.

0 commit comments

Comments
 (0)