Tracking de l'application VApp (IHM du jeu)

This commit is contained in:
2025-05-11 18:04:12 +02:00
commit 89e9db9b62
17763 changed files with 3718499 additions and 0 deletions

View File

@ -0,0 +1,18 @@
import { ContainerIterator } from "../../ContainerBase";
import TreeContainer from "./index";
declare abstract class TreeIterator<K, V> extends ContainerIterator<K | [K, V]> {
abstract readonly container: TreeContainer<K, V>;
/**
* @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`.
* @returns The index subscript of the node in the tree.
* @example
* const st = new OrderedSet([1, 2, 3], true);
* console.log(st.begin().next().index); // 1
*/
get index(): number;
pre(): this;
next(): this;
}
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");
var _throwError = require("../../../utils/throwError");
class TreeIterator extends _ContainerBase.ContainerIterator {
constructor(t, r, i) {
super(i);
this.o = t;
this.h = r;
if (this.iteratorType === 0) {
this.pre = function() {
if (this.o === this.h.U) {
(0, _throwError.throwIteratorAccessError)();
}
this.o = this.o.L();
return this;
};
this.next = function() {
if (this.o === this.h) {
(0, _throwError.throwIteratorAccessError)();
}
this.o = this.o.B();
return this;
};
} else {
this.pre = function() {
if (this.o === this.h.W) {
(0, _throwError.throwIteratorAccessError)();
}
this.o = this.o.B();
return this;
};
this.next = function() {
if (this.o === this.h) {
(0, _throwError.throwIteratorAccessError)();
}
this.o = this.o.L();
return this;
};
}
}
get index() {
let t = this.o;
const r = this.h.tt;
if (t === this.h) {
if (r) {
return r.rt - 1;
}
return 0;
}
let i = 0;
if (t.U) {
i += t.U.rt;
}
while (t !== r) {
const r = t.tt;
if (t === r.W) {
i += 1;
if (r.U) {
i += r.U.rt;
}
}
t = r;
}
return i;
}
}
var _default = TreeIterator;
exports.default = _default;
//# sourceMappingURL=TreeIterator.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,47 @@
export declare const enum TreeNodeColor {
RED = 1,
BLACK = 0
}
export declare class TreeNode<K, V> {
_color: TreeNodeColor;
_key: K | undefined;
_value: V | undefined;
_left: TreeNode<K, V> | undefined;
_right: TreeNode<K, V> | undefined;
_parent: TreeNode<K, V> | undefined;
constructor(key?: K, value?: V);
/**
* @description Get the pre node.
* @returns TreeNode about the pre node.
*/
_pre(): TreeNode<K, V>;
/**
* @description Get the next node.
* @returns TreeNode about the next node.
*/
_next(): TreeNode<K, V>;
/**
* @description Rotate left.
* @returns TreeNode about moved to original position after rotation.
*/
_rotateLeft(): TreeNode<K, V>;
/**
* @description Rotate right.
* @returns TreeNode about moved to original position after rotation.
*/
_rotateRight(): TreeNode<K, V>;
}
export declare class TreeNodeEnableIndex<K, V> extends TreeNode<K, V> {
_subTreeSize: number;
/**
* @description Rotate left and do recount.
* @returns TreeNode about moved to original position after rotation.
*/
_rotateLeft(): TreeNodeEnableIndex<K, V>;
/**
* @description Rotate right and do recount.
* @returns TreeNode about moved to original position after rotation.
*/
_rotateRight(): TreeNodeEnableIndex<K, V>;
_recount(): void;
}

View File

