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

24
LINES

< > BotCompany Repo | #1009691 // Splitter2 - sorts things in many categories, collects examples with occurrence count

JavaX fragment (include)

1  
sclass Splitter2<A, B> {
2  
  HashMap<A, MultiSet<B>> map = new HashMap;
3  
4  
  // may return null if unknown
5  
  B get(A a) {
6  
    MultiSet<B> ms = map.get(a);
7  
    ret ms == null ? null : ms.getMostPopularEntry();
8  
  }
9  
  
10  
  void learn(A a, B b) {
11  
    MultiSet<B> ms = map.get(a);
12  
    if (ms == null) map.put(a, ms = new MultiSet);
13  
    ms.add(internIfString(b));
14  
  }
15  
  
16  
  void unlearn(A a, B b) {
17  
    MultiSet<B> ms = map.get(a);
18  
    if (ms == null) ret;
19  
    ms.remove(b);
20  
    if (empty(ms)) map.remove(a);
21  
  }
22  
  
23  
  void clear { map.clear(); }
24  
}

Author comment

Began life as a copy of #1009690

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009691
Snippet name: Splitter2 - sorts things in many categories, collects examples with occurrence count
Eternal ID of this version: #1009691/4
Text MD5: c6793c59ecf9a8004a94451cc784351f
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-14 17:21:38
Source code size: 557 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 453 / 1029
Version history: 3 change(s)
Referenced in: [show references]