1 | static class CondensedStrings extends AbstractList<S> { |
2 | char[] data; |
3 | int[] indices; |
4 | |
5 | *(L<S> l) { |
6 | long totalLength = 0; |
7 | for (S s : l) totalLength += l(s); |
8 | int len = (int) totalLength; |
9 | if (len != totalLength) fail("TOO BIG!!!!!! " + totalLength); |
10 | data = new char[len]; |
11 | int n = l(l); |
12 | indices = new int[n]; |
13 | int idx = 0; |
14 | for (int i = 0; i < n; i++) { |
15 | S s = l.get(i); |
16 | try { |
17 | s.getChars(0, l(s), data, idx); |
18 | indices[i] = idx; |
19 | idx += l(s); |
20 | } catch (RuntimeException e) { |
21 | print("idx=" + idx + ", s=" + s + ", i=" + i +", n=" + n + ", len=" + len); |
22 | throw e; |
23 | } |
24 | } |
25 | } |
26 | |
27 | public S get(int i) { |
28 | int idx1 = indices[i]; |
29 | int idx2 = i+1 < indices.length ? indices[i+1] : data.length; |
30 | ret new String(data, idx1, idx2-idx1); |
31 | } |
32 | |
33 | public int size() { |
34 | ret indices.length; |
35 | } |
36 | |
37 | int totalSize() { |
38 | ret data.length; |
39 | } |
40 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002526 |
Snippet name: | CondensedStrings (include) |
Eternal ID of this version: | #1002526/1 |
Text MD5: | 2827b4e777b0ad3af6a140a1a56c26c4 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-01-30 23:31:48 |
Source code size: | 975 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 563 / 499 |
Referenced in: | [show references] |