@ -0,0 +1,115 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.TreeNodeEnableIndex = exports.TreeNode = void 0;
class TreeNode {
constructor(e, t) {
this.ee = 1;
this.u = undefined;
this.l = undefined;
this.U = undefined;
this.W = undefined;
this.tt = undefined;
this.u = e;
this.l = t;
}
L() {
let e = this;
if (e.ee === 1 && e.tt.tt === e) {
e = e.W;
} else if (e.U) {
e = e.U;
while (e.W) {
e = e.W;
}
} else {
let t = e.tt;
while (t.U === e) {
e = t;
t = e.tt;
}
e = t;
}
return e;
}
B() {
let e = this;
if (e.W) {
e = e.W;
while (e.U) {
e = e.U;
}
return e;
} else {
let t = e.tt;
while (t.W === e) {
e = t;
t = e.tt;
}
if (e.W !== t) {
return t;
} else return e;
}
}
te() {
const e = this.tt;
const t = this.W;
const s = t.U;
if (e.tt === this) e.tt = t; else if (e.U === this) e.U = t; else e.W = t;
t.tt = e;
t.U = this;
this.tt = t;
this.W = s;
if (s) s.tt = this;
return t;
}
se() {
const e = this.tt;
const t = this.U;
const s = t.W;
if (e.tt === this) e.tt = t; else if (e.U === this) e.U = t; else e.W = t;
t.tt = e;
t.W = 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.rt = 1;
}
te() {
const e = super.te();
this.ie();
e.ie();
return e;
}
se() {
const e = super.se();
this.ie();
e.ie();
return e;
}
ie() {
this.rt = 1;
if (this.U) {
this.rt += this.U.rt;
}
if (this.W) {
this.rt += this.W.rt;
}
}
}
exports.TreeNodeEnableIndex = TreeNodeEnableIndex;
//# sourceMappingURL=TreeNode.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,58 @@
import type TreeIterator from './TreeIterator';
import { Container } from "../../ContainerBase";
declare abstract class TreeContainer<K, V> extends Container<K | [K, V]> {
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.
* @returns Whether the modification is successful.
* @example
* const st = new orderedSet([1, 2, 5]);
* const iter = st.find(2);
* st.updateKeyByIterator(iter, 3); // then st will become [1, 3, 5]
*/
updateKeyByIterator(iter: TreeIterator<K, V>, key: K): boolean;
eraseElementByPos(pos: number): number;
/**
* @description Remove the element of the specified key.
* @param key - The key you want to remove.
* @returns Whether erase successfully.
*/
eraseElementByKey(key: K): boolean;
eraseElementByIterator(iter: TreeIterator<K, V>): TreeIterator<K, V>;
forEach(callback: (element: K | [K, V], index: number, tree: TreeContainer<K, V>) => void): void;
getElementByPos(pos: number): K | [K, V];
/**
* @description Get the height of the tree.
* @returns Number about the height of the RB-tree.
*/
getHeight(): number;
/**
* @param key - The given key you want to compare.
* @returns 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.
* @returns The size of the tree after union.
*/
abstract union(other: TreeContainer<K, V>): number;
/**
* @param key - The given key you want to compare.
* @returns 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.
* @returns 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.
* @returns An iterator to the first element greater than the given key.
*/
abstract upperBound(key: K): TreeIterator<K, V>;
}
export default TreeContainer;

View File

