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

14
LINES

< > BotCompany Repo | #1011596 // WeakHashSet (hopefully complete, synchronized)

JavaX fragment (include)

1  
sclass WeakHashSet<A> extends AbstractSet<A> {
2  
  Map<A, Bool> map = newWeakHashMap();
3  
  
4  
  public int size() { ret map.size(); }
5  
  public Iterator<A> iterator() { ret keys(map).iterator(); }
6  
  public bool contains(O o) { ret map.containsKey(o); }
7  
  
8  
  public bool add(A a) {
9  
    ret map.put(a, Bool.TRUE) != null;
10  
  }
11  
  public bool remove(O o) { ret map.remove(o) != null; }
12  
  
13  
  O mutex() { ret collectionMutex(map); }
14  
}

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: #1011596
Snippet name: WeakHashSet (hopefully complete, synchronized)
Eternal ID of this version: #1011596/8
Text MD5: 7b4383335b06d9e412fc848b5735521b
Author: stefan
Category: javax / collections
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-11 15:13:34
Source code size: 434 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 563 / 2258
Version history: 7 change(s)
Referenced in: [show references]