polars_arrow/legacy/kernels/take_agg/
boolean.rs

1use super::*;
2
3/// Take kernel for single chunk and an iterator as index.
4/// # Safety
5/// caller must ensure iterators indexes are in bounds
6#[inline]
7pub unsafe fn take_min_bool_iter_unchecked_nulls<I: IntoIterator<Item = usize>>(
8    arr: &BooleanArray,
9    indices: I,
10    len: IdxSize,
11) -> Option<bool> {
12    let mut null_count = 0 as IdxSize;
13    let validity = arr.validity().unwrap();
14
15    for idx in indices {
16        if validity.get_bit_unchecked(idx) {
17            if !arr.value_unchecked(idx) {
18                return Some(false);
19            }
20        } else {
21            null_count += 1;
22        }
23    }
24    if null_count == len {
25        None
26    } else {
27        Some(true)
28    }
29}
30
31/// Take kernel for single chunk and an iterator as index.
32/// # Safety
33/// caller must ensure iterators indexes are in bounds
34#[inline]
35pub unsafe fn take_min_bool_iter_unchecked_no_nulls<I: IntoIterator<Item = usize>>(
36    arr: &BooleanArray,
37    indices: I,
38) -> Option<bool> {
39    if arr.is_empty() {
40        return None;
41    }
42
43    for idx in indices {
44        if !arr.value_unchecked(idx) {
45            return Some(false);
46        }
47    }
48    Some(true)
49}
50
51/// Take kernel for single chunk and an iterator as index.
52/// # Safety
53/// caller must ensure iterators indexes are in bounds
54#[inline]
55pub unsafe fn take_max_bool_iter_unchecked_nulls<I: IntoIterator<Item = usize>>(
56    arr: &BooleanArray,
57    indices: I,
58    len: IdxSize,
59) -> Option<bool> {
60    let mut null_count = 0 as IdxSize;
61    let validity = arr.validity().unwrap();
62
63    for idx in indices {
64        if validity.get_bit_unchecked(idx) {
65            if arr.value_unchecked(idx) {
66                return Some(true);
67            }
68        } else {
69            null_count += 1;
70        }
71    }
72    if null_count == len {
73        None
74    } else {
75        Some(false)
76    }
77}
78
79/// Take kernel for single chunk and an iterator as index.
80/// # Safety
81/// caller must ensure iterators indexes are in bounds
82#[inline]
83pub unsafe fn take_max_bool_iter_unchecked_no_nulls<I: IntoIterator<Item = usize>>(
84    arr: &BooleanArray,
85    indices: I,
86) -> Option<bool> {
87    if arr.is_empty() {
88        return None;
89    }
90
91    for idx in indices {
92        if arr.value_unchecked(idx) {
93            return Some(true);
94        }
95    }
96    Some(false)
97}