Class DensePoly
java.lang.Object
it.unimi.di.prog2.h18.AbstractPoly
it.unimi.di.prog2.h18.DensePoly
A dense implementation of non-zero
Polys.-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int[]The array of coefficients, thecoeff[i]is the coefficient of \( x^i \). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDensePoly(int[] coefficient) Initializes the polynomial given an array of coefficients. -
Method Summary
Modifier and TypeMethodDescriptionPerforms polynomial addition.intcoefficient(int d) Returns the coefficient of the term of given exponent.static DensePolyCopies the dense polynomial.static DensePolyCopies the polynomial.iterator()minus()Returns the negate polynomial.Performs polynomial multiplication.static PolyofCoefficientDegree(int c, int n) Creates the polynomial \(p = cx^n\).static PolyofCoefficients(int[] coefficient) Creates a polynomial given an array of coefficients.Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
coefficient
private final int[] coefficientThe array of coefficients, thecoeff[i]is the coefficient of \( x^i \).
-
-
Constructor Details
-
DensePoly
private DensePoly(int[] coefficient) Initializes the polynomial given an array of coefficients.- Parameters:
coefficient- must satisfy the RI (this is a partial method).
-
-
Method Details
-
copyOf
Copies the dense polynomial.- Parameters:
poly- the polynomial to copy.- Returns:
- the copy of the polynomial.
- Throws:
NullPointerException- ifpolyisnull.
-
copyOf
Copies the polynomial.- Parameters:
poly- the polynomial to copy.- Returns:
- the copy of the polynomial.
- Throws:
NullPointerException- ifpolyisnull.
-
ofCoefficients
Creates a polynomial given an array of coefficients.The coefficient array can have trailing zeros, in case all coefficients are zero, this will return the zero polynomial.
- Parameters:
coefficient- the array of coefficients.- Returns:
- the polynomial.
- Throws:
NullPointerException- ifcoefficientisnull.
-
ofCoefficientDegree
Creates the polynomial \(p = cx^n\).The coefficient can be zero, resulting in the zero polynomial.
- Parameters:
c- the coefficient.n- the degree.- Returns:
- the polynomial \( p = cx^n \).
- Throws:
IllegalArgumentException- ifn< 0.
-
coefficient
public int coefficient(int d) Description copied from interface:PolyReturns the coefficient of the term of given exponent.- Parameters:
d- the exponent of the term to consider.- Returns:
- the coefficient of the considered term.
-
add
Performs polynomial addition.If \( p \) is this polynomial, returns \( p + q \).
- Parameters:
q- the polynomial to add to this one.- Returns:
- the sum among this and the given polynomial.
- Throws:
NullPointerException- ifqisnull.
-
mul
Performs polynomial multiplication.If \( p \) is this polynomial, returns \( p q \).
- Parameters:
q- the polynomial to multiply by this one.- Returns:
- the product among this and the given polynomial.
- Throws:
NullPointerException- ifqisnull.
-
minus
Returns the negate polynomial.If \( p \) is this polynomial, returns \( -p \).
- Returns:
- this polynomial multiplied by \( -1 \).
-
iterator
-