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

22
LINES

< > BotCompany Repo | #1022171 // LinkedTreeSet [TreeSet + order of insertion, not synchronized, optimized except for remove]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (59L/1K).

1  
persistable sclass LinkedTreeSet<A> extends AbstractSet<A> {
2  
  Set<A> set;
3  
  new LinkedList<A> list;
4  
  
5  
  *() { set = new TreeSet; }
6  
  *(Set<A> *set) {}
7  
8  
  public int size() { ret list.size(); }
9  
  public Iterator<A> iterator() { ret list.iterator(); }
10  
  public bool contains(O o) { ret set.contains(o); }
11  
  
12  
  public bool add(A a) {
13  
    if (!set.add(a)) false;
14  
    ret true with list.add(a);
15  
  }
16  
  
17  
  // TODO: optimize
18  
  public bool remove(O o) {
19  
    if (!set.remove(o)) false;
20  
    ret true with list.remove(o);
21  
  }
22  
}

Author comment

Began life as a copy of #1018030

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1022171
Snippet name: LinkedTreeSet [TreeSet + order of insertion, not synchronized, optimized except for remove]
Eternal ID of this version: #1022171/6
Text MD5: 277c9c4e474956594a1ccbbaa54ca132
Transpilation MD5: 0033ad2d1ed0cf4a39dce4a774463cdf
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-06 19:48:02
Source code size: 540 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 326 / 884
Version history: 5 change(s)
Referenced in: [show references]