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