@@ -20,7 +20,12 @@ use crate::BooleanBuffer;
2020use crate :: util:: bit_util:: ceil;
2121
2222/// Apply a bitwise operation `op` to four inputs and return the result as a Buffer.
23- /// The inputs are treated as bitmaps, meaning that offsets and length are specified in number of bits.
23+ ///
24+ /// The inputs are treated as bitmaps, meaning that offsets and length are
25+ /// specified in number of bits.
26+ ///
27+ /// NOTE: The operation `op` is applied to chunks of 64 bits (u64) and any bits
28+ /// outside the offsets and len are set to zero out before calling `op`.
2429pub fn bitwise_quaternary_op_helper < F > (
2530 buffers : [ & Buffer ; 4 ] ,
2631 offsets : [ usize ; 4 ] ,
6065}
6166
6267/// Apply a bitwise operation `op` to two inputs and return the result as a Buffer.
63- /// The inputs are treated as bitmaps, meaning that offsets and length are specified in number of bits.
68+ ///
69+ /// The inputs are treated as bitmaps, meaning that offsets and length are
70+ /// specified in number of bits.
71+ ///
72+ /// NOTE: The operation `op` is applied to chunks of 64 bits (u64) and any bits
73+ /// outside the offsets and len are set to zero out before calling `op`.
6474pub fn bitwise_bin_op_helper < F > (
6575 left : & Buffer ,
6676 left_offset_in_bits : usize ,
@@ -93,21 +103,42 @@ where
93103}
94104
95105/// Apply a bitwise operation `op` to one input and return the result as a Buffer.
96- /// The input is treated as a bitmap, meaning that offset and length are specified in number of bits.
97- #[ deprecated(
98- since = "57.2.0" ,
99- note = "use BooleanBuffer::from_bitwise_unary_op instead"
100- ) ]
106+ ///
107+ /// The input is treated as a bitmap, meaning that offset and length are
108+ /// specified in number of bits.
109+ ///
110+ /// NOTE: The operation `op` is applied to chunks of 64 bits (u64) and any bits
111+ /// outside the offsets and len are set to zero out before calling `op`.
101112pub fn bitwise_unary_op_helper < F > (
102113 left : & Buffer ,
103114 offset_in_bits : usize ,
104115 len_in_bits : usize ,
105- op : F ,
116+ mut op : F ,
106117) -> Buffer
107118where
108119 F : FnMut ( u64 ) -> u64 ,
109120{
110- BooleanBuffer :: from_bitwise_unary_op ( left, offset_in_bits, len_in_bits, op) . into_inner ( )
121+ // reserve capacity and set length so we can get a typed view of u64 chunks
122+ let mut result =
123+ MutableBuffer :: new ( ceil ( len_in_bits, 8 ) ) . with_bitset ( len_in_bits / 64 * 8 , false ) ;
124+
125+ let left_chunks = left. bit_chunks ( offset_in_bits, len_in_bits) ;
126+
127+ let result_chunks = result. typed_data_mut :: < u64 > ( ) . iter_mut ( ) ;
128+
129+ result_chunks
130+ . zip ( left_chunks. iter ( ) )
131+ . for_each ( |( res, left) | {
132+ * res = op ( left) ;
133+ } ) ;
134+
135+ let remainder_bytes = ceil ( left_chunks. remainder_len ( ) , 8 ) ;
136+ let rem = op ( left_chunks. remainder_bits ( ) ) ;
137+ // we are counting its starting from the least significant bit, to to_le_bytes should be correct
138+ let rem = & rem. to_le_bytes ( ) [ 0 ..remainder_bytes] ;
139+ result. extend_from_slice ( rem) ;
140+
141+ result. into ( )
111142}
112143
113144/// Apply a bitwise and to two inputs and return the result as a Buffer.
0 commit comments