addOrSubstract method
Implementation
GFPoly addOrSubstract(GFPoly other) {
if (zero()) {
return other;
} else if (other.zero()) {
return this;
}
List<int> smallCoeff = coefficients;
List<int> largeCoeff = other.coefficients;
if (smallCoeff.length > largeCoeff.length) {
final List<int> swap = largeCoeff;
largeCoeff = smallCoeff;
smallCoeff = swap;
}
final List<int> sumDiff = List<int>.filled(largeCoeff.length, 0);
final int lenDiff = largeCoeff.length - smallCoeff.length;
sumDiff.setAll(0, largeCoeff.sublist(0, lenDiff));
for (int i = lenDiff; i < largeCoeff.length; i++) {
sumDiff[i] = gf.addOrSub(smallCoeff[i - lenDiff], largeCoeff[i]);
}
return GFPoly(gf, sumDiff);
}