public class SparseTernaryPolynomial extends java.lang.Object implements TernaryPolynomial
TernaryPolynomial with a "low" number of nonzero coefficients.| Constructor and Description |
|---|
SparseTernaryPolynomial(int[] coeffs)
Constructs a new
SparseTernaryPolynomial with a given set of coefficients. |
SparseTernaryPolynomial(IntegerPolynomial intPoly)
Constructs a
DenseTernaryPolynomial from a IntegerPolynomial. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
equals(java.lang.Object obj) |
static SparseTernaryPolynomial |
fromBinary(java.io.InputStream is,
int N,
int numOnes,
int numNegOnes)
Decodes a byte array encoded with
toBinary() to a ploynomial. |
static SparseTernaryPolynomial |
generateRandom(int N,
int numOnes,
int numNegOnes,
java.security.SecureRandom random)
Generates a random polynomial with
numOnes coefficients equal to 1,
numNegOnes coefficients equal to -1, and the rest equal to 0. |
int[] |
getNegOnes() |
int[] |
getOnes() |
int |
hashCode() |
BigIntPolynomial |
mult(BigIntPolynomial poly2)
Multiplies the polynomial by a
BigIntPolynomial, taking the indices mod N. |
IntegerPolynomial |
mult(IntegerPolynomial poly2)
Multiplies the polynomial by an
IntegerPolynomial, taking the indices mod N |
IntegerPolynomial |
mult(IntegerPolynomial poly2,
int modulus)
Multiplies the polynomial by an
IntegerPolynomial,
taking the coefficient values mod modulus and the indices mod N. |
int |
size()
Returns the maximum number of coefficients the polynomial can have
|
byte[] |
toBinary()
Encodes the polynomial to a byte array writing
BITS_PER_INDEX bits for each coefficient. |
IntegerPolynomial |
toIntegerPolynomial()
Returns a polynomial that is equal to this polynomial (in the sense that
Polynomial.mult(IntegerPolynomial, int)
returns equal IntegerPolynomials). |
public SparseTernaryPolynomial(IntegerPolynomial intPoly)
DenseTernaryPolynomial from a IntegerPolynomial. The two polynomials are
independent of each other.intPoly - the original polynomialpublic SparseTernaryPolynomial(int[] coeffs)
SparseTernaryPolynomial with a given set of coefficients.coeffs - the coefficientspublic static SparseTernaryPolynomial fromBinary(java.io.InputStream is, int N, int numOnes, int numNegOnes) throws java.io.IOException
toBinary() to a ploynomial.is - an input stream containing an encoded polynomialN - number of coefficients including zerosnumOnes - number of coefficients equal to 1numNegOnes - number of coefficients equal to -1java.io.IOExceptionpublic static SparseTernaryPolynomial generateRandom(int N, int numOnes, int numNegOnes, java.security.SecureRandom random)
numOnes coefficients equal to 1,
numNegOnes coefficients equal to -1, and the rest equal to 0.N - number of coefficientsnumOnes - number of 1'snumNegOnes - number of -1'spublic IntegerPolynomial mult(IntegerPolynomial poly2)
TernaryPolynomialIntegerPolynomial, taking the indices mod Nmult in interface Polynomialmult in interface TernaryPolynomialpoly2 - a polynomialpublic IntegerPolynomial mult(IntegerPolynomial poly2, int modulus)
PolynomialIntegerPolynomial,
taking the coefficient values mod modulus and the indices mod N.mult in interface Polynomialpoly2 - a polynomialmodulus - a modulus to applypublic BigIntPolynomial mult(BigIntPolynomial poly2)
PolynomialBigIntPolynomial, taking the indices mod N. Does not
change this polynomial but returns the result as a new polynomial.mult in interface Polynomialpoly2 - the polynomial to multiply bypublic int[] getOnes()
getOnes in interface TernaryPolynomialpublic int[] getNegOnes()
getNegOnes in interface TernaryPolynomialpublic byte[] toBinary()
BITS_PER_INDEX bits for each coefficient.public IntegerPolynomial toIntegerPolynomial()
PolynomialPolynomial.mult(IntegerPolynomial, int)
returns equal IntegerPolynomials). The new polynomial is guaranteed to be independent of the original.toIntegerPolynomial in interface PolynomialIntegerPolynomial.public int size()
TernaryPolynomialsize in interface TernaryPolynomialpublic void clear()
clear in interface TernaryPolynomialpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Object