Skip to main content

malachite_nz/integer_vector/comparison/
partial_eq_natural_vector.rs

1// Copyright © 2026 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8use crate::integer_vector::IntegerVector;
9use crate::natural_vector::NaturalVector;
10
11impl PartialEq<NaturalVector> for IntegerVector {
12    /// Determines whether an [`IntegerVector`] is equal to a [`NaturalVector`].
13    ///
14    /// The two are equal when they have the same dimension and equal elements in each position. So
15    /// the 0-dimensional vectors are equal, and an [`IntegerVector`] with a negative element is
16    /// equal to no [`NaturalVector`].
17    ///
18    /// # Worst-case complexity
19    /// $T(n) = O(n)$
20    ///
21    /// $M(n) = O(1)$
22    ///
23    /// where $T$ is time, $M$ is additional memory, and $n$ is `self.dimension()`. Vectors of
24    /// different dimensions are compared in constant time.
25    ///
26    /// # Examples
27    /// See [here](super::partial_eq_natural_vector#partial_eq).
28    fn eq(&self, other: &NaturalVector) -> bool {
29        self.elements.len() == other.elements.len()
30            && self
31                .elements
32                .iter()
33                .zip(&other.elements)
34                .all(|(x, y)| x == y)
35    }
36}
37
38impl PartialEq<IntegerVector> for NaturalVector {
39    /// Determines whether a [`NaturalVector`] is equal to an [`IntegerVector`].
40    ///
41    /// The two are equal when they have the same dimension and equal elements in each position, so
42    /// the 0-dimensional vectors are equal.
43    ///
44    /// # Worst-case complexity
45    /// $T(n) = O(n)$
46    ///
47    /// $M(n) = O(1)$
48    ///
49    /// where $T$ is time, $M$ is additional memory, and $n$ is `self.dimension()`. Vectors of
50    /// different dimensions are compared in constant time.
51    ///
52    /// # Examples
53    /// See [here](super::partial_eq_natural_vector#partial_eq).
54    #[inline]
55    fn eq(&self, other: &IntegerVector) -> bool {
56        other == self
57    }
58}