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

40
LINES

< > BotCompany Repo | #1002526 // CondensedStrings (include)

JavaX fragment (include)

static class CondensedStrings extends AbstractList<S> {
  char[] data;
  int[] indices;
  
  *(L<S> l) {
    long totalLength = 0;
    for (S s : l) totalLength += l(s);
    int len = (int) totalLength;
    if (len != totalLength) fail("TOO BIG!!!!!! " + totalLength);
    data = new char[len];
    int n = l(l);
    indices = new int[n];
    int idx = 0;
    for (int i = 0; i < n; i++) {
      S s = l.get(i);
      try {
        s.getChars(0, l(s), data, idx);
        indices[i] = idx;
        idx += l(s);
      } catch (RuntimeException e) {
        print("idx=" + idx + ", s=" + s + ", i=" + i +", n=" + n + ", len=" + len);
        throw e;
      }
    }
  }
  
  public S get(int i) {
    int idx1 = indices[i];
    int idx2 = i+1 < indices.length ? indices[i+1] : data.length;
    ret new String(data, idx1, idx2-idx1);
  }
  
  public int size() {
    ret indices.length;
  }
  
  int totalSize() {
    ret data.length;
  }
}

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: 562 / 498
Referenced in: #1002528 - CondensedStrings2 (include)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)