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)

1  
sclass CombinedList<A> extends RandomAccessAbstractList<A> {
2  
  int size;
3  
  new LL<A> lists;
4  
  
5  
  *() {}
6  
  
7  
  void addList(L<A> l) {
8  
    lists.add(l);
9  
    size += l(l);
10  
  }
11  
  
12  
  public int size() { ret size; }
13  
  
14  
  public A get(int index) {
15  
    int idx = 0;
16  
    for (L<A> l : lists) {
17  
      int j = idx+l(l);
18  
      if (index < j)
19  
        ret l.get(index-idx);
20  
      idx = j;
21  
    }
22  
    throw new NoSuchElementException;
23  
  }
24  
}

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: 542 / 1152
Version history: 4 change(s)
Referenced in: [show references]