113 lines
2.4 KiB
JavaScript
113 lines
2.4 KiB
JavaScript
// Metro module 6033 (f6034).
|
|
import * as _TreeBase from "./TreeBase";
|
|
const Node2 = function(a0) {
|
|
this.data = a0;
|
|
this.left = null;
|
|
this.right = null;
|
|
};
|
|
const BinTree = function BinTree(a0) {
|
|
this._root = null;
|
|
this._comparator = a0;
|
|
this.size = 0;
|
|
};
|
|
Node2.prototype.get_child = function(a0) {
|
|
return a0 ? this.right : this.left;
|
|
};
|
|
Node2.prototype.set_child = function(a0, a1) {
|
|
if (a0) {
|
|
this.right = a1;
|
|
} else {
|
|
this.left = a1;
|
|
}
|
|
};
|
|
BinTree.prototype = new _TreeBase();
|
|
BinTree.prototype.insert = function(a0) {
|
|
if (this._root === null) {
|
|
const _root2 = {
|
|
__proto__: Node2.prototype
|
|
};
|
|
_root2.data = a0;
|
|
_root2.left = null;
|
|
_root2.right = null;
|
|
this._root = _root2;
|
|
this.size = this.size + 1;
|
|
return true;
|
|
}
|
|
let _root = this._root;
|
|
let r14 = null;
|
|
let r1 = 0;
|
|
while (true) {
|
|
const r11 = _root;
|
|
const r10 = r14;
|
|
const r3 = r1;
|
|
if (r11 === null) {
|
|
const r23 = {
|
|
__proto__: Node2.prototype
|
|
};
|
|
r23.data = a0;
|
|
r23.left = null;
|
|
r23.right = null;
|
|
r10.set_child(r3, r23);
|
|
globalThis.ret = true;
|
|
this.size = this.size + 1;
|
|
return true;
|
|
}
|
|
if (this._comparator(r11.data, a0) === 0) {
|
|
return false;
|
|
}
|
|
const r2 = this._comparator(r11.data, a0) < 0;
|
|
_root = r11.get_child(r2);
|
|
r14 = r11;
|
|
r1 = r2;
|
|
}
|
|
};
|
|
BinTree.prototype.remove = function(a0) {
|
|
let r29;
|
|
if (this._root === null) {
|
|
return false;
|
|
}
|
|
const r19 = {
|
|
__proto__: Node2.prototype
|
|
};
|
|
r19.data = void 0;
|
|
r19.left = null;
|
|
r19.right = null;
|
|
r19.right = this._root;
|
|
const r22 = r19.get_child(1);
|
|
let r23 = 1;
|
|
let r12 = null;
|
|
let r10 = r19;
|
|
let r8 = null;
|
|
let r11 = r10;
|
|
let r9 = null;
|
|
if (r22 !== null) {
|
|
do {
|
|
const r14 = r10.get_child(r23);
|
|
const r26 = this._comparator(a0, r14.data);
|
|
const r3 = r26 > 0;
|
|
let r16 = r12;
|
|
const r27 = r10;
|
|
if (r26 === 0) {
|
|
r16 = r14;
|
|
}
|
|
r29 = r14.get_child(r3);
|
|
r12 = r16;
|
|
r23 = r3;
|
|
r10 = r14;
|
|
r8 = r12;
|
|
r9 = r27;
|
|
r11 = r10;
|
|
} while (r29 !== null);
|
|
}
|
|
let r30 = r8 !== null;
|
|
if (r30) {
|
|
r8.data = r11.data;
|
|
r9.set_child(r9.right === r11, r11.get_child(r11.left === null));
|
|
this._root = r19.right;
|
|
this.size = this.size - 1;
|
|
r30 = true;
|
|
}
|
|
return r30;
|
|
};
|
|
module.exports = BinTree;
|