@fluidframework/matrix 2.0.0-dev.5.2.0.169897 → 2.0.0-dev.6.4.0.191258
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -0
- package/README.md +4 -3
- package/dist/handlecache.js +3 -3
- package/dist/handlecache.js.map +1 -1
- package/dist/handletable.d.ts +8 -1
- package/dist/handletable.d.ts.map +1 -1
- package/dist/handletable.js +11 -3
- package/dist/handletable.js.map +1 -1
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +17 -18
- package/dist/matrix.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/permutationvector.d.ts +1 -2
- package/dist/permutationvector.d.ts.map +1 -1
- package/dist/permutationvector.js +11 -8
- package/dist/permutationvector.js.map +1 -1
- package/dist/serialization.js +2 -2
- package/dist/serialization.js.map +1 -1
- package/dist/sparsearray2d.d.ts.map +1 -1
- package/dist/sparsearray2d.js +1 -0
- package/dist/sparsearray2d.js.map +1 -1
- package/dist/undoprovider.js +8 -9
- package/dist/undoprovider.js.map +1 -1
- package/lib/handlecache.js +1 -1
- package/lib/handlecache.js.map +1 -1
- package/lib/handletable.d.ts +8 -1
- package/lib/handletable.d.ts.map +1 -1
- package/lib/handletable.js +11 -3
- package/lib/handletable.js.map +1 -1
- package/lib/matrix.d.ts.map +1 -1
- package/lib/matrix.js +3 -4
- package/lib/matrix.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/permutationvector.d.ts +1 -2
- package/lib/permutationvector.d.ts.map +1 -1
- package/lib/permutationvector.js +6 -3
- package/lib/permutationvector.js.map +1 -1
- package/lib/serialization.js +1 -1
- package/lib/serialization.js.map +1 -1
- package/lib/sparsearray2d.d.ts.map +1 -1
- package/lib/sparsearray2d.js +1 -0
- package/lib/sparsearray2d.js.map +1 -1
- package/lib/undoprovider.js +5 -6
- package/lib/undoprovider.js.map +1 -1
- package/package.json +29 -33
- package/src/handlecache.ts +1 -1
- package/src/handletable.ts +22 -2
- package/src/matrix.ts +2 -1
- package/src/packageVersion.ts +1 -1
- package/src/permutationvector.ts +4 -6
- package/src/serialization.ts +1 -1
- package/src/sparsearray2d.ts +1 -0
- package/src/undoprovider.ts +1 -1
- package/dist/bspSet.d.ts +0 -125
- package/dist/bspSet.d.ts.map +0 -1
- package/dist/bspSet.js +0 -425
- package/dist/bspSet.js.map +0 -1
- package/dist/productSet.d.ts +0 -61
- package/dist/productSet.d.ts.map +0 -1
- package/dist/productSet.js +0 -679
- package/dist/productSet.js.map +0 -1
- package/dist/split.d.ts +0 -41
- package/dist/split.d.ts.map +0 -1
- package/dist/split.js +0 -127
- package/dist/split.js.map +0 -1
- package/lib/bspSet.d.ts +0 -125
- package/lib/bspSet.d.ts.map +0 -1
- package/lib/bspSet.js +0 -402
- package/lib/bspSet.js.map +0 -1
- package/lib/productSet.d.ts +0 -61
- package/lib/productSet.d.ts.map +0 -1
- package/lib/productSet.js +0 -665
- package/lib/productSet.js.map +0 -1
- package/lib/split.d.ts +0 -41
- package/lib/split.d.ts.map +0 -1
- package/lib/split.js +0 -116
- package/lib/split.js.map +0 -1
- package/src/bspSet.ts +0 -722
- package/src/productSet.ts +0 -1038
- package/src/split.ts +0 -171
package/lib/productSet.js
DELETED
|
@@ -1,665 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
6
|
-
var t = {};
|
|
7
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
8
|
-
t[p] = s[p];
|
|
9
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
10
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
11
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
12
|
-
t[p[i]] = s[p[i]];
|
|
13
|
-
}
|
|
14
|
-
return t;
|
|
15
|
-
};
|
|
16
|
-
import { empty, dense, combineCmp, intersectUntyped, compareUntyped, unionUntyped, exceptUntyped, lazy, fromUntyped, meetsUntyped, } from "./bspSet";
|
|
17
|
-
const tops = {};
|
|
18
|
-
const top = (productOperations) => {
|
|
19
|
-
const dims = [];
|
|
20
|
-
for (const dimStr of Object.keys(productOperations)) {
|
|
21
|
-
const dim = dimStr;
|
|
22
|
-
dims.push([dim, productOperations[dim].id]);
|
|
23
|
-
}
|
|
24
|
-
const poKey = JSON.stringify(dims.sort());
|
|
25
|
-
let currTop = tops[poKey];
|
|
26
|
-
if (currTop === undefined) {
|
|
27
|
-
currTop = { box: {}, probabilities: {}, depth: 1 };
|
|
28
|
-
tops[poKey] = currTop;
|
|
29
|
-
}
|
|
30
|
-
return currTop;
|
|
31
|
-
};
|
|
32
|
-
function subspace(bounds) {
|
|
33
|
-
let isDense = true;
|
|
34
|
-
for (const dim of Object.keys(bounds)) {
|
|
35
|
-
if (Object.prototype.hasOwnProperty.call(bounds, dim)) {
|
|
36
|
-
isDense = false;
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (isDense) {
|
|
41
|
-
return dense;
|
|
42
|
-
}
|
|
43
|
-
return { isSubspace: true, bounds };
|
|
44
|
-
}
|
|
45
|
-
function getUntypedSubspaceCount(set) {
|
|
46
|
-
if (set.isSubspace) {
|
|
47
|
-
return 1;
|
|
48
|
-
}
|
|
49
|
-
return set.subspaceCount;
|
|
50
|
-
}
|
|
51
|
-
const union = (left, right, bounds) => ({
|
|
52
|
-
isSubspace: false,
|
|
53
|
-
left,
|
|
54
|
-
right,
|
|
55
|
-
bounds,
|
|
56
|
-
subspaceCount: getUntypedSubspaceCount(left) + getUntypedSubspaceCount(right),
|
|
57
|
-
});
|
|
58
|
-
function sparseProduct(productOperations, root) {
|
|
59
|
-
if (root === dense) {
|
|
60
|
-
return root;
|
|
61
|
-
}
|
|
62
|
-
if (root.isSubspace) {
|
|
63
|
-
let hasSparseDimensions = false;
|
|
64
|
-
for (const dim of Object.keys(root.bounds)) {
|
|
65
|
-
if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {
|
|
66
|
-
hasSparseDimensions = true;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (!hasSparseDimensions) {
|
|
71
|
-
return dense;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return { productOperations, root };
|
|
75
|
-
}
|
|
76
|
-
function toBspSet(set) {
|
|
77
|
-
if (set === undefined) {
|
|
78
|
-
return dense;
|
|
79
|
-
}
|
|
80
|
-
return set;
|
|
81
|
-
}
|
|
82
|
-
/** An object that contains all downcasts. The operations in here are generally of the kind that need dynamic
|
|
83
|
-
* features, i.e. iterate over the object properties somehow. Their *usage* can be considered safe, but they warrant
|
|
84
|
-
* more careful review whenever a change occurs, because we get less support from the type system and we are
|
|
85
|
-
* downcasting. */
|
|
86
|
-
const unsafe = {
|
|
87
|
-
unzip(product) {
|
|
88
|
-
const productOperations = {};
|
|
89
|
-
const root = {};
|
|
90
|
-
for (const dimStr of Object.keys(product)) {
|
|
91
|
-
const dim = dimStr;
|
|
92
|
-
if (Object.prototype.hasOwnProperty.call(product, dim)) {
|
|
93
|
-
const set = product[dim];
|
|
94
|
-
if (set === empty) {
|
|
95
|
-
return empty;
|
|
96
|
-
}
|
|
97
|
-
if (set === dense) {
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
productOperations[dim] = set.setOperations;
|
|
101
|
-
root[dim] = set.root;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return sparseProduct(productOperations, subspace(root));
|
|
105
|
-
},
|
|
106
|
-
combineProduct(productOperations, left, right, combineFunc) {
|
|
107
|
-
const res = {};
|
|
108
|
-
for (const dimStr of Object.keys(productOperations)) {
|
|
109
|
-
const dim = dimStr;
|
|
110
|
-
if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {
|
|
111
|
-
const combined = combineFunc(productOperations[dim], toBspSet(left[dim]), toBspSet(right[dim]));
|
|
112
|
-
if (combined === empty) {
|
|
113
|
-
return combined;
|
|
114
|
-
}
|
|
115
|
-
if (combined === dense) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
res[dim] = combined;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return res;
|
|
122
|
-
},
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
124
|
-
restrict(object, ...props) {
|
|
125
|
-
const res = {};
|
|
126
|
-
for (const key of props) {
|
|
127
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
128
|
-
const prop = object[key];
|
|
129
|
-
res[key] = prop;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return res;
|
|
133
|
-
},
|
|
134
|
-
fromUntypedProduct(productOperations, bounds, dims) {
|
|
135
|
-
const product = {};
|
|
136
|
-
for (const dim of dims) {
|
|
137
|
-
const bound = bounds[dim];
|
|
138
|
-
product[dim] = fromUntyped(productOperations[dim], bound !== undefined ? bound : dense);
|
|
139
|
-
}
|
|
140
|
-
return product;
|
|
141
|
-
},
|
|
142
|
-
denseProduct(dims) {
|
|
143
|
-
const top_inner = {};
|
|
144
|
-
for (const dim of dims) {
|
|
145
|
-
top_inner[dim] = dense;
|
|
146
|
-
}
|
|
147
|
-
return top_inner;
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
export const createFromProduct = unsafe.unzip.bind(unsafe);
|
|
151
|
-
function joinBounds(productOperations, left, right) {
|
|
152
|
-
const join = unsafe.combineProduct(productOperations, left, right, unionUntyped);
|
|
153
|
-
if (join === empty) {
|
|
154
|
-
throw new Error("broken invariant: the union of two non-empty products cannot be empty");
|
|
155
|
-
}
|
|
156
|
-
return join;
|
|
157
|
-
}
|
|
158
|
-
function compareSubspace(productOperations, left, right) {
|
|
159
|
-
let cmp = 0;
|
|
160
|
-
for (const dimStr of Object.keys(productOperations)) {
|
|
161
|
-
const dim = dimStr;
|
|
162
|
-
if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {
|
|
163
|
-
const lProj = toBspSet(left[dim]);
|
|
164
|
-
const rProj = toBspSet(right[dim]);
|
|
165
|
-
const setOperations = productOperations[dim];
|
|
166
|
-
cmp = combineCmp(cmp, compareUntyped(setOperations, lProj, rProj));
|
|
167
|
-
if (cmp === undefined) {
|
|
168
|
-
return undefined;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return cmp;
|
|
173
|
-
}
|
|
174
|
-
const tryUnionSubspaces = (() => {
|
|
175
|
-
const cache = {};
|
|
176
|
-
return (productOperations, left, right) => {
|
|
177
|
-
if (left === cache.left && right === cache.right) {
|
|
178
|
-
return cache.res;
|
|
179
|
-
}
|
|
180
|
-
cache.left = left;
|
|
181
|
-
cache.right = right;
|
|
182
|
-
const cmp = compareSubspace(productOperations, left.bounds, right.bounds);
|
|
183
|
-
if (cmp !== undefined) {
|
|
184
|
-
return (cache.res = cmp <= 0 ? right : left);
|
|
185
|
-
}
|
|
186
|
-
let differentDimension;
|
|
187
|
-
// because Object.keys only returns string[], we need to downcast
|
|
188
|
-
const po_keys = Object.keys(productOperations);
|
|
189
|
-
for (const dim of po_keys) {
|
|
190
|
-
if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {
|
|
191
|
-
const cmp_inner = compareUntyped(productOperations[dim], toBspSet(left.bounds[dim]), toBspSet(right.bounds[dim]));
|
|
192
|
-
if (cmp_inner !== 0) {
|
|
193
|
-
if (differentDimension !== undefined) {
|
|
194
|
-
return (cache.res = undefined);
|
|
195
|
-
}
|
|
196
|
-
differentDimension = dim;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (differentDimension !== undefined) {
|
|
201
|
-
const newDim = unionUntyped(productOperations[differentDimension], toBspSet(left.bounds[differentDimension]), toBspSet(right.bounds[differentDimension]));
|
|
202
|
-
if (newDim === empty) {
|
|
203
|
-
return (cache.res = empty);
|
|
204
|
-
}
|
|
205
|
-
if (newDim === dense) {
|
|
206
|
-
// we are actually deleting the `differentDimension`, so the variable
|
|
207
|
-
// `deleted` must be there. Hence disabling the rule here.
|
|
208
|
-
const _a = left.bounds, _b = differentDimension, deleted = _a[_b], leftBoundsWithoutDifferentDimension = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
209
|
-
return (cache.res = subspace(leftBoundsWithoutDifferentDimension));
|
|
210
|
-
}
|
|
211
|
-
const newBounds = Object.assign(Object.assign({}, left.bounds), { [differentDimension]: newDim });
|
|
212
|
-
return (cache.res = subspace(newBounds));
|
|
213
|
-
}
|
|
214
|
-
return (cache.res = undefined);
|
|
215
|
-
};
|
|
216
|
-
})();
|
|
217
|
-
function combineChildren(productOperations, left, right) {
|
|
218
|
-
if (right === empty) {
|
|
219
|
-
return left;
|
|
220
|
-
}
|
|
221
|
-
if (right === dense) {
|
|
222
|
-
return right;
|
|
223
|
-
}
|
|
224
|
-
if (left === empty) {
|
|
225
|
-
return right;
|
|
226
|
-
}
|
|
227
|
-
if (left === dense) {
|
|
228
|
-
return left;
|
|
229
|
-
}
|
|
230
|
-
if (!left.isSubspace || !right.isSubspace) {
|
|
231
|
-
return union(left, right, joinBounds(productOperations, left.bounds, right.bounds));
|
|
232
|
-
}
|
|
233
|
-
const combinedSubspace = tryUnionSubspaces(productOperations, left, right);
|
|
234
|
-
if (combinedSubspace !== undefined) {
|
|
235
|
-
return combinedSubspace;
|
|
236
|
-
}
|
|
237
|
-
return union(left, right, joinBounds(productOperations, left.bounds, right.bounds));
|
|
238
|
-
}
|
|
239
|
-
function projectUntyped(productOperations, set, ...dims) {
|
|
240
|
-
const bounds = unsafe.restrict(set.bounds, ...dims);
|
|
241
|
-
if (set.isSubspace) {
|
|
242
|
-
return subspace(bounds);
|
|
243
|
-
}
|
|
244
|
-
const lChild = projectUntyped(productOperations, set.left, ...dims);
|
|
245
|
-
if (lChild === dense) {
|
|
246
|
-
return dense;
|
|
247
|
-
}
|
|
248
|
-
const rChild = projectUntyped(productOperations, set.right, ...dims);
|
|
249
|
-
return combineChildren(productOperations, lChild, rChild);
|
|
250
|
-
}
|
|
251
|
-
export function project(set, ...dims) {
|
|
252
|
-
if (set === dense || set === empty) {
|
|
253
|
-
return set;
|
|
254
|
-
}
|
|
255
|
-
const productOperations = unsafe.restrict(set.productOperations, ...dims);
|
|
256
|
-
const root = projectUntyped(productOperations, set.root, ...dims);
|
|
257
|
-
if (root === empty) {
|
|
258
|
-
return root;
|
|
259
|
-
}
|
|
260
|
-
return sparseProduct(productOperations, root);
|
|
261
|
-
}
|
|
262
|
-
function splitBox(productOperations, currentBox) {
|
|
263
|
-
if (currentBox.children !== undefined) {
|
|
264
|
-
return currentBox.children;
|
|
265
|
-
}
|
|
266
|
-
const { box, probabilities } = currentBox;
|
|
267
|
-
let biggestDim;
|
|
268
|
-
let biggestDimKey;
|
|
269
|
-
let currentProb = 0;
|
|
270
|
-
// because Object.keys only returns string[], we need to downcast
|
|
271
|
-
const po_keys = Object.keys(productOperations);
|
|
272
|
-
for (const dim of po_keys) {
|
|
273
|
-
if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {
|
|
274
|
-
const prob = probabilities[dim];
|
|
275
|
-
const setOperations_inner = productOperations[dim];
|
|
276
|
-
if (prob === undefined) {
|
|
277
|
-
biggestDim = dim;
|
|
278
|
-
biggestDimKey = setOperations_inner.top;
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
if (prob > currentProb) {
|
|
282
|
-
const dimensionSet = toBspSet(box[dim]);
|
|
283
|
-
if (dimensionSet === empty) {
|
|
284
|
-
throw new Error("the key split can never return empty");
|
|
285
|
-
}
|
|
286
|
-
let key = setOperations_inner.top;
|
|
287
|
-
if (dimensionSet !== dense) {
|
|
288
|
-
if (!dimensionSet.isExact) {
|
|
289
|
-
throw new Error("the key can always be represented exactly");
|
|
290
|
-
}
|
|
291
|
-
key = dimensionSet.key;
|
|
292
|
-
}
|
|
293
|
-
if (!setOperations_inner.canSplit(key)) {
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
biggestDim = dim;
|
|
297
|
-
currentProb = prob;
|
|
298
|
-
biggestDimKey = key;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
if (biggestDim === undefined || biggestDimKey === undefined) {
|
|
303
|
-
throw new Error("there has to be at least one dimension");
|
|
304
|
-
}
|
|
305
|
-
const setOperations = productOperations[biggestDim];
|
|
306
|
-
const [[leftDim, leftProb], [rightDim, rightProb]] = setOperations.split(biggestDimKey);
|
|
307
|
-
const res = [
|
|
308
|
-
{
|
|
309
|
-
box: Object.assign(Object.assign({}, box), { [biggestDim]: lazy(setOperations, setOperations.top, leftDim) }),
|
|
310
|
-
probabilities: Object.assign(Object.assign({}, probabilities), { [biggestDim]: leftProb }),
|
|
311
|
-
depth: currentBox.depth + 1,
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
box: Object.assign(Object.assign({}, box), { [biggestDim]: lazy(setOperations, setOperations.top, rightDim) }),
|
|
315
|
-
probabilities: Object.assign(Object.assign({}, probabilities), { [biggestDim]: rightProb }),
|
|
316
|
-
depth: currentBox.depth + 1,
|
|
317
|
-
},
|
|
318
|
-
];
|
|
319
|
-
if (currentBox.depth < 10) {
|
|
320
|
-
currentBox.children = res;
|
|
321
|
-
}
|
|
322
|
-
return res;
|
|
323
|
-
}
|
|
324
|
-
function restrictByBounds(productOperations, set, leftBounds, rightBounds) {
|
|
325
|
-
if (set === empty) {
|
|
326
|
-
return [empty, empty];
|
|
327
|
-
}
|
|
328
|
-
if (set === dense) {
|
|
329
|
-
return [subspace(leftBounds), subspace(rightBounds)];
|
|
330
|
-
}
|
|
331
|
-
const cmp = compareSubspace(productOperations, set.bounds, leftBounds);
|
|
332
|
-
// the set is fully contained in the left half, i.e. we know the pair.
|
|
333
|
-
if (cmp !== undefined && cmp <= 0) {
|
|
334
|
-
return [set, empty];
|
|
335
|
-
}
|
|
336
|
-
const newLeftBounds = unsafe.combineProduct(productOperations, set.bounds, leftBounds, intersectUntyped);
|
|
337
|
-
// if we know, that the left set is completely empty, then the whole set is in the right bounds.
|
|
338
|
-
if (newLeftBounds === empty) {
|
|
339
|
-
return [empty, set];
|
|
340
|
-
}
|
|
341
|
-
const newRightBounds = unsafe.combineProduct(productOperations, set.bounds, rightBounds, intersectUntyped);
|
|
342
|
-
if (set.isSubspace) {
|
|
343
|
-
return [
|
|
344
|
-
subspace(newLeftBounds),
|
|
345
|
-
newRightBounds === empty ? empty : subspace(newRightBounds),
|
|
346
|
-
];
|
|
347
|
-
}
|
|
348
|
-
const [ll, lr] = restrictByBounds(productOperations, set.left, leftBounds, rightBounds);
|
|
349
|
-
const [rl, rr] = restrictByBounds(productOperations, set.right, leftBounds, rightBounds);
|
|
350
|
-
return [combineChildren(productOperations, ll, rl), combineChildren(productOperations, lr, rr)];
|
|
351
|
-
}
|
|
352
|
-
const splitByBox = (productOperations, set, { box: leftBounds }, { box: rightBounds }) => {
|
|
353
|
-
return restrictByBounds(productOperations, set, leftBounds, rightBounds);
|
|
354
|
-
};
|
|
355
|
-
function recurse(productOperations, left, right, currentBox, visitFunc) {
|
|
356
|
-
const [leftBox, rightBox] = splitBox(productOperations, currentBox);
|
|
357
|
-
const [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);
|
|
358
|
-
const [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);
|
|
359
|
-
const lChild = visitFunc(productOperations, ll, rl, leftBox);
|
|
360
|
-
if (lChild === dense) {
|
|
361
|
-
return dense;
|
|
362
|
-
}
|
|
363
|
-
const rChild = visitFunc(productOperations, lr, rr, rightBox);
|
|
364
|
-
return combineChildren(productOperations, lChild, rChild);
|
|
365
|
-
}
|
|
366
|
-
function unionUntypedProduct(productOperations, left, right, currentBox) {
|
|
367
|
-
if (right === empty) {
|
|
368
|
-
return left;
|
|
369
|
-
}
|
|
370
|
-
if (left === empty) {
|
|
371
|
-
return right;
|
|
372
|
-
}
|
|
373
|
-
if (left === dense) {
|
|
374
|
-
return left;
|
|
375
|
-
}
|
|
376
|
-
if (right === dense) {
|
|
377
|
-
return right;
|
|
378
|
-
}
|
|
379
|
-
if (left.isSubspace && right.isSubspace) {
|
|
380
|
-
const combinedSubspace = tryUnionSubspaces(productOperations, left, right);
|
|
381
|
-
if (combinedSubspace !== undefined) {
|
|
382
|
-
return combinedSubspace;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return recurse(productOperations, left, right, currentBox, unionUntypedProduct);
|
|
386
|
-
}
|
|
387
|
-
export function unionProduct(left, right) {
|
|
388
|
-
if (right === empty) {
|
|
389
|
-
return left;
|
|
390
|
-
}
|
|
391
|
-
if (right === dense) {
|
|
392
|
-
return right;
|
|
393
|
-
}
|
|
394
|
-
if (left === empty) {
|
|
395
|
-
return right;
|
|
396
|
-
}
|
|
397
|
-
if (left === dense) {
|
|
398
|
-
return left;
|
|
399
|
-
}
|
|
400
|
-
const productOperations = Object.assign(Object.assign({}, left.productOperations), right.productOperations);
|
|
401
|
-
const res = unionUntypedProduct(productOperations, left.root, right.root, top(productOperations));
|
|
402
|
-
if (res === empty) {
|
|
403
|
-
return res;
|
|
404
|
-
}
|
|
405
|
-
return sparseProduct(productOperations, res);
|
|
406
|
-
}
|
|
407
|
-
function intersectUntypedProduct(productOperations, left, right, currentBox) {
|
|
408
|
-
if (left === empty || right === empty) {
|
|
409
|
-
return empty;
|
|
410
|
-
}
|
|
411
|
-
if (left === dense) {
|
|
412
|
-
return right;
|
|
413
|
-
}
|
|
414
|
-
if (right === dense) {
|
|
415
|
-
return left;
|
|
416
|
-
}
|
|
417
|
-
if (left.isSubspace && right.isSubspace) {
|
|
418
|
-
const res = unsafe.combineProduct(productOperations, left.bounds, right.bounds, intersectUntyped);
|
|
419
|
-
if (res === empty) {
|
|
420
|
-
return empty;
|
|
421
|
-
}
|
|
422
|
-
return subspace(res);
|
|
423
|
-
}
|
|
424
|
-
return recurse(productOperations, left, right, currentBox, intersectUntypedProduct);
|
|
425
|
-
}
|
|
426
|
-
export function intersectProduct(left, right) {
|
|
427
|
-
if (left === empty) {
|
|
428
|
-
return left;
|
|
429
|
-
}
|
|
430
|
-
if (right === empty) {
|
|
431
|
-
return right;
|
|
432
|
-
}
|
|
433
|
-
if (left === dense) {
|
|
434
|
-
return right;
|
|
435
|
-
}
|
|
436
|
-
if (right === dense) {
|
|
437
|
-
return left;
|
|
438
|
-
}
|
|
439
|
-
const productOperations = Object.assign(Object.assign({}, left.productOperations), right.productOperations);
|
|
440
|
-
const res = intersectUntypedProduct(productOperations, left.root, right.root, top(productOperations));
|
|
441
|
-
if (res === empty) {
|
|
442
|
-
return res;
|
|
443
|
-
}
|
|
444
|
-
return sparseProduct(productOperations, res);
|
|
445
|
-
}
|
|
446
|
-
function tryExceptSubspaces(productOperations, left, right) {
|
|
447
|
-
const cmp = compareSubspace(productOperations, left.bounds, right.bounds);
|
|
448
|
-
if (cmp === 0 || cmp === -1) {
|
|
449
|
-
return empty;
|
|
450
|
-
}
|
|
451
|
-
let notContainedDimension;
|
|
452
|
-
// because Object.keys only returns string[], we need to downcast
|
|
453
|
-
const po_keys = Object.keys(productOperations);
|
|
454
|
-
for (const dim of po_keys) {
|
|
455
|
-
if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {
|
|
456
|
-
const cmp_inner = compareUntyped(productOperations[dim], toBspSet(left.bounds[dim]), toBspSet(right.bounds[dim]));
|
|
457
|
-
if (cmp_inner === undefined || cmp_inner > 0) {
|
|
458
|
-
if (notContainedDimension !== undefined) {
|
|
459
|
-
return undefined;
|
|
460
|
-
}
|
|
461
|
-
notContainedDimension = dim;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if (notContainedDimension !== undefined) {
|
|
466
|
-
const newDim = exceptUntyped(productOperations[notContainedDimension], toBspSet(left.bounds[notContainedDimension]), toBspSet(right.bounds[notContainedDimension]));
|
|
467
|
-
if (newDim === empty) {
|
|
468
|
-
return empty;
|
|
469
|
-
}
|
|
470
|
-
if (newDim === dense) {
|
|
471
|
-
// we are actually deleting the `differentDimension`, so the variable
|
|
472
|
-
// `deleted` must be there. Hence disabling the rule here.
|
|
473
|
-
const _a = left.bounds, _b = notContainedDimension, deleted = _a[_b], leftBoundsWithoutDifferentDimension = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
474
|
-
return subspace(leftBoundsWithoutDifferentDimension);
|
|
475
|
-
}
|
|
476
|
-
const newBounds = Object.assign(Object.assign({}, left.bounds), { [notContainedDimension]: newDim });
|
|
477
|
-
return subspace(newBounds);
|
|
478
|
-
}
|
|
479
|
-
return undefined;
|
|
480
|
-
}
|
|
481
|
-
function exceptUntypedProduct(productOperations, left, right, currentBox) {
|
|
482
|
-
if (left === empty) {
|
|
483
|
-
return left;
|
|
484
|
-
}
|
|
485
|
-
if (right === dense) {
|
|
486
|
-
return empty;
|
|
487
|
-
}
|
|
488
|
-
if (right === empty) {
|
|
489
|
-
return left;
|
|
490
|
-
}
|
|
491
|
-
if (left === dense) {
|
|
492
|
-
return recurse(productOperations, left, right, currentBox, exceptUntypedProduct);
|
|
493
|
-
}
|
|
494
|
-
if (left.isSubspace && right.isSubspace) {
|
|
495
|
-
const combinedSubspace = tryExceptSubspaces(productOperations, left, right);
|
|
496
|
-
if (combinedSubspace !== undefined) {
|
|
497
|
-
return combinedSubspace;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
return recurse(productOperations, left, right, currentBox, exceptUntypedProduct);
|
|
501
|
-
}
|
|
502
|
-
export function exceptProduct(left, right) {
|
|
503
|
-
if (left === empty) {
|
|
504
|
-
return left;
|
|
505
|
-
}
|
|
506
|
-
if (right === empty) {
|
|
507
|
-
return left;
|
|
508
|
-
}
|
|
509
|
-
if (right === dense) {
|
|
510
|
-
return empty;
|
|
511
|
-
}
|
|
512
|
-
if (left === dense) {
|
|
513
|
-
const res_inner = exceptUntypedProduct(right.productOperations, dense, right.root, top(right.productOperations));
|
|
514
|
-
if (res_inner === empty) {
|
|
515
|
-
return res_inner;
|
|
516
|
-
}
|
|
517
|
-
return sparseProduct(right.productOperations, res_inner);
|
|
518
|
-
}
|
|
519
|
-
const productOperations = Object.assign(Object.assign({}, left.productOperations), right.productOperations);
|
|
520
|
-
const res = exceptUntypedProduct(productOperations, left.root, right.root, top(productOperations));
|
|
521
|
-
if (res === empty) {
|
|
522
|
-
return res;
|
|
523
|
-
}
|
|
524
|
-
return sparseProduct(productOperations, res);
|
|
525
|
-
}
|
|
526
|
-
function compareUntypedProduct(productOperations, left, right, boundingBox) {
|
|
527
|
-
if (left === right) {
|
|
528
|
-
return 0;
|
|
529
|
-
}
|
|
530
|
-
if (left === empty) {
|
|
531
|
-
return -1;
|
|
532
|
-
}
|
|
533
|
-
if (right === empty) {
|
|
534
|
-
return 1;
|
|
535
|
-
}
|
|
536
|
-
if (left === dense) {
|
|
537
|
-
if (right === dense) {
|
|
538
|
-
return 0;
|
|
539
|
-
}
|
|
540
|
-
return 1;
|
|
541
|
-
}
|
|
542
|
-
if (right === dense) {
|
|
543
|
-
return -1;
|
|
544
|
-
}
|
|
545
|
-
if (left.isSubspace) {
|
|
546
|
-
if (right.isSubspace) {
|
|
547
|
-
return compareSubspace(productOperations, left.bounds, right.bounds);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
const [leftBox, rightBox] = splitBox(productOperations, boundingBox);
|
|
551
|
-
const [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);
|
|
552
|
-
const [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);
|
|
553
|
-
const leftCmp = compareUntypedProduct(productOperations, ll, rl, leftBox);
|
|
554
|
-
if (leftCmp === undefined) {
|
|
555
|
-
return undefined;
|
|
556
|
-
}
|
|
557
|
-
return combineCmp(leftCmp, compareUntypedProduct(productOperations, lr, rr, rightBox));
|
|
558
|
-
}
|
|
559
|
-
export function compareProduct(left, right) {
|
|
560
|
-
if (left === right) {
|
|
561
|
-
return 0;
|
|
562
|
-
}
|
|
563
|
-
if (left === empty) {
|
|
564
|
-
return -1;
|
|
565
|
-
}
|
|
566
|
-
if (right === empty) {
|
|
567
|
-
return 1;
|
|
568
|
-
}
|
|
569
|
-
if (left === dense) {
|
|
570
|
-
if (right === dense) {
|
|
571
|
-
return 0;
|
|
572
|
-
}
|
|
573
|
-
return 1;
|
|
574
|
-
}
|
|
575
|
-
if (right === dense) {
|
|
576
|
-
return -1;
|
|
577
|
-
}
|
|
578
|
-
const productOperations = Object.assign(Object.assign({}, left.productOperations), right.productOperations);
|
|
579
|
-
return compareUntypedProduct(productOperations, left.root, right.root, top(productOperations));
|
|
580
|
-
}
|
|
581
|
-
function meetsSubspace(productOperations, left, right) {
|
|
582
|
-
for (const dimStr of Object.keys(productOperations)) {
|
|
583
|
-
const dim = dimStr;
|
|
584
|
-
if (Object.prototype.hasOwnProperty.call(productOperations, dim)) {
|
|
585
|
-
const lProj = toBspSet(left[dim]);
|
|
586
|
-
const rProj = toBspSet(right[dim]);
|
|
587
|
-
const setOperations = productOperations[dim];
|
|
588
|
-
if (!meetsUntyped(setOperations, lProj, rProj)) {
|
|
589
|
-
return false;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
return true;
|
|
594
|
-
}
|
|
595
|
-
function meetsUntypedProduct(productOperations, left, right, boundingBox) {
|
|
596
|
-
if (left === empty || right === empty) {
|
|
597
|
-
return false;
|
|
598
|
-
}
|
|
599
|
-
if (left === dense || right === dense) {
|
|
600
|
-
return true;
|
|
601
|
-
}
|
|
602
|
-
if (!meetsSubspace(productOperations, left.bounds, right.bounds)) {
|
|
603
|
-
return false;
|
|
604
|
-
}
|
|
605
|
-
if (left.isSubspace && right.isSubspace) {
|
|
606
|
-
return true;
|
|
607
|
-
}
|
|
608
|
-
const [leftBox, rightBox] = splitBox(productOperations, boundingBox);
|
|
609
|
-
const [ll, lr] = splitByBox(productOperations, left, leftBox, rightBox);
|
|
610
|
-
const [rl, rr] = splitByBox(productOperations, right, leftBox, rightBox);
|
|
611
|
-
return (meetsUntypedProduct(productOperations, ll, rl, leftBox) ||
|
|
612
|
-
meetsUntypedProduct(productOperations, lr, rr, rightBox));
|
|
613
|
-
}
|
|
614
|
-
export function meetsProduct(left, right) {
|
|
615
|
-
if (left === empty || right === empty) {
|
|
616
|
-
return false;
|
|
617
|
-
}
|
|
618
|
-
if (left === dense || right === dense) {
|
|
619
|
-
return true;
|
|
620
|
-
}
|
|
621
|
-
const productOperations = Object.assign(Object.assign({}, left.productOperations), right.productOperations);
|
|
622
|
-
return meetsUntypedProduct(productOperations, left.root, right.root, top(productOperations));
|
|
623
|
-
}
|
|
624
|
-
export const complementProduct = (set) => exceptProduct(dense, set);
|
|
625
|
-
export const symmetricDiffProduct = (left, right) => unionProduct(exceptProduct(left, right), exceptProduct(right, left));
|
|
626
|
-
export function getSubspaces(set) {
|
|
627
|
-
if (set === empty || set === dense) {
|
|
628
|
-
return [];
|
|
629
|
-
}
|
|
630
|
-
const res = [];
|
|
631
|
-
function loop(root) {
|
|
632
|
-
if (root.isSubspace) {
|
|
633
|
-
res.push(root.bounds);
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
loop(root.left);
|
|
637
|
-
loop(root.right);
|
|
638
|
-
}
|
|
639
|
-
loop(set.root);
|
|
640
|
-
return res;
|
|
641
|
-
}
|
|
642
|
-
export function forEachProduct(set, f, ...dims) {
|
|
643
|
-
const newSet = project(set, ...dims);
|
|
644
|
-
if (newSet === empty) {
|
|
645
|
-
return true;
|
|
646
|
-
}
|
|
647
|
-
if (newSet === dense) {
|
|
648
|
-
return f(unsafe.denseProduct(dims));
|
|
649
|
-
}
|
|
650
|
-
const { productOperations, root } = newSet;
|
|
651
|
-
function loop(root_inner) {
|
|
652
|
-
if (root_inner.isSubspace) {
|
|
653
|
-
return f(unsafe.fromUntypedProduct(productOperations, root_inner.bounds, dims));
|
|
654
|
-
}
|
|
655
|
-
return loop(root_inner.left) && loop(root_inner.right);
|
|
656
|
-
}
|
|
657
|
-
return loop(root);
|
|
658
|
-
}
|
|
659
|
-
export function getSubspaceCount(set) {
|
|
660
|
-
if (set === empty || set === dense) {
|
|
661
|
-
return 0;
|
|
662
|
-
}
|
|
663
|
-
return getUntypedSubspaceCount(set.root);
|
|
664
|
-
}
|
|
665
|
-
//# sourceMappingURL=productSet.js.map
|