Libraryless. Click here for Pure Java version (2985L/18K).
1 | persistable sclass AutoGrowingList<A> extends RandomAccessAbstractList<A> {
|
2 | new L<A> list; |
3 | IF1<Int, A> createEmptyElement; // optional, takes index and produces element |
4 | |
5 | *(IF1<Int, A> *createEmptyElement) {}
|
6 | *(IF0<A> createEmptyElement) { this(if0ToIF1(createEmptyElement)); }
|
7 | |
8 | public int size() { ret list.size(); }
|
9 | public A get(int i) { ret list.get(i); }
|
10 | |
11 | public A set(int i, A a) {
|
12 | while (i > size()) |
13 | list.add(createEmptyElement?.get(i)); |
14 | if (i == size()) {
|
15 | add(a); |
16 | null; |
17 | } else |
18 | ret list.set(i, a); |
19 | }; |
20 | |
21 | public bool add(A a) { ret list.add(a); }
|
22 | } |
Began life as a copy of #1030633
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1031197 |
| Snippet name: | AutoGrowingList - this only grows on set |
| Eternal ID of this version: | #1031197/10 |
| Text MD5: | 5badc0313b4e16cd44fb40bfc2c8cf94 |
| Transpilation MD5: | a7cb4c58db8c31592117023727d531ce |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-05-20 02:42:48 |
| Source code size: | 633 bytes / 22 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 443 / 689 |
| Version history: | 9 change(s) |
| Referenced in: | [show references] |