Insane number of adds to setup env and packages

This commit is contained in:
2022-11-07 17:45:54 -05:00
parent 62c2bb73a9
commit 55ecf095a9
3127 changed files with 485223 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
import { ContainerIterator } from "../../ContainerBase";
declare abstract class TreeIterator<K, V> extends ContainerIterator<K | [K, V]> {
pre: () => this;
next: () => this;
/**
* @description Get the sequential index of the iterator in the tree container.<br/>
* <strong>
* Note:
* </strong>
* This function only takes effect when the specified tree container `enableIndex = true`.
*/
get index(): number;
equals(obj: TreeIterator<K, V>): boolean;
}
export default TreeIterator;

View File

@@ -0,0 +1,80 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _ContainerBase = require("../../ContainerBase");
class TreeIterator extends _ContainerBase.ContainerIterator {
constructor(t, e, r) {
super(r);
this.I = t;
this.S = e;
if (this.iteratorType === 0) {
this.pre = function() {
if (this.I === this.S.U) {
throw new RangeError("Tree iterator access denied!");
}
this.I = this.I.pre();
return this;
};
this.next = function() {
if (this.I === this.S) {
throw new RangeError("Tree iterator access denied!");
}
this.I = this.I.next();
return this;
};
} else {
this.pre = function() {
if (this.I === this.S.J) {
throw new RangeError("Tree iterator access denied!");
}
this.I = this.I.next();
return this;
};
this.next = function() {
if (this.I === this.S) {
throw new RangeError("Tree iterator access denied!");
}
this.I = this.I.pre();
return this;
};
}
}
get index() {
let t = this.I;
const e = this.S.tt;
if (t === this.S) {
if (e) {
return e.et - 1;
}
return 0;
}
let r = 0;
if (t.U) {
r += t.U.et;
}
while (t !== e) {
const e = t.tt;
if (t === e.J) {
r += 1;
if (e.U) {
r += e.U.et;
}
}
t = e;
}
return r;
}
equals(t) {
return this.I === t.I;
}
}
var _default = TreeIterator;
exports.default = _default;

View File

@@ -0,0 +1,36 @@
export declare class TreeNode<K, V> {
constructor(_key?: K, _value?: V);
/**
* @description Get the pre node.
* @return TreeNode about the pre node.
*/
pre(): TreeNode<K, V>;
/**
* @description Get the next node.
* @return TreeNode about the next node.
*/
next(): TreeNode<K, V>;
/**
* @description Rotate _left.
* @return TreeNode about moved to original position after rotation.
*/
rotateLeft(): TreeNode<K, V>;
/**
* @description Rotate _right.
* @return TreeNode about moved to original position after rotation.
*/
rotateRight(): TreeNode<K, V>;
}
export declare class TreeNodeEnableIndex<K, V> extends TreeNode<K, V> {
/**
* @description Rotate _left and do recount.
* @return TreeNode about moved to original position after rotation.
*/
rotateLeft(): TreeNodeEnableIndex<K, V>;
/**
* @description Rotate _right and do recount.
* @return TreeNode about moved to original position after rotation.
*/
rotateRight(): TreeNode<K, V>;
recount(): void;
}

View File

@@ -0,0 +1,113 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.TreeNodeEnableIndex = exports.TreeNode = void 0;
class TreeNode {
constructor(e, t) {
this.se = 1;
this.T = undefined;
this.L = undefined;
this.U = undefined;
this.J = undefined;
this.tt = undefined;
this.T = e;
this.L = t;
}
pre() {
let e = this;
if (e.se === 1 && e.tt.tt === e) {
e = e.J;
} else if (e.U) {
e = e.U;
while (e.J) {
e = e.J;
}
} else {
let t = e.tt;
while (t.U === e) {
e = t;
t = e.tt;
}
e = t;
}
return e;
}
next() {
let e = this;
if (e.J) {
e = e.J;
while (e.U) {
e = e.U;
}
return e;
} else {
let t = e.tt;
while (t.J === e) {
e = t;
t = e.tt;
}
if (e.J !== t) {
return t;
} else return e;
}
}
rotateLeft() {
const e = this.tt;
const t = this.J;
const s = t.U;
if (e.tt === this) e.tt = t; else if (e.U === this) e.U = t; else e.J = t;
t.tt = e;
t.U = this;
this.tt = t;
this.J = s;
if (s) s.tt = this;
return t;
}
rotateRight() {
const e = this.tt;
const t = this.U;
const s = t.J;
if (e.tt === this) e.tt = t; else if (e.U === this) e.U = t; else e.J = t;
t.tt = e;
t.J = this;
this.tt = t;
this.U = s;
if (s) s.tt = this;
return t;
}
}
exports.TreeNode = TreeNode;
class TreeNodeEnableIndex extends TreeNode {
constructor() {
super(...arguments);
this.U = undefined;
this.J = undefined;
this.tt = undefined;
this.et = 1;
}
rotateLeft() {
const e = super.rotateLeft();
this.recount();
e.recount();
return e;
}
rotateRight() {
const e = super.rotateRight();
this.recount();
e.recount();
return e;
}
recount() {
this.et = 1;
if (this.U) this.et += this.U.et;
if (this.J) this.et += this.J.et;
}
}
exports.TreeNodeEnableIndex = TreeNodeEnableIndex;

