malachite_nz/integer_vector/comparison/partial_eq_unsigned_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::Integer;
9use crate::integer_vector::IntegerVector;
10use malachite_base::num::basic::unsigneds::PrimitiveUnsigned;
11use malachite_base::unsigned_vector::UnsignedVector;
12
13impl<T: PrimitiveUnsigned> PartialEq<UnsignedVector<T>> for IntegerVector
14where
15 Integer: PartialEq<T>,
16{
17 /// Determines whether an [`IntegerVector`] is equal to an [`UnsignedVector`].
18 ///
19 /// The two are equal when they have the same dimension and equal elements in each position. So
20 /// the 0-dimensional vectors are equal, and an [`IntegerVector`] with an element that is
21 /// negative or too large for `T` is equal to no [`UnsignedVector<T>`].
22 ///
23 /// # Worst-case complexity
24 /// $T(n) = O(n)$
25 ///
26 /// $M(n) = O(1)$
27 ///
28 /// where $T$ is time, $M$ is additional memory, and $n$ is `self.dimension()`. Vectors of
29 /// different dimensions are compared in constant time.
30 ///
31 /// # Examples
32 /// See [here](super::partial_eq_unsigned_vector#partial_eq).
33 fn eq(&self, other: &UnsignedVector<T>) -> bool {
34 self.elements.len() == other.elements.len()
35 && self
36 .elements
37 .iter()
38 .zip(&other.elements)
39 .all(|(x, y)| x == y)
40 }
41}
42
43impl<T: PrimitiveUnsigned> PartialEq<IntegerVector> for UnsignedVector<T>
44where
45 Integer: PartialEq<T>,
46{
47 /// Determines whether an [`UnsignedVector`] is equal to an [`IntegerVector`].
48 ///
49 /// The two are equal when they have the same dimension and equal elements in each position, so
50 /// the 0-dimensional vectors are equal.
51 ///
52 /// # Worst-case complexity
53 /// $T(n) = O(n)$
54 ///
55 /// $M(n) = O(1)$
56 ///
57 /// where $T$ is time, $M$ is additional memory, and $n$ is `self.dimension()`. Vectors of
58 /// different dimensions are compared in constant time.
59 ///
60 /// # Examples
61 /// See [here](super::partial_eq_unsigned_vector#partial_eq).
62 #[inline]
63 fn eq(&self, other: &IntegerVector) -> bool {
64 other == self
65 }
66}