Skip to content

Commit 14b5096

Browse files
committed
better
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent 321208f commit 14b5096

File tree

1 file changed

+38
-19
lines changed
  • encodings/fastlanes/src/bitpacking/compute

1 file changed

+38
-19
lines changed

encodings/fastlanes/src/bitpacking/compute/compare.rs

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,52 @@ fn compare_constant_typed<U, T>(
109109
where
110110
T: NativePType + FastLanesComparable<Bitpacked = U>,
111111
U: UnsignedPType + BitPacking + BitPackingCompare,
112+
{
113+
match operator {
114+
CompareOperator::Eq => {
115+
compare_constant_with::<U, T, _>(array, value, nullability, ctx, T::is_eq)
116+
}
117+
CompareOperator::NotEq => {
118+
compare_constant_with::<U, T, _>(array, value, nullability, ctx, is_ne::<T>)
119+
}
120+
CompareOperator::Gt => {
121+
compare_constant_with::<U, T, _>(array, value, nullability, ctx, T::is_gt)
122+
}
123+
CompareOperator::Gte => {
124+
compare_constant_with::<U, T, _>(array, value, nullability, ctx, T::is_ge)
125+
}
126+
CompareOperator::Lt => {
127+
compare_constant_with::<U, T, _>(array, value, nullability, ctx, T::is_lt)
128+
}
129+
CompareOperator::Lte => {
130+
compare_constant_with::<U, T, _>(array, value, nullability, ctx, T::is_le)
131+
}
132+
}
133+
}
134+
135+
fn compare_constant_with<U, T, C>(
136+
array: ArrayView<'_, BitPacked>,
137+
value: T,
138+
nullability: Nullability,
139+
ctx: &mut ExecutionCtx,
140+
compare: C,
141+
) -> VortexResult<ArrayRef>
142+
where
143+
T: NativePType + FastLanesComparable<Bitpacked = U>,
144+
U: UnsignedPType + BitPacking + BitPackingCompare,
145+
C: Fn(T, T) -> bool + Copy,
112146
{
113147
let mut bits = collect_chunk_masks::<U>(
114148
array.data(),
115149
array.len(),
116150
array.offset(),
117151
|bit_width, packed_chunk, chunk_matches| unsafe {
118-
U::unchecked_unpack_cmp(
119-
bit_width,
120-
packed_chunk,
121-
chunk_matches,
122-
|lhs, rhs| compare_values(lhs, rhs, operator),
123-
value,
124-
);
152+
U::unchecked_unpack_cmp(bit_width, packed_chunk, chunk_matches, compare, value);
125153
},
126154
);
127155

128156
if let Some(patches) = array.patches() {
129-
apply_patch_predicate::<T>(&mut bits, &patches, ctx, |patched| {
130-
compare_values(patched, value, operator)
131-
})?;
157+
apply_patch_predicate::<T>(&mut bits, &patches, ctx, |patched| compare(patched, value))?;
132158
}
133159

134160
Ok(BoolArray::new(
@@ -425,15 +451,8 @@ where
425451
}
426452

427453
#[inline]
428-
fn compare_values<T: NativePType>(lhs: T, rhs: T, operator: CompareOperator) -> bool {
429-
match operator {
430-
CompareOperator::Eq => lhs.is_eq(rhs),
431-
CompareOperator::NotEq => !lhs.is_eq(rhs),
432-
CompareOperator::Gt => lhs.is_gt(rhs),
433-
CompareOperator::Gte => lhs.is_ge(rhs),
434-
CompareOperator::Lt => lhs.is_lt(rhs),
435-
CompareOperator::Lte => lhs.is_le(rhs),
436-
}
454+
fn is_ne<T: NativePType>(lhs: T, rhs: T) -> bool {
455+
!lhs.is_eq(rhs)
437456
}
438457

439458
#[inline]

0 commit comments

Comments
 (0)