Skip to main content

vortex_mask/
eq.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::mem;
5
6use crate::Mask;
7
8impl PartialEq for Mask {
9    #[inline]
10    fn eq(&self, other: &Self) -> bool {
11        if self.len() != other.len() {
12            return false;
13        }
14        if self.is_empty() {
15            return true;
16        }
17        if mem::discriminant(self) == mem::discriminant(other) && !matches!(self, Mask::Values(_)) {
18            return true;
19        }
20        if self.true_count() != other.true_count() {
21            return false;
22        }
23
24        // TODO(ngates): we could compare by indices if density is low enough
25        self.bit_buffer() == other.bit_buffer()
26    }
27}
28
29impl Eq for Mask {}