| 107325 | return this; |
| 107326 | }, |
| 107327 | pulse (pulse1, tuples) { |
| 107328 | const cur = {}, out = {}; |
| 107329 | let i, n, m, f1, t1, id; // build lookup table of current tuples |
| 107330 | for(i = 0, n = tuples.length; i < n; ++i)cur[tupleid(tuples[i])] = 1; |
| 107331 | // process individual tuples to remove |
| 107332 | for(i = 0, n = rem.length; i < n; ++i){ |
| 107333 | t1 = rem[i]; |
| 107334 | cur[tupleid(t1)] = -1; |
| 107335 | } // process predicate-based removals |
| 107336 | for(i = 0, n = remp.length; i < n; ++i){ |
| 107337 | f1 = remp[i]; |
| 107338 | tuples.forEach((t)=>{ |
| 107339 | if (f1(t)) cur[tupleid(t)] = -1; |
| 107340 | }); |
| 107341 | } // process all add tuples |
| 107342 | for(i = 0, n = add1.length; i < n; ++i){ |
| 107343 | t1 = add1[i]; |
| 107344 | id = tupleid(t1); |
| 107345 | if (cur[id]) // tuple already resides in dataset |
| 107346 | // if flagged for both add and remove, cancel |
| 107347 | cur[id] = 1; |
| 107348 | else // tuple does not reside in dataset, add |
| 107349 | pulse1.add.push(ingest$1(add1[i])); |
| 107350 | } // populate pulse rem list |
| 107351 | for(i = 0, n = tuples.length; i < n; ++i){ |
| 107352 | t1 = tuples[i]; |
| 107353 | if (cur[tupleid(t1)] < 0) pulse1.rem.push(t1); |
| 107354 | } // modify helper method |
| 107355 | function modify(t, f, v) { |
| 107356 | if (v) t[f] = v(t); |
| 107357 | else pulse1.encode = f; |
| 107358 | if (!reflow) out[tupleid(t)] = t; |
| 107359 | } // process individual tuples to modify |
| 107360 | for(i = 0, n = mod.length; i < n; ++i){ |
| 107361 | m = mod[i]; |
| 107362 | t1 = m.tuple; |
| 107363 | f1 = m.field; |
| 107364 | id = cur[tupleid(t1)]; |
| 107365 | if (id > 0) { |
| 107366 | modify(t1, f1, m.value); |
| 107367 | pulse1.modifies(f1); |
| 107368 | } |
| 107369 | } // process predicate-based modifications |
| 107370 | for(i = 0, n = modp.length; i < n; ++i){ |
| 107371 | m = modp[i]; |
| 107372 | f1 = m.filter; |
| 107373 | tuples.forEach((t)=>{ |
| 107374 | if (f1(t) && cur[tupleid(t)] > 0) modify(t, m.field, m.value); |
| 107375 | }); |
| 107376 | pulse1.modifies(m.field); |
| 107377 | } // upon reflow request, populate mod with all non-removed tuples |
| 107378 | // otherwise, populate mod with modified tuples only |
| 107379 | if (reflow) pulse1.mod = rem.length || remp.length ? tuples.filter((t)=>cur[tupleid(t)] > 0) : tuples.slice(); |
| 107380 | else for(id in out)pulse1.mod.push(out[id]); |
| 107381 | // set pulse garbage collection request |
| 107382 | if (clean || clean == null && (rem.length || remp.length)) pulse1.clean(true); |
| 107383 | return pulse1; |
| 107384 | } |