Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function update(t) {
var p, idx;
if (res.length < num) {
res.push(t);
} else {
idx = ~~((cnt + 1) * random());
if (idx < res.length && idx >= cap) {
p = res[idx];
if (map[tupleid(p)]) out.rem.push(p); // eviction
res[idx] = t;
}
}
++cnt;
}
pulse.visit(pulse.MOD, function(t) {
var id = tupleid(t),
k0 = cache.get(id),
k1 = key(t);
if (k0 === k1) {
subflow(k1).mod(t);
} else {
cache.set(id, k1);
subflow(k0).rem(t);
subflow(k1).add(t);
}
});
} else if (pulse.changed(pulse.MOD)) {
pulse.visit(pulse.REM, function(t) {
var id = tupleid(t);
out.rem.push(lut[id]);
lut[id] = null;
});
pulse.visit(pulse.REM, function(t) {
var id = tupleid(t);
if (map[id]) {
map[id] = -1;
out.rem.push(t);
}
--cnt;
});
pulse.visit(pulse.MOD, function(t) {
subflow(cache.get(tupleid(t))).mod(t);
});
}
pulse.visit(pulse.SOURCE, function(t) { lut[tupleid(t)] = 1; });
pulse.visit(pulse.REM, function(t) {
var id = tupleid(t);
out.rem.push(lut[id]);
lut[id] = null;
});
pulse.visit(pulse.REM, function(t) {
var id = tupleid(t),
k = cache.get(id);
if (k !== undefined) {
cache.delete(id);
subflow(k).rem(t);
}
});
tree.each(function(node) {
var t = node.data,
p = node.parent && node.parent.data;
if (p && lut[tupleid(t)] && lut[tupleid(p)]) {
out.add.push(ingest({source: p, target: t}));
}
});
this.value = out.add;
links.forEach(function(link) {
if (lut[tupleid(link.source)] || lut[tupleid(link.target)]) {
out.mod.push(link);
}
});
}