slide function

void slide(
  1. Int8List r,
  2. Uint8List a
)

Implementation

void slide(Int8List r, Uint8List a) {
  for (var i = 0; i < r.length; i++) {
    r[i] = 1 & (a[i >> 3] >> (i & 7));
  }

  for (var i = 0; i < r.length; i++) {
    if (r[i] != 0) {
      for (var b = 1; b <= 6 && i + b < 256; b++) {
        if (r[i + b] != 0) {
          if (r[i] + (r[i + b] << b) <= 15) {
            r[i] += r[i + b] << b;
            r[i + b] = 0;
          } else if (r[i] - (r[i + b] << b) >= -15) {
            r[i] -= r[i + b] << b;
            for (var k = i + b; k < 256; k++) {
              if (r[k] == 0) {
                r[k] = 1;
                break;
              }
              r[k] = 0;
            }
          } else {
            break;
          }
        }
      }
    }
  }
}