sclass SimpleIntList extends RandomAccessAbstractList<Int> { int[] data = EMPTY_ELEMENTDATA; int size; private static final int[] EMPTY_ELEMENTDATA = {}; public void add(int i) { ensureCapacityInternal(size+1); data[size++] = i; } public bool add(Int i) { add((int) i); true; } public Int set(int i, Int value) { if (i >= size) fail("Index out of range: " + i); int old = data[i]; data[i] = value; ret old; } public int size() { ret size; } public Int get(int i) { if (i >= 0 && i < size) ret data[i]; throw new IndexOutOfBoundsException(i + "/" + size); } void ensureCapacityInternal(int minCapacity) { if (data.length < minCapacity) grow(minCapacity); } private void grow(int minCapacity) { int oldCapacity = data.length; int newCapacity = oldCapacity + (oldCapacity >> 1); if (newCapacity - minCapacity < 0) newCapacity = minCapacity; data = Arrays.copyOf(data, newCapacity); } // always returns a fresh copy int[] toIntArray() { int[] a = new int[size]; System.arraycopy(data, 0, a, 0, size); ret a; } }
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1012238 |
Snippet name: | SimpleIntList |
Eternal ID of this version: | #1012238/8 |
Text MD5: | 1f06ddb709895475103ecf80b4fde86d |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-23 19:04:28 |
Source code size: | 1196 bytes / 49 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 514 / 1082 |
Version history: | 7 change(s) |
Referenced in: | [show references] |