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

Function reinit

docs/app/js/sanddance-app.js:141394–141428  ·  view source on GitHub ↗
(_, pulse)

Source from the content-addressed store, hash-verified

141392 return this.eval(_, pulse);
141393 },
141394 reinit (_, pulse) {
141395 const output = pulse.materialize().fork(), fields = _.fields, query = _.query, indices = this._indices, dims = this._dims, bits = this.value, curr = bits.curr(), prev = bits.prev(), all = bits.all(), out = output.rem = output.add, mod = output.mod, m = query.length, adds = {};
141396 let add, index, key, mods, remMap, modMap, i, n, f; // set prev to current state
141397 prev.set(curr); // if pulse has remove tuples, process them first
141398 if (pulse.rem.length) remMap = this.remove(_, pulse, output);
141399 // if pulse has added tuples, add them to state
141400 if (pulse.add.length) bits.add(pulse.add);
141401 // if pulse has modified tuples, create an index map
141402 if (pulse.mod.length) {
141403 modMap = {};
141404 for(mods = pulse.mod, i = 0, n = mods.length; i < n; ++i)modMap[mods[i]._index] = 1;
141405 } // re-initialize indices as needed, update curr bitmap
141406 for(i = 0; i < m; ++i){
141407 f = fields[i];
141408 if (!dims[i] || _.modified("fields", i) || pulse.modified(f.fields)) {
141409 key = f.fname;
141410 if (!(add = adds[key])) {
141411 indices[key] = index = SortedIndex();
141412 adds[key] = add = index.insert(f, pulse.source, 0);
141413 }
141414 dims[i] = Dimension(index, i, query[i]).onAdd(add, curr);
141415 }
141416 } // visit each tuple
141417 // if filter state changed, push index to add/rem
141418 // else if in mod and passes a filter, push index to mod
141419 for(i = 0, n = bits.data().length; i < n; ++i){
141420 if (remMap[i]) continue;
141421 else if (prev[i] !== curr[i]) // add if state changed
141422 out.push(i);
141423 else if (modMap[i] && curr[i] !== all) // otherwise, pass mods through
141424 mod.push(i);
141425 }
141426 bits.mask = (1 << m) - 1;
141427 return output;
141428 },
141429 eval (_, pulse) {
141430 const output = pulse.materialize().fork(), m = this._dims.length;
141431 let mask = 0;

Callers

nothing calls this directly

Calls 5

SortedIndexFunction · 0.70
DimensionFunction · 0.70
setMethod · 0.45
removeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected