Anonymous user
Best shuffle: Difference between revisions
Cleaned up first D version
(Better first D version) |
(Cleaned up first D version) |
||
Line 285:
// all character positions, grouped by character
int[] ndx1 = (cast(int*)alloca(len * int.sizeof))[0 .. len];
int i = 0;
foreach (ch; 0 .. counts.length)
Line 291 ⟶ 290:
for (j = 0; j < len; j++)
if (ch == txt[j])
ndx1[i++] = j;
// regroup them for cycles
int[] ndx2 = (cast(int*)alloca(len * int.sizeof))[0 .. len];
for (i = 0, n = 0, m = 0; i < len; i++) {
ndx2[i] = ndx1[n];
Line 310 ⟶ 308:
// rotate each group
for (i = 0, j = 0; i < mx; i++) {
int first = ndx2[j];
|