From 8f83a6683086de277b87c92510e052ced065ea79 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Thu, 10 Nov 2022 14:53:24 +1300 Subject: [PATCH 1/2] Deprecate Buffer::count_set_bits (#3067) --- arrow-buffer/src/buffer/immutable.rs | 21 +++++++++++---------- arrow-select/src/filter.rs | 2 +- arrow/src/compute/kernels/arithmetic.rs | 3 --- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/arrow-buffer/src/buffer/immutable.rs b/arrow-buffer/src/buffer/immutable.rs index c60d28afc782..afac76c4dd75 100644 --- a/arrow-buffer/src/buffer/immutable.rs +++ b/arrow-buffer/src/buffer/immutable.rs @@ -215,6 +215,7 @@ impl Buffer { } /// Returns the number of 1-bits in this buffer. + #[deprecated(note = "use count_set_bits_offset instead")] pub fn count_set_bits(&self) -> usize { let len_in_bits = self.len() * 8; // self.offset is already taken into consideration by the bit_chunks implementation @@ -466,11 +467,11 @@ mod tests { #[test] fn test_count_bits() { - assert_eq!(0, Buffer::from(&[0b00000000]).count_set_bits()); - assert_eq!(8, Buffer::from(&[0b11111111]).count_set_bits()); - assert_eq!(3, Buffer::from(&[0b00001101]).count_set_bits()); - assert_eq!(6, Buffer::from(&[0b01001001, 0b01010010]).count_set_bits()); - assert_eq!(16, Buffer::from(&[0b11111111, 0b11111111]).count_set_bits()); + assert_eq!(0, Buffer::from(&[0b00000000]).count_set_bits_offset(0, 8)); + assert_eq!(8, Buffer::from(&[0b11111111]).count_set_bits_offset(0, 8)); + assert_eq!(3, Buffer::from(&[0b00001101]).count_set_bits_offset(0, 8)); + assert_eq!(6, Buffer::from(&[0b01001001, 0b01010010]).count_set_bits_offset(0, 16)); + assert_eq!(16, Buffer::from(&[0b11111111, 0b11111111]).count_set_bits_offset(0, 16)); } #[test] @@ -479,31 +480,31 @@ mod tests { 0, Buffer::from(&[0b11111111, 0b00000000]) .slice(1) - .count_set_bits() + .count_set_bits_offset(0, 8) ); assert_eq!( 8, Buffer::from(&[0b11111111, 0b11111111]) .slice_with_length(1, 1) - .count_set_bits() + .count_set_bits_offset(0, 8) ); assert_eq!( 3, Buffer::from(&[0b11111111, 0b11111111, 0b00001101]) .slice(2) - .count_set_bits() + .count_set_bits_offset(0, 8) ); assert_eq!( 6, Buffer::from(&[0b11111111, 0b01001001, 0b01010010]) .slice_with_length(1, 2) - .count_set_bits() + .count_set_bits_offset(0, 16) ); assert_eq!( 16, Buffer::from(&[0b11111111, 0b11111111, 0b11111111, 0b11111111]) .slice(2) - .count_set_bits() + .count_set_bits_offset(0, 16) ); } diff --git a/arrow-select/src/filter.rs b/arrow-select/src/filter.rs index 4596afc8791f..f454397647c3 100644 --- a/arrow-select/src/filter.rs +++ b/arrow-select/src/filter.rs @@ -413,7 +413,7 @@ fn filter_null_mask( let nulls = filter_bits(data.null_buffer()?, data.offset(), predicate); // The filtered `nulls` has a length of `predicate.count` bits and // therefore the null count is this minus the number of valid bits - let null_count = predicate.count - nulls.count_set_bits(); + let null_count = predicate.count - nulls.count_set_bits_offset(0, predicate.count); if null_count == 0 { return None; diff --git a/arrow/src/compute/kernels/arithmetic.rs b/arrow/src/compute/kernels/arithmetic.rs index b310d4fbf8cd..328ce02e4f5d 100644 --- a/arrow/src/compute/kernels/arithmetic.rs +++ b/arrow/src/compute/kernels/arithmetic.rs @@ -3059,9 +3059,6 @@ mod tests { let null_buffer = null_buffer_builder.finish(); - // `count_set_bits` counts 1-bits in entire buffer. Because above `resize` doesn't - // actually truncate the buffer, `count_set_bits` still return 3. - assert_eq!(null_buffer.count_set_bits(), 3); // `count_set_bits_offset` takes len in bits as parameter. assert_eq!(null_buffer.count_set_bits_offset(0, 13), 0); From 25a37cf4ffe11d27dba538267de5d37fbe0d4221 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Thu, 10 Nov 2022 15:10:37 +1300 Subject: [PATCH 2/2] Format --- arrow-buffer/src/buffer/immutable.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arrow-buffer/src/buffer/immutable.rs b/arrow-buffer/src/buffer/immutable.rs index afac76c4dd75..94bc98678a61 100644 --- a/arrow-buffer/src/buffer/immutable.rs +++ b/arrow-buffer/src/buffer/immutable.rs @@ -470,8 +470,14 @@ mod tests { assert_eq!(0, Buffer::from(&[0b00000000]).count_set_bits_offset(0, 8)); assert_eq!(8, Buffer::from(&[0b11111111]).count_set_bits_offset(0, 8)); assert_eq!(3, Buffer::from(&[0b00001101]).count_set_bits_offset(0, 8)); - assert_eq!(6, Buffer::from(&[0b01001001, 0b01010010]).count_set_bits_offset(0, 16)); - assert_eq!(16, Buffer::from(&[0b11111111, 0b11111111]).count_set_bits_offset(0, 16)); + assert_eq!( + 6, + Buffer::from(&[0b01001001, 0b01010010]).count_set_bits_offset(0, 16) + ); + assert_eq!( + 16, + Buffer::from(&[0b11111111, 0b11111111]).count_set_bits_offset(0, 16) + ); } #[test]