polars_compute/comparisons/
boolean.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use arrow::array::BooleanArray;
use arrow::bitmap::{self, Bitmap};

use super::{TotalEqKernel, TotalOrdKernel};

impl TotalEqKernel for BooleanArray {
    type Scalar = bool;

    fn tot_eq_kernel(&self, other: &Self) -> Bitmap {
        bitmap::binary(self.values(), other.values(), |l, r| !(l ^ r))
    }

    fn tot_ne_kernel(&self, other: &Self) -> Bitmap {
        self.values() ^ other.values()
    }

    fn tot_eq_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        if *other {
            self.values().clone()
        } else {
            !self.values()
        }
    }

    fn tot_ne_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.tot_eq_kernel_broadcast(&!*other)
    }
}

impl TotalOrdKernel for BooleanArray {
    type Scalar = bool;

    fn tot_lt_kernel(&self, other: &Self) -> Bitmap {
        bitmap::binary(self.values(), other.values(), |l, r| !l & r)
    }

    fn tot_le_kernel(&self, other: &Self) -> Bitmap {
        bitmap::binary(self.values(), other.values(), |l, r| !l | r)
    }

    fn tot_lt_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        if *other {
            !self.values()
        } else {
            Bitmap::new_zeroed(self.len())
        }
    }

    fn tot_le_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        if *other {
            Bitmap::new_with_value(true, self.len())
        } else {
            !self.values()
        }
    }

    fn tot_gt_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        if *other {
            Bitmap::new_zeroed(self.len())
        } else {
            self.values().clone()
        }
    }

    fn tot_ge_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        if *other {
            self.values().clone()
        } else {
            Bitmap::new_with_value(true, self.len())
        }
    }
}