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