polars_compute/comparisons/
binary.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use arrow::array::{BinaryArray, FixedSizeBinaryArray};
use arrow::bitmap::Bitmap;
use arrow::types::Offset;
use polars_utils::total_ord::{TotalEq, TotalOrd};

use super::{TotalEqKernel, TotalOrdKernel};

impl<O: Offset> TotalEqKernel for BinaryArray<O> {
    type Scalar = [u8];

    fn tot_eq_kernel(&self, other: &Self) -> Bitmap {
        assert!(self.len() == other.len());
        self.values_iter()
            .zip(other.values_iter())
            .map(|(l, r)| l.tot_eq(&r))
            .collect()
    }

    fn tot_ne_kernel(&self, other: &Self) -> Bitmap {
        assert!(self.len() == other.len());
        self.values_iter()
            .zip(other.values_iter())
            .map(|(l, r)| l.tot_ne(&r))
            .collect()
    }

    fn tot_eq_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values_iter().map(|l| l.tot_eq(&other)).collect()
    }

    fn tot_ne_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values_iter().map(|l| l.tot_ne(&other)).collect()
    }
}

impl<O: Offset> TotalOrdKernel for BinaryArray<O> {
    type Scalar = [u8];

    fn tot_lt_kernel(&self, other: &Self) -> Bitmap {
        assert!(self.len() == other.len());
        self.values_iter()
            .zip(other.values_iter())
            .map(|(l, r)| l.tot_lt(&r))
            .collect()
    }

    fn tot_le_kernel(&self, other: &Self) -> Bitmap {
        assert!(self.len() == other.len());
        self.values_iter()
            .zip(other.values_iter())
            .map(|(l, r)| l.tot_le(&r))
            .collect()
    }

    fn tot_lt_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values_iter().map(|l| l.tot_lt(&other)).collect()
    }

    fn tot_le_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values_iter().map(|l| l.tot_le(&other)).collect()
    }

    fn tot_gt_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values_iter().map(|l| l.tot_gt(&other)).collect()
    }

    fn tot_ge_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values_iter().map(|l| l.tot_ge(&other)).collect()
    }
}

impl TotalEqKernel for FixedSizeBinaryArray {
    type Scalar = [u8];

    fn tot_eq_kernel(&self, other: &Self) -> Bitmap {
        assert!(self.len() == other.len());

        if self.size() != other.size() {
            return Bitmap::new_zeroed(self.len());
        }

        (0..self.len())
            .map(|i| self.value(i) == other.value(i))
            .collect()
    }

    fn tot_ne_kernel(&self, other: &Self) -> Bitmap {
        assert!(self.len() == other.len());

        if self.size() != other.size() {
            return Bitmap::new_with_value(true, self.len());
        }

        (0..self.len())
            .map(|i| self.value(i) != other.value(i))
            .collect()
    }

    fn tot_eq_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        if self.size() != other.len() {
            return Bitmap::new_zeroed(self.len());
        }

        (0..self.len()).map(|i| self.value(i) == other).collect()
    }

    fn tot_ne_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        if self.size() != other.len() {
            return Bitmap::new_with_value(true, self.len());
        }

        (0..self.len()).map(|i| self.value(i) != other).collect()
    }
}