@@ -6,28 +6,23 @@ use std::fmt::Debug;
66use std:: hash:: Hash ;
77use std:: ops:: Range ;
88
9- use itertools:: Itertools ;
109use num_traits:: NumCast ;
1110use vortex_buffer:: BitBuffer ;
1211use vortex_buffer:: BufferMut ;
1312use vortex_error:: VortexError ;
14- use vortex_error:: VortexExpect ;
1513use vortex_error:: VortexResult ;
1614use vortex_error:: vortex_bail;
1715use vortex_error:: vortex_ensure;
1816use vortex_error:: vortex_err;
1917use vortex_mask:: AllOr ;
2018use vortex_mask:: Mask ;
21- use vortex_mask:: MaskMut ;
2219use vortex_utils:: aliases:: hash_map:: HashMap ;
2320
2421use crate :: ArrayRef ;
2522use crate :: ExecutionCtx ;
2623use crate :: IntoArray ;
2724use crate :: ToCanonical ;
28- use crate :: arrays:: BoolArray ;
2925use crate :: arrays:: PrimitiveArray ;
30- use crate :: arrays:: bool:: BoolArrayExt ;
3126use crate :: builtins:: ArrayBuiltins ;
3227use crate :: dtype:: DType ;
3328use 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
1025891fn take_map < I : NativePType + Hash + Eq + TryFrom < usize > , T : NativePType > (
1026892 indices : & [ I ] ,
0 commit comments