polars_arrow/array/boolean/
iterator.rs1use super::super::MutableArray;
2use super::{BooleanArray, MutableBooleanArray};
3use crate::array::ArrayAccessor;
4use crate::bitmap::utils::{BitmapIter, ZipValidity};
5use crate::bitmap::IntoIter;
6
7impl<'a> IntoIterator for &'a BooleanArray {
8 type Item = Option<bool>;
9 type IntoIter = ZipValidity<bool, BitmapIter<'a>, BitmapIter<'a>>;
10
11 #[inline]
12 fn into_iter(self) -> Self::IntoIter {
13 self.iter()
14 }
15}
16
17impl IntoIterator for BooleanArray {
18 type Item = Option<bool>;
19 type IntoIter = ZipValidity<bool, IntoIter, IntoIter>;
20
21 #[inline]
22 fn into_iter(self) -> Self::IntoIter {
23 let (_, values, validity) = self.into_inner();
24 let values = values.into_iter();
25 let validity =
26 validity.and_then(|validity| (validity.unset_bits() > 0).then(|| validity.into_iter()));
27 ZipValidity::new(values, validity)
28 }
29}
30
31impl<'a> IntoIterator for &'a MutableBooleanArray {
32 type Item = Option<bool>;
33 type IntoIter = ZipValidity<bool, BitmapIter<'a>, BitmapIter<'a>>;
34
35 #[inline]
36 fn into_iter(self) -> Self::IntoIter {
37 self.iter()
38 }
39}
40
41impl<'a> MutableBooleanArray {
42 #[inline]
44 pub fn iter(&'a self) -> ZipValidity<bool, BitmapIter<'a>, BitmapIter<'a>> {
45 ZipValidity::new(
46 self.values().iter(),
47 self.validity().as_ref().map(|x| x.iter()),
48 )
49 }
50
51 #[inline]
53 pub fn values_iter(&'a self) -> BitmapIter<'a> {
54 self.values().iter()
55 }
56}
57
58unsafe impl<'a> ArrayAccessor<'a> for BooleanArray {
59 type Item = bool;
60
61 #[inline]
62 unsafe fn value_unchecked(&'a self, index: usize) -> Self::Item {
63 (*self).value_unchecked(index)
64 }
65
66 #[inline]
67 fn len(&self) -> usize {
68 (*self).len()
69 }
70}