ReedSolomonErasureLocator constructor
- Logic erasureMask, {
- required ReedSolomonCode code,
- required int erasureCount,
- String name = 'reed_solomon_erasure_locator',
Creates a fixed-erasure-count locator builder.
Implementation
ReedSolomonErasureLocator(
Logic erasureMask, {
required ReedSolomonCode code,
required int erasureCount,
super.name = 'reed_solomon_erasure_locator',
}) : super(
definitionName:
'ReedSolomonErasureLocator_N${code.length}_E$erasureCount',
) {
if (erasureCount < 0 || erasureCount > code.paritySymbols) {
throw ArgumentError.value(erasureCount, 'erasureCount');
}
if (erasureMask.width != code.length) {
throw PortWidthMismatchException(erasureMask, code.length);
}
final width = code.field.degree;
final localMask = addInput('erasureMask', erasureMask, width: code.length);
var coefficients = <GfLogic>[
GfLogic.constant(code.field.one),
for (var index = 0; index < erasureCount; index++)
GfLogic.constant(code.field.zero),
];
for (var position = 0; position < code.length; position++) {
final location = GfLogic.constant(
code.field.x.pow(BigInt.from(position)),
);
final selected = localMask.slice(position, position);
final next = <GfLogic>[
for (var coefficient = 0; coefficient <= erasureCount; coefficient++)
GfLogic.constant(code.field.zero),
];
for (var coefficient = 0; coefficient <= erasureCount; coefficient++) {
var product = GfLogic.constant(code.field.zero);
if (coefficient < coefficients.length) {
product += coefficients[coefficient];
}
if (coefficient > 0) {
product += coefficients[coefficient - 1] * location;
}
next[coefficient] = GfLogic.of(
mux(selected, product, coefficients[coefficient]),
field: code.field,
);
}
coefficients = next;
}
addOutput('locator', width: (erasureCount + 1) * width)
.gets(coefficients.rconcat());
}