Skip to content

Commit acc8256

Browse files
committed
move patch chunk
Signed-off-by: Alexander Droste <[email protected]>
1 parent bf7dd27 commit acc8256

File tree

4 files changed

+41
-39
lines changed

4 files changed

+41
-39
lines changed

encodings/alp/src/alp/compress.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::mem::transmute;
55

66
use itertools::Itertools;
7-
use vortex_array::arrays::PrimitiveArray;
7+
use vortex_array::arrays::{PrimitiveArray, patch_chunk};
88
use vortex_array::patches::Patches;
99
use vortex_array::validity::Validity;
1010
use vortex_array::vtable::ValidityHelper;
@@ -187,7 +187,7 @@ pub fn decompress_chunked(
187187
<T>::decode_slice_inplace(chunk_slice, exponents);
188188

189189
let decoded_chunk: &mut [T] = unsafe { transmute(chunk_slice) };
190-
PrimitiveArray::patch_chunk(
190+
patch_chunk(
191191
decoded_chunk,
192192
patches_indices,
193193
patches_values,

vortex-array/src/arrays/primitive/array/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ mod conversion;
1818
mod patch;
1919
mod top_value;
2020

21+
pub use patch::patch_chunk;
22+
2123
/// A primitive array that stores [native types][vortex_dtype::NativePType] in a contiguous buffer
2224
/// of memory, along with an optional validity child.
2325
///

vortex-array/src/arrays/primitive/array/patch.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -55,44 +55,44 @@ impl PrimitiveArray {
5555
}
5656
Self::new(own_values, patched_validity)
5757
}
58+
}
5859

59-
/// Patches a chunk of decoded values with the given patches.
60-
///
61-
/// # Arguments
62-
///
63-
/// * `decoded_values` - Mutable slice of decoded values to be patched
64-
/// * `patches_indices` - Indices indicating which positions to patch
65-
/// * `patches_values` - Values to apply at the patched indices
66-
/// * `patches_offset` - Offset to subtract from patch indices
67-
/// * `chunk_offsets_slice` - Slice containing offsets for each chunk
68-
/// * `chunk_idx` - Index of the chunk to patch
69-
#[inline]
70-
pub fn patch_chunk<T, I, C>(
71-
decoded_values: &mut [T],
72-
patches_indices: &[I],
73-
patches_values: &[T],
74-
patches_offset: usize,
75-
chunk_offsets_slice: &[C],
76-
chunk_idx: usize,
77-
) where
78-
T: NativePType,
79-
I: UnsignedPType,
80-
C: UnsignedPType,
81-
{
82-
let patches_start_idx = chunk_offsets_slice[chunk_idx].as_();
83-
let patches_end_idx = if chunk_idx + 1 < chunk_offsets_slice.len() {
84-
chunk_offsets_slice[chunk_idx + 1].as_()
85-
} else {
86-
patches_indices.len()
87-
};
60+
/// Patches a chunk of decoded values.
61+
///
62+
/// # Arguments
63+
///
64+
/// * `decoded_values` - Mutable slice of decoded values to be patched
65+
/// * `patches_indices` - Indices indicating which positions to patch
66+
/// * `patches_values` - Values to apply at the patched indices
67+
/// * `patches_offset` - Offset to subtract from patch indices
68+
/// * `chunk_offsets_slice` - Slice containing offsets for each chunk
69+
/// * `chunk_idx` - Index of the chunk to patch
70+
#[inline]
71+
pub fn patch_chunk<T, I, C>(
72+
decoded_values: &mut [T],
73+
patches_indices: &[I],
74+
patches_values: &[T],
75+
patches_offset: usize,
76+
chunk_offsets_slice: &[C],
77+
chunk_idx: usize,
78+
) where
79+
T: NativePType,
80+
I: UnsignedPType,
81+
C: UnsignedPType,
82+
{
83+
let patches_start_idx = chunk_offsets_slice[chunk_idx].as_();
84+
let patches_end_idx = if chunk_idx + 1 < chunk_offsets_slice.len() {
85+
chunk_offsets_slice[chunk_idx + 1].as_()
86+
} else {
87+
patches_indices.len()
88+
};
8889

89-
let chunk_start = chunk_idx * 1024;
90-
for patches_idx in patches_start_idx..patches_end_idx {
91-
let patched_value = patches_values[patches_idx];
92-
let absolute_index: usize = patches_indices[patches_idx].as_() - patches_offset;
93-
let chunk_relative_index = absolute_index - chunk_start;
94-
decoded_values[chunk_relative_index] = patched_value;
95-
}
90+
let chunk_start = chunk_idx * 1024;
91+
for patches_idx in patches_start_idx..patches_end_idx {
92+
let patched_value = patches_values[patches_idx];
93+
let absolute_index: usize = patches_indices[patches_idx].as_() - patches_offset;
94+
let chunk_relative_index = absolute_index - chunk_start;
95+
decoded_values[chunk_relative_index] = patched_value;
9696
}
9797
}
9898

vortex-array/src/arrays/primitive/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
mod array;
5-
pub use array::PrimitiveArray;
5+
pub use array::{PrimitiveArray, patch_chunk};
66

77
mod compute;
88
pub use compute::{IS_CONST_LANE_WIDTH, compute_is_constant};

0 commit comments

Comments
 (0)