polars_arrow/array/fixed_size_binary/
iterator.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use super::{FixedSizeBinaryArray, MutableFixedSizeBinaryArray};
use crate::array::MutableArray;
use crate::bitmap::utils::{BitmapIter, ZipValidity};

impl<'a> IntoIterator for &'a FixedSizeBinaryArray {
    type Item = Option<&'a [u8]>;
    type IntoIter = ZipValidity<&'a [u8], std::slice::ChunksExact<'a, u8>, BitmapIter<'a>>;

    fn into_iter(self) -> Self::IntoIter {
        self.iter()
    }
}

impl<'a> FixedSizeBinaryArray {
    /// constructs a new iterator
    pub fn iter(
        &'a self,
    ) -> ZipValidity<&'a [u8], std::slice::ChunksExact<'a, u8>, BitmapIter<'a>> {
        ZipValidity::new_with_validity(self.values_iter(), self.validity())
    }

    /// Returns iterator over the values of [`FixedSizeBinaryArray`]
    pub fn values_iter(&'a self) -> std::slice::ChunksExact<'a, u8> {
        self.values().chunks_exact(self.size)
    }
}

impl<'a> IntoIterator for &'a MutableFixedSizeBinaryArray {
    type Item = Option<&'a [u8]>;
    type IntoIter = ZipValidity<&'a [u8], std::slice::ChunksExact<'a, u8>, BitmapIter<'a>>;

    fn into_iter(self) -> Self::IntoIter {
        self.iter()
    }
}

impl<'a> MutableFixedSizeBinaryArray {
    /// constructs a new iterator
    pub fn iter(
        &'a self,
    ) -> ZipValidity<&'a [u8], std::slice::ChunksExact<'a, u8>, BitmapIter<'a>> {
        ZipValidity::new(self.iter_values(), self.validity().map(|x| x.iter()))
    }

    /// Returns iterator over the values of [`MutableFixedSizeBinaryArray`]
    pub fn iter_values(&'a self) -> std::slice::ChunksExact<'a, u8> {
        self.values().chunks_exact(self.size())
    }
}