LfsrDescriptor.fromFeedbackTaps constructor

LfsrDescriptor.fromFeedbackTaps({
  1. required int stateWidth,
  2. required Iterable<int> feedbackTaps,
})

Creates a descriptor from zero-based feedback state-bit indices.

Taps must be nonempty, unique, and in the range 0..stateWidth - 1. Unlike the polynomial constructor, bit zero need not be a tap.

Implementation

factory LfsrDescriptor.fromFeedbackTaps({
  required int stateWidth,
  required Iterable<int> feedbackTaps,
}) {
  if (stateWidth < 1) {
    throw RohdHclException('LFSR state width must be positive.');
  }
  final taps = <int>{};
  for (final tap in feedbackTaps) {
    if (tap < 0 || tap >= stateWidth) {
      throw RohdHclException(
          'LFSR feedback tap $tap is outside 0..${stateWidth - 1}.');
    }
    if (!taps.add(tap)) {
      throw RohdHclException('Duplicate LFSR feedback tap $tap.');
    }
  }
  if (taps.isEmpty) {
    throw RohdHclException('LFSR feedback taps must not be empty.');
  }
  return LfsrDescriptor._fromTapPolynomial(
      BinaryPolynomial.fromExponents([stateWidth, ...taps]));
}