Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-compute/src/comparisons/boolean.rs
6939 views
1
use arrow::array::BooleanArray;
2
use arrow::bitmap::{self, Bitmap};
3
4
use super::{TotalEqKernel, TotalOrdKernel};
5
6
impl TotalEqKernel for BooleanArray {
7
type Scalar = bool;
8
9
fn tot_eq_kernel(&self, other: &Self) -> Bitmap {
10
bitmap::binary(self.values(), other.values(), |l, r| !(l ^ r))
11
}
12
13
fn tot_ne_kernel(&self, other: &Self) -> Bitmap {
14
self.values() ^ other.values()
15
}
16
17
fn tot_eq_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
18
if *other {
19
self.values().clone()
20
} else {
21
!self.values()
22
}
23
}
24
25
fn tot_ne_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
26
self.tot_eq_kernel_broadcast(&!*other)
27
}
28
}
29
30
impl TotalOrdKernel for BooleanArray {
31
type Scalar = bool;
32
33
fn tot_lt_kernel(&self, other: &Self) -> Bitmap {
34
bitmap::binary(self.values(), other.values(), |l, r| !l & r)
35
}
36
37
fn tot_le_kernel(&self, other: &Self) -> Bitmap {
38
bitmap::binary(self.values(), other.values(), |l, r| !l | r)
39
}
40
41
fn tot_lt_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
42
if *other {
43
!self.values()
44
} else {
45
Bitmap::new_zeroed(self.len())
46
}
47
}
48
49
fn tot_le_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
50
if *other {
51
Bitmap::new_with_value(true, self.len())
52
} else {
53
!self.values()
54
}
55
}
56
57
fn tot_gt_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
58
if *other {
59
Bitmap::new_zeroed(self.len())
60
} else {
61
self.values().clone()
62
}
63
}
64
65
fn tot_ge_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
66
if *other {
67
self.values().clone()
68
} else {
69
Bitmap::new_with_value(true, self.len())
70
}
71
}
72
}
73
74