PermutationDescriptor.rotateLeft constructor

PermutationDescriptor.rotateLeft(
  1. int length,
  2. int amount
)

Creates a left rotation of length elements by amount.

Implementation

factory PermutationDescriptor.rotateLeft(int length, int amount) {
  if (amount < 0) {
    throw RohdHclException('Permutation rotation amount cannot be negative.');
  }
  if (length <= 0) {
    throw RohdHclException('Permutation rotation length must be positive.');
  }
  final normalizedAmount = amount % length;
  return PermutationDescriptor([
    for (var outputIndex = 0; outputIndex < length; outputIndex++)
      (outputIndex - normalizedAmount + length) % length,
  ]);
}