document-dataply 0.0.9-alpha.12 → 0.0.9-alpha.13
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/dist/cjs/index.js +83 -20
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -6485,21 +6485,68 @@ var require_cjs = __commonJS({
|
|
|
6485
6485
|
}
|
|
6486
6486
|
return (crc ^ -1) >>> 0;
|
|
6487
6487
|
}
|
|
6488
|
-
function
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6488
|
+
function calcThreshold(sortedGaps, n) {
|
|
6489
|
+
const gLen = sortedGaps.length;
|
|
6490
|
+
if (gLen === 0) return 0;
|
|
6491
|
+
const median = sortedGaps[Math.floor(gLen * 0.5)];
|
|
6492
|
+
const q1 = sortedGaps[Math.floor(gLen * 0.25)];
|
|
6493
|
+
const q3 = sortedGaps[Math.floor(gLen * 0.75)];
|
|
6494
|
+
const iqr = q3 - q1;
|
|
6495
|
+
const logN = Math.max(1, Math.log10(n));
|
|
6496
|
+
if (iqr > 0) {
|
|
6497
|
+
const threshold2 = q3 + iqr * 1.5 * logN;
|
|
6498
|
+
const minJump = Math.max(median * 5, 20);
|
|
6499
|
+
return Math.max(threshold2, minJump);
|
|
6500
|
+
}
|
|
6501
|
+
const baseGap = median > 0 ? median : 1;
|
|
6502
|
+
const p90 = sortedGaps[Math.floor(gLen * 0.9)];
|
|
6503
|
+
if (p90 > baseGap) {
|
|
6504
|
+
const threshold2 = baseGap + (p90 - baseGap) * 0.5 * logN;
|
|
6505
|
+
return Math.max(threshold2, baseGap * 5, 20);
|
|
6506
|
+
}
|
|
6507
|
+
let mean = 0;
|
|
6508
|
+
for (let i = 0; i < gLen; i++) mean += sortedGaps[i];
|
|
6509
|
+
mean /= gLen;
|
|
6510
|
+
let variance = 0;
|
|
6511
|
+
for (let i = 0; i < gLen; i++) {
|
|
6512
|
+
const d = sortedGaps[i] - mean;
|
|
6513
|
+
variance += d * d;
|
|
6514
|
+
}
|
|
6515
|
+
const stddev = Math.sqrt(variance / gLen);
|
|
6516
|
+
if (stddev === 0) {
|
|
6517
|
+
return baseGap * 2;
|
|
6518
|
+
}
|
|
6519
|
+
const threshold = mean + stddev * logN;
|
|
6520
|
+
return Math.max(threshold, baseGap * 5, 20);
|
|
6521
|
+
}
|
|
6522
|
+
function clusterNumbers(numbers, gapMultiplier) {
|
|
6523
|
+
const n = numbers.length;
|
|
6524
|
+
if (n === 0) return [];
|
|
6525
|
+
if (n === 1) return [new Float64Array([numbers[0]])];
|
|
6526
|
+
const sorted = (numbers instanceof Float64Array ? numbers.slice() : Float64Array.from(numbers)).sort();
|
|
6527
|
+
const gaps = new Float64Array(n - 1);
|
|
6528
|
+
for (let i = 0, len = n - 1; i < len; i++) {
|
|
6529
|
+
gaps[i] = sorted[i + 1] - sorted[i];
|
|
6530
|
+
}
|
|
6531
|
+
const sortedGaps = gaps.slice().sort();
|
|
6532
|
+
let threshold;
|
|
6533
|
+
if (gapMultiplier !== void 0) {
|
|
6534
|
+
const q3 = sortedGaps[Math.floor((n - 1) * 0.75)];
|
|
6535
|
+
const iqr = q3 - sortedGaps[Math.floor((n - 1) * 0.25)];
|
|
6536
|
+
threshold = q3 + iqr * gapMultiplier;
|
|
6537
|
+
} else {
|
|
6538
|
+
threshold = calcThreshold(sortedGaps, n);
|
|
6539
|
+
}
|
|
6540
|
+
const clusters = [];
|
|
6541
|
+
let clusterStart = 0;
|
|
6542
|
+
for (let i = 0, len = n - 1; i < len; i++) {
|
|
6543
|
+
if (gaps[i] > threshold) {
|
|
6544
|
+
clusters.push(sorted.subarray(clusterStart, i + 1));
|
|
6545
|
+
clusterStart = i + 1;
|
|
6499
6546
|
}
|
|
6500
|
-
i++;
|
|
6501
6547
|
}
|
|
6502
|
-
|
|
6548
|
+
clusters.push(sorted.subarray(clusterStart));
|
|
6549
|
+
return clusters;
|
|
6503
6550
|
}
|
|
6504
6551
|
var Row = class _Row {
|
|
6505
6552
|
static CONSTANT = {
|
|
@@ -9439,14 +9486,30 @@ var require_cjs = __commonJS({
|
|
|
9439
9486
|
for (let i = 0, len = pks.length; i < len; i++) {
|
|
9440
9487
|
pkIndexMap.set(pks[i], i);
|
|
9441
9488
|
}
|
|
9442
|
-
const [minPk, maxPk] = getMinMaxValue(pks);
|
|
9443
9489
|
const pkRidPairs = new Array(pks.length).fill(null);
|
|
9444
9490
|
const btx = await this.getBPTreeTransaction(tx);
|
|
9445
|
-
const
|
|
9446
|
-
for
|
|
9447
|
-
const
|
|
9448
|
-
|
|
9449
|
-
|
|
9491
|
+
const clusters = clusterNumbers(pks);
|
|
9492
|
+
for (let i = 0, len = clusters.length; i < len; i++) {
|
|
9493
|
+
const cluster = clusters[i];
|
|
9494
|
+
const minPk = cluster[0];
|
|
9495
|
+
const maxPk = cluster[cluster.length - 1];
|
|
9496
|
+
if (minPk === maxPk) {
|
|
9497
|
+
const keys = await btx.keys({ equal: minPk });
|
|
9498
|
+
if (keys.size > 0) {
|
|
9499
|
+
const rid = keys.values().next().value;
|
|
9500
|
+
const index = pkIndexMap.get(minPk);
|
|
9501
|
+
if (index !== void 0) {
|
|
9502
|
+
pkRidPairs[index] = { pk: minPk, rid, index };
|
|
9503
|
+
}
|
|
9504
|
+
}
|
|
9505
|
+
continue;
|
|
9506
|
+
}
|
|
9507
|
+
const stream = btx.whereStream({ gte: minPk, lte: maxPk });
|
|
9508
|
+
for await (const [rid, pk] of stream) {
|
|
9509
|
+
const index = pkIndexMap.get(pk);
|
|
9510
|
+
if (index !== void 0) {
|
|
9511
|
+
pkRidPairs[index] = { pk, rid, index };
|
|
9512
|
+
}
|
|
9450
9513
|
}
|
|
9451
9514
|
}
|
|
9452
9515
|
return this.fetchRowsByRids(pkRidPairs, tx);
|
|
@@ -11248,7 +11311,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
11248
11311
|
}
|
|
11249
11312
|
candidates.sort((a, b) => b.score - a.score);
|
|
11250
11313
|
const driver = candidates[0];
|
|
11251
|
-
const others = candidates.slice(1);
|
|
11314
|
+
const others = candidates.slice(1).filter((c) => c.field !== driver.field);
|
|
11252
11315
|
const compositeVerifyConditions = [];
|
|
11253
11316
|
for (const field of driver.compositeVerifyFields) {
|
|
11254
11317
|
if (query[field]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-dataply",
|
|
3
|
-
"version": "0.0.9-alpha.
|
|
3
|
+
"version": "0.0.9-alpha.13",
|
|
4
4
|
"description": "Simple and powerful JSON document database supporting complex queries and flexible indexing policies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "izure <admin@izure.org>",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"dataply"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"dataply": "^0.0.24-alpha.
|
|
45
|
+
"dataply": "^0.0.24-alpha.12"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/jest": "^30.0.0",
|