Jump to content

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];
ndx1[] = 0;
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];
ndx2[] = 0;
for (i = 0, n = 0, m = 0; i < len; i++) {
ndx2[i] = ndx1[n];
Line 310 ⟶ 308:
 
// rotate each group
ndx1[] = 0;
for (i = 0, j = 0; i < mx; i++) {
int first = ndx2[j];
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.