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

22
LINES

< > BotCompany Repo | #1032183 // PMapCollector - probabilistic map collector (collects key-value pairs during a probabilistic computation)

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

Libraryless. Click here for Pure Java version (3241L/18K).

// a scheduler isn't actually referenced, but might be
// (e.g. for collection stats)
sclass PMapCollector<A, B> /*extends Probabilistic*/ {
  new Map<A, B> map;
  new L<IVF2<A, B>> onNewEntry;
  new L<IVF3<A, B, B>> onChangedEntry;
  
  *() {}
  *(Map<A, B> *map) {}
  
  void put(A key, B value) {
    bool isNew = !map.containsKey(key);
    B oldValue = null;
    bool isChanged = !isNew && !eq(oldValue = map.get(key), value);
    if (isNew || isChanged)
      map.put(key, value);
    if (isNew)
      pcallFAll(onNewEntry, key, value);
    else
      pcallFAll(onChangedEntry, key, oldValue, value);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032183
Snippet name: PMapCollector - probabilistic map collector (collects key-value pairs during a probabilistic computation)
Eternal ID of this version: #1032183/6
Text MD5: 98f017f84d9b18ae6767d4e561358052
Transpilation MD5: 6fde69a44bcc1eebb4e688c988b2fbce
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-17 19:52:35
Source code size: 632 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 206 / 349
Version history: 5 change(s)
Referenced in: #1032184 - pSortedMapCollector
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)