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

29
LINES

< > BotCompany Repo | #1025480 // TokenIndexedList [dev.]

JavaX fragment (include)

1  
sclass TokenIndexedList extends RandomAccessAbstractList<S> {
2  
  new Map<S, Token> index; // first occurrence of token
3  
  new L<Token> list;
4  
  
5  
  sclass Token {
6  
    S s;
7  
    Token prevSame, nextSame;
8  
  }
9  
  
10  
  public S get(int i) { ret list.get(i).s; }
11  
  public int size() { ret list.size(); }
12  
  public void set(int i, S s) {
13  
    Token t = list.get(i);
14  
    if (eq(t.s, s)) ret;
15  
    
16  
    // remove from chain
17  
    if (t.prevSame == null)
18  
      index.put(t.s, t.nextSame);
19  
    else
20  
      t.prevSame.nextSame = t.nextSame;
21  
    if (t.nextSame != null)
22  
      t.nextSame.prevSame = t.nextSame;
23  
      
24  
    // change token, add to chain
25  
    Token t2 = index.get(s);
26  
    t.s = s;
27  
    ...
28  
  }
29  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025480
Snippet name: TokenIndexedList [dev.]
Eternal ID of this version: #1025480/2
Text MD5: 16b2bd84bb8a5605873b443b6cfeb768
Author: stefan
Category: javax / image analysis
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-30 14:43:46
Source code size: 708 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 214 / 239
Version history: 1 change(s)
Referenced in: [show references]