@ -0,0 +1,514 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _TreeNode = require("./TreeNode");
var _ContainerBase = require("../../ContainerBase");
var _throwError = require("../../../utils/throwError");
class TreeContainer extends _ContainerBase.Container {
constructor(e = function(e, t) {
if (e < t) return -1;
if (e > t) return 1;
return 0;
}, t = false) {
super();
this.Y = undefined;
this.v = e;
if (t) {
this.re = _TreeNode.TreeNodeEnableIndex;
this.M = function(e, t, i) {
const s = this.ne(e, t, i);
if (s) {
let e = s.tt;
while (e !== this.h) {
e.rt += 1;
e = e.tt;
}
const t = this.he(s);
if (t) {
const {parentNode: e, grandParent: i, curNode: s} = t;
e.ie();
i.ie();
s.ie();
}
}
return this.i;
};
this.V = function(e) {
let t = this.fe(e);
while (t !== this.h) {
t.rt -= 1;
t = t.tt;
}
};
} else {
this.re = _TreeNode.TreeNode;
this.M = function(e, t, i) {
const s = this.ne(e, t, i);
if (s) this.he(s);
return this.i;
};
this.V = this.fe;
}
this.h = new this.re;
}
X(e, t) {
let i = this.h;
while (e) {
const s = this.v(e.u, t);
if (s < 0) {
e = e.W;
} else if (s > 0) {
i = e;
e = e.U;
} else return e;
}
return i;
}
Z(e, t) {
let i = this.h;
while (e) {
const s = this.v(e.u, t);
if (s <= 0) {
e = e.W;
} else {
i = e;
e = e.U;
}
}
return i;
}
$(e, t) {
let i = this.h;
while (e) {
const s = this.v(e.u, t);
if (s < 0) {
i = e;
e = e.W;
} else if (s > 0) {
e = e.U;
} else return e;
}
return i;
}
rr(e, t) {
let i = this.h;
while (e) {
const s = this.v(e.u, t);
if (s < 0) {
i = e;
e = e.W;
} else {
e = e.U;
}
}
return i;
}
ue(e) {
while (true) {
const t = e.tt;
if (t === this.h) return;
if (e.ee === 1) {
e.ee = 0;
return;
}
if (e === t.U) {
const i = t.W;
if (i.ee === 1) {
i.ee = 0;
t.ee = 1;
if (t === this.Y) {
this.Y = t.te();
} else t.te();
} else {
if (i.W && i.W.ee === 1) {
i.ee = t.ee;
t.ee = 0;
i.W.ee = 0;
if (t === this.Y) {
this.Y = t.te();
} else t.te();
return;
} else if (i.U && i.U.ee === 1) {
i.ee = 1;
i.U.ee = 0;
i.se();
} else {
i.ee = 1;
e = t;
}
}
} else {
const i = t.U;
if (i.ee === 1) {
i.ee = 0;
t.ee = 1;
if (t === this.Y) {
this.Y = t.se();
} else t.se();
} else {
if (i.U && i.U.ee === 1) {
i.ee = t.ee;
t.ee = 0;
i.U.ee = 0;
if (t === this.Y) {
this.Y = t.se();
} else t.se();
return;
} else if (i.W && i.W.ee === 1) {
i.ee = 1;
i.W.ee = 0;
i.te();
} else {
i.ee = 1;
e = t;
}
}
}
}
}
fe(e) {
if (this.i === 1) {
this.clear();
return this.h;
}
let t = e;
while (t.U || t.W) {
if (t.W) {
t = t.W;
while (t.U) t = t.U;
} else {
t = t.U;
}
[e.u, t.u] = [ t.u, e.u ];
[e.l, t.l] = [ t.l, e.l ];
e = t;
}
if (this.h.U === t) {
this.h.U = t.tt;
} else if (this.h.W === t) {
this.h.W = t.tt;
}
this.ue(t);
const i = t.tt;
if (t === i.U) {
i.U = undefined;
} else i.W = undefined;
this.i -= 1;
this.Y.ee = 0;
return i;
}
oe(e, t) {
if (e === undefined) return false;
const i = this.oe(e.U, t);
if (i) return true;
if (t(e)) return true;
return this.oe(e.W, t);
}
he(e) {
while (true) {
const t = e.tt;
if (t.ee === 0) return;
const i = t.tt;
if (t === i.U) {
const s = i.W;
if (s && s.ee === 1) {
s.ee = t.ee = 0;
if (i === this.Y) return;
i.ee = 1;
e = i;
continue;
} else if (e === t.W) {
e.ee = 0;
if (e.U) e.U.tt = t;
if (e.W) e.W.tt = i;
t.W = e.U;
i.U = e.W;
e.U = t;
e.W = i;
if (i === this.Y) {
this.Y = e;
this.h.tt = e;
} else {
const t = i.tt;
if (t.U === i) {
t.U = e;
} else t.W = e;
}
e.tt = i.tt;
t.tt = e;
i.tt = e;
i.ee = 1;
return {
parentNode: t,
grandParent: i,
curNode: e
};
} else {
t.ee = 0;
if (i === this.Y) {
this.Y = i.se();
} else i.se();
i.ee = 1;
}
} else {
const s = i.U;
if (s && s.ee === 1) {
s.ee = t.ee = 0;
if (i === this.Y) return;
i.ee = 1;
e = i;
continue;
} else if (e === t.U) {
e.ee = 0;
if (e.U) e.U.tt = i;
if (e.W) e.W.tt = t;
i.W = e.U;
t.U = e.W;
e.U = i;
e.W = t;
if (i === this.Y) {
this.Y = e;
this.h.tt = e;
} else {
const t = i.tt;
if (t.U === i) {
t.U = e;
} else t.W = e;
}
e.tt = i.tt;
t.tt = e;
i.tt = e;
i.ee = 1;
return {
parentNode: t,
grandParent: i,
curNode: e
};
} else {
t.ee = 0;
if (i === this.Y) {
this.Y = i.te();
} else i.te();
i.ee = 1;
}
}
return;
}
}
ne(e, t, i) {
if (this.Y === undefined) {
this.i += 1;
this.Y = new this.re(e, t);
this.Y.ee = 0;
this.Y.tt = this.h;
this.h.tt = this.Y;
this.h.U = this.Y;
this.h.W = this.Y;
return;
}
let s;
const r = this.h.U;
const n = this.v(r.u, e);
if (n === 0) {
r.l = t;
return;
} else if (n > 0) {
r.U = new this.re(e, t);
r.U.tt = r;
s = r.U;
this.h.U = s;
} else {
const r = this.h.W;
const n = this.v(r.u, e);
if (n === 0) {
r.l = t;
return;
} else if (n < 0) {
r.W = new this.re(e, t);
r.W.tt = r;
s = r.W;
this.h.W = s;
} else {
if (i !== undefined) {
const r = i.o;
if (r !== this.h) {
const i = this.v(r.u, e);
if (i === 0) {
r.l = t;
return;
} else if (i > 0) {
const i = r.L();
const n = this.v(i.u, e);
if (n === 0) {
i.l = t;
return;
} else if (n < 0) {
s = new this.re(e, t);
if (i.W === undefined) {
i.W = s;
s.tt = i;
} else {
r.U = s;
s.tt = r;
}
}
}
}
}
if (s === undefined) {
s = this.Y;
while (true) {
const i = this.v(s.u, e);
if (i > 0) {
if (s.U === undefined) {
s.U = new this.re(e, t);
s.U.tt = s;
s = s.U;
break;
}
s = s.U;
} else if (i < 0) {
if (s.W === undefined) {
s.W = new this.re(e, t);
s.W.tt = s;
s = s.W;
break;
}
s = s.W;
} else {
s.l = t;
return;
}
}
}
}
}
this.i += 1;
return s;
}
I(e, t) {
while (e) {
const i = this.v(e.u, t);
if (i < 0) {
e = e.W;
} else if (i > 0) {
e = e.U;
} else return e;
}
return e || this.h;
}
clear() {
this.i = 0;
this.Y = undefined;
this.h.tt = undefined;
this.h.U = this.h.W = undefined;
}
updateKeyByIterator(e, t) {
const i = e.o;
if (i === this.h) {
(0, _throwError.throwIteratorAccessError)();
}
if (this.i === 1) {
i.u = t;
return true;
}
if (i === this.h.U) {
if (this.v(i.B().u, t) > 0) {
i.u = t;
return true;
}
return false;
}
if (i === this.h.W) {
if (this.v(i.L().u, t) < 0) {
i.u = t;
return true;
}
return false;
}
const s = i.L().u;
if (this.v(s, t) >= 0) return false;
const r = i.B().u;
if (this.v(r, t) <= 0) return false;
i.u = t;
return true;
}
eraseElementByPos(e) {
if (e < 0 || e > this.i - 1) {
throw new RangeError;
}
let t = 0;
const i = this;
this.oe(this.Y, (function(s) {
if (e === t) {
i.V(s);
return true;
}
t += 1;
return false;
}));
return this.i;
}
eraseElementByKey(e) {
if (this.i === 0) return false;
const t = this.I(this.Y, e);
if (t === this.h) return false;
this.V(t);
return true;
}
eraseElementByIterator(e) {
const t = e.o;
if (t === this.h) {
(0, _throwError.throwIteratorAccessError)();
}
const i = t.W === undefined;
const s = e.iteratorType === 0;
if (s) {
if (i) e.next();
} else {
if (!i || t.U === undefined) e.next();
}
this.V(t);
return e;
}
forEach(e) {
let t = 0;
for (const i of this) e(i, t++, this);
}
getElementByPos(e) {
if (e < 0 || e > this.i - 1) {
throw new RangeError;
}
let t;
let i = 0;
for (const s of this) {
if (i === e) {
t = s;
break;
}
i += 1;
}
return t;
}
getHeight() {
if (this.i === 0) return 0;
const traversal = function(e) {
if (!e) return 0;
return Math.max(traversal(e.U), traversal(e.W)) + 1;
};
return traversal(this.Y);
}
}
var _default = TreeContainer;
exports.default = _default;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,62 @@
import TreeContainer from './Base';
import TreeIterator from './Base/TreeIterator';
import { TreeNode } from './Base/TreeNode';
import { initContainer, IteratorType } from "../ContainerBase";
declare class OrderedMapIterator<K, V> extends TreeIterator<K, V> {
container: OrderedMap<K, V>;
constructor(node: TreeNode<K, V>, header: TreeNode<K, V>, container: OrderedMap<K, V>, iteratorType?: IteratorType);
get pointer(): [K, V];
copy(): OrderedMapIterator<K, V>;
equals(iter: OrderedMapIterator<K, V>): boolean;
}
export type { OrderedMapIterator };
declare class OrderedMap<K, V> extends TreeContainer<K, V> {
/**
* @param container - The initialization container.
* @param cmp - The compare function.
* @param enableIndex - Whether to enable iterator indexing function.
* @example
* new OrderedMap();
* new OrderedMap([[0, 1], [2, 1]]);
* new OrderedMap([[0, 1], [2, 1]], (x, y) => x - y);
* new OrderedMap([[0, 1], [2, 1]], (x, y) => x - y, true);
*/
constructor(container?: initContainer<[K, V]>, cmp?: (x: K, y: K) => number, enableIndex?: boolean);
begin(): OrderedMapIterator<K, V>;
end(): OrderedMapIterator<K, V>;
rBegin(): OrderedMapIterator<K, V>;
rEnd(): OrderedMapIterator<K, V>;
front(): [K, V] | undefined;
back(): [K, V] | undefined;
lowerBound(key: K): OrderedMapIterator<K, V>;
upperBound(key: K): OrderedMapIterator<K, V>;
reverseLowerBound(key: K): OrderedMapIterator<K, V>;
reverseUpperBound(key: K): OrderedMapIterator<K, V>;
/**
* @description Insert a key-value pair or set value by the given key.
* @param key - The key want to insert.
* @param value - The value want to set.
* @param hint - You can give an iterator hint to improve insertion efficiency.
* @return The size of container after setting.
* @example
* const mp = new OrderedMap([[2, 0], [4, 0], [5, 0]]);
* const iter = mp.begin();
* mp.setElement(1, 0);
* mp.setElement(3, 0, iter); // give a hint will be faster.
*/
setElement(key: K, value: V, hint?: OrderedMapIterator<K, V>): number;
find(key: K): OrderedMapIterator<K, V>;
/**
* @description Get the value of the element of the specified key.
* @param key - The specified key you want to get.
* @example
* const val = container.getElementByKey(1);
*/
getElementByKey(key: K): V | undefined;
union(other: OrderedMap<K, V>): number;
[Symbol.iterator](): Generator<[K, V], void, unknown>;
eraseElementByIterator(iter: OrderedMapIterator<K, V>): OrderedMapIterator<K, V>;
forEach(callback: (element: [K, V], index: number, map: OrderedMap<K, V>) => void): void;
getElementByPos(pos: number): [K, V];
}
export default OrderedMap;

