correct method

List<GfValue> correct(
  1. Iterable<GfValue> received,
  2. Iterable<int> positions,
  3. Iterable<GfValue> magnitudes
)

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);
}