Skip to content

Commit

Permalink
Deprecate Buffer::count_set_bits (#3067) (#3071)
Browse files Browse the repository at this point in the history
* Deprecate Buffer::count_set_bits (#3067)

* Format
  • Loading branch information
tustvold authored Nov 10, 2022
1 parent 0e97338 commit c027c70
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
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);

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

0 comments on commit c027c70

Please sign in to comment.