View File

@ -0,0 +1,127 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _Base = _interopRequireDefault(require("./Base"));
var _TreeIterator = _interopRequireDefault(require("./Base/TreeIterator"));
var _throwError = require("../../utils/throwError");
function _interopRequireDefault(r) {
return r && r.t ? r : {
default: r
};
}
class OrderedMapIterator extends _TreeIterator.default {
constructor(r, t, e, s) {
super(r, t, s);
this.container = e;
}
get pointer() {
if (this.o === this.h) {
(0, _throwError.throwIteratorAccessError)();
}
const r = this;
return new Proxy([], {
get(t, e) {
if (e === "0") return r.o.u; else if (e === "1") return r.o.l;
},
set(t, e, s) {
if (e !== "1") {
throw new TypeError("props must be 1");
}
r.o.l = s;
return true;
}
});
}
copy() {
return new OrderedMapIterator(this.o, this.h, this.container, this.iteratorType);
}
}
class OrderedMap extends _Base.default {
constructor(r = [], t, e) {
super(t, e);
const s = this;
r.forEach((function(r) {
s.setElement(r[0], r[1]);
}));
}
* K(r) {
if (r === undefined) return;
yield* this.K(r.U);
yield [ r.u, r.l ];
yield* this.K(r.W);
}
begin() {
return new OrderedMapIterator(this.h.U || this.h, this.h, this);
}
end() {
return new OrderedMapIterator(this.h, this.h, this);
}
rBegin() {
return new OrderedMapIterator(this.h.W || this.h, this.h, this, 1);
}
rEnd() {
return new OrderedMapIterator(this.h, this.h, this, 1);
}
front() {
if (this.i === 0) return;
const r = this.h.U;
return [ r.u, r.l ];
}
back() {
if (this.i === 0) return;
const r = this.h.W;
return [ r.u, r.l ];
}
lowerBound(r) {
const t = this.X(this.Y, r);
return new OrderedMapIterator(t, this.h, this);
}
upperBound(r) {
const t = this.Z(this.Y, r);
return new OrderedMapIterator(t, this.h, this);
}
reverseLowerBound(r) {
const t = this.$(this.Y, r);
return new OrderedMapIterator(t, this.h, this);
}
reverseUpperBound(r) {
const t = this.rr(this.Y, r);
return new OrderedMapIterator(t, this.h, this);
}
setElement(r, t, e) {
return this.M(r, t, e);
}
find(r) {
const t = this.I(this.Y, r);
return new OrderedMapIterator(t, this.h, this);
}
getElementByKey(r) {
const t = this.I(this.Y, r);
return t.l;
}
union(r) {
const t = this;
r.forEach((function(r) {
t.setElement(r[0], r[1]);
}));
return this.i;
}
[Symbol.iterator]() {
return this.K(this.Y);
}
}
var _default = OrderedMap;
exports.default = _default;
//# sourceMappingURL=OrderedMap.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,54 @@
import TreeContainer from './Base';
import TreeIterator from './Base/TreeIterator';
import { TreeNode } from './Base/TreeNode';
import { initContainer, IteratorType } from "../ContainerBase";
declare class OrderedSetIterator<K> extends TreeIterator<K, undefined> {
container: OrderedSet<K>;
constructor(node: TreeNode<K, undefined>, header: TreeNode<K, undefined>, container: OrderedSet<K>, iteratorType?: IteratorType);
get pointer(): NonNullable<K>;
copy(): OrderedSetIterator<K>;
equals(iter: OrderedSetIterator<K>): boolean;
}
export type { OrderedSetIterator };
declare class OrderedSet<K> extends TreeContainer<K, undefined> {
/**
* @param container - The initialization container.
* @param cmp - The compare function.
* @param enableIndex - Whether to enable iterator indexing function.
* @example
* new OrderedSet();
* new OrderedSet([0, 1, 2]);
* new OrderedSet([0, 1, 2], (x, y) => x - y);
* new OrderedSet([0, 1, 2], (x, y) => x - y, true);
*/
constructor(container?: initContainer<K>, cmp?: (x: K, y: K) => number, enableIndex?: boolean);
begin(): OrderedSetIterator<K>;
end(): OrderedSetIterator<K>;
rBegin(): OrderedSetIterator<K>;
rEnd(): OrderedSetIterator<K>;
front(): K | undefined;
back(): K | undefined;
/**
* @description Insert element to set.
* @param key - The key want to insert.
* @param hint - You can give an iterator hint to improve insertion efficiency.
* @return The size of container after setting.
* @example
* const st = new OrderedSet([2, 4, 5]);
* const iter = st.begin();
* st.insert(1);
* st.insert(3, iter); // give a hint will be faster.
*/
insert(key: K, hint?: OrderedSetIterator<K>): number;
find(element: K): OrderedSetIterator<K>;
lowerBound(key: K): OrderedSetIterator<K>;
upperBound(key: K): OrderedSetIterator<K>;
reverseLowerBound(key: K): OrderedSetIterator<K>;
reverseUpperBound(key: K): OrderedSetIterator<K>;
union(other: OrderedSet<K>): number;
[Symbol.iterator](): Generator<K, void, unknown>;
eraseElementByIterator(iter: OrderedSetIterator<K>): OrderedSetIterator<K>;
forEach(callback: (element: K, index: number, tree: OrderedSet<K>) => void): void;
getElementByPos(pos: number): K;
}
export default OrderedSet;

