Skip to content

Commit d296528

Browse files
authored
Remove MaskMut and unused functions from BitBufferMut (#7379)
A lot of this logic dates back to earlier expriments. We don't need this logic and in some cases it's duplicate with a logic we have optimised elsewhere Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent 7618c23 commit d296528

9 files changed

Lines changed: 5 additions & 1359 deletions

File tree

vortex-array/public-api.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13576,8 +13576,6 @@ pub struct vortex_array::patches::Patches
1357613576

1357713577
impl vortex_array::patches::Patches
1357813578

13579-
pub unsafe fn vortex_array::patches::Patches::apply_to_buffer<P: vortex_array::dtype::NativePType>(&self, buffer: &mut [P], validity: &mut vortex_mask::mask_mut::MaskMut, ctx: &mut vortex_array::ExecutionCtx)
13580-
1358113579
pub fn vortex_array::patches::Patches::array_len(&self) -> usize
1358213580

1358313581
pub fn vortex_array::patches::Patches::cast_values(self, values_dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<Self>

vortex-array/src/patches.rs

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,23 @@ use std::fmt::Debug;
66
use std::hash::Hash;
77
use std::ops::Range;
88

9-
use itertools::Itertools;
109
use num_traits::NumCast;
1110
use vortex_buffer::BitBuffer;
1211
use vortex_buffer::BufferMut;
1312
use vortex_error::VortexError;
14-
use vortex_error::VortexExpect;
1513
use vortex_error::VortexResult;
1614
use vortex_error::vortex_bail;
1715
use vortex_error::vortex_ensure;
1816
use vortex_error::vortex_err;
1917
use vortex_mask::AllOr;
2018
use vortex_mask::Mask;
21-
use vortex_mask::MaskMut;
2219
use vortex_utils::aliases::hash_map::HashMap;
2320

2421
use crate::ArrayRef;
2522
use crate::ExecutionCtx;
2623
use crate::IntoArray;
2724
use crate::ToCanonical;
28-
use crate::arrays::BoolArray;
2925
use crate::arrays::PrimitiveArray;
30-
use crate::arrays::bool::BoolArrayExt;
3126
use crate::builtins::ArrayBuiltins;
3227
use crate::dtype::DType;
3328
use crate::dtype::IntegerPType;
@@ -868,59 +863,6 @@ impl Patches {
868863
}))
869864
}
870865

871-
/// Apply patches to a mutable buffer and validity mask.
872-
///
873-
/// This method applies the patch values to the given buffer at the positions specified by the
874-
/// patch indices. For non-null patch values, it updates the buffer and marks the position as
875-
/// valid. For null patch values, it marks the position as invalid.
876-
///
877-
/// # Safety
878-
///
879-
/// - All patch indices after offset adjustment must be valid indices into the buffer.
880-
/// - The buffer and validity mask must have the same length.
881-
pub unsafe fn apply_to_buffer<P: NativePType>(
882-
&self,
883-
buffer: &mut [P],
884-
validity: &mut MaskMut,
885-
ctx: &mut ExecutionCtx,
886-
) {
887-
let patch_indices = self
888-
.indices
889-
.clone()
890-
.execute::<PrimitiveArray>(ctx)
891-
.vortex_expect("patch indices must be convertible to PrimitiveArray");
892-
let patch_values = self
893-
.values
894-
.clone()
895-
.execute::<PrimitiveArray>(ctx)
896-
.vortex_expect("patch values must be convertible to PrimitiveArray");
897-
let patches_validity = patch_values
898-
.validity()
899-
.vortex_expect("patch values validity should be derivable");
900-
901-
let patch_values_slice = patch_values.as_slice::<P>();
902-
match_each_unsigned_integer_ptype!(patch_indices.ptype(), |I| {
903-
let patch_indices_slice = patch_indices.as_slice::<I>();
904-
905-
// SAFETY:
906-
// - `Patches` invariant guarantees indices are sorted and within array bounds.
907-
// - `patch_indices` and `patch_values` have equal length (from `Patches` invariant).
908-
// - `buffer` and `validity` have equal length (precondition).
909-
// - All patch indices are valid after offset adjustment (precondition).
910-
unsafe {
911-
apply_patches_to_buffer_inner(
912-
buffer,
913-
validity,
914-
patch_indices_slice,
915-
self.offset,
916-
patch_values_slice,
917-
&patches_validity,
918-
ctx,
919-
);
920-
}
921-
});
922-
}
923-
924866
pub fn map_values<F>(self, f: F) -> VortexResult<Self>
925867
where
926868
F: FnOnce(ArrayRef) -> VortexResult<ArrayRef>,
@@ -945,82 +887,6 @@ impl Patches {
945887
}
946888
}
947889

