use crate::integer::Integer;
use crate::integer_polynomial::IntegerPolynomial;
use crate::natural_polynomial::NaturalPolynomial;
use malachite_base::num::basic::unsigneds::PrimitiveUnsigned;
use malachite_base::polynomial::{EqTruncated, slices_eq_truncated};
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
fn integer_is_zero(x: &Integer) -> bool {
*x == 0u32
}
impl EqTruncated for IntegerPolynomial {
#[inline]
fn eq_truncated(&self, other: &Self, len: u64) -> bool {
slices_eq_truncated(
&self.coefficients,
&other.coefficients,
len,
integer_is_zero,
|y| *y == 0u32,
|x, y| x == y,
)
}
}
impl<T: PrimitiveUnsigned> EqTruncated<UnsignedPolynomial<T>> for IntegerPolynomial
where
Integer: PartialEq<T>,
{
#[inline]
fn eq_truncated(&self, other: &UnsignedPolynomial<T>, len: u64) -> bool {
slices_eq_truncated(
&self.coefficients,
other.coefficients_asc(),
len,
integer_is_zero,
|&y| y == T::ZERO,
|x, y| x == y,
)
}
}
impl<T: PrimitiveUnsigned> EqTruncated<IntegerPolynomial> for UnsignedPolynomial<T>
where
Integer: PartialEq<T>,
{
#[inline]
fn eq_truncated(&self, other: &IntegerPolynomial, len: u64) -> bool {
other.eq_truncated(self, len)
}
}
impl EqTruncated<NaturalPolynomial> for IntegerPolynomial {
#[inline]
fn eq_truncated(&self, other: &NaturalPolynomial, len: u64) -> bool {
slices_eq_truncated(
&self.coefficients,
other.coefficients_asc(),
len,
integer_is_zero,
|y| *y == 0u32,
|x, y| x == y,
)
}
}
impl EqTruncated<IntegerPolynomial> for NaturalPolynomial {
#[inline]
fn eq_truncated(&self, other: &IntegerPolynomial, len: u64) -> bool {
other.eq_truncated(self, len)
}
}