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
use memchr::memmem::find;
use super::*;
pub trait BinaryNameSpaceImpl: AsBinary {
fn contains(&self, lit: &[u8]) -> PolarsResult<BooleanChunked> {
let ca = self.as_binary();
let f = |s: &[u8]| find(s, lit).is_some();
let mut out: BooleanChunked = if !ca.has_validity() {
ca.into_no_null_iter().map(f).collect()
} else {
ca.into_iter().map(|opt_s| opt_s.map(f)).collect()
};
out.rename(ca.name());
Ok(out)
}
fn contains_literal(&self, lit: &[u8]) -> PolarsResult<BooleanChunked> {
self.contains(lit)
}
fn ends_with(&self, sub: &[u8]) -> BooleanChunked {
let ca = self.as_binary();
let f = |s: &[u8]| s.ends_with(sub);
let mut out: BooleanChunked = ca.into_iter().map(|opt_s| opt_s.map(f)).collect();
out.rename(ca.name());
out
}
fn starts_with(&self, sub: &[u8]) -> BooleanChunked {
let ca = self.as_binary();
let f = |s: &[u8]| s.starts_with(sub);
let mut out: BooleanChunked = ca.into_iter().map(|opt_s| opt_s.map(f)).collect();
out.rename(ca.name());
out
}
}
impl BinaryNameSpaceImpl for BinaryChunked {}