From ac5f5d7a9aac6519a2b0cd7bd5400bb3c403bc10 Mon Sep 17 00:00:00 2001 From: Aryansh Omray Date: Mon, 6 Nov 2023 18:11:52 +0530 Subject: [PATCH] add null_count for MutablePrimitiveArray --- src/array/primitive/mutable.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/array/primitive/mutable.rs b/src/array/primitive/mutable.rs index 4432ab2e33..9f71e066fc 100644 --- a/src/array/primitive/mutable.rs +++ b/src/array/primitive/mutable.rs @@ -93,6 +93,20 @@ impl MutablePrimitiveArray { pub fn apply_values(&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 Default for MutablePrimitiveArray {