addOrSubtract method
Implementation
GenericGFPoly addOrSubtract(GenericGFPoly other) {
if (_field != other._field) {
throw ArgumentError('GenericGFPolys do not have same GenericGF field');
}
if (isZero) {
return other;
}
if (other.isZero) {
return this;
}
List<int> smallerCoefficients = _coefficients;
List<int> largerCoefficients = other._coefficients;
if (smallerCoefficients.length > largerCoefficients.length) {
final temp = smallerCoefficients;
smallerCoefficients = largerCoefficients;
largerCoefficients = temp;
}
final sumDiff = Int32List(largerCoefficients.length);
final lengthDiff = largerCoefficients.length - smallerCoefficients.length;
// Copy high-order terms only found in higher-degree polynomial's coefficients
List.copyRange(sumDiff, 0, largerCoefficients, 0, lengthDiff);
for (int i = lengthDiff; i < largerCoefficients.length; i++) {
sumDiff[i] = GenericGF.addOrSubtract(
smallerCoefficients[i - lengthDiff],
largerCoefficients[i],
);
}
return GenericGFPoly(_field, sumDiff);
}