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

24
LINES

< > BotCompany Repo | #1012347 // CombinedList - concatenated immutable list that preserves laziness - fast access near the beginning

JavaX fragment (include)

sclass CombinedList<A> extends RandomAccessAbstractList<A> {
  int size;
  new LL<A> lists;
  
  *() {}
  
  void addList(L<A> l) {
    lists.add(l);
    size += l(l);
  }
  
  public int size() { ret size; }
  
  public A get(int index) {
    int idx = 0;
    for (L<A> l : lists) {
      int j = idx+l(l);
      if (index < j)
        ret l.get(index-idx);
      idx = j;
    }
    throw new NoSuchElementException;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1012347
Snippet name: CombinedList - concatenated immutable list that preserves laziness - fast access near the beginning
Eternal ID of this version: #1012347/5
Text MD5: 5441bb75086a03e26f621fa835743850
Author: stefan
Category: javax / collections
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-09 23:34:54
Source code size: 446 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 452 / 1055
Version history: 4 change(s)
Referenced in: [show references]