From 8d13c514b0a63b514ce3fce3d5c1992b16ea6588 Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Wed, 23 Oct 2019 09:17:25 +0200 Subject: [PATCH] mol-data: SortedArray fix --- src/mol-data/int/impl/sorted-array.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mol-data/int/impl/sorted-array.ts b/src/mol-data/int/impl/sorted-array.ts index 1a27740ed..9aed13025 100644 --- a/src/mol-data/int/impl/sorted-array.ts +++ b/src/mol-data/int/impl/sorted-array.ts @@ -171,13 +171,17 @@ export function isSubset(a: Nums, b: Nums) { return equal === lenB; } -export function union(a: Nums, b: Nums) { +export function union(a: Nums, b: Nums): Nums { if (a === b) return a; + const lenA = a.length, lenB = b.length; + if (lenA === 0) return b; + if (lenB === 0) return a; + if (a[0] > b[0]) return union(b, a); + const { startI, startJ, endI, endJ } = getSuitableIntersectionRange(a, b); const commonCount = getCommonCount(a, b, startI, startJ, endI, endJ); - const lenA = a.length, lenB = b.length; // A === B || B is subset of A ==> A if ((commonCount === lenA && commonCount === lenB) || commonCount === lenB) return a; // A is subset of B ===> B -- GitLab