Skip to content

Instantly share code, notes, and snippets.

@kaizhu256
Created June 4, 2012 19:16
Show Gist options
  • Save kaizhu256/2870264 to your computer and use it in GitHub Desktop.
Save kaizhu256/2870264 to your computer and use it in GitHub Desktop.
javascript bit reverse array index
## inplace bit-reverse
my.Array2.prototype.bitReverse = function() {};:
{{my.Array2.rgxEach1.1}}, jj3, jj4, ll0, ll3, offset, tmp; this.transpose();
{{my.Array2.rgxEach1.2}}
offset = this.offset; jj3 = 0; ll0 = ll1 * stride1 >> 1; jj1 += stride1; ll1 -= 2;
{{my.Array2.rgxEach1.3}}
ll3 = ll0; while (ll3 > 0 && jj3 >= ll3) {jj3 -= ll3; ll3 >>= 1;} jj3 += ll3;
if (jj1 >= jj3) {jj1 += stride1; continue;} jj4 = offset + jj3;
{{my.Array2.rgxEach1.4}}
tmp = arr[jj2]; arr[jj2] = arr[jj4]; arr[jj4] = tmp; jj4 += stride2;
{{my.Array2.rgxEach1.5}}
{{my.Array2.rgxEach1.6}} return this.transpose();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment