static class Grid { int[] mem = new int[0]; *() {} *(int[] data) { set(0, data); } void set(int addr, int x) { if (addr < 0) ret; expandTo(addr); mem[addr] = x; } void set(int addr, int[] x) { for (int i = l(x)-1; i >= 0; i--) set(addr+i, x[i]); } int get(int addr) { if (addr < 0 || addr >= l(mem)) ret 0; ret mem[addr]; } void expandTo(int n) { if (n >= l(mem)) { int[] m = new int[max(n+1, l(mem)*2)]; arraycopy(mem, 0, m, 0, l(mem)); mem = m; } } int lastNonZero() { int i = l(mem)-1; while (i > 0 && get(i) == 0) --i; ret i; } int[] getRange(int a, int b) { ret subArray(mem, a, b); } void swap(int a, int b) { int i = get(a); set(a, get(b)); set(b, i); } }
Began life as a copy of #1003139
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004583 |
Snippet name: | class Grid - basically a growable int[]. used for simple virtual machines |
Eternal ID of this version: | #1004583/2 |
Text MD5: | 581b3bc5db363a78a889355d0b41b1ce |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-09-16 21:15:47 |
Source code size: | 856 bytes / 47 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 627 / 1222 |
Version history: | 1 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |