MCPcopy Create free account
hub / github.com/microsoft/SandDance / update2

Function update2

docs/app/js/sanddance-app.js:118420–118432  ·  view source on GitHub ↗
(t)

Source from the content-addressed store, hash-verified

118418 const out = pulse.fork(pulse.NO_SOURCE), mod = _.modified("size"), num = _.size, map = this.value.reduce((m, t)=>(m[(0, _vegaDataflow.tupleid)(t)] = 1, m), {});
118419 let res = this.value, cnt = this.count, cap = 0; // sample reservoir update function
118420 function update2(t) {
118421 let p, idx;
118422 if (res.length < num) res.push(t);
118423 else {
118424 idx = ~~((cnt + 1) * (0, _vegaStatistics.random)());
118425 if (idx < res.length && idx >= cap) {
118426 p = res[idx];
118427 if (map[(0, _vegaDataflow.tupleid)(p)]) out.rem.push(p); // eviction
118428 res[idx] = t;
118429 }
118430 }
118431 ++cnt;
118432 }
118433 if (pulse.rem.length) {
118434 // find all tuples that should be removed, add to output
118435 pulse.visit(pulse.REM, (t)=>{

Callers 1

transformFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected