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