View File

@ -0,0 +1,107 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _Base = _interopRequireDefault(require("./Base"));
var _TreeIterator = _interopRequireDefault(require("./Base/TreeIterator"));
var _throwError = require("../../utils/throwError");
function _interopRequireDefault(e) {
return e && e.t ? e : {
default: e
};
}
class OrderedSetIterator extends _TreeIterator.default {
constructor(e, t, r, i) {
super(e, t, i);
this.container = r;
}
get pointer() {
if (this.o === this.h) {
(0, _throwError.throwIteratorAccessError)();
}
return this.o.u;
}
copy() {
return new OrderedSetIterator(this.o, this.h, this.container, this.iteratorType);
}
}
class OrderedSet extends _Base.default {
constructor(e = [], t, r) {
super(t, r);
const i = this;
e.forEach((function(e) {
i.insert(e);
}));
}
* K(e) {
if (e === undefined) return;
yield* this.K(e.U);
yield e.u;
yield* this.K(e.W);
}
begin() {
return new OrderedSetIterator(this.h.U || this.h, this.h, this);
}
end() {
return new OrderedSetIterator(this.h, this.h, this);
}
rBegin() {
return new OrderedSetIterator(this.h.W || this.h, this.h, this, 1);
}
rEnd() {
return new OrderedSetIterator(this.h, this.h, this, 1);
}
front() {
return this.h.U ? this.h.U.u : undefined;
}
back() {
return this.h.W ? this.h.W.u : undefined;
}
insert(e, t) {
return this.M(e, undefined, t);
}
find(e) {
const t = this.I(this.Y, e);
return new OrderedSetIterator(t, this.h, this);
}
lowerBound(e) {
const t = this.X(this.Y, e);
return new OrderedSetIterator(t, this.h, this);
}
upperBound(e) {
const t = this.Z(this.Y, e);
return new OrderedSetIterator(t, this.h, this);
}
reverseLowerBound(e) {
const t = this.$(this.Y, e);
return new OrderedSetIterator(t, this.h, this);
}
reverseUpperBound(e) {
const t = this.rr(this.Y, e);
return new OrderedSetIterator(t, this.h, this);
}
union(e) {
const t = this;
e.forEach((function(e) {
t.insert(e);
}));
return this.i;
}
[Symbol.iterator]() {
return this.K(this.Y);
}
}
var _default = OrderedSet;
exports.default = _default;
//# sourceMappingURL=OrderedSet.js.map

File diff suppressed because one or more lines are too long