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)

sclass Splitter2<A, B> {
  HashMap<A, MultiSet<B>> map = new HashMap;

  // may return null if unknown
  B get(A a) {
    MultiSet<B> ms = map.get(a);
    ret ms == null ? null : ms.getMostPopularEntry();
  }
  
  void learn(A a, B b) {
    MultiSet<B> ms = map.get(a);
    if (ms == null) map.put(a, ms = new MultiSet);
    ms.add(internIfString(b));
  }
  
  void unlearn(A a, B b) {
    MultiSet<B> ms = map.get(a);
    if (ms == null) ret;
    ms.remove(b);
    if (empty(ms)) map.remove(a);
  }
  
  void clear { map.clear(); }
}

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: 521 / 1103
Version history: 3 change(s)
Referenced in: [show references]