PermutationDescriptor constructor
Creates and validates a permutation from output-to-source indices.
Implementation
PermutationDescriptor(Iterable<int> sourceIndices)
: _sourceIndices = List<int>.unmodifiable(sourceIndices) {
if (_sourceIndices.isEmpty) {
throw RohdHclException('A permutation must contain at least one index.');
}
final seen = List<bool>.filled(length, false);
for (var outputIndex = 0; outputIndex < length; outputIndex++) {
final sourceIndex = _sourceIndices[outputIndex];
if (sourceIndex < 0 || sourceIndex >= length) {
throw RohdHclException(
'Permutation source index $sourceIndex at output $outputIndex is '
'outside the range 0 through ${length - 1}.',
);
}
if (seen[sourceIndex]) {
throw RohdHclException(
'Permutation source index $sourceIndex appears more than once.');
}
seen[sourceIndex] = true;
}
}