malachite_nz/natural_polynomial/comparison/partial_eq_gaussian_integer.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/>.
8
9use crate::gaussian_integer::GaussianInteger;
10use crate::natural_polynomial::NaturalPolynomial;
11
12impl PartialEq<GaussianInteger> for NaturalPolynomial {
13 /// Determines whether a [`NaturalPolynomial`] is equal to a [`GaussianInteger`].
14 ///
15 /// The polynomial is equal to the [`GaussianInteger`] when it is the constant polynomial with
16 /// that value, so the zero polynomial is equal to 0 and nothing else, no polynomial is equal to
17 /// a [`GaussianInteger`] with a nonzero imaginary part or a negative real part, and no
18 /// polynomial of positive degree is equal to any [`GaussianInteger`].
19 ///
20 /// # Worst-case complexity
21 /// $T(n) = O(n)$
22 ///
23 /// $M(n) = O(1)$
24 ///
25 /// where $T$ is time, $M$ is additional memory, and $n$ is
26 /// `min(self.coefficient(0).significant_bits(), other.real.significant_bits())`.
27 ///
28 /// # Examples
29 /// See [here](super::partial_eq_gaussian_integer#partial_eq).
30 fn eq(&self, other: &GaussianInteger) -> bool {
31 match self.coefficients.as_slice() {
32 [] => *other == 0u32,
33 [c] => other == c,
34 _ => false,
35 }
36 }
37}
38
39impl PartialEq<NaturalPolynomial> for GaussianInteger {
40 /// Determines whether a [`GaussianInteger`] is equal to a [`NaturalPolynomial`].
41 ///
42 /// The [`GaussianInteger`] is equal to the polynomial when the polynomial is the constant
43 /// polynomial with that value, so 0 is equal to the zero polynomial, and a [`GaussianInteger`]
44 /// with a nonzero imaginary part or a negative real part is equal to no polynomial.
45 ///
46 /// # Worst-case complexity
47 /// $T(n) = O(n)$
48 ///
49 /// $M(n) = O(1)$
50 ///
51 /// where $T$ is time, $M$ is additional memory, and $n$ is `min(self.real.significant_bits(),
52 /// other.coefficient(0).significant_bits())`.
53 ///
54 /// # Examples
55 /// See [here](super::partial_eq_gaussian_integer#partial_eq).
56 #[inline]
57 fn eq(&self, other: &NaturalPolynomial) -> bool {
58 other == self
59 }
60}