View File

@@ -0,0 +1,55 @@
import type TreeIterator from './TreeIterator';
import { Container } from "../../ContainerBase";
declare abstract class TreeContainer<K, V> extends Container<K | [K, V]> {
/**
* @param cmp The compare function.
* @param enableIndex Whether to enable iterator indexing function.
*/
protected constructor(cmp?: (x: K, y: K) => number, enableIndex?: boolean);
/**
* @param _key The given _key you want to compare.
* @return An iterator to the first element not less than the given _key.
*/
abstract lowerBound(_key: K): TreeIterator<K, V>;
/**
* @param _key The given _key you want to compare.
* @return An iterator to the first element greater than the given _key.
*/
abstract upperBound(_key: K): TreeIterator<K, V>;
/**
* @param _key The given _key you want to compare.
* @return An iterator to the first element not greater than the given _key.
*/
abstract reverseLowerBound(_key: K): TreeIterator<K, V>;
/**
* @param _key The given _key you want to compare.
* @return An iterator to the first element less than the given _key.
*/
abstract reverseUpperBound(_key: K): TreeIterator<K, V>;
/**
* @description Union the other tree to self.
* @param other The other tree container you want to merge.
*/
abstract union(other: TreeContainer<K, V>): void;
clear(): void;
/**
* @description Update node's _key by iterator.
* @param iter The iterator you want to change.
* @param _key The _key you want to update.
* @return Boolean about if the modification is successful.
*/
updateKeyByIterator(iter: TreeIterator<K, V>, _key: K): boolean;
eraseElementByPos(pos: number): void;
/**
* @description Remove the element of the specified _key.
* @param _key The _key you want to remove.
*/
eraseElementByKey(_key: K): void;
eraseElementByIterator(iter: TreeIterator<K, V>): TreeIterator<K, V>;
/**
* @description Get the height of the tree.
* @return Number about the height of the RB-tree.
*/
getHeight(): number;
}
export default TreeContainer;

View File

