Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

44
LINES

< > BotCompany Repo | #1002525 // Compact String List Test (v1, char array with indices, developing)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (579L/5K/15K).

1  
!752
2  
3  
static class CondensedStrings {
4  
  char[] data;
5  
  int[] indices;
6  
  
7  
  *(L<S> l) {
8  
    long totalLength = 0;
9  
    for (S s : l) totalLength += l(s);
10  
    int len = (int) totalLength;
11  
    if (len != totalLength) fail("TOO BIG!!!!!! " + totalLength);
12  
    data = new char[len];
13  
    int n = l(l);
14  
    indices = new int[n];
15  
    int idx = 0;
16  
    for (int i = 0; i < n; i++) {
17  
      S s = l.get(i);
18  
      try {
19  
        s.getChars(0, l(s), data, idx);
20  
        indices[i] = idx;
21  
        idx += l(s);
22  
      } catch (RuntimeException e) {
23  
        print("idx=" + idx + ", s=" + s + ", i=" + i +", n=" + n + ", len=" + len);
24  
        throw e;
25  
      }
26  
    }
27  
  }
28  
  
29  
  S get(int i) {
30  
    int idx1 = indices[i];
31  
    int idx2 = i+1 < indices.length ? indices[i+1] : data.length;
32  
    ret new String(data, idx1, idx2-idx1);
33  
  }
34  
  
35  
  int size() {
36  
    ret indices.length;
37  
  }
38  
}
39  
40  
p {
41  
  CondensedStrings cs = new CondensedStrings(litlist("hello", "world!"));
42  
  print(quote(cs.get(0)));
43  
  print(quote(cs.get(1)));
44  
}

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: #1002525
Snippet name: Compact String List Test (v1, char array with indices, developing)
Eternal ID of this version: #1002525/1
Text MD5: 6e35d679e5e0e138811e045707db5103
Transpilation MD5: b6d62cc7ec9cfb578034224b7c5f4d84
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-30 23:18:06
Source code size: 1034 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 575 / 588
Referenced in: [show references]