| 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)=>{ |