Skip to content
Snippets Groups Projects
Commit 94e7820b authored by David Sehnal's avatar David Sehnal
Browse files

mol-data: SortedArray fix

parent a47df577
No related branches found
No related tags found
No related merge requests found
...@@ -188,17 +188,13 @@ export function union(a: Nums, b: Nums): Nums { ...@@ -188,17 +188,13 @@ export function union(a: Nums, b: Nums): Nums {
if (commonCount === lenA) return b; if (commonCount === lenA) return b;
const indices = new Int32Array(lenA + lenB - commonCount); const indices = new Int32Array(lenA + lenB - commonCount);
let offset = 0; let i = 0, j = 0, offset = 0;
// insert the "prefixes" // insert the "prefixes"
let k = 0; for (i = 0; i < startI; i++) indices[offset++] = a[i];
for (k = 0; k < startI; k++) indices[offset++] = a[k]; while (j < endJ && a[startI] > b[j]) indices[offset++] = b[j++];
k = 0;
while (k <= startJ && a[startI] > b[k]) indices[offset++] = b[k++];
// insert the common part // insert the common part
let i = startI;
let j = startJ;
while (i < endI && j < endJ) { while (i < endI && j < endJ) {
const x = a[i], y = b[j]; const x = a[i], y = b[j];
if (x < y) { indices[offset++] = x; i++; } if (x < y) { indices[offset++] = x; i++; }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment