Path: blob/main/crates/polars-arrow/src/array/boolean/iterator.rs
6939 views
use super::super::MutableArray;1use super::{BooleanArray, MutableBooleanArray};2use crate::array::ArrayAccessor;3use crate::bitmap::IntoIter;4use crate::bitmap::utils::{BitmapIter, ZipValidity};56impl<'a> IntoIterator for &'a BooleanArray {7type Item = Option<bool>;8type IntoIter = ZipValidity<bool, BitmapIter<'a>, BitmapIter<'a>>;910#[inline]11fn into_iter(self) -> Self::IntoIter {12self.iter()13}14}1516impl IntoIterator for BooleanArray {17type Item = Option<bool>;18type IntoIter = ZipValidity<bool, IntoIter, IntoIter>;1920#[inline]21fn into_iter(self) -> Self::IntoIter {22let (_, values, validity) = self.into_inner();23let values = values.into_iter();24let validity =25validity.and_then(|validity| (validity.unset_bits() > 0).then(|| validity.into_iter()));26ZipValidity::new(values, validity)27}28}2930impl<'a> IntoIterator for &'a MutableBooleanArray {31type Item = Option<bool>;32type IntoIter = ZipValidity<bool, BitmapIter<'a>, BitmapIter<'a>>;3334#[inline]35fn into_iter(self) -> Self::IntoIter {36self.iter()37}38}3940impl<'a> MutableBooleanArray {41/// Returns an iterator over the optional values of this [`MutableBooleanArray`].42#[inline]43pub fn iter(&'a self) -> ZipValidity<bool, BitmapIter<'a>, BitmapIter<'a>> {44ZipValidity::new(45self.values().iter(),46self.validity().as_ref().map(|x| x.iter()),47)48}4950/// Returns an iterator over the values of this [`MutableBooleanArray`]51#[inline]52pub fn values_iter(&'a self) -> BitmapIter<'a> {53self.values().iter()54}55}5657unsafe impl<'a> ArrayAccessor<'a> for BooleanArray {58type Item = bool;5960#[inline]61unsafe fn value_unchecked(&'a self, index: usize) -> Self::Item {62(*self).value_unchecked(index)63}6465#[inline]66fn len(&self) -> usize {67(*self).len()68}69}707172