Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Buffer::count_set_bits (#3067) #3071

Merged
merged 2 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions arrow-buffer/src/buffer/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -466,11 +467,17 @@ 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]
Expand All @@ -479,31 +486,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)
);
}

Expand Down
2 changes: 1 addition & 1 deletion arrow-select/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


if null_count == 0 {
return None;
Expand Down
3 changes: 0 additions & 3 deletions arrow/src/compute/kernels/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down