Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
add null_count for MutablePrimitiveArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryansh Omray committed Nov 6, 2023
1 parent 747005e commit ac5f5d7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/array/primitive/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ impl<T: NativeType> MutablePrimitiveArray<T> {
pub fn apply_values<F: Fn(&mut [T])>(&mut self, f: F) {
f(&mut self.values);
}

/// The number of null slots on this [`Array`].
/// # Implementation
/// This is `O(1)` since the number of null elements is pre-computed.
#[inline]
pub fn null_count(&self) -> usize {
if self.data_type() == &DataType::Null {
return self.len();
};
self.validity()
.as_ref()
.map(|x| x.unset_bits())
.unwrap_or(0)
}
}

impl<T: NativeType> Default for MutablePrimitiveArray<T> {
Expand Down

0 comments on commit ac5f5d7

Please sign in to comment.