Skip to content

Commit

Permalink
make chunked_indices mod-private
Browse files Browse the repository at this point in the history
  • Loading branch information
a10y committed Dec 12, 2024
1 parent b3199a2 commit 184c2a9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
31 changes: 1 addition & 30 deletions encodings/fastlanes/src/bitpacking/compute/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use vortex_array::{ArrayData, IntoArrayData, IntoArrayVariant};
use vortex_dtype::{match_each_unsigned_integer_ptype, NativePType};
use vortex_error::VortexResult;

use super::chunked_indices;
use crate::bitpacking::compute::take::UNPACK_CHUNK_THRESHOLD;
use crate::{BitPackedArray, BitPackedEncoding};

Expand Down Expand Up @@ -104,36 +105,6 @@ fn filter_indices<T: NativePType + BitPacking + ArrowNativeType>(
values
}

pub fn chunked_indices<F: FnMut(usize, &[usize])>(
mut indices: impl Iterator<Item = usize>,
offset: usize,
mut chunk_fn: F,
) {
let mut indices_within_chunk: Vec<usize> = Vec::with_capacity(1024);

let Some(first_idx) = indices.next() else {
return;
};

let mut current_chunk_idx = (first_idx + offset) / 1024;
indices_within_chunk.push((first_idx + offset) % 1024);
for idx in indices {
let new_chunk_idx = (idx + offset) / 1024;

if new_chunk_idx != current_chunk_idx {
chunk_fn(current_chunk_idx, &indices_within_chunk);
indices_within_chunk.clear();
}

current_chunk_idx = new_chunk_idx;
indices_within_chunk.push((idx + offset) % 1024);
}

if !indices_within_chunk.is_empty() {
chunk_fn(current_chunk_idx, &indices_within_chunk);
}
}

fn filter_slices<T: NativePType + BitPacking + ArrowNativeType>(
array: &BitPackedArray,
indices_len: usize,
Expand Down
30 changes: 30 additions & 0 deletions encodings/fastlanes/src/bitpacking/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,33 @@ impl ComputeVTable for BitPackedEncoding {
Some(self)
}
}

fn chunked_indices<F: FnMut(usize, &[usize])>(
mut indices: impl Iterator<Item = usize>,
offset: usize,
mut chunk_fn: F,
) {
let mut indices_within_chunk: Vec<usize> = Vec::with_capacity(1024);

let Some(first_idx) = indices.next() else {
return;
};

let mut current_chunk_idx = (first_idx + offset) / 1024;
indices_within_chunk.push((first_idx + offset) % 1024);
for idx in indices {
let new_chunk_idx = (idx + offset) / 1024;

if new_chunk_idx != current_chunk_idx {
chunk_fn(current_chunk_idx, &indices_within_chunk);
indices_within_chunk.clear();
}

current_chunk_idx = new_chunk_idx;
indices_within_chunk.push((idx + offset) % 1024);
}

if !indices_within_chunk.is_empty() {
chunk_fn(current_chunk_idx, &indices_within_chunk);
}
}
2 changes: 1 addition & 1 deletion encodings/fastlanes/src/bitpacking/compute/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use vortex_dtype::{
};
use vortex_error::{VortexExpect as _, VortexResult};

use crate::bitpacking::compute::filter::chunked_indices;
use super::chunked_indices;
use crate::{unpack_single_primitive, BitPackedArray, BitPackedEncoding};

// assuming the buffer is already allocated (which will happen at most once) then unpacking
Expand Down

0 comments on commit 184c2a9

Please sign in to comment.