Skip to main content

vortex_array/arrays/bool/
test_harness.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexExpect;
5use vortex_error::vortex_panic;
6
7use crate::arrays::BoolArray;
8use crate::arrays::bool::BoolArrayExt;
9
10impl BoolArray {
11    pub fn opt_bool_vec(&self) -> Vec<Option<bool>> {
12        self.validity_mask()
13            .vortex_expect("validity_mask")
14            .to_bit_buffer()
15            .iter()
16            .zip(self.to_bit_buffer().iter())
17            .map(|(valid, value)| valid.then_some(value))
18            .collect()
19    }
20
21    pub fn bool_vec(&self) -> Vec<bool> {
22        self.validity_mask()
23            .vortex_expect("validity_mask")
24            .to_bit_buffer()
25            .iter()
26            .zip(self.to_bit_buffer().iter())
27            .map(|(valid, value)| {
28                if !valid {
29                    vortex_panic!("trying to get bool values from an array with null elements")
30                }
31
32                value
33            })
34            .collect()
35    }
36}