ReedSolomonCombinedLocator constructor
Creates a combinational locator multiplication stage.
Implementation
ReedSolomonCombinedLocator(
Logic erasureLocator,
Logic errorLocator, {
required ReedSolomonCode code,
required int erasureCount,
required int errorCapacity,
super.name = 'reed_solomon_combined_locator',
}) : super(
definitionName:
'ReedSolomonCombinedLocator_N${code.length}_E$erasureCount'
'_T$errorCapacity',
) {
if (erasureCount < 0 || errorCapacity < 0) {
throw ArgumentError('Locator degrees cannot be negative.');
}
final width = code.field.degree;
final erasureWidth = (erasureCount + 1) * width;
final errorWidth = (errorCapacity + 1) * width;
if (erasureLocator.width != erasureWidth) {
throw PortWidthMismatchException(erasureLocator, erasureWidth);
}
if (errorLocator.width != errorWidth) {
throw PortWidthMismatchException(errorLocator, errorWidth);
}
final localErasure =
addInput('erasureLocator', erasureLocator, width: erasureWidth);
final localError =
addInput('errorLocator', errorLocator, width: errorWidth);
GfLogic erasureCoefficient(int index) => GfLogic.of(
localErasure.slice((index + 1) * width - 1, index * width),
field: code.field,
);
GfLogic errorCoefficient(int index) => GfLogic.of(
localError.slice((index + 1) * width - 1, index * width),
field: code.field,
);
final coefficients = <GfLogic>[];
for (var index = 0; index <= erasureCount + errorCapacity; index++) {
var value = GfLogic.constant(code.field.zero);
for (var erasureIndex = 0; erasureIndex <= erasureCount; erasureIndex++) {
final errorIndex = index - erasureIndex;
if (errorIndex >= 0 && errorIndex <= errorCapacity) {
value +=
erasureCoefficient(erasureIndex) * errorCoefficient(errorIndex);
}
}
coefficients.add(value);
}
addOutput(
'locator',
width: (erasureCount + errorCapacity + 1) * width,
).gets(coefficients.rconcat());
}