MCPcopy Index your code
hub / github.com/microsoft/SandDance / Bitmaps

Function Bitmaps

docs/app/js/sanddance-app.js:141167–141221  ·  view source on GitHub ↗

* Maintains CrossFilter state.

()

Source from the content-addressed store, hash-verified

141165/**
141166 * Maintains CrossFilter state.
141167 */ function Bitmaps() {
141168 let width = 8, data = [], seen = array32(0), curr = array(0, width), prev = array(0, width);
141169 return {
141170 data: ()=>data,
141171 seen: ()=>seen = lengthen(seen, data.length),
141172 add (array1) {
141173 for(let i = 0, j = data.length, n = array1.length, t; i < n; ++i){
141174 t = array1[i];
141175 t._index = j++;
141176 data.push(t);
141177 }
141178 },
141179 remove (num, map) {
141180 // map: index -> boolean (true => remove)
141181 const n = data.length, copy = Array(n - num), reindex = data; // reuse old data array for index map
141182 let t, i, j; // seek forward to first removal
141183 for(i = 0; !map[i] && i < n; ++i){
141184 copy[i] = data[i];
141185 reindex[i] = i;
141186 } // condense arrays
141187 for(j = i; i < n; ++i){
141188 t = data[i];
141189 if (!map[i]) {
141190 reindex[i] = j;
141191 curr[j] = curr[i];
141192 prev[j] = prev[i];
141193 copy[j] = t;
141194 t._index = j++;
141195 } else reindex[i] = -1;
141196 curr[i] = 0; // clear unused bits
141197 }
141198 data = copy;
141199 return reindex;
141200 },
141201 size: ()=>data.length,
141202 curr: ()=>curr,
141203 prev: ()=>prev,
141204 reset: (k)=>prev[k] = curr[k],
141205 all: ()=>width < 0x101 ? 0xff : width < 0x10001 ? 0xffff : 0xffffffff,
141206 set (k, one) {
141207 curr[k] |= one;
141208 },
141209 clear (k, one) {
141210 curr[k] &= ~one;
141211 },
141212 resize (n, m) {
141213 const k = curr.length;
141214 if (n > k || m > width) {
141215 width = Math.max(m, width);
141216 curr = array(n, width, curr);
141217 prev = array(n, width);
141218 }
141219 }
141220 };
141221}
141222function lengthen(array2, length, copy) {
141223 if (array2.length >= length) return array2;
141224 copy = copy || new array2.constructor(length);

Callers 1

CrossFilterFunction · 0.70

Calls 3

array32Function · 0.70
arrayFunction · 0.70
lengthenFunction · 0.70

Tested by

no test coverage detected