decodeWithECCount method
Implementation
int decodeWithECCount(List<int> received, int twoS) {
final poly = GenericGFPoly(_field, received);
final syndromeCoefficients = Int32List(twoS);
bool noError = true;
for (int i = 0; i < twoS; i++) {
final eval = poly.evaluateAt(_field.exp(i + _field.generatorBase));
syndromeCoefficients[syndromeCoefficients.length - 1 - i] = eval;
if (eval != 0) {
noError = false;
}
}
if (noError) {
return 0;
}
final syndrome = GenericGFPoly(_field, syndromeCoefficients);
final sigmaOmega = _runEuclideanAlgorithm(
_field.buildMonomial(twoS, 1),
syndrome,
twoS,
);
final sigma = sigmaOmega[0];
final omega = sigmaOmega[1];
final errorLocations = _findErrorLocations(sigma);
final errorMagnitudes = _findErrorMagnitudes(omega, errorLocations);
for (int i = 0; i < errorLocations.length; i++) {
final position = received.length - 1 - _field.log(errorLocations[i]);
if (position < 0) {
throw ReedSolomonException('Bad error location');
}
received[position] = GenericGF.addOrSubtract(
received[position],
errorMagnitudes[i],
);
}
return errorLocations.length;
}