isLU property Null safety

bool isLU

Implementation

bool get isLU => _rowSwaps != null;
void isLU=(bool v)

Implementation

set isLU(bool v) {
  if (v == isLU) {
    return;
  }
  final swaps = _rowSwaps;
  if (swaps == null) {
    if (rows != columns) {
      throw CalculatorError(11);
    }
    _rowSwaps = List.generate(rows, (i) => i, growable: false);
  } else {
    _rowSwaps = null;
    for (int r = 0; r < rows; r++) {
      final sr = swaps[r];
      if (sr != r) {
        assert(sr > r);
        for (int c = 0; c < columns; c++) {
          final t = get(r, c);
          set(r, c, get(sr, c));
          set(sr, c, t);
        }
        swaps[r] = r;
        bool ok = false;
        for (int i = r + 1; i < swaps.length; i++) {
          if (swaps[i] == r) {
            swaps[i] = sr;
            ok = true;
            break;
          }
        }
        assert(ok);
      }
    }
    assert(() {
      for (int r = 0; r < rows; r++) {
        assert(r == swaps[r]);
      }
      return true;
    }());
  }
  assert(isLU == v);
}