Class GaloisField
java.lang.Object
org.apache.hadoop.io.erasurecode.rawcoder.util.GaloisField
Implementation of Galois field arithmetic with 2^p elements. The input must
be unsigned integers. It's ported from HDFS-RAID, slightly adapted.
-
Method Summary
Modifier and TypeMethodDescriptionint[]add(int[] p, int[] q) Compute the sum of two polynomials.intadd(int x, int y) Compute the sum of two fieldsintdivide(int x, int y) Compute the division of two fieldsvoidgaussianElimination(int[][] matrix) Perform Gaussian elimination on the given matrix.intReturn number of elements in the fieldstatic GaloisFieldGet the object performs Galois field arithmetic with default setting.static GaloisFieldgetInstance(int fieldSize, int primitivePolynomial) Get the object performs Galois field arithmetics.intReturn the primitive polynomial in GF(2)int[]multiply(int[] p, int[] q) Compute the multiplication of two polynomials.intmultiply(int x, int y) Compute the multiplication of two fieldsintpower(int x, int n) Compute power n of a fieldvoidremainder(byte[][] dividend, int[] divisor) The "bulk" version of the remainder.voidremainder(byte[][] dividend, int[] offsets, int len, int[] divisor) The "bulk" version of the remainder.voidremainder(int[] dividend, int[] divisor) Compute the remainder of a dividend and divisor pair.voidremainder(ByteBuffer[] dividend, int[] divisor) The "bulk" version of the remainder, using ByteBuffer.voidsolveVandermondeSystem(int[] x, byte[][] y, int[] outputOffsets, int len, int dataLen) A "bulk" version to the solving of Vandermonde System.voidsolveVandermondeSystem(int[] x, int[] y) Given a Vandermonde matrix V[i][j]=x[j]^i and vector y, solve for z such that Vz=y.voidsolveVandermondeSystem(int[] x, int[] y, int len) Given a Vandermonde matrix V[i][j]=x[j]^i and vector y, solve for z such that Vz=y.voidsolveVandermondeSystem(int[] x, ByteBuffer[] y, int len) A "bulk" version of the solveVandermondeSystem, using ByteBuffer.voidsubstitute(byte[][] p, byte[] q, int x) A "bulk" version of the substitute.voidsubstitute(byte[][] p, int[] offsets, int len, byte[] q, int offset, int x) A "bulk" version of the substitute.intsubstitute(int[] p, int x) Substitute x into polynomial p(x).voidsubstitute(ByteBuffer[] p, int len, ByteBuffer q, int x) A "bulk" version of the substitute, using ByteBuffer.
-
Method Details
-
getInstance
Get the object performs Galois field arithmetics.- Parameters:
fieldSize- size of the fieldprimitivePolynomial- a primitive polynomial corresponds to the size- Returns:
- GaloisField.
-
getInstance
Get the object performs Galois field arithmetic with default setting.- Returns:
- GaloisField.
-
getFieldSize
public int getFieldSize()Return number of elements in the field- Returns:
- number of elements in the field
-
getPrimitivePolynomial
public int getPrimitivePolynomial()Return the primitive polynomial in GF(2)- Returns:
- primitive polynomial as a integer
-
add
public int add(int x, int y) Compute the sum of two fields- Parameters:
x- input fieldy- input field- Returns:
- result of addition
-
multiply
public int multiply(int x, int y) Compute the multiplication of two fields- Parameters:
x- input fieldy- input field- Returns:
- result of multiplication
-
divide
public int divide(int x, int y) Compute the division of two fields- Parameters:
x- input fieldy- input field- Returns:
- x/y
-
power
public int power(int x, int n) Compute power n of a field- Parameters:
x- input fieldn- power- Returns:
- x^n
-
solveVandermondeSystem
public void solveVandermondeSystem(int[] x, int[] y) Given a Vandermonde matrix V[i][j]=x[j]^i and vector y, solve for z such that Vz=y. The output z will be placed in y.- Parameters:
x- the vector which describe the Vandermonde matrixy- right-hand side of the Vandermonde system equation. will be replaced the output in this vector
-
solveVandermondeSystem
public void solveVandermondeSystem(int[] x, int[] y, int len) Given a Vandermonde matrix V[i][j]=x[j]^i and vector y, solve for z such that Vz=y. The output z will be placed in y.- Parameters:
x- the vector which describe the Vandermonde matrixy- right-hand side of the Vandermonde system equation. will be replaced the output in this vectorlen- consider x and y only from 0...len-1
-
solveVandermondeSystem
public void solveVandermondeSystem(int[] x, byte[][] y, int[] outputOffsets, int len, int dataLen) A "bulk" version to the solving of Vandermonde System.- Parameters:
x- input x.y- input y.outputOffsets- input outputOffsets.len- input len.dataLen- input dataLen.
-
solveVandermondeSystem
A "bulk" version of the solveVandermondeSystem, using ByteBuffer.- Parameters:
x- input x.y- input y.len- input len.
-
multiply
public int[] multiply(int[] p, int[] q) Compute the multiplication of two polynomials. The index in the array corresponds to the power of the entry. For example p[0] is the constant term of the polynomial p.- Parameters:
p- input polynomialq- input polynomial- Returns:
- polynomial represents p*q
-
remainder
public void remainder(int[] dividend, int[] divisor) Compute the remainder of a dividend and divisor pair. The index in the array corresponds to the power of the entry. For example p[0] is the constant term of the polynomial p.- Parameters:
dividend- dividend polynomial, the remainder will be placed here when returndivisor- divisor polynomial
-
add
public int[] add(int[] p, int[] q) Compute the sum of two polynomials. The index in the array corresponds to the power of the entry. For example p[0] is the constant term of the polynomial p.- Parameters:
p- input polynomialq- input polynomial- Returns:
- polynomial represents p+q
-
substitute
public int substitute(int[] p, int x) Substitute x into polynomial p(x).- Parameters:
p- input polynomialx- input field- Returns:
- p(x)
-
substitute
public void substitute(byte[][] p, byte[] q, int x) A "bulk" version of the substitute. Tends to be 2X faster than the "int" substitute in a loop.- Parameters:
p- input polynomialq- store the return resultx- input field
-
substitute
public void substitute(byte[][] p, int[] offsets, int len, byte[] q, int offset, int x) A "bulk" version of the substitute. Tends to be 2X faster than the "int" substitute in a loop.- Parameters:
p- input polynomialoffsets- input offset.len- input len.q- store the return resultoffset- input offset.x- input field
-
substitute
A "bulk" version of the substitute, using ByteBuffer. Tends to be 2X faster than the "int" substitute in a loop.- Parameters:
p- input polynomialq- store the return resultx- input fieldlen- input len.
-
remainder
public void remainder(byte[][] dividend, int[] divisor) The "bulk" version of the remainder. Warning: This function will modify the "dividend" inputs.- Parameters:
divisor- divisor.dividend- dividend.
-
remainder
public void remainder(byte[][] dividend, int[] offsets, int len, int[] divisor) The "bulk" version of the remainder. Warning: This function will modify the "dividend" inputs.- Parameters:
dividend- dividend.offsets- offsets.len- len.divisor- divisor.
-
remainder
The "bulk" version of the remainder, using ByteBuffer. Warning: This function will modify the "dividend" inputs.- Parameters:
dividend- dividend.divisor- divisor.
-
gaussianElimination
public void gaussianElimination(int[][] matrix) Perform Gaussian elimination on the given matrix. This matrix has to be a fat matrix (number of rows > number of columns).- Parameters:
matrix- matrix.
-