java.lang.Object
com.google.zxing.common.reedsolomon.GenericGFPoly

final class GenericGFPolyextends Object

Represents a polynomial whose coefficients are elements of a GF. Instances of this class are immutable.

Much credit is due to William Rucklidge since portions of this code are an indirect port of his C++ Reed-Solomon implementation.

  • Field Details

    • field

      private final GenericGF field
      The Galois field the coefficients are arithmetic in.
    • coefficients

      private final int[] coefficients
      Coefficients, highest power first, with no leading zeroes
  • Constructor Details

    • GenericGFPoly

      GenericGFPoly(GenericGF field, int[] coefficients)
      Builds a polynomial over a given field, in the standard form.
      Parameters:
      field - the GenericGF instance representing the field to use to perform computations
      coefficients - coefficients as ints representing elements of GF(size), arranged from most significant (highest-power term) coefficient to least significant
      Throws:
      IllegalArgumentException - if argument is null or empty, or if leading coefficient is 0 and this is not a constant polynomial (that is, it is not the monomial "0")
  • Method Details

    • getCoefficients

      int[] getCoefficients()
      Get the coefficients.
      Returns:
      the coefficients, highest power of x first, so element 0 multiplies x^0
    • getDegree

      int getDegree()
      Get the degree.
      Returns:
      degree of this polynomial
    • isZero

      boolean isZero()
      Whether zero.
      Returns:
      true iff this polynomial is the monomial "0"
    • getCoefficient

      int getCoefficient(int degree)
      Get the coefficient.
      Parameters:
      degree - the power of x whose coefficient is wanted
      Returns:
      coefficient of x^degree term in this polynomial
    • evaluateAt

      int evaluateAt(int a)
      Evaluate this polynomial at a value.
      Parameters:
      a - the field element at which to evaluate
      Returns:
      evaluation of this polynomial at a given point
    • addOrSubtract

      GenericGFPoly addOrSubtract(GenericGFPoly other)
      Add or subtract another polynomial.
      Parameters:
      other - the polynomial to add, which must be over the same field
      Returns:
      the field sum if the field is characteristic two, the difference otherwise
    • multiply

      GenericGFPoly multiply(GenericGFPoly other)
      Multiplies by another polynomial over the same field.
      Parameters:
      other - the polynomial to multiply by, which must be over the same field
      Returns:
      a new polynomial holding the product
    • multiply

      GenericGFPoly multiply(int scalar)
      Multiplies every coefficient by a field element.
      Parameters:
      scalar - the field element to multiply every coefficient by
      Returns:
      a new polynomial holding the scaled coefficients
    • multiplyByMonomial

      GenericGFPoly multiplyByMonomial(int degree, int coefficient)
      Multiply by a monomial term.
      Parameters:
      degree - the power of x to multiply by, which must not be negative
      coefficient - the field element scaling each existing coefficient
      Returns:
      a new polynomial shifted up by degree and scaled by coefficient
    • divide

      GenericGFPoly[] divide(GenericGFPoly other)
      Divides by another polynomial, yielding quotient and remainder.
      Parameters:
      other - the polynomial to divide by, which must be non-zero and over the same field
      Returns:
      a two-element array holding the quotient and the remainder
    • toString

      public String toString()
      Overrides:
      toString in class Object