correct method
Applies magnitudes at positions and returns the corrected codeword.
Implementation
List<GfValue> correct(
Iterable<GfValue> received,
Iterable<int> positions,
Iterable<GfValue> magnitudes,
) {
final symbols = received.toList(growable: false);
final errorPositions = _validateErasurePositions(positions);
final corrections = magnitudes.toList(growable: false);
if (symbols.length != length) {
throw ArgumentError.value(
symbols, 'received', 'Expected $length symbols.');
}
if (corrections.length != errorPositions.length) {
throw ArgumentError.value(
corrections,
'magnitudes',
'Expected one magnitude per position.',
);
}
_requireSymbols(symbols);
_requireSymbols(corrections);
final corrected = List<GfValue>.from(symbols);
for (var index = 0; index < errorPositions.length; index++) {
corrected[errorPositions[index]] += corrections[index];
}
return List<GfValue>.unmodifiable(corrected);
}