@@ -0,0 +1,483 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _ContainerBase = require("../../ContainerBase");
var _TreeNode = require("./TreeNode");
class TreeContainer extends _ContainerBase.Container {
constructor(e = ((e, t) => {
if (e < t) return -1;
if (e > t) return 1;
return 0;
}), t = false) {
super();
this.X = undefined;
this.ie = (e, t) => {
if (e === undefined) return false;
const i = this.ie(e.U, t);
if (i) return true;
if (t(e)) return true;
return this.ie(e.J, t);
};
this.p = e;
if (t) {
this.ne = _TreeNode.TreeNodeEnableIndex;
this.ee = function(e, t, i) {
const s = this.he(e, t, i);
if (s) {
let e = s.tt;
while (e !== this.S) {
e.et += 1;
e = e.tt;
}
const t = this.fe(s);
if (t) {
const {parentNode: e, grandParent: i, curNode: s} = t;
e.recount();
i.recount();
s.recount();
}
}
};
this.ue = function(e) {
let t = this.le(e);
while (t !== this.S) {
t.et -= 1;
t = t.tt;
}
};
} else {
this.ne = _TreeNode.TreeNode;
this.ee = function(e, t, i) {
const s = this.he(e, t, i);
if (s) this.fe(s);
};
this.ue = this.le;
}
this.S = new this.ne;
}
W(e, t) {
let i;
while (e) {
const s = this.p(e.T, t);
if (s < 0) {
e = e.J;
} else if (s > 0) {
i = e;
e = e.U;
} else return e;
}
return i === undefined ? this.S : i;
}
Y(e, t) {
let i;
while (e) {
const s = this.p(e.T, t);
if (s <= 0) {
e = e.J;
} else {
i = e;
e = e.U;
}
}
return i === undefined ? this.S : i;
}
Z(e, t) {
let i;
while (e) {
const s = this.p(e.T, t);
if (s < 0) {
i = e;
e = e.J;
} else if (s > 0) {
e = e.U;
} else return e;
}
return i === undefined ? this.S : i;
}
$(e, t) {
let i;
while (e) {
const s = this.p(e.T, t);
if (s < 0) {
i = e;
e = e.J;
} else {
e = e.U;
}
}
return i === undefined ? this.S : i;
}
oe(e) {
while (true) {
const t = e.tt;
if (t === this.S) return;
if (e.se === 1) {
e.se = 0;
return;
}
if (e === t.U) {
const i = t.J;
if (i.se === 1) {
i.se = 0;
t.se = 1;
if (t === this.X) {
this.X = t.rotateLeft();
} else t.rotateLeft();
} else {
if (i.J && i.J.se === 1) {
i.se = t.se;
t.se = 0;
i.J.se = 0;
if (t === this.X) {
this.X = t.rotateLeft();
} else t.rotateLeft();
return;
} else if (i.U && i.U.se === 1) {
i.se = 1;
i.U.se = 0;
i.rotateRight();
} else {
i.se = 1;
e = t;
}
}
} else {
const i = t.U;
if (i.se === 1) {
i.se = 0;
t.se = 1;
if (t === this.X) {
this.X = t.rotateRight();
} else t.rotateRight();
} else {
if (i.U && i.U.se === 1) {
i.se = t.se;
t.se = 0;
i.U.se = 0;
if (t === this.X) {
this.X = t.rotateRight();
} else t.rotateRight();
return;
} else if (i.J && i.J.se === 1) {
i.se = 1;
i.J.se = 0;
i.rotateLeft();
} else {
i.se = 1;
e = t;
}
}
}
}
}
le(e) {
if (this.o === 1) {
this.clear();
return this.S;
}
let t = e;
while (t.U || t.J) {
if (t.J) {
t = t.J;
while (t.U) t = t.U;
} else {
t = t.U;
}
[e.T, t.T] = [ t.T, e.T ];
[e.L, t.L] = [ t.L, e.L ];
e = t;
}
if (this.S.U === t) {
this.S.U = t.tt;
} else if (this.S.J === t) {
this.S.J = t.tt;
}
this.oe(t);
const i = t.tt;
if (t === i.U) {
i.U = undefined;
} else i.J = undefined;
this.o -= 1;
this.X.se = 0;
return i;
}
fe(e) {
while (true) {
const t = e.tt;
if (t.se === 0) return;
const i = t.tt;
if (t === i.U) {
const s = i.J;
if (s && s.se === 1) {
s.se = t.se = 0;
if (i === this.X) return;
i.se = 1;
e = i;
continue;
} else if (e === t.J) {
e.se = 0;
if (e.U) e.U.tt = t;
if (e.J) e.J.tt = i;
t.J = e.U;
i.U = e.J;
e.U = t;
e.J = i;
if (i === this.X) {
this.X = e;
this.S.tt = e;
} else {
const t = i.tt;
if (t.U === i) {
t.U = e;
} else t.J = e;
}
e.tt = i.tt;
t.tt = e;
i.tt = e;
i.se = 1;
return {
parentNode: t,
grandParent: i,
curNode: e
};
} else {
t.se = 0;
if (i === this.X) {
this.X = i.rotateRight();
} else i.rotateRight();
i.se = 1;
}
} else {
const s = i.U;
if (s && s.se === 1) {
s.se = t.se = 0;
if (i === this.X) return;
i.se = 1;
e = i;
continue;
} else if (e === t.U) {
e.se = 0;
if (e.U) e.U.tt = i;
if (e.J) e.J.tt = t;
i.J = e.U;
t.U = e.J;
e.U = i;
e.J = t;
if (i === this.X) {
this.X = e;
this.S.tt = e;
} else {
const t = i.tt;
if (t.U === i) {
t.U = e;
} else t.J = e;
}
e.tt = i.tt;
t.tt = e;
i.tt = e;
i.se = 1;
return {
parentNode: t,
grandParent: i,
curNode: e
};
} else {
t.se = 0;
if (i === this.X) {
this.X = i.rotateLeft();
} else i.rotateLeft();
i.se = 1;
}
}
return;
}
}
he(e, t, i) {
if (this.X === undefined) {
this.o += 1;
this.X = new this.ne(e, t);
this.X.se = 0;
this.X.tt = this.S;
this.S.tt = this.X;
this.S.U = this.X;
this.S.J = this.X;
return;
}
let s;
const r = this.S.U;
const n = this.p(r.T, e);
if (n === 0) {
r.L = t;
return;
} else if (n > 0) {
r.U = new this.ne(e, t);
r.U.tt = r;
s = r.U;
this.S.U = s;
} else {
const r = this.S.J;
const n = this.p(r.T, e);
if (n === 0) {
r.L = t;
return;
} else if (n < 0) {
r.J = new this.ne(e, t);
r.J.tt = r;
s = r.J;
this.S.J = s;
} else {
if (i !== undefined) {
const r = i.I;
if (r !== this.S) {
const i = this.p(r.T, e);
if (i === 0) {
r.L = t;
return;
} else if (i > 0) {
const i = r.pre();
const n = this.p(i.T, e);
if (n === 0) {
i.L = t;
return;
} else if (n < 0) {
s = new this.ne(e, t);
if (i.J === undefined) {
i.J = s;
s.tt = i;
} else {
r.U = s;
s.tt = r;
}
}
}
}
}
if (s === undefined) {
s = this.X;
while (true) {
const i = this.p(s.T, e);
if (i > 0) {
if (s.U === undefined) {
s.U = new this.ne(e, t);
s.U.tt = s;
s = s.U;
break;
}
s = s.U;
} else if (i < 0) {
if (s.J === undefined) {
s.J = new this.ne(e, t);
s.J.tt = s;
s = s.J;
break;
}
s = s.J;
} else {
s.L = t;
return;
}
}
}
}
}
this.o += 1;
return s;
}
clear() {
this.o = 0;
this.X = undefined;
this.S.tt = undefined;
this.S.U = this.S.J = undefined;
}
updateKeyByIterator(e, t) {
const i = e.I;
if (i === this.S) {
throw new TypeError("Invalid iterator!");
}
if (this.o === 1) {
i.T = t;
return true;
}
if (i === this.S.U) {
if (this.p(i.next().T, t) > 0) {
i.T = t;
return true;
}
return false;
}
if (i === this.S.J) {
if (this.p(i.pre().T, t) < 0) {
i.T = t;
return true;
}
return false;
}
const s = i.pre().T;
if (this.p(s, t) >= 0) return false;
const r = i.next().T;
if (this.p(r, t) <= 0) return false;
i.T = t;
return true;
}
eraseElementByPos(e) {
if (e < 0 || e > this.o - 1) {
throw new RangeError;
}
let t = 0;
this.ie(this.X, (i => {
if (e === t) {
this.ue(i);
return true;
}
t += 1;
return false;
}));
}
re(e, t) {
while (e) {
const i = this.p(e.T, t);
if (i < 0) {
e = e.J;
} else if (i > 0) {
e = e.U;
} else return e;
}
return e;
}
eraseElementByKey(e) {
if (!this.o) return;
const t = this.re(this.X, e);
if (t === undefined) return;
this.ue(t);
}
eraseElementByIterator(e) {
const t = e.I;
if (t === this.S) {
throw new RangeError("Invalid iterator");
}
if (t.J === undefined) {
e = e.next();
}
this.ue(t);
return e;
}
getHeight() {
if (!this.o) return 0;
const traversal = e => {
if (!e) return 0;
return Math.max(traversal(e.U), traversal(e.J)) + 1;
};
return traversal(this.X);
}
}
var _default = TreeContainer;
exports.default = _default;