Skip to content

Commit 0e23a21

Browse files
committed
wip
Signed-off-by: Alexander Droste <[email protected]>
1 parent 35ad7c1 commit 0e23a21

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

encodings/sparse/src/canonical.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use vortex_dtype::StructFields;
4141
use vortex_dtype::match_each_decimal_value_type;
4242
use vortex_dtype::match_each_integer_ptype;
4343
use vortex_dtype::match_each_native_ptype;
44+
use vortex_dtype::match_smallest_offset_type;
4445
use vortex_error::VortexError;
4546
use vortex_error::VortexExpect;
4647
use vortex_error::vortex_panic;
@@ -124,27 +125,6 @@ fn canonicalize_sparse_lists(
124125
values_dtype: Arc<DType>,
125126
nullability: Nullability,
126127
) -> Canonical {
127-
// TODO(connor): We should move this to `vortex-dtype` so that we can use this elsewhere.
128-
macro_rules! match_smallest_offset_type {
129-
($n_elements:expr, | $offset_type:ident | $body:block) => {{
130-
let n_elements = $n_elements;
131-
if n_elements <= u8::MAX as usize {
132-
type $offset_type = u8;
133-
$body
134-
} else if n_elements <= u16::MAX as usize {
135-
type $offset_type = u16;
136-
$body
137-
} else if n_elements <= u32::MAX as usize {
138-
type $offset_type = u32;
139-
$body
140-
} else {
141-
assert!(u64::try_from(n_elements).is_ok());
142-
type $offset_type = u64;
143-
$body
144-
}
145-
}};
146-
}
147-
148128
let resolved_patches = array.resolved_patches();
149129

150130
let indices = resolved_patches.indices().to_primitive();

vortex-dtype/src/ptype.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,34 @@ macro_rules! match_each_native_simd_ptype {
668668
}};
669669
}
670670

671+
/// Macro to match the smallest offset type that can fit the given number of elements.
672+
///
673+
/// This macro selects u8, u16, u32, or u64 based on the size of `n_elements`:
674+
/// - u8 if n_elements <= 255
675+
/// - u16 if n_elements <= 65535
676+
/// - u32 if n_elements <= 4294967295
677+
/// - u64 otherwise
678+
#[macro_export]
679+
macro_rules! match_smallest_offset_type {
680+
($n_elements:expr, | $offset_type:ident | $body:block) => {{
681+
let n_elements = $n_elements;
682+
if n_elements <= u8::MAX as usize {
683+
type $offset_type = u8;
684+
$body
685+
} else if n_elements <= u16::MAX as usize {
686+
type $offset_type = u16;
687+
$body
688+
} else if n_elements <= u32::MAX as usize {
689+
type $offset_type = u32;
690+
$body
691+
} else {
692+
assert!(u64::try_from(n_elements).is_ok());
693+
type $offset_type = u64;
694+
$body
695+
}
696+
}};
697+
}
698+
671699
impl PType {
672700
/// Returns `true` iff this PType is an unsigned integer type
673701
#[inline]

0 commit comments

Comments
 (0)