Coverage Report

Created: 2025-08-26 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/Users/andrewlamb/Software/arrow-rs/arrow-data/src/equal/structure.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::{contains_nulls, ArrayData};
19
20
use super::equal_range;
21
22
/// Compares the values of two [ArrayData] starting at `lhs_start` and `rhs_start` respectively
23
/// for `len` slots.
24
75
fn equal_child_values(
25
75
    lhs: &ArrayData,
26
75
    rhs: &ArrayData,
27
75
    lhs_start: usize,
28
75
    rhs_start: usize,
29
75
    len: usize,
30
75
) -> bool {
31
75
    lhs.child_data()
32
75
        .iter()
33
75
        .zip(rhs.child_data())
34
134
        .
all75
(|(lhs_values, rhs_values)| {
35
134
            equal_range(lhs_values, rhs_values, lhs_start, rhs_start, len)
36
134
        })
37
75
}
38
39
62
pub(super) fn struct_equal(
40
62
    lhs: &ArrayData,
41
62
    rhs: &ArrayData,
42
62
    lhs_start: usize,
43
62
    rhs_start: usize,
44
62
    len: usize,
45
62
) -> bool {
46
    // Only checking one null mask here because by the time the control flow reaches
47
    // this point, the equality of the two masks would have already been verified.
48
62
    if !contains_nulls(lhs.nulls(), lhs_start, len) {
49
50
        equal_child_values(lhs, rhs, lhs_start, rhs_start, len)
50
    } else {
51
        // get a ref of the null buffer bytes, to use in testing for nullness
52
12
        let lhs_nulls = lhs.nulls().unwrap();
53
12
        let rhs_nulls = rhs.nulls().unwrap();
54
        // with nulls, we need to compare item by item whenever it is not null
55
41
        
(0..len)12
.
all12
(|i| {
56
41
            let lhs_pos = lhs_start + i;
57
41
            let rhs_pos = rhs_start + i;
58
            // if both struct and child had no null buffers,
59
41
            let lhs_is_null = lhs_nulls.is_null(lhs_pos);
60
41
            let rhs_is_null = rhs_nulls.is_null(rhs_pos);
61
62
41
            if lhs_is_null != rhs_is_null {
63
0
                return false;
64
41
            }
65
66
41
            lhs_is_null || 
equal_child_values25
(
lhs25
,
rhs25
,
lhs_pos25
,
rhs_pos25
, 1)
67
41
        })
68
    }
69
62
}