CompressorDelayTable constructor
Creates an immutable, validated delay table.
Implementation
CompressorDelayTable({
required List<double> sum,
required List<double> carry,
List<double?>? cout,
}) : sum = List.unmodifiable(sum),
carry = List.unmodifiable(carry),
cout = cout == null ? null : List.unmodifiable(cout) {
if (![2, 3, 5].contains(sum.length) || carry.length != sum.length) {
throw ArgumentError('A compressor table must have 2, 3, or 5 inputs '
'and one sum and carry delay per input.');
}
if (sum.length == 5) {
if (cout == null ||
cout.length != 5 ||
cout.take(3).any((delay) => delay == null) ||
cout[3] != null ||
cout[4] != null) {
throw ArgumentError('A 4:2 cout must have delays for bits 0-2 and '
'no paths from bit 3 or carryIn.');
}
} else if (cout != null) {
throw ArgumentError('Only a 4:2 compressor has a cout output.');
}
for (final delay in [...sum, ...carry, ...?cout]) {
if (delay != null && (!delay.isFinite || delay < 0)) {
throw ArgumentError.value(
delay,
'delay',
'Must be finite and '
'nonnegative.');
}
}
}