@fluidframework/matrix 2.0.0-dev.5.3.2.178189 → 2.0.0-dev.6.4.0.191457
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 +51 -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.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.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 +27 -31
- 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 +3 -4
- 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/src/split.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { SetOperations, Pair } from "./bspSet";
|
|
7
|
-
|
|
8
|
-
/** Represents a half-open interval [a, b) */
|
|
9
|
-
export type Ivl<Index extends number = number> = Pair<Index>;
|
|
10
|
-
|
|
11
|
-
/** A much faster version of `Math.max` specialized to two numeric arguments. */
|
|
12
|
-
const fastMax = <Index extends number>(x1: Index, x2: Index): Index => (x1 < x2 ? x2 : x1);
|
|
13
|
-
|
|
14
|
-
/** A much faster version of `Math.min` specialized to two numeric arguments. */
|
|
15
|
-
const fastMin = <Index extends number>(x1: Index, x2: Index): Index => (x1 < x2 ? x1 : x2);
|
|
16
|
-
|
|
17
|
-
export function ivlJoin<Index extends number>(ivl1: Ivl<Index>, ivl2: Ivl<Index>): Ivl<Index> {
|
|
18
|
-
const [x1a, x1b] = ivl1;
|
|
19
|
-
const [x2a, x2b] = ivl2;
|
|
20
|
-
return [fastMin(x1a, x2a), fastMax(x1b, x2b)];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function ivlMeets(ivl1: Ivl, ivl2: Ivl): boolean {
|
|
24
|
-
const [x1a, x1b] = ivl1;
|
|
25
|
-
const [x2a, x2b] = ivl2;
|
|
26
|
-
return fastMax(x1a, x2a) < fastMin(x1b, x2b);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function ivlMeetsOrTouches(ivl1: Ivl, ivl2: Ivl): boolean {
|
|
30
|
-
const [x1a, x1b] = ivl1;
|
|
31
|
-
const [x2a, x2b] = ivl2;
|
|
32
|
-
return fastMax(x1a, x2a) <= fastMin(x1b, x2b);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** computes the set difference on intervals. Precondition: they meet */
|
|
36
|
-
export function ivlExcept<Index extends number>(
|
|
37
|
-
ivl1: Ivl<Index>,
|
|
38
|
-
ivl2: Ivl<Index>,
|
|
39
|
-
): Ivl<Index> | undefined {
|
|
40
|
-
const [x1a, x1b] = ivl1;
|
|
41
|
-
const [x2a, x2b] = ivl2;
|
|
42
|
-
if (x1a < x2a && x2b >= x1b) {
|
|
43
|
-
return [x1a, x2a];
|
|
44
|
-
}
|
|
45
|
-
if (x1a >= x2a && x2b < x1b) {
|
|
46
|
-
return [x2b, x1b];
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function ivlMeet<Index extends number>(ivl1: Ivl<Index>, ivl2: Ivl<Index>): Ivl<Index> {
|
|
52
|
-
const [x1a, x1b] = ivl1;
|
|
53
|
-
const [x2a, x2b] = ivl2;
|
|
54
|
-
return [fastMax(x1a, x2a), fastMin(x1b, x2b)];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function ivlCompare<Index extends number>(
|
|
58
|
-
ivl1: Ivl<Index>,
|
|
59
|
-
ivl2: Ivl<Index>,
|
|
60
|
-
): -1 | 0 | 1 | undefined {
|
|
61
|
-
const [x1a, x1b] = ivl1;
|
|
62
|
-
const [x2a, x2b] = ivl2;
|
|
63
|
-
if (x1a === x2a && x1b === x2b) {
|
|
64
|
-
return 0;
|
|
65
|
-
}
|
|
66
|
-
if (x1a >= x2a && x1b <= x2b) {
|
|
67
|
-
return -1;
|
|
68
|
-
}
|
|
69
|
-
if (x1a <= x2a && x1b >= x2b) {
|
|
70
|
-
return 1;
|
|
71
|
-
}
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface Distribution {
|
|
76
|
-
/** The cummulative distribution function. This is used to compute the probabilty mass of a given interval. */
|
|
77
|
-
readonly cdf: (x: number) => number;
|
|
78
|
-
|
|
79
|
-
/** The inverse cummulative distribution function. This is used to estimate a point given a quantile. */
|
|
80
|
-
readonly invCdf: (x: number) => number;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** This is a bounded pareto distribution with a shape parameter `alpha`, a lower bound `L` and an upper bound `H`.
|
|
84
|
-
* It has good properties for being used as a space splitting function in sofar, as it causes the indices to grow
|
|
85
|
-
* exponentially. This behavior guarantees `O(log k)` as worst-case execution time when it's used as a space-splitting
|
|
86
|
-
* function.
|
|
87
|
-
*
|
|
88
|
-
* On the other hand, we now can use it to approximate the access to grids better than just binary search, a
|
|
89
|
-
* similar argument as for using exponential search. But we can use it to give exact probability masses for arbitrary
|
|
90
|
-
* intervals. This allows us to search in both dimensions of a grid and use the probability mass to decide what axis
|
|
91
|
-
* to cut next.
|
|
92
|
-
*/
|
|
93
|
-
export function boundedPareto(alpha: number, L: number, H: number): Distribution {
|
|
94
|
-
const lAlpha = L ** alpha;
|
|
95
|
-
const cdfDenom = 1 - (L / H) ** alpha;
|
|
96
|
-
const hAlpha = H ** alpha;
|
|
97
|
-
const hlAlpha = hAlpha * lAlpha;
|
|
98
|
-
const hAlphaSubLAlpha = hAlpha - lAlpha;
|
|
99
|
-
const negAlphaInv = -1 / alpha;
|
|
100
|
-
|
|
101
|
-
const cdf =
|
|
102
|
-
alpha === 1
|
|
103
|
-
? (x: number) => (1 - lAlpha / x) / cdfDenom
|
|
104
|
-
: (x: number) => (1 - lAlpha * x ** -alpha) / cdfDenom;
|
|
105
|
-
const invCdf =
|
|
106
|
-
alpha === 1
|
|
107
|
-
? (y: number) => 1 / ((hAlpha - y * hAlphaSubLAlpha) / hlAlpha)
|
|
108
|
-
: (y: number) => ((hAlpha - y * hAlphaSubLAlpha) / hlAlpha) ** negAlphaInv;
|
|
109
|
-
|
|
110
|
-
return { cdf, invCdf };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** Creates a dimension splitter that operates on integer interval values and is based on a bounded Pareto
|
|
114
|
-
* distribution. */
|
|
115
|
-
export function boundedParetoSplitter<Index extends number>(
|
|
116
|
-
alpha: number,
|
|
117
|
-
L: number,
|
|
118
|
-
H: number,
|
|
119
|
-
): DimensionSplitter<Pair<Index>> {
|
|
120
|
-
const distribution = boundedPareto(alpha, L, H);
|
|
121
|
-
return {
|
|
122
|
-
canSplit: ([keyLb, keyUb]) => keyUb - keyLb > 1,
|
|
123
|
-
split([keyLb, keyUb]: Pair<Index>) {
|
|
124
|
-
const ubCdf = distribution.cdf(keyUb);
|
|
125
|
-
const lbCdf = distribution.cdf(keyLb + 1);
|
|
126
|
-
const cuttingPoint = distribution.invCdf((ubCdf + lbCdf) / 2);
|
|
127
|
-
// pick a cutting point, but making sure either side has at least one element in it.
|
|
128
|
-
const discreteCuttingPoint = Math.min(
|
|
129
|
-
Math.max(Math.round(cuttingPoint), keyLb + 1),
|
|
130
|
-
keyUb - 1,
|
|
131
|
-
) as Index;
|
|
132
|
-
|
|
133
|
-
const leftProb = distribution.cdf(discreteCuttingPoint) - distribution.cdf(keyLb + 1);
|
|
134
|
-
const rightProb = distribution.cdf(keyUb) - distribution.cdf(discreteCuttingPoint);
|
|
135
|
-
|
|
136
|
-
const result: Pair<Pair<Pair<Index>, number>> = [
|
|
137
|
-
[[keyLb, discreteCuttingPoint], leftProb],
|
|
138
|
-
[[discreteCuttingPoint, keyUb], rightProb],
|
|
139
|
-
];
|
|
140
|
-
return result;
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function boundedParetoSetOperations<Index extends number, Id>(
|
|
146
|
-
alpha: number,
|
|
147
|
-
L: number,
|
|
148
|
-
H: number,
|
|
149
|
-
top: Pair<Index>,
|
|
150
|
-
id: Id,
|
|
151
|
-
): SetOperations<Pair<Index>, Id> {
|
|
152
|
-
const splitter = boundedParetoSplitter<Index>(alpha, L, H);
|
|
153
|
-
return {
|
|
154
|
-
id,
|
|
155
|
-
split: (key) => splitter.split(key),
|
|
156
|
-
canSplit: (key) => splitter.canSplit(key),
|
|
157
|
-
meets: ivlMeets,
|
|
158
|
-
intersect: ivlMeet,
|
|
159
|
-
union: (x, y) => (ivlMeetsOrTouches(x, y) ? ivlJoin(x, y) : undefined),
|
|
160
|
-
except: ivlExcept,
|
|
161
|
-
compare: ivlCompare,
|
|
162
|
-
top,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export interface DimensionSplitter<Key> {
|
|
167
|
-
/** For a given key, returns if the key can be further sub-divided. */
|
|
168
|
-
canSplit(key: Key): boolean;
|
|
169
|
-
/** Splits a key and returns the probability mass for either half. */
|
|
170
|
-
split(key: Key): Pair<Pair<Key, number>>;
|
|
171
|
-
}
|