Cut a rectangle: Difference between revisions
Content added Content deleted
(Fixed comment to D entry) |
(Updated D entry) |
||
Line 402: | Line 402: | ||
core.stdc.string, std.typetuple; |
core.stdc.string, std.typetuple; |
||
template Range(int stop) { |
template Range(int stop) { // for manual loop unroll |
||
static if (stop <= 0) |
static if (stop <= 0) |
||
alias TypeTuple!() Range; |
alias TypeTuple!() Range; |
||
Line 409: | Line 409: | ||
} |
} |
||
enum int[2][4] dir = [[0, -1], [-1, 0], [0, 1], [1, 0]]; |
|||
__gshared ubyte |
__gshared ubyte[] grid; |
||
__gshared int w, h, len; |
__gshared int w, h, len; |
||
__gshared ulong cnt; |
__gshared ulong cnt; |
||
Line 447: | Line 447: | ||
len = (h + 1) * (w + 1); |
len = (h + 1) * (w + 1); |
||
{ |
|||
grid = cast(ubyte*)alloca(len); |
|||
// grid = new ubyte[len]; // slower |
|||
ubyte* ptr = cast(ubyte*)alloca(len); |
|||
if (ptr == null) |
|||
exit(1); |
|||
grid = ptr[0 .. len]; |
|||
} |
|||
grid[] = 0; |
|||
len--; |
len--; |
||
//next = [-1, -w - 1, 1, w + 1]; // slow |
|||
next[0] = -1; |
next[0] = -1; |
||
next[1] = -w - 1; |
next[1] = -w - 1; |