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

Function variable_sized_equal

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

Source from the content-addressed store, hash-verified

47}
48
49pub(super) fn variable_sized_equal<T: ArrowNativeType + Integer>(
50 lhs: &ArrayData,
51 rhs: &ArrayData,
52 lhs_start: usize,
53 rhs_start: usize,
54 len: usize,
55) -> bool {
56 let lhs_offsets = lhs.buffer::<T>(0);
57 let rhs_offsets = rhs.buffer::<T>(0);
58
59 // the offsets of the `ArrayData` are ignored as they are only applied to the offset buffer.
60 let lhs_values = lhs.buffers()[1].as_slice();
61 let rhs_values = rhs.buffers()[1].as_slice();
62
63 // Only checking one null mask here because by the time the control flow reaches
64 // this point, the equality of the two masks would have already been verified.
65 if !contains_nulls(lhs.nulls(), lhs_start, len) {
66 let lhs_offsets_slice = &lhs_offsets[lhs_start..lhs_start + len + 1];
67 let rhs_offsets_slice = &rhs_offsets[rhs_start..rhs_start + len + 1];
68 lengths_equal(lhs_offsets_slice, rhs_offsets_slice)
69 && offset_value_equal(
70 lhs_values,
71 rhs_values,
72 lhs_offsets,
73 rhs_offsets,
74 lhs_start,
75 rhs_start,
76 len,
77 )
78 } else {
79 (0..len).all(|i| {
80 let lhs_pos = lhs_start + i;
81 let rhs_pos = rhs_start + i;
82
83 // the null bits can still be `None`, indicating that the value is valid.
84 let lhs_is_null = lhs.nulls().map(|v| v.is_null(lhs_pos)).unwrap_or_default();
85 let rhs_is_null = rhs.nulls().map(|v| v.is_null(rhs_pos)).unwrap_or_default();
86
87 lhs_is_null
88 || (lhs_is_null == rhs_is_null)
89 && offset_value_equal(
90 lhs_values,
91 rhs_values,
92 lhs_offsets,
93 rhs_offsets,
94 lhs_pos,
95 rhs_pos,
96 1,
97 )
98 })
99 }
100}
101
102#[cfg(test)]
103mod tests {

Callers

nothing calls this directly

Calls 8

contains_nullsFunction · 0.85
lengths_equalFunction · 0.85
offset_value_equalFunction · 0.85
allMethod · 0.80
as_sliceMethod · 0.45
buffersMethod · 0.45
nullsMethod · 0.45
is_nullMethod · 0.45

Tested by

no test coverage detected