948-
/// Helper function to apply patches to a buffer.
949-
///
950-
/// # Safety
951-
///
952-
/// - All indices in `patch_indices` after subtracting `patch_offset` must be valid indices
953-
/// into both `buffer` and `validity`.
954-
/// - `patch_indices` must be sorted in ascending order.
955-
/// - `patch_indices` and `patch_values` must have the same length.
956-
/// - `buffer` and `validity` must have the same length.
957-
unsafe fn apply_patches_to_buffer_inner<P, I>(
958-
buffer: &mut [P],
959-
validity: &mut MaskMut,
960-
patch_indices: &[I],
961-
patch_offset: usize,
962-
patch_values: &[P],
963-
patches_validity: &Validity,
964-
ctx: &mut ExecutionCtx,
965-
) where
966-
P: NativePType,
967-
I: UnsignedPType,
968-
{
969-
debug_assert!(!patch_indices.is_empty());
970-
debug_assert_eq!(patch_indices.len(), patch_values.len());
971-
debug_assert_eq!(buffer.len(), validity.len());
972-
973-
match patches_validity {
974-
Validity::NonNullable | Validity::AllValid => {
975-
// All patch values are valid, apply them all.
976-
for (&i, &value) in patch_indices.iter().zip_eq(patch_values) {
977-
let index = i.as_() - patch_offset;
978-
979-
// SAFETY: `index` is valid because caller guarantees all patch indices are within
980-
// bounds after offset adjustment.
981-
unsafe {
982-
validity.set_unchecked(index);
983-
}
984-
buffer[index] = value;
985-
}
986-
}
987-
Validity::AllInvalid => {
988-
// All patch values are null, just mark positions as invalid.
989-
for &i in patch_indices {
990-
let index = i.as_() - patch_offset;
991-
992-
// SAFETY: `index` is valid because caller guarantees all patch indices are within
993-
// bounds after offset adjustment.
994-
unsafe {
995-
validity.unset_unchecked(index);
996-
}
997-
}
998-
}
999-
Validity::Array(array) => {
1000-
// Some patch values may be null, check each one.
1001-
let bool_array = array
1002-
.clone()
1003-
.execute::<BoolArray>(ctx)
1004-
.vortex_expect("validity array must be convertible to BoolArray");
1005-
let mask = bool_array.to_bit_buffer();
1006-
for (patch_idx, (&i, &value)) in patch_indices.iter().zip_eq(patch_values).enumerate() {
1007-
let index = i.as_() - patch_offset;
1008-
1009-
// SAFETY: `index` and `patch_idx` are valid because caller guarantees all patch
1010-
// indices are within bounds after offset adjustment.
1011-
unsafe {
1012-
if mask.value_unchecked(patch_idx) {
1013-
buffer[index] = value;
1014-
validity.set_unchecked(index);
1015-
} else {
1016-
validity.unset_unchecked(index);
1017-
}
1018-
}
1019-
}
1020-
}
1021-
}
1022-
}
1023-
1024890
#[allow(clippy::too_many_arguments)] // private function, can clean up one day
1025891
fn take_map<I: NativePType + Hash + Eq + TryFrom<usize>, T: NativePType>(
1026892
indices: &[I],

vortex-buffer/public-api.lock

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,12 @@ pub fn vortex_buffer::BitBufferMut::append_n(&mut self, value: bool, n: usize)
430430

431431
pub fn vortex_buffer::BitBufferMut::append_true(&mut self)
432432

433-
pub fn vortex_buffer::BitBufferMut::as_mut_ptr(&mut self) -> *mut u8
434-
435433
pub fn vortex_buffer::BitBufferMut::as_mut_slice(&mut self) -> &mut [u8]
436434

437435
pub fn vortex_buffer::BitBufferMut::as_slice(&self) -> &[u8]
438436

439437
pub fn vortex_buffer::BitBufferMut::capacity(&self) -> usize
440438

441-
pub fn vortex_buffer::BitBufferMut::chunks(&self) -> arrow_buffer::util::bit_chunk_iterator::BitChunks<'_>
442-
443439
pub fn vortex_buffer::BitBufferMut::clear(&mut self)
444440

445441
pub fn vortex_buffer::BitBufferMut::collect_bool<F: core::ops::function::FnMut(usize) -> bool>(len: usize, f: F) -> Self
@@ -448,8 +444,6 @@ pub fn vortex_buffer::BitBufferMut::copy_from(bit_buffer: &vortex_buffer::BitBuf
448444

449445
pub fn vortex_buffer::BitBufferMut::empty() -> Self
450446

451-
pub fn vortex_buffer::BitBufferMut::false_count(&self) -> usize
452-
453447
pub fn vortex_buffer::BitBufferMut::fill_range(&mut self, start: usize, end: usize, value: bool)
454448

455449
pub unsafe fn vortex_buffer::BitBufferMut::fill_range_unchecked(&mut self, start: usize, end: usize, value: bool)
@@ -486,14 +480,10 @@ pub fn vortex_buffer::BitBufferMut::set_to(&mut self, index: usize, value: bool)
486480

487481
pub unsafe fn vortex_buffer::BitBufferMut::set_to_unchecked(&mut self, index: usize, value: bool)
488482

489-
pub fn vortex_buffer::BitBufferMut::split_off(&mut self, at: usize) -> Self
490-
491-
pub fn vortex_buffer::BitBufferMut::true_count(&self) -> usize
483+
pub unsafe fn vortex_buffer::BitBufferMut::set_unchecked(&mut self, index: usize)
492484

493485
pub fn vortex_buffer::BitBufferMut::truncate(&mut self, len: usize)
494486

495-
pub fn vortex_buffer::BitBufferMut::unaligned_chunks(&self) -> arrow_buffer::util::bit_chunk_iterator::UnalignedBitChunk<'_>
496-
497487
pub fn vortex_buffer::BitBufferMut::unset(&mut self, index: usize)
498488

499489
pub unsafe fn vortex_buffer::BitBufferMut::unset_unchecked(&mut self, index: usize)
@@ -510,12 +500,6 @@ impl core::clone::Clone for vortex_buffer::BitBufferMut
510500

511501
pub fn vortex_buffer::BitBufferMut::clone(&self) -> vortex_buffer::BitBufferMut
512502

513-
impl core::cmp::Eq for vortex_buffer::BitBufferMut
514-
515-
impl core::cmp::PartialEq for vortex_buffer::BitBufferMut
516-
517-
pub fn vortex_buffer::BitBufferMut::eq(&self, other: &Self) -> bool
518-
519503
impl core::convert::From<&[bool]> for vortex_buffer::BitBufferMut
520504

521505
pub fn vortex_buffer::BitBufferMut::from(value: &[bool]) -> Self

0 commit comments

Comments
 (0)