MCPcopy Create free account
hub / github.com/apache/arrow-rs / fixed_binary_equal

Function fixed_binary_equal

arrow-data/src/equal/fixed_binary.rs:25–95  ·  view source on GitHub ↗
(
    lhs: &ArrayData,
    rhs: &ArrayData,
    lhs_start: usize,
    rhs_start: usize,
    len: usize,
)

Source from the content-addressed store, hash-verified

23use super::utils::equal_len;
24
25pub(super) fn fixed_binary_equal(
26 lhs: &ArrayData,
27 rhs: &ArrayData,
28 lhs_start: usize,
29 rhs_start: usize,
30 len: usize,
31) -> bool {
32 let size = get_fixed_size_binary_width(lhs.data_type());
33
34 let lhs_values = &lhs.buffers()[0].as_slice()[lhs.offset() * size..];
35 let rhs_values = &rhs.buffers()[0].as_slice()[rhs.offset() * size..];
36
37 // Only checking one null mask here because by the time the control flow reaches
38 // this point, the equality of the two masks would have already been verified.
39 if !contains_nulls(lhs.nulls(), lhs_start, len) {
40 equal_len(
41 lhs_values,
42 rhs_values,
43 size * lhs_start,
44 size * rhs_start,
45 size * len,
46 )
47 } else {
48 let selectivity_frac = lhs.null_count() as f64 / lhs.len() as f64;
49
50 if selectivity_frac >= NULL_SLICES_SELECTIVITY_THRESHOLD {
51 // get a ref of the null buffer bytes, to use in testing for nullness
52 let lhs_nulls = lhs.nulls().unwrap();
53 let rhs_nulls = rhs.nulls().unwrap();
54 // with nulls, we need to compare item by item whenever it is not null
55 (0..len).all(|i| {
56 let lhs_pos = lhs_start + i;
57 let rhs_pos = rhs_start + i;
58
59 let lhs_is_null = lhs_nulls.is_null(lhs_pos);
60 let rhs_is_null = rhs_nulls.is_null(rhs_pos);
61
62 lhs_is_null
63 || (lhs_is_null == rhs_is_null)
64 && equal_len(
65 lhs_values,
66 rhs_values,
67 lhs_pos * size,
68 rhs_pos * size,
69 size, // 1 * size since we are comparing a single entry
70 )
71 })
72 } else {
73 let lhs_nulls = lhs.nulls().unwrap();
74 let lhs_slices_iter =
75 BitSliceIterator::new(lhs_nulls.validity(), lhs_start + lhs_nulls.offset(), len);
76 let rhs_nulls = rhs.nulls().unwrap();
77 let rhs_slices_iter =
78 BitSliceIterator::new(rhs_nulls.validity(), rhs_start + rhs_nulls.offset(), len);
79
80 lhs_slices_iter
81 .zip(rhs_slices_iter)
82 .all(|((l_start, l_end), (r_start, r_end))| {

Callers 1

equal_valuesFunction · 0.85

Calls 14

contains_nullsFunction · 0.85
equal_lenFunction · 0.85
allMethod · 0.80
validityMethod · 0.80
zipMethod · 0.80
data_typeMethod · 0.45
as_sliceMethod · 0.45
buffersMethod · 0.45
offsetMethod · 0.45
nullsMethod · 0.45
null_countMethod · 0.45

Tested by

no test coverage detected