Skip to content

Commit 1b32f6c

Browse files
committed
some cleanup
Signed-off-by: Connor Tsui <[email protected]>
1 parent 9f3e424 commit 1b32f6c

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

vortex-compute/src/take/bit_buffer.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
//! Take operation on [`BitBuffer`].
5+
//!
6+
//! NB: We do NOT implement `impl<I: UnsignedPType> Take<PVector<I>> for &BitBuffer`, specifically
7+
//! because there is a very similar implementation on `Mask` that has special logic for working with
8+
//! null indices. That logic could also be implemented on `BitBuffer`, but since it is not
9+
//! immediately clear what should happen in the case of a null index when taking a `BitBuffer` (do
10+
//! you set it to true or false?), we do not implement this at all.
11+
412
use vortex_buffer::BitBuffer;
513
use vortex_buffer::get_bit;
614
use vortex_dtype::UnsignedPType;
715

16+
use crate::take::LINUX_PAGE_SIZE;
817
use crate::take::Take;
918

1019
impl<I: UnsignedPType> Take<[I]> for &BitBuffer {
@@ -13,7 +22,7 @@ impl<I: UnsignedPType> Take<[I]> for &BitBuffer {
1322
fn take(self, indices: &[I]) -> BitBuffer {
1423
// For boolean arrays that roughly fit into a single page (at least, on Linux), it's worth
1524
// the overhead to convert to a `Vec<bool>`.
16-
if self.len() <= 4096 {
25+
if self.len() <= LINUX_PAGE_SIZE {
1726
let bools = self.iter().collect();
1827
take_byte_bool(bools, indices)
1928
} else {
@@ -22,12 +31,6 @@ impl<I: UnsignedPType> Take<[I]> for &BitBuffer {
2231
}
2332
}
2433

25-
// NB: We do NOT implement `impl<I: UnsignedPType> Take<PVector<I>> for &BitBuffer`, specifically
26-
// because there is a very similar implementation on `Mask` that has special logic for working with
27-
// null indices. That logic could also be implemented on `BitBuffer`, but since it is not
28-
// immediately clear what should happen in the case of a null index when taking a `BitBuffer` (do
29-
// you set it to true or false?), we do not implement this at all.
30-
3134
/// # Panics
3235
///
3336
/// Panics if an index is out of bounds.

vortex-compute/src/take/mask.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use vortex_mask::Mask;
88
use vortex_vector::VectorOps;
99
use vortex_vector::primitive::PVector;
1010

11+
use crate::take::LINUX_PAGE_SIZE;
1112
use crate::take::Take;
1213

1314
impl<I: UnsignedPType> Take<[I]> for &Mask {
@@ -38,14 +39,10 @@ impl<I: UnsignedPType> Take<PVector<I>> for &Mask {
3839
let indices_validity = indices.validity();
3940
let indices_len = indices.len();
4041

41-
match indices_validity {
42+
let indices_validity_values = match indices_validity {
4243
Mask::AllTrue(_) => return self.take(indices.elements().as_slice()),
4344
Mask::AllFalse(_) => return Mask::AllFalse(indices_len),
44-
Mask::Values(_) => (),
45-
};
46-
47-
let Mask::Values(indices_validity_values) = indices_validity else {
48-
unreachable!("we just matched on the other cases above");
45+
Mask::Values(indices_validity_values) => indices_validity_values,
4946
};
5047

5148
match self {
@@ -56,7 +53,7 @@ impl<I: UnsignedPType> Take<PVector<I>> for &Mask {
5653
Mask::Values(mask_values) => {
5754
// For boolean arrays that roughly fit into a single page (at least, on Linux), it's
5855
// worth the overhead to convert to a `Vec<bool>`.
59-
if self.len() <= 4096 {
56+
if self.len() <= LINUX_PAGE_SIZE {
6057
let bools = mask_values.bit_buffer().iter().collect();
6158
Mask::from_buffer(take_byte_bool_nullable(bools, indices))
6259
} else {

vortex-compute/src/take/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ mod mask;
99
pub mod slice;
1010
mod vector;
1111

12+
/// The size of a page in Linux.
13+
const LINUX_PAGE_SIZE: usize = 4096;
14+
1215
/// Function for taking based on indices (which can have different representations).
1316
pub trait Take<Indices: ?Sized> {
1417
/// The result type after performing the operation.

0 commit comments

Comments
 (0)