lucid-extension-sdk 0.0.298 → 0.0.299
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.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function implements the O(n*log(n)) algorithm from the wikipedia article
|
|
3
|
+
* https://en.wikipedia.org/wiki/Longest_increasing_subsequence to get the longest increasing sub-sequence of the numbers
|
|
4
|
+
* in the array. Note that the algorithm simply ignores undefined entries. This is current used to optimize data usage
|
|
5
|
+
* in the ItemOrderPatch metadata collection.
|
|
6
|
+
*
|
|
7
|
+
* @param X an array of distinct numbers (or undefineds, which are ignored)
|
|
8
|
+
* @returns An array of numeric entries pulled from X which are in the same order as they were in X, and have the
|
|
9
|
+
* longest possible length of all such possible arrays. This answer may not be unique, but it will be
|
|
10
|
+
* as long or longer than all other candidates.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getMaximalOrderedSubset(X: (number | undefined)[]): number[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMaximalOrderedSubset = void 0;
|
|
4
|
+
const checks_1 = require("../../checks");
|
|
5
|
+
/**
|
|
6
|
+
* This function implements the O(n*log(n)) algorithm from the wikipedia article
|
|
7
|
+
* https://en.wikipedia.org/wiki/Longest_increasing_subsequence to get the longest increasing sub-sequence of the numbers
|
|
8
|
+
* in the array. Note that the algorithm simply ignores undefined entries. This is current used to optimize data usage
|
|
9
|
+
* in the ItemOrderPatch metadata collection.
|
|
10
|
+
*
|
|
11
|
+
* @param X an array of distinct numbers (or undefineds, which are ignored)
|
|
12
|
+
* @returns An array of numeric entries pulled from X which are in the same order as they were in X, and have the
|
|
13
|
+
* longest possible length of all such possible arrays. This answer may not be unique, but it will be
|
|
14
|
+
* as long or longer than all other candidates.
|
|
15
|
+
*/
|
|
16
|
+
function getMaximalOrderedSubset(X) {
|
|
17
|
+
var _a;
|
|
18
|
+
const M = [];
|
|
19
|
+
const P = [];
|
|
20
|
+
X.forEach((val, valInd) => {
|
|
21
|
+
if ((0, checks_1.isNumber)(val)) {
|
|
22
|
+
let lo = 0;
|
|
23
|
+
let hi = M.length;
|
|
24
|
+
while (lo < hi) {
|
|
25
|
+
const mid = lo + Math.floor((hi - lo) / 2);
|
|
26
|
+
const compValue = X[M[mid]];
|
|
27
|
+
if (compValue != null && compValue > val) {
|
|
28
|
+
hi = mid;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
lo = mid + 1;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
P.push(lo > 0 ? M[lo - 1] : undefined);
|
|
35
|
+
M[lo] = valInd;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
P.push(undefined);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const S = [];
|
|
42
|
+
if (M.length > 0) {
|
|
43
|
+
let k = M[M.length - 1];
|
|
44
|
+
for (let j = M.length - 1; j >= 0; j--) {
|
|
45
|
+
const val = X[k];
|
|
46
|
+
val != null && S.unshift(val);
|
|
47
|
+
k = (_a = P[k]) !== null && _a !== void 0 ? _a : -1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return S;
|
|
51
|
+
}
|
|
52
|
+
exports.getMaximalOrderedSubset = getMaximalOrderedSubset;
|