@actyx/sdk
Version:
Actyx SDK
61 lines • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BinaryMerge = void 0;
class BinaryMerge {
collision(_ai, _bi) { }
fromA(_a0, _a1, _bi) { }
fromB(_ai, _b0, _b1) { }
merge0(a0, a1, b0, b1) {
if (a0 === a1) {
if (b0 !== b1) {
this.fromB(a0, b0, b1);
}
}
else if (b0 === b1) {
this.fromA(a0, a1, b0);
}
else {
const am = (a0 + a1) >>> 1;
const res = this.binarySearchB(am, b0, b1);
if (res >= 0) {
// same elements
const bm = res;
// merge everything below a(am) with everything below the found element
this.merge0(a0, am, b0, bm);
// add the elements a(am) and b(bm)
this.collision(am, bm);
// merge everything above a(am) with everything above the found element
this.merge0(am + 1, a1, bm + 1, b1);
}
else {
const bm = -res - 1;
// merge everything below a(am) with everything below the found insertion point
this.merge0(a0, am, b0, bm);
// add a(am)
this.fromA(am, am + 1, bm);
// everything above a(am) with everything above the found insertion point
this.merge0(am + 1, a1, bm, b1);
}
}
}
binarySearchB(ai, b0, b1) {
let m = b0;
let n = b1 - 1;
while (m <= n) {
const k = (n + m) >>> 1;
const cmp = this.compare(ai, k);
if (cmp > 0) {
m = k + 1;
}
else if (cmp < 0) {
n = k - 1;
}
else {
return k;
}
}
return -m - 1;
}
}
exports.BinaryMerge = BinaryMerge;
//# sourceMappingURL=binaryMerge.js.map