Sklansky constructor

Sklansky(
  1. List<Logic> inps,
  2. Logic op(
    1. Logic term1,
    2. Logic term2
    ), {
  3. bool reserveName = false,
  4. bool reserveDefinitionName = false,
  5. String? definitionName,
})

Sklansky constructor.

Implementation

Sklansky(List<Logic> inps, Logic Function(Logic term1, Logic term2) op,
    {super.reserveName, super.reserveDefinitionName, String? definitionName})
    : super(definitionName: definitionName ?? 'Skanskly', inps, 'sklansky') {
  final iseq = <Logic>[];

  inps.forEachIndexed((i, el) {
    iseq.add(addInput('i$i', el, width: el.width));
    _oseq.add(addOutput('o$i', width: el.width));
  });

  if (iseq.length == 1) {
    _oseq[0] <= iseq[0];
  } else {
    final n = iseq.length;
    final m = largestPow2LessThan(n);
    final u = Sklansky(iseq.getRange(0, m).toList(), op).val;
    final v = Sklansky(iseq.getRange(m, n).toList(), op).val;
    u.forEachIndexed((i, el) {
      _oseq[i] <= el;
    });
    v.forEachIndexed((i, el) {
      _oseq[m + i] <= op(u[m - 1], el);
    });
  }
}