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).

persistable sclass LinkedTreeSet<A> extends AbstractSet<A> {
  Set<A> set;
  new LinkedList<A> list;
  
  *() { set = new TreeSet; }
  *(Set<A> *set) {}

  public int size() { ret list.size(); }
  public Iterator<A> iterator() { ret list.iterator(); }
  public bool contains(O o) { ret set.contains(o); }
  
  public bool add(A a) {
    if (!set.add(a)) false;
    ret true with list.add(a);
  }
  
  // TODO: optimize
  public bool remove(O o) {
    if (!set.remove(o)) false;
    ret true with list.remove(o);
  }
}

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: 327 / 885
Version history: 5 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)