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