Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-arrow/src/array/boolean/iterator.rs
6939 views
1
use super::super::MutableArray;
2
use super::{BooleanArray, MutableBooleanArray};
3
use crate::array::ArrayAccessor;
4
use crate::bitmap::IntoIter;
5
use crate::bitmap::utils::{BitmapIter, ZipValidity};
6
7
impl<'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
17
impl 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
31
impl<'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
41
impl<'a> MutableBooleanArray {
42
/// Returns an iterator over the optional values of this [`MutableBooleanArray`].
43
#[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
/// Returns an iterator over the values of this [`MutableBooleanArray`]
52
#[inline]
53
pub fn values_iter(&'a self) -> BitmapIter<'a> {
54
self.values().iter()
55
}
56
}
57
58
unsafe 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
}
71
72