/Users/andrewlamb/Software/arrow-rs/arrow-data/src/equal/boolean.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::bit_iterator::BitIndexIterator; |
19 | | use crate::data::{contains_nulls, ArrayData}; |
20 | | use arrow_buffer::bit_util::get_bit; |
21 | | |
22 | | use super::utils::{equal_bits, equal_len}; |
23 | | |
24 | | /// Returns true if the value data for the arrays is equal, assuming the null masks have |
25 | | /// already been checked for equality |
26 | 37 | pub(super) fn boolean_equal( |
27 | 37 | lhs: &ArrayData, |
28 | 37 | rhs: &ArrayData, |
29 | 37 | mut lhs_start: usize, |
30 | 37 | mut rhs_start: usize, |
31 | 37 | mut len: usize, |
32 | 37 | ) -> bool { |
33 | 37 | let lhs_values = lhs.buffers()[0].as_slice(); |
34 | 37 | let rhs_values = rhs.buffers()[0].as_slice(); |
35 | | |
36 | 37 | let contains_nulls = contains_nulls(lhs.nulls(), lhs_start, len); |
37 | | |
38 | 37 | if !contains_nulls { |
39 | | // Optimize performance for starting offset at u8 boundary. |
40 | 35 | if lhs_start % 8 == 0 |
41 | 35 | && rhs_start % 8 == 0 |
42 | 35 | && lhs.offset() % 8 == 0 |
43 | 35 | && rhs.offset() % 8 == 0 |
44 | | { |
45 | 35 | let quot = len / 8; |
46 | 35 | if quot > 0 |
47 | 30 | && !equal_len( |
48 | 30 | lhs_values, |
49 | 30 | rhs_values, |
50 | 30 | lhs_start / 8 + lhs.offset() / 8, |
51 | 30 | rhs_start / 8 + rhs.offset() / 8, |
52 | 30 | quot, |
53 | 30 | ) |
54 | | { |
55 | 0 | return false; |
56 | 35 | } |
57 | | |
58 | | // Calculate for suffix bits. |
59 | 35 | let rem = len % 8; |
60 | 35 | if rem == 0 { |
61 | 30 | return true; |
62 | | } else { |
63 | 5 | let aligned_bits = len - rem; |
64 | 5 | lhs_start += aligned_bits; |
65 | 5 | rhs_start += aligned_bits; |
66 | 5 | len = rem |
67 | | } |
68 | 0 | } |
69 | | |
70 | 5 | equal_bits( |
71 | 5 | lhs_values, |
72 | 5 | rhs_values, |
73 | 5 | lhs_start + lhs.offset(), |
74 | 5 | rhs_start + rhs.offset(), |
75 | 5 | len, |
76 | | ) |
77 | | } else { |
78 | | // get a ref of the null buffer bytes, to use in testing for nullness |
79 | 2 | let lhs_nulls = lhs.nulls().unwrap(); |
80 | | |
81 | 2 | BitIndexIterator::new(lhs_nulls.validity(), lhs_start + lhs_nulls.offset(), len).all(|i| {0 |
82 | 0 | let lhs_pos = lhs_start + lhs.offset() + i; |
83 | 0 | let rhs_pos = rhs_start + rhs.offset() + i; |
84 | 0 | get_bit(lhs_values, lhs_pos) == get_bit(rhs_values, rhs_pos) |
85 | 0 | }) |
86 | | } |
87 | 37 | } |