Coverage Report

Created: 2025-11-17 14:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/Users/andrewlamb/Software/arrow-rs/arrow-data/src/equal/variable_size.rs
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
use crate::data::{ArrayData, contains_nulls};
19
use arrow_buffer::ArrowNativeType;
20
use num_integer::Integer;
21
22
use super::utils::equal_len;
23
24
97.2k
fn offset_value_equal<T: ArrowNativeType + Integer>(
25
97.2k
    lhs_values: &[u8],
26
97.2k
    rhs_values: &[u8],
27
97.2k
    lhs_offsets: &[T],
28
97.2k
    rhs_offsets: &[T],
29
97.2k
    lhs_pos: usize,
30
97.2k
    rhs_pos: usize,
31
97.2k
    len: usize,
32
97.2k
) -> bool {
33
97.2k
    let lhs_start = lhs_offsets[lhs_pos].as_usize();
34
97.2k
    let rhs_start = rhs_offsets[rhs_pos].as_usize();
35
97.2k
    let lhs_len = (lhs_offsets[lhs_pos + len] - lhs_offsets[lhs_pos])
36
97.2k
        .to_usize()
37
97.2k
        .unwrap();
38
97.2k
    let rhs_len = (rhs_offsets[rhs_pos + len] - rhs_offsets[rhs_pos])
39
97.2k
        .to_usize()
40
97.2k
        .unwrap();
41
42
97.2k
    if lhs_len == 0 && 
rhs_len == 03
{
43
3
        return true;
44
97.2k
    }
45
46
97.2k
    lhs_len == rhs_len && equal_len(lhs_values, rhs_values, lhs_start, rhs_start, lhs_len)
47
97.2k
}
48
49
80.1k
pub(super) fn variable_sized_equal<T: ArrowNativeType + Integer>(
50
80.1k
    lhs: &ArrayData,
51
80.1k
    rhs: &ArrayData,
52
80.1k
    lhs_start: usize,
53
80.1k
    rhs_start: usize,
54
80.1k
    len: usize,
55
80.1k
) -> bool {
56
80.1k
    let lhs_offsets = lhs.buffer::<T>(0);
57
80.1k
    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
80.1k
    let lhs_values = lhs.buffers()[1].as_slice();
61
80.1k
    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
80.1k
    if !contains_nulls(lhs.nulls(), lhs_start, len) {
66
80.0k
        offset_value_equal(
67
80.0k
            lhs_values,
68
80.0k
            rhs_values,
69
80.0k
            lhs_offsets,
70
80.0k
            rhs_offsets,
71
80.0k
            lhs_start,
72
80.0k
            rhs_start,
73
80.0k
            len,
74
        )
75
    } else {
76
20.1k
        
(0..len)50
.
all50
(|i| {
77
20.1k
            let lhs_pos = lhs_start + i;
78
20.1k
            let rhs_pos = rhs_start + i;
79
80
            // the null bits can still be `None`, indicating that the value is valid.
81
20.1k
            let lhs_is_null = lhs.nulls().map(|v| v.is_null(lhs_pos)).unwrap_or_default();
82
20.1k
            let rhs_is_null = rhs.nulls().map(|v| v.is_null(rhs_pos)).unwrap_or_default();
83
84
20.1k
            lhs_is_null
85
17.2k
                || (lhs_is_null == rhs_is_null)
86
17.2k
                    && offset_value_equal(
87
17.2k
                        lhs_values,
88
17.2k
                        rhs_values,
89
17.2k
                        lhs_offsets,
90
17.2k
                        rhs_offsets,
91
17.2k
                        lhs_pos,
92
17.2k
                        rhs_pos,
93
                        1,
94
                    )
95
20.1k
        })
96
    }
97
80.1k
}