data-structure-typed 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +4 -0
- package/README.md +19 -7
- package/dist/cjs/index.cjs +1175 -585
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/{index.cjs → cjs-legacy/index.cjs} +1145 -613
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +1175 -585
- package/dist/esm/index.mjs.map +1 -1
- package/dist/{index.js → esm-legacy/index.mjs} +1147 -615
- package/dist/esm-legacy/index.mjs.map +1 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +66 -4
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +59 -5
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/bst.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +60 -6
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +66 -4
- package/dist/types/data-structures/heap/heap.d.ts +4 -4
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
- package/dist/types/interfaces/binary-tree.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +711 -228
- package/dist/umd/data-structure-typed.js.map +1 -1
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/jest.integration.config.js +7 -3
- package/package.json +29 -7
- package/src/data-structures/binary-tree/avl-tree-counter.ts +106 -15
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
- package/src/data-structures/binary-tree/avl-tree.ts +107 -16
- package/src/data-structures/binary-tree/binary-tree.ts +4 -4
- package/src/data-structures/binary-tree/bst.ts +103 -12
- package/src/data-structures/binary-tree/red-black-tree.ts +110 -20
- package/src/data-structures/binary-tree/tree-counter.ts +105 -14
- package/src/data-structures/binary-tree/tree-multi-map.ts +123 -12
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/interfaces/binary-tree.ts +1 -1
- package/test/integration/compile.test.mjs +159 -0
- package/test/integration/compile.test.ts +176 -0
- package/test/integration/heap.test.js +1 -1
- package/test/integration/index.html +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +5 -4
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/bst.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +5 -4
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +4 -4
- package/{tsconfig-base.json → tsconfig.base.json} +0 -1
- package/tsconfig.test.json +1 -0
- package/{tsconfig-types.json → tsconfig.types.json} +1 -3
- package/tsup.config.js +2 -3
- package/tsup.node.config.js +71 -0
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/test/integration/compile.js +0 -144
- package/test/integration/compile.mjs +0 -135
- package/test/integration/compile.ts +0 -171
- package/tsup.node.config.ts +0 -37
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3
5
|
|
|
4
6
|
// src/data-structures/base/iterable-entry-base.ts
|
|
5
|
-
var
|
|
6
|
-
static {
|
|
7
|
-
__name(this, "IterableEntryBase");
|
|
8
|
-
}
|
|
7
|
+
var _IterableEntryBase = class _IterableEntryBase {
|
|
9
8
|
/**
|
|
10
9
|
* Default iterator yielding `[key, value]` entries.
|
|
11
10
|
* @returns Iterator of `[K, V]`.
|
|
@@ -174,12 +173,11 @@ var IterableEntryBase = class {
|
|
|
174
173
|
console.log(this.toVisual());
|
|
175
174
|
}
|
|
176
175
|
};
|
|
176
|
+
__name(_IterableEntryBase, "IterableEntryBase");
|
|
177
|
+
var IterableEntryBase = _IterableEntryBase;
|
|
177
178
|
|
|
178
179
|
// src/data-structures/base/iterable-element-base.ts
|
|
179
|
-
var
|
|
180
|
-
static {
|
|
181
|
-
__name(this, "IterableElementBase");
|
|
182
|
-
}
|
|
180
|
+
var _IterableElementBase = class _IterableElementBase {
|
|
183
181
|
/**
|
|
184
182
|
* Create a new iterable base.
|
|
185
183
|
*
|
|
@@ -190,19 +188,19 @@ var IterableElementBase = class {
|
|
|
190
188
|
* Time O(1), Space O(1).
|
|
191
189
|
*/
|
|
192
190
|
constructor(options) {
|
|
191
|
+
/**
|
|
192
|
+
* The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
193
|
+
*
|
|
194
|
+
* @remarks
|
|
195
|
+
* Time O(1), Space O(1).
|
|
196
|
+
*/
|
|
197
|
+
__publicField(this, "_toElementFn");
|
|
193
198
|
if (options) {
|
|
194
199
|
const { toElementFn } = options;
|
|
195
200
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
196
201
|
else if (toElementFn) throw new TypeError("toElementFn must be a function type");
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
|
-
/**
|
|
200
|
-
* The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
201
|
-
*
|
|
202
|
-
* @remarks
|
|
203
|
-
* Time O(1), Space O(1).
|
|
204
|
-
*/
|
|
205
|
-
_toElementFn;
|
|
206
204
|
/**
|
|
207
205
|
* Exposes the current `toElementFn`, if configured.
|
|
208
206
|
*
|
|
@@ -397,6 +395,8 @@ var IterableElementBase = class {
|
|
|
397
395
|
console.log(this.toVisual());
|
|
398
396
|
}
|
|
399
397
|
};
|
|
398
|
+
__name(_IterableElementBase, "IterableElementBase");
|
|
399
|
+
var IterableElementBase = _IterableElementBase;
|
|
400
400
|
|
|
401
401
|
// src/utils/utils.ts
|
|
402
402
|
var uuidV4 = /* @__PURE__ */ __name(function() {
|
|
@@ -517,10 +517,7 @@ function toBinaryString(num, digit = 32) {
|
|
|
517
517
|
__name(toBinaryString, "toBinaryString");
|
|
518
518
|
|
|
519
519
|
// src/data-structures/hash/hash-map.ts
|
|
520
|
-
var
|
|
521
|
-
static {
|
|
522
|
-
__name(this, "HashMap");
|
|
523
|
-
}
|
|
520
|
+
var _HashMap = class _HashMap extends IterableEntryBase {
|
|
524
521
|
/**
|
|
525
522
|
* Create a HashMap and optionally bulk-insert entries.
|
|
526
523
|
* @remarks Time O(N), Space O(N)
|
|
@@ -530,6 +527,11 @@ var HashMap = class extends IterableEntryBase {
|
|
|
530
527
|
*/
|
|
531
528
|
constructor(entryOrRawElements = [], options) {
|
|
532
529
|
super();
|
|
530
|
+
__publicField(this, "_store", {});
|
|
531
|
+
__publicField(this, "_objMap", /* @__PURE__ */ new Map());
|
|
532
|
+
__publicField(this, "_toEntryFn");
|
|
533
|
+
__publicField(this, "_size", 0);
|
|
534
|
+
__publicField(this, "_hashFn", /* @__PURE__ */ __name((key) => String(key), "_hashFn"));
|
|
533
535
|
if (options) {
|
|
534
536
|
const { hashFn, toEntryFn } = options;
|
|
535
537
|
if (hashFn) this._hashFn = hashFn;
|
|
@@ -537,7 +539,6 @@ var HashMap = class extends IterableEntryBase {
|
|
|
537
539
|
}
|
|
538
540
|
if (entryOrRawElements) this.setMany(entryOrRawElements);
|
|
539
541
|
}
|
|
540
|
-
_store = {};
|
|
541
542
|
/**
|
|
542
543
|
* Get the internal store for non-object keys.
|
|
543
544
|
* @remarks Time O(1), Space O(1)
|
|
@@ -546,7 +547,6 @@ var HashMap = class extends IterableEntryBase {
|
|
|
546
547
|
get store() {
|
|
547
548
|
return this._store;
|
|
548
549
|
}
|
|
549
|
-
_objMap = /* @__PURE__ */ new Map();
|
|
550
550
|
/**
|
|
551
551
|
* Get the internal Map used for object/function keys.
|
|
552
552
|
* @remarks Time O(1), Space O(1)
|
|
@@ -555,7 +555,6 @@ var HashMap = class extends IterableEntryBase {
|
|
|
555
555
|
get objMap() {
|
|
556
556
|
return this._objMap;
|
|
557
557
|
}
|
|
558
|
-
_toEntryFn;
|
|
559
558
|
/**
|
|
560
559
|
* Get the raw→entry converter function if present.
|
|
561
560
|
* @remarks Time O(1), Space O(1)
|
|
@@ -564,7 +563,6 @@ var HashMap = class extends IterableEntryBase {
|
|
|
564
563
|
get toEntryFn() {
|
|
565
564
|
return this._toEntryFn;
|
|
566
565
|
}
|
|
567
|
-
_size = 0;
|
|
568
566
|
/**
|
|
569
567
|
* Get the number of distinct keys stored.
|
|
570
568
|
* @remarks Time O(1), Space O(1)
|
|
@@ -573,7 +571,6 @@ var HashMap = class extends IterableEntryBase {
|
|
|
573
571
|
get size() {
|
|
574
572
|
return this._size;
|
|
575
573
|
}
|
|
576
|
-
_hashFn = /* @__PURE__ */ __name((key) => String(key), "_hashFn");
|
|
577
574
|
/**
|
|
578
575
|
* Get the current hash function for non-object keys.
|
|
579
576
|
* @remarks Time O(1), Space O(1)
|
|
@@ -649,9 +646,10 @@ var HashMap = class extends IterableEntryBase {
|
|
|
649
646
|
* @returns Value or undefined.
|
|
650
647
|
*/
|
|
651
648
|
get(key) {
|
|
649
|
+
var _a;
|
|
652
650
|
if (this._isObjKey(key)) return this.objMap.get(key);
|
|
653
651
|
const strKey = this._getNoObjKey(key);
|
|
654
|
-
return this._store[strKey]
|
|
652
|
+
return (_a = this._store[strKey]) == null ? void 0 : _a.value;
|
|
655
653
|
}
|
|
656
654
|
/**
|
|
657
655
|
* Check if a key exists.
|
|
@@ -776,11 +774,9 @@ var HashMap = class extends IterableEntryBase {
|
|
|
776
774
|
return strKey;
|
|
777
775
|
}
|
|
778
776
|
};
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
}
|
|
783
|
-
_sentinel;
|
|
777
|
+
__name(_HashMap, "HashMap");
|
|
778
|
+
var HashMap = _HashMap;
|
|
779
|
+
var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
784
780
|
/**
|
|
785
781
|
* Create a LinkedHashMap and optionally bulk-insert entries.
|
|
786
782
|
* @remarks Time O(N), Space O(N)
|
|
@@ -790,6 +786,22 @@ var LinkedHashMap = class extends IterableEntryBase {
|
|
|
790
786
|
*/
|
|
791
787
|
constructor(entryOrRawElements = [], options) {
|
|
792
788
|
super();
|
|
789
|
+
__publicField(this, "_sentinel");
|
|
790
|
+
__publicField(this, "_hashFn", /* @__PURE__ */ __name((key) => String(key), "_hashFn"));
|
|
791
|
+
__publicField(this, "_objHashFn", /* @__PURE__ */ __name((key) => key, "_objHashFn"));
|
|
792
|
+
__publicField(this, "_noObjMap", {});
|
|
793
|
+
__publicField(this, "_objMap", /* @__PURE__ */ new WeakMap());
|
|
794
|
+
__publicField(this, "_head");
|
|
795
|
+
__publicField(this, "_tail");
|
|
796
|
+
__publicField(this, "_toEntryFn", /* @__PURE__ */ __name((rawElement) => {
|
|
797
|
+
if (this.isEntry(rawElement)) {
|
|
798
|
+
return rawElement;
|
|
799
|
+
}
|
|
800
|
+
throw new Error(
|
|
801
|
+
"If `entryOrRawElements` does not adhere to [key,value], provide `options.toEntryFn` to transform raw records."
|
|
802
|
+
);
|
|
803
|
+
}, "_toEntryFn"));
|
|
804
|
+
__publicField(this, "_size", 0);
|
|
793
805
|
this._sentinel = {};
|
|
794
806
|
this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
|
|
795
807
|
if (options) {
|
|
@@ -800,11 +812,9 @@ var LinkedHashMap = class extends IterableEntryBase {
|
|
|
800
812
|
}
|
|
801
813
|
if (entryOrRawElements) this.setMany(entryOrRawElements);
|
|
802
814
|
}
|
|
803
|
-
_hashFn = /* @__PURE__ */ __name((key) => String(key), "_hashFn");
|
|
804
815
|
get hashFn() {
|
|
805
816
|
return this._hashFn;
|
|
806
817
|
}
|
|
807
|
-
_objHashFn = /* @__PURE__ */ __name((key) => key, "_objHashFn");
|
|
808
818
|
/**
|
|
809
819
|
* Get the hash function for object/weak keys.
|
|
810
820
|
* @remarks Time O(1), Space O(1)
|
|
@@ -813,7 +823,6 @@ var LinkedHashMap = class extends IterableEntryBase {
|
|
|
813
823
|
get objHashFn() {
|
|
814
824
|
return this._objHashFn;
|
|
815
825
|
}
|
|
816
|
-
_noObjMap = {};
|
|
817
826
|
/**
|
|
818
827
|
* Get the internal record for non-object keys.
|
|
819
828
|
* @remarks Time O(1), Space O(1)
|
|
@@ -822,11 +831,9 @@ var LinkedHashMap = class extends IterableEntryBase {
|
|
|
822
831
|
get noObjMap() {
|
|
823
832
|
return this._noObjMap;
|
|
824
833
|
}
|
|
825
|
-
_objMap = /* @__PURE__ */ new WeakMap();
|
|
826
834
|
get objMap() {
|
|
827
835
|
return this._objMap;
|
|
828
836
|
}
|
|
829
|
-
_head;
|
|
830
837
|
/**
|
|
831
838
|
* Get the head node (first entry) sentinel link.
|
|
832
839
|
* @remarks Time O(1), Space O(1)
|
|
@@ -835,7 +842,6 @@ var LinkedHashMap = class extends IterableEntryBase {
|
|
|
835
842
|
get head() {
|
|
836
843
|
return this._head;
|
|
837
844
|
}
|
|
838
|
-
_tail;
|
|
839
845
|
/**
|
|
840
846
|
* Get the tail node (last entry) sentinel link.
|
|
841
847
|
* @remarks Time O(1), Space O(1)
|
|
@@ -844,18 +850,9 @@ var LinkedHashMap = class extends IterableEntryBase {
|
|
|
844
850
|
get tail() {
|
|
845
851
|
return this._tail;
|
|
846
852
|
}
|
|
847
|
-
_toEntryFn = /* @__PURE__ */ __name((rawElement) => {
|
|
848
|
-
if (this.isEntry(rawElement)) {
|
|
849
|
-
return rawElement;
|
|
850
|
-
}
|
|
851
|
-
throw new Error(
|
|
852
|
-
"If `entryOrRawElements` does not adhere to [key,value], provide `options.toEntryFn` to transform raw records."
|
|
853
|
-
);
|
|
854
|
-
}, "_toEntryFn");
|
|
855
853
|
get toEntryFn() {
|
|
856
854
|
return this._toEntryFn;
|
|
857
855
|
}
|
|
858
|
-
_size = 0;
|
|
859
856
|
get size() {
|
|
860
857
|
return this._size;
|
|
861
858
|
}
|
|
@@ -1098,22 +1095,22 @@ var LinkedHashMap = class extends IterableEntryBase {
|
|
|
1098
1095
|
return new Ctor(entries, options);
|
|
1099
1096
|
}
|
|
1100
1097
|
};
|
|
1098
|
+
__name(_LinkedHashMap, "LinkedHashMap");
|
|
1099
|
+
var LinkedHashMap = _LinkedHashMap;
|
|
1101
1100
|
|
|
1102
1101
|
// src/data-structures/base/linear-base.ts
|
|
1103
|
-
var
|
|
1104
|
-
static {
|
|
1105
|
-
__name(this, "LinkedListNode");
|
|
1106
|
-
}
|
|
1102
|
+
var _LinkedListNode = class _LinkedListNode {
|
|
1107
1103
|
/**
|
|
1108
1104
|
* Initialize a node.
|
|
1109
1105
|
* @param value - Element value.
|
|
1110
1106
|
* @remarks Time O(1), Space O(1)
|
|
1111
1107
|
*/
|
|
1112
1108
|
constructor(value) {
|
|
1109
|
+
__publicField(this, "_value");
|
|
1110
|
+
__publicField(this, "_next");
|
|
1113
1111
|
this._value = value;
|
|
1114
1112
|
this._next = void 0;
|
|
1115
1113
|
}
|
|
1116
|
-
_value;
|
|
1117
1114
|
/**
|
|
1118
1115
|
* Element payload getter.
|
|
1119
1116
|
* @returns Element value.
|
|
@@ -1130,7 +1127,6 @@ var LinkedListNode = class {
|
|
|
1130
1127
|
set value(value) {
|
|
1131
1128
|
this._value = value;
|
|
1132
1129
|
}
|
|
1133
|
-
_next;
|
|
1134
1130
|
/**
|
|
1135
1131
|
* Next node getter.
|
|
1136
1132
|
* @returns Next node or `undefined`.
|
|
@@ -1148,10 +1144,9 @@ var LinkedListNode = class {
|
|
|
1148
1144
|
this._next = value;
|
|
1149
1145
|
}
|
|
1150
1146
|
};
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
}
|
|
1147
|
+
__name(_LinkedListNode, "LinkedListNode");
|
|
1148
|
+
var LinkedListNode = _LinkedListNode;
|
|
1149
|
+
var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
1155
1150
|
/**
|
|
1156
1151
|
* Construct a linear container with runtime options.
|
|
1157
1152
|
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
@@ -1159,12 +1154,12 @@ var LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
1159
1154
|
*/
|
|
1160
1155
|
constructor(options) {
|
|
1161
1156
|
super(options);
|
|
1157
|
+
__publicField(this, "_maxLen", -1);
|
|
1162
1158
|
if (options) {
|
|
1163
1159
|
const { maxLen } = options;
|
|
1164
1160
|
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
1165
1161
|
}
|
|
1166
1162
|
}
|
|
1167
|
-
_maxLen = -1;
|
|
1168
1163
|
/**
|
|
1169
1164
|
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
1170
1165
|
* @returns Maximum allowed length.
|
|
@@ -1297,7 +1292,7 @@ var LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
1297
1292
|
return array;
|
|
1298
1293
|
}
|
|
1299
1294
|
reduceRight(callbackfn, initialValue) {
|
|
1300
|
-
let accumulator = initialValue
|
|
1295
|
+
let accumulator = initialValue != null ? initialValue : 0;
|
|
1301
1296
|
for (let i = this.length - 1; i >= 0; i--) {
|
|
1302
1297
|
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
1303
1298
|
}
|
|
@@ -1339,10 +1334,9 @@ var LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
1339
1334
|
return this;
|
|
1340
1335
|
}
|
|
1341
1336
|
};
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
}
|
|
1337
|
+
__name(_LinearBase, "LinearBase");
|
|
1338
|
+
var LinearBase = _LinearBase;
|
|
1339
|
+
var _LinearLinkedBase = class _LinearLinkedBase extends LinearBase {
|
|
1346
1340
|
constructor(options) {
|
|
1347
1341
|
super(options);
|
|
1348
1342
|
if (options) {
|
|
@@ -1472,7 +1466,7 @@ var LinearLinkedBase = class extends LinearBase {
|
|
|
1472
1466
|
return removedList;
|
|
1473
1467
|
}
|
|
1474
1468
|
reduceRight(callbackfn, initialValue) {
|
|
1475
|
-
let accumulator = initialValue
|
|
1469
|
+
let accumulator = initialValue != null ? initialValue : 0;
|
|
1476
1470
|
let index = this.length - 1;
|
|
1477
1471
|
for (const item of this._getReverseIterator()) {
|
|
1478
1472
|
accumulator = callbackfn(accumulator, item, index--, this);
|
|
@@ -1480,12 +1474,11 @@ var LinearLinkedBase = class extends LinearBase {
|
|
|
1480
1474
|
return accumulator;
|
|
1481
1475
|
}
|
|
1482
1476
|
};
|
|
1477
|
+
__name(_LinearLinkedBase, "LinearLinkedBase");
|
|
1478
|
+
var LinearLinkedBase = _LinearLinkedBase;
|
|
1483
1479
|
|
|
1484
1480
|
// src/data-structures/linked-list/singly-linked-list.ts
|
|
1485
|
-
var
|
|
1486
|
-
static {
|
|
1487
|
-
__name(this, "SinglyLinkedListNode");
|
|
1488
|
-
}
|
|
1481
|
+
var _SinglyLinkedListNode = class _SinglyLinkedListNode extends LinkedListNode {
|
|
1489
1482
|
/**
|
|
1490
1483
|
* Create a list node.
|
|
1491
1484
|
* @remarks Time O(1), Space O(1)
|
|
@@ -1494,10 +1487,10 @@ var SinglyLinkedListNode = class extends LinkedListNode {
|
|
|
1494
1487
|
*/
|
|
1495
1488
|
constructor(value) {
|
|
1496
1489
|
super(value);
|
|
1490
|
+
__publicField(this, "_next");
|
|
1497
1491
|
this._value = value;
|
|
1498
1492
|
this._next = void 0;
|
|
1499
1493
|
}
|
|
1500
|
-
_next;
|
|
1501
1494
|
/**
|
|
1502
1495
|
* Get the next node.
|
|
1503
1496
|
* @remarks Time O(1), Space O(1)
|
|
@@ -1516,11 +1509,9 @@ var SinglyLinkedListNode = class extends LinkedListNode {
|
|
|
1516
1509
|
this._next = value;
|
|
1517
1510
|
}
|
|
1518
1511
|
};
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
}
|
|
1523
|
-
_equals = Object.is;
|
|
1512
|
+
__name(_SinglyLinkedListNode, "SinglyLinkedListNode");
|
|
1513
|
+
var SinglyLinkedListNode = _SinglyLinkedListNode;
|
|
1514
|
+
var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
1524
1515
|
/**
|
|
1525
1516
|
* Create a SinglyLinkedList and optionally bulk-insert elements.
|
|
1526
1517
|
* @remarks Time O(N), Space O(N)
|
|
@@ -1530,9 +1521,12 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1530
1521
|
*/
|
|
1531
1522
|
constructor(elements = [], options) {
|
|
1532
1523
|
super(options);
|
|
1524
|
+
__publicField(this, "_equals", Object.is);
|
|
1525
|
+
__publicField(this, "_head");
|
|
1526
|
+
__publicField(this, "_tail");
|
|
1527
|
+
__publicField(this, "_length", 0);
|
|
1533
1528
|
this.pushMany(elements);
|
|
1534
1529
|
}
|
|
1535
|
-
_head;
|
|
1536
1530
|
/**
|
|
1537
1531
|
* Get the head node.
|
|
1538
1532
|
* @remarks Time O(1), Space O(1)
|
|
@@ -1541,7 +1535,6 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1541
1535
|
get head() {
|
|
1542
1536
|
return this._head;
|
|
1543
1537
|
}
|
|
1544
|
-
_tail;
|
|
1545
1538
|
/**
|
|
1546
1539
|
* Get the tail node.
|
|
1547
1540
|
* @remarks Time O(1), Space O(1)
|
|
@@ -1550,7 +1543,6 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1550
1543
|
get tail() {
|
|
1551
1544
|
return this._tail;
|
|
1552
1545
|
}
|
|
1553
|
-
_length = 0;
|
|
1554
1546
|
/**
|
|
1555
1547
|
* Get the number of elements.
|
|
1556
1548
|
* @remarks Time O(1), Space O(1)
|
|
@@ -1565,7 +1557,8 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1565
1557
|
* @returns First element or undefined.
|
|
1566
1558
|
*/
|
|
1567
1559
|
get first() {
|
|
1568
|
-
|
|
1560
|
+
var _a;
|
|
1561
|
+
return (_a = this.head) == null ? void 0 : _a.value;
|
|
1569
1562
|
}
|
|
1570
1563
|
/**
|
|
1571
1564
|
* Get the last element value.
|
|
@@ -1573,7 +1566,8 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1573
1566
|
* @returns Last element or undefined.
|
|
1574
1567
|
*/
|
|
1575
1568
|
get last() {
|
|
1576
|
-
|
|
1569
|
+
var _a;
|
|
1570
|
+
return (_a = this.tail) == null ? void 0 : _a.value;
|
|
1577
1571
|
}
|
|
1578
1572
|
/**
|
|
1579
1573
|
* Create a new list from an iterable of elements.
|
|
@@ -2052,7 +2046,7 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
2052
2046
|
* @returns A new SinglyLinkedList with mapped values.
|
|
2053
2047
|
*/
|
|
2054
2048
|
map(callback, options, thisArg) {
|
|
2055
|
-
const out = this._createLike([], { ...options
|
|
2049
|
+
const out = this._createLike([], { ...options != null ? options : {}, maxLen: this._maxLen });
|
|
2056
2050
|
let index = 0;
|
|
2057
2051
|
for (const value of this) out.push(callback.call(thisArg, value, index++, this));
|
|
2058
2052
|
return out;
|
|
@@ -2063,7 +2057,7 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
2063
2057
|
* @param value - Value to wrap in a node.
|
|
2064
2058
|
* @returns A new SinglyLinkedListNode instance.
|
|
2065
2059
|
*/
|
|
2066
|
-
|
|
2060
|
+
createNode(value) {
|
|
2067
2061
|
return new SinglyLinkedListNode(value);
|
|
2068
2062
|
}
|
|
2069
2063
|
/**
|
|
@@ -2083,7 +2077,7 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
2083
2077
|
*/
|
|
2084
2078
|
_ensureNode(elementOrNode) {
|
|
2085
2079
|
if (this.isNode(elementOrNode)) return elementOrNode;
|
|
2086
|
-
return this.
|
|
2080
|
+
return this.createNode(elementOrNode);
|
|
2087
2081
|
}
|
|
2088
2082
|
/**
|
|
2089
2083
|
* (Protected) Normalize input into a node predicate.
|
|
@@ -2177,6 +2171,8 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
2177
2171
|
return this._createLike([], options);
|
|
2178
2172
|
}
|
|
2179
2173
|
};
|
|
2174
|
+
__name(_SinglyLinkedList, "SinglyLinkedList");
|
|
2175
|
+
var SinglyLinkedList = _SinglyLinkedList;
|
|
2180
2176
|
function elementOrPredicate(input, equals) {
|
|
2181
2177
|
if (input instanceof SinglyLinkedListNode) return (node) => node === input;
|
|
2182
2178
|
if (typeof input === "function") return input;
|
|
@@ -2186,10 +2182,7 @@ function elementOrPredicate(input, equals) {
|
|
|
2186
2182
|
__name(elementOrPredicate, "elementOrPredicate");
|
|
2187
2183
|
|
|
2188
2184
|
// src/data-structures/linked-list/doubly-linked-list.ts
|
|
2189
|
-
var
|
|
2190
|
-
static {
|
|
2191
|
-
__name(this, "DoublyLinkedListNode");
|
|
2192
|
-
}
|
|
2185
|
+
var _DoublyLinkedListNode = class _DoublyLinkedListNode extends LinkedListNode {
|
|
2193
2186
|
/**
|
|
2194
2187
|
* Create a node.
|
|
2195
2188
|
* @remarks Time O(1), Space O(1)
|
|
@@ -2198,11 +2191,12 @@ var DoublyLinkedListNode = class extends LinkedListNode {
|
|
|
2198
2191
|
*/
|
|
2199
2192
|
constructor(value) {
|
|
2200
2193
|
super(value);
|
|
2194
|
+
__publicField(this, "_next");
|
|
2195
|
+
__publicField(this, "_prev");
|
|
2201
2196
|
this._value = value;
|
|
2202
2197
|
this._next = void 0;
|
|
2203
2198
|
this._prev = void 0;
|
|
2204
2199
|
}
|
|
2205
|
-
_next;
|
|
2206
2200
|
/**
|
|
2207
2201
|
* Get the next node link.
|
|
2208
2202
|
* @remarks Time O(1), Space O(1)
|
|
@@ -2220,7 +2214,6 @@ var DoublyLinkedListNode = class extends LinkedListNode {
|
|
|
2220
2214
|
set next(value) {
|
|
2221
2215
|
this._next = value;
|
|
2222
2216
|
}
|
|
2223
|
-
_prev;
|
|
2224
2217
|
/**
|
|
2225
2218
|
* Get the previous node link.
|
|
2226
2219
|
* @remarks Time O(1), Space O(1)
|
|
@@ -2239,11 +2232,9 @@ var DoublyLinkedListNode = class extends LinkedListNode {
|
|
|
2239
2232
|
this._prev = value;
|
|
2240
2233
|
}
|
|
2241
2234
|
};
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
}
|
|
2246
|
-
_equals = Object.is;
|
|
2235
|
+
__name(_DoublyLinkedListNode, "DoublyLinkedListNode");
|
|
2236
|
+
var DoublyLinkedListNode = _DoublyLinkedListNode;
|
|
2237
|
+
var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
2247
2238
|
/**
|
|
2248
2239
|
* Create a DoublyLinkedList and optionally bulk-insert elements.
|
|
2249
2240
|
* @remarks Time O(N), Space O(N)
|
|
@@ -2253,15 +2244,18 @@ var DoublyLinkedList = class extends LinearLinkedBase {
|
|
|
2253
2244
|
*/
|
|
2254
2245
|
constructor(elements = [], options) {
|
|
2255
2246
|
super(options);
|
|
2247
|
+
__publicField(this, "_equals", Object.is);
|
|
2248
|
+
__publicField(this, "_head");
|
|
2249
|
+
__publicField(this, "_tail");
|
|
2250
|
+
__publicField(this, "_length", 0);
|
|
2256
2251
|
this._head = void 0;
|
|
2257
2252
|
this._tail = void 0;
|
|
2258
2253
|
this._length = 0;
|
|
2259
|
-
if (options
|
|
2254
|
+
if ((options == null ? void 0 : options.maxLen) && Number.isInteger(options.maxLen) && options.maxLen > 0) {
|
|
2260
2255
|
this._maxLen = options.maxLen;
|
|
2261
2256
|
}
|
|
2262
2257
|
this.pushMany(elements);
|
|
2263
2258
|
}
|
|
2264
|
-
_head;
|
|
2265
2259
|
/**
|
|
2266
2260
|
* Get the head node.
|
|
2267
2261
|
* @remarks Time O(1), Space O(1)
|
|
@@ -2270,7 +2264,6 @@ var DoublyLinkedList = class extends LinearLinkedBase {
|
|
|
2270
2264
|
get head() {
|
|
2271
2265
|
return this._head;
|
|
2272
2266
|
}
|
|
2273
|
-
_tail;
|
|
2274
2267
|
/**
|
|
2275
2268
|
* Get the tail node.
|
|
2276
2269
|
* @remarks Time O(1), Space O(1)
|
|
@@ -2279,7 +2272,6 @@ var DoublyLinkedList = class extends LinearLinkedBase {
|
|
|
2279
2272
|
get tail() {
|
|
2280
2273
|
return this._tail;
|
|
2281
2274
|
}
|
|
2282
|
-
_length = 0;
|
|
2283
2275
|
/**
|
|
2284
2276
|
* Get the number of elements.
|
|
2285
2277
|
* @remarks Time O(1), Space O(1)
|
|
@@ -2294,7 +2286,8 @@ var DoublyLinkedList = class extends LinearLinkedBase {
|
|
|
2294
2286
|
* @returns First element or undefined.
|
|
2295
2287
|
*/
|
|
2296
2288
|
get first() {
|
|
2297
|
-
|
|
2289
|
+
var _a;
|
|
2290
|
+
return (_a = this.head) == null ? void 0 : _a.value;
|
|
2298
2291
|
}
|
|
2299
2292
|
/**
|
|
2300
2293
|
* Get the last element value.
|
|
@@ -2302,7 +2295,8 @@ var DoublyLinkedList = class extends LinearLinkedBase {
|
|
|
2302
2295
|
* @returns Last element or undefined.
|
|
2303
2296
|
*/
|
|
2304
2297
|
get last() {
|
|
2305
|
-
|
|
2298
|
+
var _a;
|
|
2299
|
+
return (_a = this.tail) == null ? void 0 : _a.value;
|
|
2306
2300
|
}
|
|
2307
2301
|
/**
|
|
2308
2302
|
* Create a new list from an array of elements.
|
|
@@ -2717,7 +2711,7 @@ var DoublyLinkedList = class extends LinearLinkedBase {
|
|
|
2717
2711
|
* @returns A new DoublyLinkedList with mapped values.
|
|
2718
2712
|
*/
|
|
2719
2713
|
map(callback, options, thisArg) {
|
|
2720
|
-
const out = this._createLike([], { ...options
|
|
2714
|
+
const out = this._createLike([], { ...options != null ? options : {}, maxLen: this._maxLen });
|
|
2721
2715
|
let index = 0;
|
|
2722
2716
|
for (const v of this) out.push(callback.call(thisArg, v, index++, this));
|
|
2723
2717
|
return out;
|
|
@@ -2803,26 +2797,28 @@ var DoublyLinkedList = class extends LinearLinkedBase {
|
|
|
2803
2797
|
}
|
|
2804
2798
|
}
|
|
2805
2799
|
};
|
|
2800
|
+
__name(_DoublyLinkedList, "DoublyLinkedList");
|
|
2801
|
+
var DoublyLinkedList = _DoublyLinkedList;
|
|
2806
2802
|
|
|
2807
2803
|
// src/data-structures/linked-list/skip-linked-list.ts
|
|
2808
|
-
var
|
|
2809
|
-
static {
|
|
2810
|
-
__name(this, "SkipListNode");
|
|
2811
|
-
}
|
|
2812
|
-
key;
|
|
2813
|
-
value;
|
|
2814
|
-
forward;
|
|
2804
|
+
var _SkipListNode = class _SkipListNode {
|
|
2815
2805
|
constructor(key, value, level) {
|
|
2806
|
+
__publicField(this, "key");
|
|
2807
|
+
__publicField(this, "value");
|
|
2808
|
+
__publicField(this, "forward");
|
|
2816
2809
|
this.key = key;
|
|
2817
2810
|
this.value = value;
|
|
2818
2811
|
this.forward = new Array(level);
|
|
2819
2812
|
}
|
|
2820
2813
|
};
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
}
|
|
2814
|
+
__name(_SkipListNode, "SkipListNode");
|
|
2815
|
+
var SkipListNode = _SkipListNode;
|
|
2816
|
+
var _SkipList = class _SkipList {
|
|
2825
2817
|
constructor(elements = [], options) {
|
|
2818
|
+
__publicField(this, "_head", new SkipListNode(void 0, void 0, this.maxLevel));
|
|
2819
|
+
__publicField(this, "_level", 0);
|
|
2820
|
+
__publicField(this, "_maxLevel", 16);
|
|
2821
|
+
__publicField(this, "_probability", 0.5);
|
|
2826
2822
|
if (options) {
|
|
2827
2823
|
const { maxLevel, probability } = options;
|
|
2828
2824
|
if (typeof maxLevel === "number") this._maxLevel = maxLevel;
|
|
@@ -2832,19 +2828,15 @@ var SkipList = class {
|
|
|
2832
2828
|
for (const [key, value] of elements) this.add(key, value);
|
|
2833
2829
|
}
|
|
2834
2830
|
}
|
|
2835
|
-
_head = new SkipListNode(void 0, void 0, this.maxLevel);
|
|
2836
2831
|
get head() {
|
|
2837
2832
|
return this._head;
|
|
2838
2833
|
}
|
|
2839
|
-
_level = 0;
|
|
2840
2834
|
get level() {
|
|
2841
2835
|
return this._level;
|
|
2842
2836
|
}
|
|
2843
|
-
_maxLevel = 16;
|
|
2844
2837
|
get maxLevel() {
|
|
2845
2838
|
return this._maxLevel;
|
|
2846
2839
|
}
|
|
2847
|
-
_probability = 0.5;
|
|
2848
2840
|
get probability() {
|
|
2849
2841
|
return this._probability;
|
|
2850
2842
|
}
|
|
@@ -2950,13 +2942,11 @@ var SkipList = class {
|
|
|
2950
2942
|
return level;
|
|
2951
2943
|
}
|
|
2952
2944
|
};
|
|
2945
|
+
__name(_SkipList, "SkipList");
|
|
2946
|
+
var SkipList = _SkipList;
|
|
2953
2947
|
|
|
2954
2948
|
// src/data-structures/stack/stack.ts
|
|
2955
|
-
var
|
|
2956
|
-
static {
|
|
2957
|
-
__name(this, "Stack");
|
|
2958
|
-
}
|
|
2959
|
-
_equals = Object.is;
|
|
2949
|
+
var _Stack = class _Stack extends IterableElementBase {
|
|
2960
2950
|
/**
|
|
2961
2951
|
* Create a Stack and optionally bulk-push elements.
|
|
2962
2952
|
* @remarks Time O(N), Space O(N)
|
|
@@ -2966,9 +2956,10 @@ var Stack = class extends IterableElementBase {
|
|
|
2966
2956
|
*/
|
|
2967
2957
|
constructor(elements = [], options) {
|
|
2968
2958
|
super(options);
|
|
2959
|
+
__publicField(this, "_equals", Object.is);
|
|
2960
|
+
__publicField(this, "_elements", []);
|
|
2969
2961
|
this.pushMany(elements);
|
|
2970
2962
|
}
|
|
2971
|
-
_elements = [];
|
|
2972
2963
|
/**
|
|
2973
2964
|
* Get the backing array of elements.
|
|
2974
2965
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3143,7 +3134,7 @@ var Stack = class extends IterableElementBase {
|
|
|
3143
3134
|
* @returns A new Stack with mapped elements.
|
|
3144
3135
|
*/
|
|
3145
3136
|
map(callback, options, thisArg) {
|
|
3146
|
-
const out = this._createLike([], { ...options
|
|
3137
|
+
const out = this._createLike([], { ...options != null ? options : {} });
|
|
3147
3138
|
let index = 0;
|
|
3148
3139
|
for (const v of this) {
|
|
3149
3140
|
out.push(thisArg === void 0 ? callback(v, index, this) : callback.call(thisArg, v, index, this));
|
|
@@ -3203,12 +3194,11 @@ var Stack = class extends IterableElementBase {
|
|
|
3203
3194
|
for (let i = 0; i < this.elements.length; i++) yield this.elements[i];
|
|
3204
3195
|
}
|
|
3205
3196
|
};
|
|
3197
|
+
__name(_Stack, "Stack");
|
|
3198
|
+
var Stack = _Stack;
|
|
3206
3199
|
|
|
3207
3200
|
// src/data-structures/queue/queue.ts
|
|
3208
|
-
var
|
|
3209
|
-
static {
|
|
3210
|
-
__name(this, "Queue");
|
|
3211
|
-
}
|
|
3201
|
+
var _Queue = class _Queue extends LinearBase {
|
|
3212
3202
|
/**
|
|
3213
3203
|
* Create a Queue and optionally bulk-insert elements.
|
|
3214
3204
|
* @remarks Time O(N), Space O(N)
|
|
@@ -3218,13 +3208,15 @@ var Queue = class _Queue extends LinearBase {
|
|
|
3218
3208
|
*/
|
|
3219
3209
|
constructor(elements = [], options) {
|
|
3220
3210
|
super(options);
|
|
3211
|
+
__publicField(this, "_elements", []);
|
|
3212
|
+
__publicField(this, "_offset", 0);
|
|
3213
|
+
__publicField(this, "_autoCompactRatio", 0.5);
|
|
3221
3214
|
if (options) {
|
|
3222
3215
|
const { autoCompactRatio = 0.5 } = options;
|
|
3223
3216
|
this._autoCompactRatio = autoCompactRatio;
|
|
3224
3217
|
}
|
|
3225
3218
|
this.pushMany(elements);
|
|
3226
3219
|
}
|
|
3227
|
-
_elements = [];
|
|
3228
3220
|
/**
|
|
3229
3221
|
* Get the underlying array buffer.
|
|
3230
3222
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3233,7 +3225,6 @@ var Queue = class _Queue extends LinearBase {
|
|
|
3233
3225
|
get elements() {
|
|
3234
3226
|
return this._elements;
|
|
3235
3227
|
}
|
|
3236
|
-
_offset = 0;
|
|
3237
3228
|
/**
|
|
3238
3229
|
* Get the current start offset into the array.
|
|
3239
3230
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3242,7 +3233,6 @@ var Queue = class _Queue extends LinearBase {
|
|
|
3242
3233
|
get offset() {
|
|
3243
3234
|
return this._offset;
|
|
3244
3235
|
}
|
|
3245
|
-
_autoCompactRatio = 0.5;
|
|
3246
3236
|
/**
|
|
3247
3237
|
* Get the compaction threshold (offset/size).
|
|
3248
3238
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3487,10 +3477,11 @@ var Queue = class _Queue extends LinearBase {
|
|
|
3487
3477
|
* @returns A new Queue with mapped elements.
|
|
3488
3478
|
*/
|
|
3489
3479
|
map(callback, options, thisArg) {
|
|
3480
|
+
var _a, _b;
|
|
3490
3481
|
const out = new this.constructor([], {
|
|
3491
|
-
toElementFn: options
|
|
3492
|
-
maxLen: options
|
|
3493
|
-
autoCompactRatio: options
|
|
3482
|
+
toElementFn: options == null ? void 0 : options.toElementFn,
|
|
3483
|
+
maxLen: (_a = options == null ? void 0 : options.maxLen) != null ? _a : this._maxLen,
|
|
3484
|
+
autoCompactRatio: (_b = options == null ? void 0 : options.autoCompactRatio) != null ? _b : this._autoCompactRatio
|
|
3494
3485
|
});
|
|
3495
3486
|
let index = 0;
|
|
3496
3487
|
for (const v of this)
|
|
@@ -3505,13 +3496,14 @@ var Queue = class _Queue extends LinearBase {
|
|
|
3505
3496
|
* @returns A new queue with mapped elements (same element type).
|
|
3506
3497
|
*/
|
|
3507
3498
|
mapSame(callback, thisArg) {
|
|
3499
|
+
var _a;
|
|
3508
3500
|
const Ctor = this.constructor;
|
|
3509
3501
|
const out = new Ctor([], {
|
|
3510
3502
|
toElementFn: this.toElementFn,
|
|
3511
3503
|
maxLen: this._maxLen,
|
|
3512
3504
|
autoCompactRatio: this._autoCompactRatio
|
|
3513
3505
|
});
|
|
3514
|
-
out._setAutoCompactRatio
|
|
3506
|
+
(_a = out._setAutoCompactRatio) == null ? void 0 : _a.call(out, this._autoCompactRatio);
|
|
3515
3507
|
let index = 0;
|
|
3516
3508
|
for (const v of this) {
|
|
3517
3509
|
const mv = thisArg === void 0 ? callback(v, index++, this) : callback.call(thisArg, v, index++, this);
|
|
@@ -3571,10 +3563,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
3571
3563
|
return new Ctor(elements, options);
|
|
3572
3564
|
}
|
|
3573
3565
|
};
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
}
|
|
3566
|
+
__name(_Queue, "Queue");
|
|
3567
|
+
var Queue = _Queue;
|
|
3568
|
+
var _LinkedListQueue = class _LinkedListQueue extends SinglyLinkedList {
|
|
3578
3569
|
/**
|
|
3579
3570
|
* Deep clone this linked-list-based queue.
|
|
3580
3571
|
* @remarks Time O(N), Space O(N)
|
|
@@ -3586,13 +3577,11 @@ var LinkedListQueue = class extends SinglyLinkedList {
|
|
|
3586
3577
|
return out;
|
|
3587
3578
|
}
|
|
3588
3579
|
};
|
|
3580
|
+
__name(_LinkedListQueue, "LinkedListQueue");
|
|
3581
|
+
var LinkedListQueue = _LinkedListQueue;
|
|
3589
3582
|
|
|
3590
3583
|
// src/data-structures/queue/deque.ts
|
|
3591
|
-
var
|
|
3592
|
-
static {
|
|
3593
|
-
__name(this, "Deque");
|
|
3594
|
-
}
|
|
3595
|
-
_equals = Object.is;
|
|
3584
|
+
var _Deque = class _Deque extends LinearBase {
|
|
3596
3585
|
/**
|
|
3597
3586
|
* Create a Deque and optionally bulk-insert elements.
|
|
3598
3587
|
* @remarks Time O(N), Space O(N)
|
|
@@ -3602,6 +3591,15 @@ var Deque = class extends LinearBase {
|
|
|
3602
3591
|
*/
|
|
3603
3592
|
constructor(elements = [], options) {
|
|
3604
3593
|
super(options);
|
|
3594
|
+
__publicField(this, "_equals", Object.is);
|
|
3595
|
+
__publicField(this, "_bucketSize", 1 << 12);
|
|
3596
|
+
__publicField(this, "_bucketFirst", 0);
|
|
3597
|
+
__publicField(this, "_firstInBucket", 0);
|
|
3598
|
+
__publicField(this, "_bucketLast", 0);
|
|
3599
|
+
__publicField(this, "_lastInBucket", 0);
|
|
3600
|
+
__publicField(this, "_bucketCount", 0);
|
|
3601
|
+
__publicField(this, "_buckets", []);
|
|
3602
|
+
__publicField(this, "_length", 0);
|
|
3605
3603
|
if (options) {
|
|
3606
3604
|
const { bucketSize } = options;
|
|
3607
3605
|
if (typeof bucketSize === "number") this._bucketSize = bucketSize;
|
|
@@ -3621,7 +3619,6 @@ var Deque = class extends LinearBase {
|
|
|
3621
3619
|
this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
|
|
3622
3620
|
this.pushMany(elements);
|
|
3623
3621
|
}
|
|
3624
|
-
_bucketSize = 1 << 12;
|
|
3625
3622
|
/**
|
|
3626
3623
|
* Get the current bucket size.
|
|
3627
3624
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3630,7 +3627,6 @@ var Deque = class extends LinearBase {
|
|
|
3630
3627
|
get bucketSize() {
|
|
3631
3628
|
return this._bucketSize;
|
|
3632
3629
|
}
|
|
3633
|
-
_bucketFirst = 0;
|
|
3634
3630
|
/**
|
|
3635
3631
|
* Get the index of the first bucket in use.
|
|
3636
3632
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3639,7 +3635,6 @@ var Deque = class extends LinearBase {
|
|
|
3639
3635
|
get bucketFirst() {
|
|
3640
3636
|
return this._bucketFirst;
|
|
3641
3637
|
}
|
|
3642
|
-
_firstInBucket = 0;
|
|
3643
3638
|
/**
|
|
3644
3639
|
* Get the index inside the first bucket.
|
|
3645
3640
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3648,7 +3643,6 @@ var Deque = class extends LinearBase {
|
|
|
3648
3643
|
get firstInBucket() {
|
|
3649
3644
|
return this._firstInBucket;
|
|
3650
3645
|
}
|
|
3651
|
-
_bucketLast = 0;
|
|
3652
3646
|
/**
|
|
3653
3647
|
* Get the index of the last bucket in use.
|
|
3654
3648
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3657,7 +3651,6 @@ var Deque = class extends LinearBase {
|
|
|
3657
3651
|
get bucketLast() {
|
|
3658
3652
|
return this._bucketLast;
|
|
3659
3653
|
}
|
|
3660
|
-
_lastInBucket = 0;
|
|
3661
3654
|
/**
|
|
3662
3655
|
* Get the index inside the last bucket.
|
|
3663
3656
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3666,7 +3659,6 @@ var Deque = class extends LinearBase {
|
|
|
3666
3659
|
get lastInBucket() {
|
|
3667
3660
|
return this._lastInBucket;
|
|
3668
3661
|
}
|
|
3669
|
-
_bucketCount = 0;
|
|
3670
3662
|
/**
|
|
3671
3663
|
* Get the number of buckets allocated.
|
|
3672
3664
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3675,7 +3667,6 @@ var Deque = class extends LinearBase {
|
|
|
3675
3667
|
get bucketCount() {
|
|
3676
3668
|
return this._bucketCount;
|
|
3677
3669
|
}
|
|
3678
|
-
_buckets = [];
|
|
3679
3670
|
/**
|
|
3680
3671
|
* Get the internal buckets array.
|
|
3681
3672
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3684,7 +3675,6 @@ var Deque = class extends LinearBase {
|
|
|
3684
3675
|
get buckets() {
|
|
3685
3676
|
return this._buckets;
|
|
3686
3677
|
}
|
|
3687
|
-
_length = 0;
|
|
3688
3678
|
/**
|
|
3689
3679
|
* Get the number of elements in the deque.
|
|
3690
3680
|
* @remarks Time O(1), Space O(1)
|
|
@@ -4200,7 +4190,7 @@ var Deque = class extends LinearBase {
|
|
|
4200
4190
|
*/
|
|
4201
4191
|
map(callback, options, thisArg) {
|
|
4202
4192
|
const out = this._createLike([], {
|
|
4203
|
-
...options
|
|
4193
|
+
...options != null ? options : {},
|
|
4204
4194
|
bucketSize: this._bucketSize,
|
|
4205
4195
|
maxLen: this._maxLen
|
|
4206
4196
|
});
|
|
@@ -4314,13 +4304,11 @@ var Deque = class extends LinearBase {
|
|
|
4314
4304
|
}
|
|
4315
4305
|
}
|
|
4316
4306
|
};
|
|
4307
|
+
__name(_Deque, "Deque");
|
|
4308
|
+
var Deque = _Deque;
|
|
4317
4309
|
|
|
4318
4310
|
// src/data-structures/heap/heap.ts
|
|
4319
|
-
var
|
|
4320
|
-
static {
|
|
4321
|
-
__name(this, "Heap");
|
|
4322
|
-
}
|
|
4323
|
-
_equals = Object.is;
|
|
4311
|
+
var _Heap = class _Heap extends IterableElementBase {
|
|
4324
4312
|
/**
|
|
4325
4313
|
* Create a Heap and optionally bulk-insert elements.
|
|
4326
4314
|
* @remarks Time O(N), Space O(N)
|
|
@@ -4330,13 +4318,23 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
4330
4318
|
*/
|
|
4331
4319
|
constructor(elements = [], options) {
|
|
4332
4320
|
super(options);
|
|
4321
|
+
__publicField(this, "_equals", Object.is);
|
|
4322
|
+
__publicField(this, "_elements", []);
|
|
4323
|
+
__publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
|
|
4324
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
4325
|
+
throw TypeError("When comparing object types, define a custom comparator in options.");
|
|
4326
|
+
}
|
|
4327
|
+
if (a > b) return 1;
|
|
4328
|
+
if (a < b) return -1;
|
|
4329
|
+
return 0;
|
|
4330
|
+
}, "_DEFAULT_COMPARATOR"));
|
|
4331
|
+
__publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
|
|
4333
4332
|
if (options) {
|
|
4334
4333
|
const { comparator } = options;
|
|
4335
4334
|
if (comparator) this._comparator = comparator;
|
|
4336
4335
|
}
|
|
4337
4336
|
this.addMany(elements);
|
|
4338
4337
|
}
|
|
4339
|
-
_elements = [];
|
|
4340
4338
|
/**
|
|
4341
4339
|
* Get the backing array of the heap.
|
|
4342
4340
|
* @remarks Time O(1), Space O(1)
|
|
@@ -4359,7 +4357,8 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
4359
4357
|
* @returns Last element or undefined.
|
|
4360
4358
|
*/
|
|
4361
4359
|
get leaf() {
|
|
4362
|
-
|
|
4360
|
+
var _a;
|
|
4361
|
+
return (_a = this.elements[this.size - 1]) != null ? _a : void 0;
|
|
4363
4362
|
}
|
|
4364
4363
|
/**
|
|
4365
4364
|
* Create a heap of the same class from an iterable.
|
|
@@ -4632,7 +4631,7 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
4632
4631
|
* @returns A new heap with mapped elements.
|
|
4633
4632
|
*/
|
|
4634
4633
|
map(callback, options, thisArg) {
|
|
4635
|
-
const { comparator, toElementFn, ...rest } = options
|
|
4634
|
+
const { comparator, toElementFn, ...rest } = options != null ? options : {};
|
|
4636
4635
|
if (!comparator) throw new TypeError("Heap.map requires options.comparator for EM");
|
|
4637
4636
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
4638
4637
|
let i = 0;
|
|
@@ -4658,15 +4657,6 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
4658
4657
|
}
|
|
4659
4658
|
return out;
|
|
4660
4659
|
}
|
|
4661
|
-
_DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
|
|
4662
|
-
if (typeof a === "object" || typeof b === "object") {
|
|
4663
|
-
throw TypeError("When comparing object types, define a custom comparator in options.");
|
|
4664
|
-
}
|
|
4665
|
-
if (a > b) return 1;
|
|
4666
|
-
if (a < b) return -1;
|
|
4667
|
-
return 0;
|
|
4668
|
-
}, "_DEFAULT_COMPARATOR");
|
|
4669
|
-
_comparator = this._DEFAULT_COMPARATOR;
|
|
4670
4660
|
/**
|
|
4671
4661
|
* Get the comparator used to order elements.
|
|
4672
4662
|
* @remarks Time O(1), Space O(1)
|
|
@@ -4720,7 +4710,7 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
4720
4710
|
*/
|
|
4721
4711
|
_createInstance(options) {
|
|
4722
4712
|
const Ctor = this.constructor;
|
|
4723
|
-
const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options
|
|
4713
|
+
const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
|
|
4724
4714
|
return next;
|
|
4725
4715
|
}
|
|
4726
4716
|
/**
|
|
@@ -4748,27 +4738,25 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
4748
4738
|
return this._createLike([], options);
|
|
4749
4739
|
}
|
|
4750
4740
|
};
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
}
|
|
4755
|
-
element;
|
|
4756
|
-
degree;
|
|
4757
|
-
left;
|
|
4758
|
-
right;
|
|
4759
|
-
child;
|
|
4760
|
-
parent;
|
|
4761
|
-
marked;
|
|
4741
|
+
__name(_Heap, "Heap");
|
|
4742
|
+
var Heap = _Heap;
|
|
4743
|
+
var _FibonacciHeapNode = class _FibonacciHeapNode {
|
|
4762
4744
|
constructor(element, degree = 0) {
|
|
4745
|
+
__publicField(this, "element");
|
|
4746
|
+
__publicField(this, "degree");
|
|
4747
|
+
__publicField(this, "left");
|
|
4748
|
+
__publicField(this, "right");
|
|
4749
|
+
__publicField(this, "child");
|
|
4750
|
+
__publicField(this, "parent");
|
|
4751
|
+
__publicField(this, "marked");
|
|
4763
4752
|
this.element = element;
|
|
4764
4753
|
this.degree = degree;
|
|
4765
4754
|
this.marked = false;
|
|
4766
4755
|
}
|
|
4767
4756
|
};
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
}
|
|
4757
|
+
__name(_FibonacciHeapNode, "FibonacciHeapNode");
|
|
4758
|
+
var FibonacciHeapNode = _FibonacciHeapNode;
|
|
4759
|
+
var _FibonacciHeap = class _FibonacciHeap {
|
|
4772
4760
|
/**
|
|
4773
4761
|
* Create a FibonacciHeap.
|
|
4774
4762
|
* @remarks Time O(1), Space O(1)
|
|
@@ -4776,11 +4764,14 @@ var FibonacciHeap = class {
|
|
|
4776
4764
|
* @returns New FibonacciHeap instance.
|
|
4777
4765
|
*/
|
|
4778
4766
|
constructor(comparator) {
|
|
4767
|
+
__publicField(this, "_root");
|
|
4768
|
+
__publicField(this, "_size", 0);
|
|
4769
|
+
__publicField(this, "_min");
|
|
4770
|
+
__publicField(this, "_comparator");
|
|
4779
4771
|
this.clear();
|
|
4780
4772
|
this._comparator = comparator || this._defaultComparator;
|
|
4781
4773
|
if (typeof this.comparator !== "function") throw new Error("FibonacciHeap: comparator must be a function.");
|
|
4782
4774
|
}
|
|
4783
|
-
_root;
|
|
4784
4775
|
/**
|
|
4785
4776
|
* Get the circular root list head.
|
|
4786
4777
|
* @remarks Time O(1), Space O(1)
|
|
@@ -4789,11 +4780,9 @@ var FibonacciHeap = class {
|
|
|
4789
4780
|
get root() {
|
|
4790
4781
|
return this._root;
|
|
4791
4782
|
}
|
|
4792
|
-
_size = 0;
|
|
4793
4783
|
get size() {
|
|
4794
4784
|
return this._size;
|
|
4795
4785
|
}
|
|
4796
|
-
_min;
|
|
4797
4786
|
/**
|
|
4798
4787
|
* Get the current minimum node.
|
|
4799
4788
|
* @remarks Time O(1), Space O(1)
|
|
@@ -4802,7 +4791,6 @@ var FibonacciHeap = class {
|
|
|
4802
4791
|
get min() {
|
|
4803
4792
|
return this._min;
|
|
4804
4793
|
}
|
|
4805
|
-
_comparator;
|
|
4806
4794
|
get comparator() {
|
|
4807
4795
|
return this._comparator;
|
|
4808
4796
|
}
|
|
@@ -4822,7 +4810,7 @@ var FibonacciHeap = class {
|
|
|
4822
4810
|
* @returns This heap.
|
|
4823
4811
|
*/
|
|
4824
4812
|
push(element) {
|
|
4825
|
-
const node = this.
|
|
4813
|
+
const node = this.createNode(element);
|
|
4826
4814
|
node.left = node;
|
|
4827
4815
|
node.right = node;
|
|
4828
4816
|
this.mergeWithRoot(node);
|
|
@@ -4921,7 +4909,7 @@ var FibonacciHeap = class {
|
|
|
4921
4909
|
this._size += heapToMerge.size;
|
|
4922
4910
|
heapToMerge.clear();
|
|
4923
4911
|
}
|
|
4924
|
-
|
|
4912
|
+
createNode(element) {
|
|
4925
4913
|
return new FibonacciHeapNode(element);
|
|
4926
4914
|
}
|
|
4927
4915
|
isEmpty() {
|
|
@@ -4979,12 +4967,11 @@ var FibonacciHeap = class {
|
|
|
4979
4967
|
}
|
|
4980
4968
|
}
|
|
4981
4969
|
};
|
|
4970
|
+
__name(_FibonacciHeap, "FibonacciHeap");
|
|
4971
|
+
var FibonacciHeap = _FibonacciHeap;
|
|
4982
4972
|
|
|
4983
4973
|
// src/data-structures/heap/max-heap.ts
|
|
4984
|
-
var
|
|
4985
|
-
static {
|
|
4986
|
-
__name(this, "MaxHeap");
|
|
4987
|
-
}
|
|
4974
|
+
var _MaxHeap = class _MaxHeap extends Heap {
|
|
4988
4975
|
/**
|
|
4989
4976
|
* Create a max-heap. For objects, supply a custom comparator.
|
|
4990
4977
|
* @param elements Optional initial elements.
|
|
@@ -5006,12 +4993,11 @@ var MaxHeap = class extends Heap {
|
|
|
5006
4993
|
});
|
|
5007
4994
|
}
|
|
5008
4995
|
};
|
|
4996
|
+
__name(_MaxHeap, "MaxHeap");
|
|
4997
|
+
var MaxHeap = _MaxHeap;
|
|
5009
4998
|
|
|
5010
4999
|
// src/data-structures/heap/min-heap.ts
|
|
5011
|
-
var
|
|
5012
|
-
static {
|
|
5013
|
-
__name(this, "MinHeap");
|
|
5014
|
-
}
|
|
5000
|
+
var _MinHeap = class _MinHeap extends Heap {
|
|
5015
5001
|
/**
|
|
5016
5002
|
* Create a min-heap.
|
|
5017
5003
|
* @param elements Optional initial elements.
|
|
@@ -5021,39 +5007,36 @@ var MinHeap = class extends Heap {
|
|
|
5021
5007
|
super(elements, options);
|
|
5022
5008
|
}
|
|
5023
5009
|
};
|
|
5010
|
+
__name(_MinHeap, "MinHeap");
|
|
5011
|
+
var MinHeap = _MinHeap;
|
|
5024
5012
|
|
|
5025
5013
|
// src/data-structures/graph/abstract-graph.ts
|
|
5026
|
-
var
|
|
5027
|
-
static {
|
|
5028
|
-
__name(this, "AbstractVertex");
|
|
5029
|
-
}
|
|
5030
|
-
key;
|
|
5031
|
-
value;
|
|
5014
|
+
var _AbstractVertex = class _AbstractVertex {
|
|
5032
5015
|
constructor(key, value) {
|
|
5016
|
+
__publicField(this, "key");
|
|
5017
|
+
__publicField(this, "value");
|
|
5033
5018
|
this.key = key;
|
|
5034
5019
|
this.value = value;
|
|
5035
5020
|
}
|
|
5036
5021
|
};
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
}
|
|
5041
|
-
value;
|
|
5042
|
-
weight;
|
|
5022
|
+
__name(_AbstractVertex, "AbstractVertex");
|
|
5023
|
+
var AbstractVertex = _AbstractVertex;
|
|
5024
|
+
var _AbstractEdge = class _AbstractEdge {
|
|
5043
5025
|
constructor(weight, value) {
|
|
5026
|
+
__publicField(this, "value");
|
|
5027
|
+
__publicField(this, "weight");
|
|
5028
|
+
__publicField(this, "_hashCode");
|
|
5044
5029
|
this.weight = weight !== void 0 ? weight : 1;
|
|
5045
5030
|
this.value = value;
|
|
5046
5031
|
this._hashCode = uuidV4();
|
|
5047
5032
|
}
|
|
5048
|
-
_hashCode;
|
|
5049
5033
|
get hashCode() {
|
|
5050
5034
|
return this._hashCode;
|
|
5051
5035
|
}
|
|
5052
5036
|
};
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
}
|
|
5037
|
+
__name(_AbstractEdge, "AbstractEdge");
|
|
5038
|
+
var AbstractEdge = _AbstractEdge;
|
|
5039
|
+
var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
|
|
5057
5040
|
/**
|
|
5058
5041
|
* Construct a graph with runtime defaults.
|
|
5059
5042
|
* @param options - `GraphOptions<V>` in `options.graph` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
|
|
@@ -5061,14 +5044,14 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5061
5044
|
*/
|
|
5062
5045
|
constructor(options) {
|
|
5063
5046
|
super();
|
|
5064
|
-
|
|
5065
|
-
this
|
|
5047
|
+
__publicField(this, "_options", { defaultEdgeWeight: 1 });
|
|
5048
|
+
__publicField(this, "_vertexMap", /* @__PURE__ */ new Map());
|
|
5049
|
+
const graph = options == null ? void 0 : options.graph;
|
|
5050
|
+
this._options = { defaultEdgeWeight: 1, ...graph != null ? graph : {} };
|
|
5066
5051
|
}
|
|
5067
|
-
_options = { defaultEdgeWeight: 1 };
|
|
5068
5052
|
get options() {
|
|
5069
5053
|
return this._options;
|
|
5070
5054
|
}
|
|
5071
|
-
_vertexMap = /* @__PURE__ */ new Map();
|
|
5072
5055
|
get vertexMap() {
|
|
5073
5056
|
return this._vertexMap;
|
|
5074
5057
|
}
|
|
@@ -5226,9 +5209,10 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5226
5209
|
* @remarks Time O(L), Space O(1) where L is path length
|
|
5227
5210
|
*/
|
|
5228
5211
|
getPathSumWeight(path) {
|
|
5212
|
+
var _a;
|
|
5229
5213
|
let sum = 0;
|
|
5230
5214
|
for (let i = 0; i < path.length; i++) {
|
|
5231
|
-
sum += this.getEdge(path[i], path[i + 1])
|
|
5215
|
+
sum += ((_a = this.getEdge(path[i], path[i + 1])) == null ? void 0 : _a.weight) || 0;
|
|
5232
5216
|
}
|
|
5233
5217
|
return sum;
|
|
5234
5218
|
}
|
|
@@ -5290,6 +5274,7 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5290
5274
|
* @remarks Time O((V + E) log V) weighted / O(V + E) unweighted, Space O(V + E)
|
|
5291
5275
|
*/
|
|
5292
5276
|
getMinPathBetween(v1, v2, isWeight, isDFS = false) {
|
|
5277
|
+
var _a, _b;
|
|
5293
5278
|
if (isWeight === void 0) isWeight = false;
|
|
5294
5279
|
if (isWeight) {
|
|
5295
5280
|
if (isDFS) {
|
|
@@ -5307,7 +5292,7 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5307
5292
|
}
|
|
5308
5293
|
return allPaths[minIndex] || void 0;
|
|
5309
5294
|
} else {
|
|
5310
|
-
return this.dijkstra(v1, v2, true, true)
|
|
5295
|
+
return (_b = (_a = this.dijkstra(v1, v2, true, true)) == null ? void 0 : _a.minPath) != null ? _b : [];
|
|
5311
5296
|
}
|
|
5312
5297
|
} else {
|
|
5313
5298
|
let minPath = [];
|
|
@@ -5436,6 +5421,7 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5436
5421
|
return { distMap, preMap, seen, paths, minDist, minPath };
|
|
5437
5422
|
}
|
|
5438
5423
|
dijkstra(src, dest = void 0, getMinDist = false, genPaths = false) {
|
|
5424
|
+
var _a;
|
|
5439
5425
|
let minDist = Number.MAX_SAFE_INTEGER;
|
|
5440
5426
|
let minDest = void 0;
|
|
5441
5427
|
let minPath = [];
|
|
@@ -5473,8 +5459,8 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5473
5459
|
}, "getPaths");
|
|
5474
5460
|
while (heap.size > 0) {
|
|
5475
5461
|
const curHeapNode = heap.poll();
|
|
5476
|
-
const dist = curHeapNode
|
|
5477
|
-
const cur = curHeapNode
|
|
5462
|
+
const dist = curHeapNode == null ? void 0 : curHeapNode.key;
|
|
5463
|
+
const cur = curHeapNode == null ? void 0 : curHeapNode.value;
|
|
5478
5464
|
if (dist !== void 0) {
|
|
5479
5465
|
if (cur) {
|
|
5480
5466
|
seen.add(cur);
|
|
@@ -5490,7 +5476,7 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5490
5476
|
const neighbors = this.getNeighbors(cur);
|
|
5491
5477
|
for (const neighbor of neighbors) {
|
|
5492
5478
|
if (!seen.has(neighbor)) {
|
|
5493
|
-
const weight = this.getEdge(cur, neighbor)
|
|
5479
|
+
const weight = (_a = this.getEdge(cur, neighbor)) == null ? void 0 : _a.weight;
|
|
5494
5480
|
if (typeof weight === "number") {
|
|
5495
5481
|
const distSrcToNeighbor = distMap.get(neighbor);
|
|
5496
5482
|
if (distSrcToNeighbor !== void 0) {
|
|
@@ -5613,6 +5599,7 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5613
5599
|
* @remarks Time O(V^3), Space O(V^2)
|
|
5614
5600
|
*/
|
|
5615
5601
|
floydWarshall() {
|
|
5602
|
+
var _a;
|
|
5616
5603
|
const idAndVertices = [...this._vertexMap];
|
|
5617
5604
|
const n = idAndVertices.length;
|
|
5618
5605
|
const costs = [];
|
|
@@ -5626,7 +5613,7 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5626
5613
|
}
|
|
5627
5614
|
for (let i = 0; i < n; i++) {
|
|
5628
5615
|
for (let j = 0; j < n; j++) {
|
|
5629
|
-
costs[i][j] = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])
|
|
5616
|
+
costs[i][j] = ((_a = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])) == null ? void 0 : _a.weight) || Number.MAX_SAFE_INTEGER;
|
|
5630
5617
|
}
|
|
5631
5618
|
}
|
|
5632
5619
|
for (let k = 0; k < n; k++) {
|
|
@@ -5769,7 +5756,7 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5769
5756
|
_createInstance(_options) {
|
|
5770
5757
|
const Ctor = this.constructor;
|
|
5771
5758
|
const instance = new Ctor();
|
|
5772
|
-
const graph = _options
|
|
5759
|
+
const graph = _options == null ? void 0 : _options.graph;
|
|
5773
5760
|
if (graph) instance._options = { ...instance._options, ...graph };
|
|
5774
5761
|
else instance._options = { ...instance._options, ...this._options };
|
|
5775
5762
|
return instance;
|
|
@@ -5848,32 +5835,29 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
5848
5835
|
return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
|
|
5849
5836
|
}
|
|
5850
5837
|
};
|
|
5838
|
+
__name(_AbstractGraph, "AbstractGraph");
|
|
5839
|
+
var AbstractGraph = _AbstractGraph;
|
|
5851
5840
|
|
|
5852
5841
|
// src/data-structures/graph/directed-graph.ts
|
|
5853
|
-
var
|
|
5854
|
-
static {
|
|
5855
|
-
__name(this, "DirectedVertex");
|
|
5856
|
-
}
|
|
5842
|
+
var _DirectedVertex = class _DirectedVertex extends AbstractVertex {
|
|
5857
5843
|
constructor(key, value) {
|
|
5858
5844
|
super(key, value);
|
|
5859
5845
|
}
|
|
5860
5846
|
};
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
}
|
|
5865
|
-
src;
|
|
5866
|
-
dest;
|
|
5847
|
+
__name(_DirectedVertex, "DirectedVertex");
|
|
5848
|
+
var DirectedVertex = _DirectedVertex;
|
|
5849
|
+
var _DirectedEdge = class _DirectedEdge extends AbstractEdge {
|
|
5867
5850
|
constructor(src, dest, weight, value) {
|
|
5868
5851
|
super(weight, value);
|
|
5852
|
+
__publicField(this, "src");
|
|
5853
|
+
__publicField(this, "dest");
|
|
5869
5854
|
this.src = src;
|
|
5870
5855
|
this.dest = dest;
|
|
5871
5856
|
}
|
|
5872
5857
|
};
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
}
|
|
5858
|
+
__name(_DirectedEdge, "DirectedEdge");
|
|
5859
|
+
var DirectedEdge = _DirectedEdge;
|
|
5860
|
+
var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
5877
5861
|
/**
|
|
5878
5862
|
* Construct a directed graph with runtime defaults.
|
|
5879
5863
|
* @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
|
|
@@ -5881,15 +5865,15 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
5881
5865
|
*/
|
|
5882
5866
|
constructor(options) {
|
|
5883
5867
|
super(options);
|
|
5868
|
+
__publicField(this, "_outEdgeMap", /* @__PURE__ */ new Map());
|
|
5869
|
+
__publicField(this, "_inEdgeMap", /* @__PURE__ */ new Map());
|
|
5884
5870
|
}
|
|
5885
|
-
_outEdgeMap = /* @__PURE__ */ new Map();
|
|
5886
5871
|
get outEdgeMap() {
|
|
5887
5872
|
return this._outEdgeMap;
|
|
5888
5873
|
}
|
|
5889
5874
|
set outEdgeMap(v) {
|
|
5890
5875
|
this._outEdgeMap = v;
|
|
5891
5876
|
}
|
|
5892
|
-
_inEdgeMap = /* @__PURE__ */ new Map();
|
|
5893
5877
|
get inEdgeMap() {
|
|
5894
5878
|
return this._inEdgeMap;
|
|
5895
5879
|
}
|
|
@@ -5942,7 +5926,8 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
5942
5926
|
* @remarks Time O(1), Space O(1)
|
|
5943
5927
|
*/
|
|
5944
5928
|
createEdge(src, dest, weight, value) {
|
|
5945
|
-
|
|
5929
|
+
var _a;
|
|
5930
|
+
return new DirectedEdge(src, dest, (_a = weight != null ? weight : this.options.defaultEdgeWeight) != null ? _a : 1, value);
|
|
5946
5931
|
}
|
|
5947
5932
|
/**
|
|
5948
5933
|
* Get the unique edge from `src` to `dest`, if present.
|
|
@@ -6013,7 +5998,7 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
6013
5998
|
if (src && dest) {
|
|
6014
5999
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
6015
6000
|
if (srcOutEdges && srcOutEdges.length > 0) {
|
|
6016
|
-
arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === dest
|
|
6001
|
+
arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === (dest == null ? void 0 : dest.key));
|
|
6017
6002
|
}
|
|
6018
6003
|
const destInEdges = this._inEdgeMap.get(dest);
|
|
6019
6004
|
if (destInEdges && destInEdges.length > 0) {
|
|
@@ -6135,7 +6120,7 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
6135
6120
|
* @remarks Time O(V + E), Space O(V)
|
|
6136
6121
|
*/
|
|
6137
6122
|
topologicalSort(propertyName) {
|
|
6138
|
-
propertyName = propertyName
|
|
6123
|
+
propertyName = propertyName != null ? propertyName : "key";
|
|
6139
6124
|
const statusMap = /* @__PURE__ */ new Map();
|
|
6140
6125
|
for (const entry of this.vertexMap) {
|
|
6141
6126
|
statusMap.set(entry[1], 0);
|
|
@@ -6328,30 +6313,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
6328
6313
|
}
|
|
6329
6314
|
}
|
|
6330
6315
|
};
|
|
6316
|
+
__name(_DirectedGraph, "DirectedGraph");
|
|
6317
|
+
var DirectedGraph = _DirectedGraph;
|
|
6331
6318
|
|
|
6332
6319
|
// src/data-structures/graph/undirected-graph.ts
|
|
6333
|
-
var
|
|
6334
|
-
static {
|
|
6335
|
-
__name(this, "UndirectedVertex");
|
|
6336
|
-
}
|
|
6320
|
+
var _UndirectedVertex = class _UndirectedVertex extends AbstractVertex {
|
|
6337
6321
|
constructor(key, value) {
|
|
6338
6322
|
super(key, value);
|
|
6339
6323
|
}
|
|
6340
6324
|
};
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
}
|
|
6345
|
-
endpoints;
|
|
6325
|
+
__name(_UndirectedVertex, "UndirectedVertex");
|
|
6326
|
+
var UndirectedVertex = _UndirectedVertex;
|
|
6327
|
+
var _UndirectedEdge = class _UndirectedEdge extends AbstractEdge {
|
|
6346
6328
|
constructor(v1, v2, weight, value) {
|
|
6347
6329
|
super(weight, value);
|
|
6330
|
+
__publicField(this, "endpoints");
|
|
6348
6331
|
this.endpoints = [v1, v2];
|
|
6349
6332
|
}
|
|
6350
6333
|
};
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
}
|
|
6334
|
+
__name(_UndirectedEdge, "UndirectedEdge");
|
|
6335
|
+
var UndirectedEdge = _UndirectedEdge;
|
|
6336
|
+
var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
6355
6337
|
/**
|
|
6356
6338
|
* Construct an undirected graph with runtime defaults.
|
|
6357
6339
|
* @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
|
|
@@ -6359,9 +6341,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
6359
6341
|
*/
|
|
6360
6342
|
constructor(options) {
|
|
6361
6343
|
super(options);
|
|
6344
|
+
__publicField(this, "_edgeMap");
|
|
6362
6345
|
this._edgeMap = /* @__PURE__ */ new Map();
|
|
6363
6346
|
}
|
|
6364
|
-
_edgeMap;
|
|
6365
6347
|
get edgeMap() {
|
|
6366
6348
|
return this._edgeMap;
|
|
6367
6349
|
}
|
|
@@ -6414,7 +6396,8 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
6414
6396
|
* @remarks Time O(1), Space O(1)
|
|
6415
6397
|
*/
|
|
6416
6398
|
createEdge(v1, v2, weight, value) {
|
|
6417
|
-
|
|
6399
|
+
var _a;
|
|
6400
|
+
return new UndirectedEdge(v1, v2, (_a = weight != null ? weight : this.options.defaultEdgeWeight) != null ? _a : 1, value);
|
|
6418
6401
|
}
|
|
6419
6402
|
/**
|
|
6420
6403
|
* Get an undirected edge between two vertices, if present.
|
|
@@ -6424,12 +6407,13 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
6424
6407
|
* @remarks Time O(1) avg, Space O(1)
|
|
6425
6408
|
*/
|
|
6426
6409
|
getEdge(v1, v2) {
|
|
6410
|
+
var _a;
|
|
6427
6411
|
let edgeMap = [];
|
|
6428
6412
|
if (v1 !== void 0 && v2 !== void 0) {
|
|
6429
6413
|
const vertex1 = this._getVertex(v1);
|
|
6430
6414
|
const vertex2 = this._getVertex(v2);
|
|
6431
6415
|
if (vertex1 && vertex2) {
|
|
6432
|
-
edgeMap = this._edgeMap.get(vertex1)
|
|
6416
|
+
edgeMap = (_a = this._edgeMap.get(vertex1)) == null ? void 0 : _a.filter((e) => e.endpoints.includes(vertex2.key));
|
|
6433
6417
|
}
|
|
6434
6418
|
}
|
|
6435
6419
|
return edgeMap ? edgeMap[0] || void 0 : void 0;
|
|
@@ -6522,9 +6506,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
6522
6506
|
* @remarks Time O(1) avg, Space O(1)
|
|
6523
6507
|
*/
|
|
6524
6508
|
degreeOf(vertexOrKey) {
|
|
6509
|
+
var _a;
|
|
6525
6510
|
const vertex = this._getVertex(vertexOrKey);
|
|
6526
6511
|
if (vertex) {
|
|
6527
|
-
return this._edgeMap.get(vertex)
|
|
6512
|
+
return ((_a = this._edgeMap.get(vertex)) == null ? void 0 : _a.length) || 0;
|
|
6528
6513
|
} else {
|
|
6529
6514
|
return 0;
|
|
6530
6515
|
}
|
|
@@ -6717,32 +6702,29 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
6717
6702
|
return true;
|
|
6718
6703
|
}
|
|
6719
6704
|
};
|
|
6705
|
+
__name(_UndirectedGraph, "UndirectedGraph");
|
|
6706
|
+
var UndirectedGraph = _UndirectedGraph;
|
|
6720
6707
|
|
|
6721
6708
|
// src/data-structures/graph/map-graph.ts
|
|
6722
|
-
var
|
|
6723
|
-
static {
|
|
6724
|
-
__name(this, "MapVertex");
|
|
6725
|
-
}
|
|
6726
|
-
lat;
|
|
6727
|
-
long;
|
|
6709
|
+
var _MapVertex = class _MapVertex extends DirectedVertex {
|
|
6728
6710
|
constructor(key, value, lat, long) {
|
|
6729
6711
|
super(key, value);
|
|
6712
|
+
__publicField(this, "lat");
|
|
6713
|
+
__publicField(this, "long");
|
|
6730
6714
|
this.lat = lat;
|
|
6731
6715
|
this.long = long;
|
|
6732
6716
|
}
|
|
6733
6717
|
};
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
}
|
|
6718
|
+
__name(_MapVertex, "MapVertex");
|
|
6719
|
+
var MapVertex = _MapVertex;
|
|
6720
|
+
var _MapEdge = class _MapEdge extends DirectedEdge {
|
|
6738
6721
|
constructor(src, dest, weight, value) {
|
|
6739
6722
|
super(src, dest, weight, value);
|
|
6740
6723
|
}
|
|
6741
6724
|
};
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
}
|
|
6725
|
+
__name(_MapEdge, "MapEdge");
|
|
6726
|
+
var MapEdge = _MapEdge;
|
|
6727
|
+
var _MapGraph = class _MapGraph extends DirectedGraph {
|
|
6746
6728
|
/**
|
|
6747
6729
|
* Construct a MapGraph.
|
|
6748
6730
|
* @param originCoord - Origin coordinate `[lat, long]` used as default.
|
|
@@ -6751,14 +6733,14 @@ var MapGraph = class _MapGraph extends DirectedGraph {
|
|
|
6751
6733
|
*/
|
|
6752
6734
|
constructor(originCoord, bottomRight) {
|
|
6753
6735
|
super();
|
|
6736
|
+
__publicField(this, "_originCoord", [0, 0]);
|
|
6737
|
+
__publicField(this, "_bottomRight");
|
|
6754
6738
|
this._originCoord = originCoord;
|
|
6755
6739
|
this._bottomRight = bottomRight;
|
|
6756
6740
|
}
|
|
6757
|
-
_originCoord = [0, 0];
|
|
6758
6741
|
get originCoord() {
|
|
6759
6742
|
return this._originCoord;
|
|
6760
6743
|
}
|
|
6761
|
-
_bottomRight;
|
|
6762
6744
|
get bottomRight() {
|
|
6763
6745
|
return this._bottomRight;
|
|
6764
6746
|
}
|
|
@@ -6810,11 +6792,13 @@ var MapGraph = class _MapGraph extends DirectedGraph {
|
|
|
6810
6792
|
*/
|
|
6811
6793
|
_createInstance(options) {
|
|
6812
6794
|
const { originCoord, bottomRight } = options || {};
|
|
6813
|
-
const oc = originCoord
|
|
6814
|
-
const br = bottomRight
|
|
6795
|
+
const oc = originCoord != null ? originCoord : this.originCoord;
|
|
6796
|
+
const br = bottomRight != null ? bottomRight : this.bottomRight;
|
|
6815
6797
|
return new _MapGraph(oc, br);
|
|
6816
6798
|
}
|
|
6817
6799
|
};
|
|
6800
|
+
__name(_MapGraph, "MapGraph");
|
|
6801
|
+
var MapGraph = _MapGraph;
|
|
6818
6802
|
|
|
6819
6803
|
// src/common/index.ts
|
|
6820
6804
|
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
@@ -6822,7 +6806,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
|
6822
6806
|
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
6823
6807
|
return DFSOperation2;
|
|
6824
6808
|
})(DFSOperation || {});
|
|
6825
|
-
var
|
|
6809
|
+
var _Range = class _Range {
|
|
6826
6810
|
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
6827
6811
|
this.low = low;
|
|
6828
6812
|
this.high = high;
|
|
@@ -6831,9 +6815,6 @@ var Range = class {
|
|
|
6831
6815
|
if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
|
|
6832
6816
|
if (low > high) throw new RangeError("low must be less than or equal to high");
|
|
6833
6817
|
}
|
|
6834
|
-
static {
|
|
6835
|
-
__name(this, "Range");
|
|
6836
|
-
}
|
|
6837
6818
|
// Determine whether a key is within the range
|
|
6838
6819
|
isInRange(key, comparator) {
|
|
6839
6820
|
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
@@ -6841,15 +6822,11 @@ var Range = class {
|
|
|
6841
6822
|
return lowCheck && highCheck;
|
|
6842
6823
|
}
|
|
6843
6824
|
};
|
|
6825
|
+
__name(_Range, "Range");
|
|
6826
|
+
var Range = _Range;
|
|
6844
6827
|
|
|
6845
6828
|
// src/data-structures/binary-tree/binary-tree.ts
|
|
6846
|
-
var
|
|
6847
|
-
static {
|
|
6848
|
-
__name(this, "BinaryTreeNode");
|
|
6849
|
-
}
|
|
6850
|
-
key;
|
|
6851
|
-
value;
|
|
6852
|
-
parent = void 0;
|
|
6829
|
+
var _BinaryTreeNode = class _BinaryTreeNode {
|
|
6853
6830
|
/**
|
|
6854
6831
|
* Creates an instance of BinaryTreeNode.
|
|
6855
6832
|
* @remarks Time O(1), Space O(1)
|
|
@@ -6858,10 +6835,17 @@ var BinaryTreeNode = class {
|
|
|
6858
6835
|
* @param [value] - The value associated with the key.
|
|
6859
6836
|
*/
|
|
6860
6837
|
constructor(key, value) {
|
|
6838
|
+
__publicField(this, "key");
|
|
6839
|
+
__publicField(this, "value");
|
|
6840
|
+
__publicField(this, "parent");
|
|
6841
|
+
__publicField(this, "_left");
|
|
6842
|
+
__publicField(this, "_right");
|
|
6843
|
+
__publicField(this, "_height", 0);
|
|
6844
|
+
__publicField(this, "_color", "BLACK");
|
|
6845
|
+
__publicField(this, "_count", 1);
|
|
6861
6846
|
this.key = key;
|
|
6862
6847
|
this.value = value;
|
|
6863
6848
|
}
|
|
6864
|
-
_left = void 0;
|
|
6865
6849
|
/**
|
|
6866
6850
|
* Gets the left child of the node.
|
|
6867
6851
|
* @remarks Time O(1), Space O(1)
|
|
@@ -6883,7 +6867,6 @@ var BinaryTreeNode = class {
|
|
|
6883
6867
|
}
|
|
6884
6868
|
this._left = v;
|
|
6885
6869
|
}
|
|
6886
|
-
_right = void 0;
|
|
6887
6870
|
/**
|
|
6888
6871
|
* Gets the right child of the node.
|
|
6889
6872
|
* @remarks Time O(1), Space O(1)
|
|
@@ -6905,7 +6888,6 @@ var BinaryTreeNode = class {
|
|
|
6905
6888
|
}
|
|
6906
6889
|
this._right = v;
|
|
6907
6890
|
}
|
|
6908
|
-
_height = 0;
|
|
6909
6891
|
/**
|
|
6910
6892
|
* Gets the height of the node (used in self-balancing trees).
|
|
6911
6893
|
* @remarks Time O(1), Space O(1)
|
|
@@ -6924,7 +6906,6 @@ var BinaryTreeNode = class {
|
|
|
6924
6906
|
set height(value) {
|
|
6925
6907
|
this._height = value;
|
|
6926
6908
|
}
|
|
6927
|
-
_color = "BLACK";
|
|
6928
6909
|
/**
|
|
6929
6910
|
* Gets the color of the node (used in Red-Black trees).
|
|
6930
6911
|
* @remarks Time O(1), Space O(1)
|
|
@@ -6943,7 +6924,6 @@ var BinaryTreeNode = class {
|
|
|
6943
6924
|
set color(value) {
|
|
6944
6925
|
this._color = value;
|
|
6945
6926
|
}
|
|
6946
|
-
_count = 1;
|
|
6947
6927
|
/**
|
|
6948
6928
|
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
6949
6929
|
* @remarks Time O(1), Space O(1)
|
|
@@ -6980,11 +6960,9 @@ var BinaryTreeNode = class {
|
|
|
6980
6960
|
return "MAL_NODE";
|
|
6981
6961
|
}
|
|
6982
6962
|
};
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
}
|
|
6987
|
-
iterationType = "ITERATIVE";
|
|
6963
|
+
__name(_BinaryTreeNode, "BinaryTreeNode");
|
|
6964
|
+
var BinaryTreeNode = _BinaryTreeNode;
|
|
6965
|
+
var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
6988
6966
|
/**
|
|
6989
6967
|
* Creates an instance of BinaryTree.
|
|
6990
6968
|
* @remarks Time O(N * M), where N is the number of items in `keysNodesEntriesOrRaws` and M is the tree size at insertion time (due to O(M) `add` operation). Space O(N) for storing the nodes.
|
|
@@ -6994,6 +6972,22 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
6994
6972
|
*/
|
|
6995
6973
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
6996
6974
|
super();
|
|
6975
|
+
__publicField(this, "iterationType", "ITERATIVE");
|
|
6976
|
+
__publicField(this, "_isMapMode", true);
|
|
6977
|
+
__publicField(this, "_isDuplicate", false);
|
|
6978
|
+
__publicField(this, "_store", /* @__PURE__ */ new Map());
|
|
6979
|
+
__publicField(this, "_root");
|
|
6980
|
+
__publicField(this, "_size", 0);
|
|
6981
|
+
__publicField(this, "_NIL", new BinaryTreeNode(NaN));
|
|
6982
|
+
__publicField(this, "_toEntryFn");
|
|
6983
|
+
/**
|
|
6984
|
+
* (Protected) Default callback function, returns the node's key.
|
|
6985
|
+
* @remarks Time O(1)
|
|
6986
|
+
*
|
|
6987
|
+
* @param node - The node.
|
|
6988
|
+
* @returns The node's key or undefined.
|
|
6989
|
+
*/
|
|
6990
|
+
__publicField(this, "_DEFAULT_NODE_CALLBACK", /* @__PURE__ */ __name((node) => node ? node.key : void 0, "_DEFAULT_NODE_CALLBACK"));
|
|
6997
6991
|
if (options) {
|
|
6998
6992
|
const { iterationType, toEntryFn, isMapMode, isDuplicate } = options;
|
|
6999
6993
|
if (iterationType) this.iterationType = iterationType;
|
|
@@ -7004,7 +6998,6 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7004
6998
|
}
|
|
7005
6999
|
if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
|
|
7006
7000
|
}
|
|
7007
|
-
_isMapMode = true;
|
|
7008
7001
|
/**
|
|
7009
7002
|
* Gets whether the tree is in Map mode.
|
|
7010
7003
|
* @remarks In Map mode (default), values are stored in an external Map, and nodes only hold keys. If false, values are stored directly on the nodes. Time O(1)
|
|
@@ -7014,7 +7007,6 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7014
7007
|
get isMapMode() {
|
|
7015
7008
|
return this._isMapMode;
|
|
7016
7009
|
}
|
|
7017
|
-
_isDuplicate = false;
|
|
7018
7010
|
/**
|
|
7019
7011
|
* Gets whether the tree allows duplicate keys.
|
|
7020
7012
|
* @remarks Time O(1)
|
|
@@ -7024,7 +7016,6 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7024
7016
|
get isDuplicate() {
|
|
7025
7017
|
return this._isDuplicate;
|
|
7026
7018
|
}
|
|
7027
|
-
_store = /* @__PURE__ */ new Map();
|
|
7028
7019
|
/**
|
|
7029
7020
|
* Gets the external value store (used in Map mode).
|
|
7030
7021
|
* @remarks Time O(1)
|
|
@@ -7034,7 +7025,6 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7034
7025
|
get store() {
|
|
7035
7026
|
return this._store;
|
|
7036
7027
|
}
|
|
7037
|
-
_root;
|
|
7038
7028
|
/**
|
|
7039
7029
|
* Gets the root node of the tree.
|
|
7040
7030
|
* @remarks Time O(1)
|
|
@@ -7044,7 +7034,6 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7044
7034
|
get root() {
|
|
7045
7035
|
return this._root;
|
|
7046
7036
|
}
|
|
7047
|
-
_size = 0;
|
|
7048
7037
|
/**
|
|
7049
7038
|
* Gets the number of nodes in the tree.
|
|
7050
7039
|
* @remarks Time O(1)
|
|
@@ -7054,7 +7043,6 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7054
7043
|
get size() {
|
|
7055
7044
|
return this._size;
|
|
7056
7045
|
}
|
|
7057
|
-
_NIL = new BinaryTreeNode(NaN);
|
|
7058
7046
|
/**
|
|
7059
7047
|
* Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
|
|
7060
7048
|
* @remarks Time O(1)
|
|
@@ -7064,7 +7052,6 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7064
7052
|
get NIL() {
|
|
7065
7053
|
return this._NIL;
|
|
7066
7054
|
}
|
|
7067
|
-
_toEntryFn;
|
|
7068
7055
|
/**
|
|
7069
7056
|
* Gets the function used to convert raw data objects (R) into [key, value] entries.
|
|
7070
7057
|
* @remarks Time O(1)
|
|
@@ -7082,7 +7069,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7082
7069
|
* @param [value] - The value for the new node (used if not in Map mode).
|
|
7083
7070
|
* @returns The newly created node.
|
|
7084
7071
|
*/
|
|
7085
|
-
|
|
7072
|
+
createNode(key, value) {
|
|
7086
7073
|
return new BinaryTreeNode(key, this._isMapMode ? void 0 : value);
|
|
7087
7074
|
}
|
|
7088
7075
|
/**
|
|
@@ -7224,7 +7211,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7224
7211
|
if (newNode === void 0) return false;
|
|
7225
7212
|
if (!this._root) {
|
|
7226
7213
|
this._setRoot(newNode);
|
|
7227
|
-
if (this._isMapMode) this._setValue(newNode
|
|
7214
|
+
if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
|
|
7228
7215
|
this._size = 1;
|
|
7229
7216
|
return true;
|
|
7230
7217
|
}
|
|
@@ -7256,7 +7243,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7256
7243
|
} else if (potentialParent.right === void 0) {
|
|
7257
7244
|
potentialParent.right = newNode;
|
|
7258
7245
|
}
|
|
7259
|
-
if (this._isMapMode) this._setValue(newNode
|
|
7246
|
+
if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
|
|
7260
7247
|
this._size++;
|
|
7261
7248
|
return true;
|
|
7262
7249
|
}
|
|
@@ -7321,7 +7308,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7321
7308
|
if (!this._root) return deletedResult;
|
|
7322
7309
|
const curr = this.getNode(keyNodeOrEntry);
|
|
7323
7310
|
if (!curr) return deletedResult;
|
|
7324
|
-
const parent = curr
|
|
7311
|
+
const parent = curr == null ? void 0 : curr.parent;
|
|
7325
7312
|
let needBalanced;
|
|
7326
7313
|
let orgCurrent = curr;
|
|
7327
7314
|
if (!curr.left && !curr.right && !parent) {
|
|
@@ -7426,12 +7413,13 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7426
7413
|
* @returns The associated value, or undefined.
|
|
7427
7414
|
*/
|
|
7428
7415
|
get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
7416
|
+
var _a;
|
|
7429
7417
|
if (this._isMapMode) {
|
|
7430
7418
|
const key = this._extractKey(keyNodeEntryOrPredicate);
|
|
7431
7419
|
if (key === null || key === void 0) return;
|
|
7432
7420
|
return this._store.get(key);
|
|
7433
7421
|
}
|
|
7434
|
-
return this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)
|
|
7422
|
+
return (_a = this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)) == null ? void 0 : _a.value;
|
|
7435
7423
|
}
|
|
7436
7424
|
has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
7437
7425
|
return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType).length > 0;
|
|
@@ -7519,7 +7507,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7519
7507
|
let distEnsured = this.ensureNode(dist);
|
|
7520
7508
|
const beginRootEnsured = this.ensureNode(startNode);
|
|
7521
7509
|
let depth = 0;
|
|
7522
|
-
while (distEnsured
|
|
7510
|
+
while (distEnsured == null ? void 0 : distEnsured.parent) {
|
|
7523
7511
|
if (distEnsured === beginRootEnsured) {
|
|
7524
7512
|
return depth;
|
|
7525
7513
|
}
|
|
@@ -8081,10 +8069,10 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8081
8069
|
const dfs = /* @__PURE__ */ __name((node) => {
|
|
8082
8070
|
if (!shouldVisitRoot(node)) return;
|
|
8083
8071
|
const visitLeft = /* @__PURE__ */ __name(() => {
|
|
8084
|
-
if (shouldVisitLeft(node) && node
|
|
8072
|
+
if (shouldVisitLeft(node) && (node == null ? void 0 : node.left) !== void 0) dfs(node == null ? void 0 : node.left);
|
|
8085
8073
|
}, "visitLeft");
|
|
8086
8074
|
const visitRight = /* @__PURE__ */ __name(() => {
|
|
8087
|
-
if (shouldVisitRight(node) && node
|
|
8075
|
+
if (shouldVisitRight(node) && (node == null ? void 0 : node.right) !== void 0) dfs(node == null ? void 0 : node.right);
|
|
8088
8076
|
}, "visitRight");
|
|
8089
8077
|
switch (pattern) {
|
|
8090
8078
|
case "IN":
|
|
@@ -8117,10 +8105,12 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8117
8105
|
} else {
|
|
8118
8106
|
const stack = [{ opt: 0 /* VISIT */, node: startNode }];
|
|
8119
8107
|
const pushLeft = /* @__PURE__ */ __name((cur) => {
|
|
8120
|
-
|
|
8108
|
+
var _a;
|
|
8109
|
+
if (shouldVisitLeft(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.left });
|
|
8121
8110
|
}, "pushLeft");
|
|
8122
8111
|
const pushRight = /* @__PURE__ */ __name((cur) => {
|
|
8123
|
-
|
|
8112
|
+
var _a;
|
|
8113
|
+
if (shouldVisitRight(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.right });
|
|
8124
8114
|
}, "pushRight");
|
|
8125
8115
|
const pushRoot = /* @__PURE__ */ __name((cur) => {
|
|
8126
8116
|
if (shouldVisitRoot(cur.node)) stack.push({ opt: 1 /* PROCESS */, node: cur.node });
|
|
@@ -8192,14 +8182,6 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8192
8182
|
}
|
|
8193
8183
|
}
|
|
8194
8184
|
}
|
|
8195
|
-
/**
|
|
8196
|
-
* (Protected) Default callback function, returns the node's key.
|
|
8197
|
-
* @remarks Time O(1)
|
|
8198
|
-
*
|
|
8199
|
-
* @param node - The node.
|
|
8200
|
-
* @returns The node's key or undefined.
|
|
8201
|
-
*/
|
|
8202
|
-
_DEFAULT_NODE_CALLBACK = /* @__PURE__ */ __name((node) => node ? node.key : void 0, "_DEFAULT_NODE_CALLBACK");
|
|
8203
8185
|
/**
|
|
8204
8186
|
* (Protected) Snapshots the current tree's configuration options.
|
|
8205
8187
|
* @remarks Time O(1)
|
|
@@ -8225,7 +8207,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8225
8207
|
*/
|
|
8226
8208
|
_createInstance(options) {
|
|
8227
8209
|
const Ctor = this.constructor;
|
|
8228
|
-
return new Ctor([], { ...this._snapshotOptions(), ...options
|
|
8210
|
+
return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
8229
8211
|
}
|
|
8230
8212
|
/**
|
|
8231
8213
|
* (Protected) Creates a new instance of the same tree constructor, potentially with different generic types.
|
|
@@ -8238,7 +8220,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8238
8220
|
*/
|
|
8239
8221
|
_createLike(iter = [], options) {
|
|
8240
8222
|
const Ctor = this.constructor;
|
|
8241
|
-
return new Ctor(iter, { ...this._snapshotOptions(), ...options
|
|
8223
|
+
return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
8242
8224
|
}
|
|
8243
8225
|
/**
|
|
8244
8226
|
* (Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
|
|
@@ -8256,10 +8238,10 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8256
8238
|
const [key, entryValue] = keyNodeOrEntry;
|
|
8257
8239
|
if (key === void 0) return [void 0, void 0];
|
|
8258
8240
|
else if (key === null) return [null, void 0];
|
|
8259
|
-
const finalValue = value
|
|
8260
|
-
return [this.
|
|
8241
|
+
const finalValue = value != null ? value : entryValue;
|
|
8242
|
+
return [this.createNode(key, finalValue), finalValue];
|
|
8261
8243
|
}
|
|
8262
|
-
return [this.
|
|
8244
|
+
return [this.createNode(keyNodeOrEntry, value), value];
|
|
8263
8245
|
}
|
|
8264
8246
|
/**
|
|
8265
8247
|
* (Protected) Helper for cloning. Performs a BFS and adds all nodes to the new tree.
|
|
@@ -8344,7 +8326,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8344
8326
|
destNode = this.ensureNode(destNode);
|
|
8345
8327
|
if (srcNode && destNode) {
|
|
8346
8328
|
const { key, value } = destNode;
|
|
8347
|
-
const tempNode = this.
|
|
8329
|
+
const tempNode = this.createNode(key, value);
|
|
8348
8330
|
if (tempNode) {
|
|
8349
8331
|
destNode.key = srcNode.key;
|
|
8350
8332
|
if (!this._isMapMode) destNode.value = srcNode.value;
|
|
@@ -8463,13 +8445,11 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8463
8445
|
this._store.clear();
|
|
8464
8446
|
}
|
|
8465
8447
|
};
|
|
8448
|
+
__name(_BinaryTree, "BinaryTree");
|
|
8449
|
+
var BinaryTree = _BinaryTree;
|
|
8466
8450
|
|
|
8467
8451
|
// src/data-structures/binary-tree/bst.ts
|
|
8468
|
-
var
|
|
8469
|
-
static {
|
|
8470
|
-
__name(this, "BSTNode");
|
|
8471
|
-
}
|
|
8472
|
-
parent = void 0;
|
|
8452
|
+
var _BSTNode = class _BSTNode {
|
|
8473
8453
|
/**
|
|
8474
8454
|
* Creates an instance of BSTNode.
|
|
8475
8455
|
* @remarks Time O(1), Space O(1)
|
|
@@ -8478,9 +8458,17 @@ var BSTNode = class extends BinaryTreeNode {
|
|
|
8478
8458
|
* @param [value] - The value associated with the key.
|
|
8479
8459
|
*/
|
|
8480
8460
|
constructor(key, value) {
|
|
8481
|
-
|
|
8461
|
+
__publicField(this, "key");
|
|
8462
|
+
__publicField(this, "value");
|
|
8463
|
+
__publicField(this, "parent");
|
|
8464
|
+
__publicField(this, "_left");
|
|
8465
|
+
__publicField(this, "_right");
|
|
8466
|
+
__publicField(this, "_height", 0);
|
|
8467
|
+
__publicField(this, "_color", "BLACK");
|
|
8468
|
+
__publicField(this, "_count", 1);
|
|
8469
|
+
this.key = key;
|
|
8470
|
+
this.value = value;
|
|
8482
8471
|
}
|
|
8483
|
-
_left = void 0;
|
|
8484
8472
|
/**
|
|
8485
8473
|
* Gets the left child of the node.
|
|
8486
8474
|
* @remarks Time O(1), Space O(1)
|
|
@@ -8500,7 +8488,6 @@ var BSTNode = class extends BinaryTreeNode {
|
|
|
8500
8488
|
if (v) v.parent = this;
|
|
8501
8489
|
this._left = v;
|
|
8502
8490
|
}
|
|
8503
|
-
_right = void 0;
|
|
8504
8491
|
/**
|
|
8505
8492
|
* Gets the right child of the node.
|
|
8506
8493
|
* @remarks Time O(1), Space O(1)
|
|
@@ -8520,11 +8507,81 @@ var BSTNode = class extends BinaryTreeNode {
|
|
|
8520
8507
|
if (v) v.parent = this;
|
|
8521
8508
|
this._right = v;
|
|
8522
8509
|
}
|
|
8523
|
-
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8510
|
+
/**
|
|
8511
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
8512
|
+
* @remarks Time O(1), Space O(1)
|
|
8513
|
+
*
|
|
8514
|
+
* @returns The height.
|
|
8515
|
+
*/
|
|
8516
|
+
get height() {
|
|
8517
|
+
return this._height;
|
|
8518
|
+
}
|
|
8519
|
+
/**
|
|
8520
|
+
* Sets the height of the node.
|
|
8521
|
+
* @remarks Time O(1), Space O(1)
|
|
8522
|
+
*
|
|
8523
|
+
* @param value - The new height.
|
|
8524
|
+
*/
|
|
8525
|
+
set height(value) {
|
|
8526
|
+
this._height = value;
|
|
8527
|
+
}
|
|
8528
|
+
/**
|
|
8529
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
8530
|
+
* @remarks Time O(1), Space O(1)
|
|
8531
|
+
*
|
|
8532
|
+
* @returns The node's color.
|
|
8533
|
+
*/
|
|
8534
|
+
get color() {
|
|
8535
|
+
return this._color;
|
|
8536
|
+
}
|
|
8537
|
+
/**
|
|
8538
|
+
* Sets the color of the node.
|
|
8539
|
+
* @remarks Time O(1), Space O(1)
|
|
8540
|
+
*
|
|
8541
|
+
* @param value - The new color.
|
|
8542
|
+
*/
|
|
8543
|
+
set color(value) {
|
|
8544
|
+
this._color = value;
|
|
8545
|
+
}
|
|
8546
|
+
/**
|
|
8547
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
8548
|
+
* @remarks Time O(1), Space O(1)
|
|
8549
|
+
*
|
|
8550
|
+
* @returns The subtree node count.
|
|
8551
|
+
*/
|
|
8552
|
+
get count() {
|
|
8553
|
+
return this._count;
|
|
8554
|
+
}
|
|
8555
|
+
/**
|
|
8556
|
+
* Sets the count of nodes in the subtree.
|
|
8557
|
+
* @remarks Time O(1), Space O(1)
|
|
8558
|
+
*
|
|
8559
|
+
* @param value - The new count.
|
|
8560
|
+
*/
|
|
8561
|
+
set count(value) {
|
|
8562
|
+
this._count = value;
|
|
8563
|
+
}
|
|
8564
|
+
/**
|
|
8565
|
+
* Gets the position of the node relative to its parent.
|
|
8566
|
+
* @remarks Time O(1), Space O(1)
|
|
8567
|
+
*
|
|
8568
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
8569
|
+
*/
|
|
8570
|
+
get familyPosition() {
|
|
8571
|
+
if (!this.parent) {
|
|
8572
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
8573
|
+
}
|
|
8574
|
+
if (this.parent.left === this) {
|
|
8575
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
8576
|
+
} else if (this.parent.right === this) {
|
|
8577
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
8578
|
+
}
|
|
8579
|
+
return "MAL_NODE";
|
|
8527
8580
|
}
|
|
8581
|
+
};
|
|
8582
|
+
__name(_BSTNode, "BSTNode");
|
|
8583
|
+
var BSTNode = _BSTNode;
|
|
8584
|
+
var _BST = class _BST extends BinaryTree {
|
|
8528
8585
|
/**
|
|
8529
8586
|
* Creates an instance of BST.
|
|
8530
8587
|
* @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
|
|
@@ -8534,6 +8591,33 @@ var BST = class extends BinaryTree {
|
|
|
8534
8591
|
*/
|
|
8535
8592
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
8536
8593
|
super([], options);
|
|
8594
|
+
__publicField(this, "_root");
|
|
8595
|
+
__publicField(this, "_isReverse", false);
|
|
8596
|
+
/**
|
|
8597
|
+
* The default comparator function.
|
|
8598
|
+
* @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
|
|
8599
|
+
*/
|
|
8600
|
+
__publicField(this, "_comparator", /* @__PURE__ */ __name((a, b) => {
|
|
8601
|
+
if (isComparable(a) && isComparable(b)) {
|
|
8602
|
+
if (a > b) return 1;
|
|
8603
|
+
if (a < b) return -1;
|
|
8604
|
+
return 0;
|
|
8605
|
+
}
|
|
8606
|
+
if (this._specifyComparable) {
|
|
8607
|
+
const va = this._specifyComparable(a);
|
|
8608
|
+
const vb = this._specifyComparable(b);
|
|
8609
|
+
if (va > vb) return 1;
|
|
8610
|
+
if (va < vb) return -1;
|
|
8611
|
+
return 0;
|
|
8612
|
+
}
|
|
8613
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
8614
|
+
throw TypeError(
|
|
8615
|
+
`When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
|
|
8616
|
+
);
|
|
8617
|
+
}
|
|
8618
|
+
return 0;
|
|
8619
|
+
}, "_comparator"));
|
|
8620
|
+
__publicField(this, "_specifyComparable");
|
|
8537
8621
|
if (options) {
|
|
8538
8622
|
const { specifyComparable, isReverse } = options;
|
|
8539
8623
|
if (typeof specifyComparable === "function") this._specifyComparable = specifyComparable;
|
|
@@ -8541,7 +8625,6 @@ var BST = class extends BinaryTree {
|
|
|
8541
8625
|
}
|
|
8542
8626
|
if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
|
|
8543
8627
|
}
|
|
8544
|
-
_root = void 0;
|
|
8545
8628
|
/**
|
|
8546
8629
|
* Gets the root node of the tree.
|
|
8547
8630
|
* @remarks Time O(1)
|
|
@@ -8551,7 +8634,6 @@ var BST = class extends BinaryTree {
|
|
|
8551
8634
|
get root() {
|
|
8552
8635
|
return this._root;
|
|
8553
8636
|
}
|
|
8554
|
-
_isReverse = false;
|
|
8555
8637
|
/**
|
|
8556
8638
|
* Gets whether the tree's comparison logic is reversed.
|
|
8557
8639
|
* @remarks Time O(1)
|
|
@@ -8561,30 +8643,6 @@ var BST = class extends BinaryTree {
|
|
|
8561
8643
|
get isReverse() {
|
|
8562
8644
|
return this._isReverse;
|
|
8563
8645
|
}
|
|
8564
|
-
/**
|
|
8565
|
-
* The default comparator function.
|
|
8566
|
-
* @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
|
|
8567
|
-
*/
|
|
8568
|
-
_comparator = /* @__PURE__ */ __name((a, b) => {
|
|
8569
|
-
if (isComparable(a) && isComparable(b)) {
|
|
8570
|
-
if (a > b) return 1;
|
|
8571
|
-
if (a < b) return -1;
|
|
8572
|
-
return 0;
|
|
8573
|
-
}
|
|
8574
|
-
if (this._specifyComparable) {
|
|
8575
|
-
const va = this._specifyComparable(a);
|
|
8576
|
-
const vb = this._specifyComparable(b);
|
|
8577
|
-
if (va > vb) return 1;
|
|
8578
|
-
if (va < vb) return -1;
|
|
8579
|
-
return 0;
|
|
8580
|
-
}
|
|
8581
|
-
if (typeof a === "object" || typeof b === "object") {
|
|
8582
|
-
throw TypeError(
|
|
8583
|
-
`When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
|
|
8584
|
-
);
|
|
8585
|
-
}
|
|
8586
|
-
return 0;
|
|
8587
|
-
}, "_comparator");
|
|
8588
8646
|
/**
|
|
8589
8647
|
* Gets the comparator function used by the tree.
|
|
8590
8648
|
* @remarks Time O(1)
|
|
@@ -8594,7 +8652,6 @@ var BST = class extends BinaryTree {
|
|
|
8594
8652
|
get comparator() {
|
|
8595
8653
|
return this._comparator;
|
|
8596
8654
|
}
|
|
8597
|
-
_specifyComparable;
|
|
8598
8655
|
/**
|
|
8599
8656
|
* Gets the function used to extract a comparable value from a complex key.
|
|
8600
8657
|
* @remarks Time O(1)
|
|
@@ -8612,7 +8669,7 @@ var BST = class extends BinaryTree {
|
|
|
8612
8669
|
* @param [value] - The value for the new node (used if not in Map mode).
|
|
8613
8670
|
* @returns The newly created BSTNode.
|
|
8614
8671
|
*/
|
|
8615
|
-
|
|
8672
|
+
createNode(key, value) {
|
|
8616
8673
|
return new BSTNode(key, this._isMapMode ? void 0 : value);
|
|
8617
8674
|
}
|
|
8618
8675
|
/**
|
|
@@ -8624,7 +8681,8 @@ var BST = class extends BinaryTree {
|
|
|
8624
8681
|
* @returns The resolved node, or undefined if not found.
|
|
8625
8682
|
*/
|
|
8626
8683
|
ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
|
|
8627
|
-
|
|
8684
|
+
var _a;
|
|
8685
|
+
return (_a = super.ensureNode(keyNodeOrEntry, iterationType)) != null ? _a : void 0;
|
|
8628
8686
|
}
|
|
8629
8687
|
/**
|
|
8630
8688
|
* Checks if the given item is a `BSTNode` instance.
|
|
@@ -8697,7 +8755,8 @@ var BST = class extends BinaryTree {
|
|
|
8697
8755
|
* @returns The first matching node, or undefined if not found.
|
|
8698
8756
|
*/
|
|
8699
8757
|
getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
8700
|
-
|
|
8758
|
+
var _a;
|
|
8759
|
+
return (_a = this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0]) != null ? _a : void 0;
|
|
8701
8760
|
}
|
|
8702
8761
|
/**
|
|
8703
8762
|
* Searches the tree for nodes matching a predicate, key, or range.
|
|
@@ -8802,7 +8861,7 @@ var BST = class extends BinaryTree {
|
|
|
8802
8861
|
if (newNode === void 0) return false;
|
|
8803
8862
|
if (this._root === void 0) {
|
|
8804
8863
|
this._setRoot(newNode);
|
|
8805
|
-
if (this._isMapMode) this._setValue(newNode
|
|
8864
|
+
if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
|
|
8806
8865
|
this._size++;
|
|
8807
8866
|
return true;
|
|
8808
8867
|
}
|
|
@@ -8815,7 +8874,7 @@ var BST = class extends BinaryTree {
|
|
|
8815
8874
|
} else if (this._compare(current.key, newNode.key) > 0) {
|
|
8816
8875
|
if (current.left === void 0) {
|
|
8817
8876
|
current.left = newNode;
|
|
8818
|
-
if (this._isMapMode) this._setValue(newNode
|
|
8877
|
+
if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
|
|
8819
8878
|
this._size++;
|
|
8820
8879
|
return true;
|
|
8821
8880
|
}
|
|
@@ -8823,7 +8882,7 @@ var BST = class extends BinaryTree {
|
|
|
8823
8882
|
} else {
|
|
8824
8883
|
if (current.right === void 0) {
|
|
8825
8884
|
current.right = newNode;
|
|
8826
|
-
if (this._isMapMode) this._setValue(newNode
|
|
8885
|
+
if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
|
|
8827
8886
|
this._size++;
|
|
8828
8887
|
return true;
|
|
8829
8888
|
}
|
|
@@ -8846,10 +8905,10 @@ var BST = class extends BinaryTree {
|
|
|
8846
8905
|
*/
|
|
8847
8906
|
addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
8848
8907
|
const inserted = [];
|
|
8849
|
-
const valuesIterator = values
|
|
8908
|
+
const valuesIterator = values == null ? void 0 : values[Symbol.iterator]();
|
|
8850
8909
|
if (!isBalanceAdd) {
|
|
8851
8910
|
for (let kve of keysNodesEntriesOrRaws) {
|
|
8852
|
-
const val = valuesIterator
|
|
8911
|
+
const val = valuesIterator == null ? void 0 : valuesIterator.next().value;
|
|
8853
8912
|
if (this.isRaw(kve)) kve = this._toEntryFn(kve);
|
|
8854
8913
|
inserted.push(this.add(kve, val));
|
|
8855
8914
|
}
|
|
@@ -8858,7 +8917,7 @@ var BST = class extends BinaryTree {
|
|
|
8858
8917
|
const realBTNExemplars = [];
|
|
8859
8918
|
let i = 0;
|
|
8860
8919
|
for (const kve of keysNodesEntriesOrRaws) {
|
|
8861
|
-
realBTNExemplars.push({ key: kve, value: valuesIterator
|
|
8920
|
+
realBTNExemplars.push({ key: kve, value: valuesIterator == null ? void 0 : valuesIterator.next().value, orgIndex: i++ });
|
|
8862
8921
|
}
|
|
8863
8922
|
const sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
|
|
8864
8923
|
let keyA, keyB;
|
|
@@ -9080,7 +9139,7 @@ var BST = class extends BinaryTree {
|
|
|
9080
9139
|
*/
|
|
9081
9140
|
_createInstance(options) {
|
|
9082
9141
|
const Ctor = this.constructor;
|
|
9083
|
-
return new Ctor([], { ...this._snapshotOptions(), ...options
|
|
9142
|
+
return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
9084
9143
|
}
|
|
9085
9144
|
/**
|
|
9086
9145
|
* (Protected) Creates a new instance of the same BST constructor, potentially with different generic types.
|
|
@@ -9093,7 +9152,7 @@ var BST = class extends BinaryTree {
|
|
|
9093
9152
|
*/
|
|
9094
9153
|
_createLike(iter = [], options) {
|
|
9095
9154
|
const Ctor = this.constructor;
|
|
9096
|
-
return new Ctor(iter, { ...this._snapshotOptions(), ...options
|
|
9155
|
+
return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
9097
9156
|
}
|
|
9098
9157
|
/**
|
|
9099
9158
|
* (Protected) Snapshots the current BST's configuration options.
|
|
@@ -9120,7 +9179,7 @@ var BST = class extends BinaryTree {
|
|
|
9120
9179
|
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
|
|
9121
9180
|
const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
9122
9181
|
if (node === null) return [void 0, void 0];
|
|
9123
|
-
return [node, value
|
|
9182
|
+
return [node, value != null ? value : entryValue];
|
|
9124
9183
|
}
|
|
9125
9184
|
/**
|
|
9126
9185
|
* (Protected) Sets the root node and clears its parent reference.
|
|
@@ -9151,6 +9210,7 @@ var BST = class extends BinaryTree {
|
|
|
9151
9210
|
* @returns True if the node was found and deleted, false otherwise.
|
|
9152
9211
|
*/
|
|
9153
9212
|
_deleteByKey(key) {
|
|
9213
|
+
var _a;
|
|
9154
9214
|
let node = this._root;
|
|
9155
9215
|
while (node) {
|
|
9156
9216
|
const cmp = this._compare(node.key, key);
|
|
@@ -9159,7 +9219,7 @@ var BST = class extends BinaryTree {
|
|
|
9159
9219
|
}
|
|
9160
9220
|
if (!node) return false;
|
|
9161
9221
|
const transplant = /* @__PURE__ */ __name((u, v) => {
|
|
9162
|
-
const p = u
|
|
9222
|
+
const p = u == null ? void 0 : u.parent;
|
|
9163
9223
|
if (!p) {
|
|
9164
9224
|
this._setRoot(v);
|
|
9165
9225
|
} else if (p.left === u) {
|
|
@@ -9189,18 +9249,15 @@ var BST = class extends BinaryTree {
|
|
|
9189
9249
|
succ.left = node.left;
|
|
9190
9250
|
if (succ.left) succ.left.parent = succ;
|
|
9191
9251
|
}
|
|
9192
|
-
this._size = Math.max(0, (this._size
|
|
9252
|
+
this._size = Math.max(0, ((_a = this._size) != null ? _a : 0) - 1);
|
|
9193
9253
|
return true;
|
|
9194
9254
|
}
|
|
9195
9255
|
};
|
|
9256
|
+
__name(_BST, "BST");
|
|
9257
|
+
var BST = _BST;
|
|
9196
9258
|
|
|
9197
9259
|
// src/data-structures/binary-tree/binary-indexed-tree.ts
|
|
9198
|
-
var
|
|
9199
|
-
static {
|
|
9200
|
-
__name(this, "BinaryIndexedTree");
|
|
9201
|
-
}
|
|
9202
|
-
_freq;
|
|
9203
|
-
_max;
|
|
9260
|
+
var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
9204
9261
|
/**
|
|
9205
9262
|
* The constructor initializes the properties of an object, including default frequency, maximum
|
|
9206
9263
|
* value, a freqMap data structure, the most significant bit, and the count of negative frequencies.
|
|
@@ -9208,13 +9265,17 @@ var BinaryIndexedTree = class {
|
|
|
9208
9265
|
* value of 0.
|
|
9209
9266
|
*/
|
|
9210
9267
|
constructor({ frequency = 0, max }) {
|
|
9268
|
+
__publicField(this, "_freq");
|
|
9269
|
+
__publicField(this, "_max");
|
|
9270
|
+
__publicField(this, "_freqMap");
|
|
9271
|
+
__publicField(this, "_msb");
|
|
9272
|
+
__publicField(this, "_negativeCount");
|
|
9211
9273
|
this._freq = frequency;
|
|
9212
9274
|
this._max = max;
|
|
9213
9275
|
this._freqMap = { 0: 0 };
|
|
9214
9276
|
this._msb = getMSB(max);
|
|
9215
9277
|
this._negativeCount = frequency < 0 ? max : 0;
|
|
9216
9278
|
}
|
|
9217
|
-
_freqMap;
|
|
9218
9279
|
/**
|
|
9219
9280
|
* The function returns the frequency map of numbers.
|
|
9220
9281
|
* @returns The `_freqMap` property, which is a record with number keys and number values, is being
|
|
@@ -9223,7 +9284,6 @@ var BinaryIndexedTree = class {
|
|
|
9223
9284
|
get freqMap() {
|
|
9224
9285
|
return this._freqMap;
|
|
9225
9286
|
}
|
|
9226
|
-
_msb;
|
|
9227
9287
|
/**
|
|
9228
9288
|
* The function returns the value of the _msb property.
|
|
9229
9289
|
* @returns The `_msb` property of the object.
|
|
@@ -9231,7 +9291,6 @@ var BinaryIndexedTree = class {
|
|
|
9231
9291
|
get msb() {
|
|
9232
9292
|
return this._msb;
|
|
9233
9293
|
}
|
|
9234
|
-
_negativeCount;
|
|
9235
9294
|
/**
|
|
9236
9295
|
* The function returns the value of the _negativeCount property.
|
|
9237
9296
|
* @returns The method is returning the value of the variable `_negativeCount`, which is of type
|
|
@@ -9480,12 +9539,11 @@ var BinaryIndexedTree = class {
|
|
|
9480
9539
|
return left;
|
|
9481
9540
|
}
|
|
9482
9541
|
};
|
|
9542
|
+
__name(_BinaryIndexedTree, "BinaryIndexedTree");
|
|
9543
|
+
var BinaryIndexedTree = _BinaryIndexedTree;
|
|
9483
9544
|
|
|
9484
9545
|
// src/data-structures/binary-tree/segment-tree.ts
|
|
9485
|
-
var
|
|
9486
|
-
static {
|
|
9487
|
-
__name(this, "SegmentTreeNode");
|
|
9488
|
-
}
|
|
9546
|
+
var _SegmentTreeNode = class _SegmentTreeNode {
|
|
9489
9547
|
/**
|
|
9490
9548
|
* The constructor initializes the properties of a SegmentTreeNode object.
|
|
9491
9549
|
* @param {number} start - The `start` parameter represents the starting index of the segment covered
|
|
@@ -9498,12 +9556,17 @@ var SegmentTreeNode = class {
|
|
|
9498
9556
|
* of type `SegmentTreeNodeVal`. It represents the value associated with the segment tree node.
|
|
9499
9557
|
*/
|
|
9500
9558
|
constructor(start, end, sum, value) {
|
|
9559
|
+
__publicField(this, "_start", 0);
|
|
9560
|
+
__publicField(this, "_end", 0);
|
|
9561
|
+
__publicField(this, "_value");
|
|
9562
|
+
__publicField(this, "_sum", 0);
|
|
9563
|
+
__publicField(this, "_left");
|
|
9564
|
+
__publicField(this, "_right");
|
|
9501
9565
|
this._start = start;
|
|
9502
9566
|
this._end = end;
|
|
9503
9567
|
this._sum = sum;
|
|
9504
9568
|
this._value = value || void 0;
|
|
9505
9569
|
}
|
|
9506
|
-
_start = 0;
|
|
9507
9570
|
/**
|
|
9508
9571
|
* The function returns the value of the protected variable _start.
|
|
9509
9572
|
* @returns The start value, which is of type number.
|
|
@@ -9518,7 +9581,6 @@ var SegmentTreeNode = class {
|
|
|
9518
9581
|
set start(value) {
|
|
9519
9582
|
this._start = value;
|
|
9520
9583
|
}
|
|
9521
|
-
_end = 0;
|
|
9522
9584
|
/**
|
|
9523
9585
|
* The function returns the value of the protected variable `_end`.
|
|
9524
9586
|
* @returns The value of the protected property `_end`.
|
|
@@ -9534,7 +9596,6 @@ var SegmentTreeNode = class {
|
|
|
9534
9596
|
set end(value) {
|
|
9535
9597
|
this._end = value;
|
|
9536
9598
|
}
|
|
9537
|
-
_value = void 0;
|
|
9538
9599
|
/**
|
|
9539
9600
|
* The function returns the value of a segment tree node.
|
|
9540
9601
|
* @returns The value being returned is either a `SegmentTreeNodeVal` object or `undefined`.
|
|
@@ -9550,7 +9611,6 @@ var SegmentTreeNode = class {
|
|
|
9550
9611
|
set value(value) {
|
|
9551
9612
|
this._value = value;
|
|
9552
9613
|
}
|
|
9553
|
-
_sum = 0;
|
|
9554
9614
|
/**
|
|
9555
9615
|
* The function returns the value of the sum property.
|
|
9556
9616
|
* @returns The method is returning the value of the variable `_sum`.
|
|
@@ -9565,7 +9625,6 @@ var SegmentTreeNode = class {
|
|
|
9565
9625
|
set sum(value) {
|
|
9566
9626
|
this._sum = value;
|
|
9567
9627
|
}
|
|
9568
|
-
_left = void 0;
|
|
9569
9628
|
/**
|
|
9570
9629
|
* The function returns the left child of a segment tree node.
|
|
9571
9630
|
* @returns The `left` property of the `SegmentTreeNode` object is being returned. It is of type
|
|
@@ -9582,7 +9641,6 @@ var SegmentTreeNode = class {
|
|
|
9582
9641
|
set left(value) {
|
|
9583
9642
|
this._left = value;
|
|
9584
9643
|
}
|
|
9585
|
-
_right = void 0;
|
|
9586
9644
|
/**
|
|
9587
9645
|
* The function returns the right child of a segment tree node.
|
|
9588
9646
|
* @returns The `getRight()` method is returning a value of type `SegmentTreeNode` or `undefined`.
|
|
@@ -9600,10 +9658,9 @@ var SegmentTreeNode = class {
|
|
|
9600
9658
|
this._right = value;
|
|
9601
9659
|
}
|
|
9602
9660
|
};
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
}
|
|
9661
|
+
__name(_SegmentTreeNode, "SegmentTreeNode");
|
|
9662
|
+
var SegmentTreeNode = _SegmentTreeNode;
|
|
9663
|
+
var _SegmentTree = class _SegmentTree {
|
|
9607
9664
|
/**
|
|
9608
9665
|
* The constructor initializes the values, start, end, and root properties of an object.
|
|
9609
9666
|
* @param {number[]} values - An array of numbers that will be used to build a binary search tree.
|
|
@@ -9614,6 +9671,10 @@ var SegmentTree = class {
|
|
|
9614
9671
|
* included in the range. If not provided, it defaults to the index of the last element in the "values" array.
|
|
9615
9672
|
*/
|
|
9616
9673
|
constructor(values, start, end) {
|
|
9674
|
+
__publicField(this, "_values", []);
|
|
9675
|
+
__publicField(this, "_start", 0);
|
|
9676
|
+
__publicField(this, "_end");
|
|
9677
|
+
__publicField(this, "_root");
|
|
9617
9678
|
start = start || 0;
|
|
9618
9679
|
end = end || values.length - 1;
|
|
9619
9680
|
this._values = values;
|
|
@@ -9626,7 +9687,6 @@ var SegmentTree = class {
|
|
|
9626
9687
|
this._values = [];
|
|
9627
9688
|
}
|
|
9628
9689
|
}
|
|
9629
|
-
_values = [];
|
|
9630
9690
|
/**
|
|
9631
9691
|
* The function returns an array of numbers.
|
|
9632
9692
|
* @returns An array of numbers is being returned.
|
|
@@ -9634,7 +9694,6 @@ var SegmentTree = class {
|
|
|
9634
9694
|
get values() {
|
|
9635
9695
|
return this._values;
|
|
9636
9696
|
}
|
|
9637
|
-
_start = 0;
|
|
9638
9697
|
/**
|
|
9639
9698
|
* The function returns the value of the protected variable _start.
|
|
9640
9699
|
* @returns The start value, which is of type number.
|
|
@@ -9642,7 +9701,6 @@ var SegmentTree = class {
|
|
|
9642
9701
|
get start() {
|
|
9643
9702
|
return this._start;
|
|
9644
9703
|
}
|
|
9645
|
-
_end;
|
|
9646
9704
|
/**
|
|
9647
9705
|
* The function returns the value of the protected variable `_end`.
|
|
9648
9706
|
* @returns The value of the protected property `_end`.
|
|
@@ -9650,7 +9708,6 @@ var SegmentTree = class {
|
|
|
9650
9708
|
get end() {
|
|
9651
9709
|
return this._end;
|
|
9652
9710
|
}
|
|
9653
|
-
_root;
|
|
9654
9711
|
/**
|
|
9655
9712
|
* The function returns the root node of a segment tree.
|
|
9656
9713
|
* @returns The `root` property of the class `SegmentTreeNode` or `undefined` if it is not defined.
|
|
@@ -9765,13 +9822,11 @@ var SegmentTree = class {
|
|
|
9765
9822
|
return dfs(root, indexA, indexB);
|
|
9766
9823
|
}
|
|
9767
9824
|
};
|
|
9825
|
+
__name(_SegmentTree, "SegmentTree");
|
|
9826
|
+
var SegmentTree = _SegmentTree;
|
|
9768
9827
|
|
|
9769
9828
|
// src/data-structures/binary-tree/avl-tree.ts
|
|
9770
|
-
var
|
|
9771
|
-
static {
|
|
9772
|
-
__name(this, "AVLTreeNode");
|
|
9773
|
-
}
|
|
9774
|
-
parent = void 0;
|
|
9829
|
+
var _AVLTreeNode = class _AVLTreeNode {
|
|
9775
9830
|
/**
|
|
9776
9831
|
* Creates an instance of AVLTreeNode.
|
|
9777
9832
|
* @remarks Time O(1), Space O(1)
|
|
@@ -9780,9 +9835,17 @@ var AVLTreeNode = class extends BSTNode {
|
|
|
9780
9835
|
* @param [value] - The value associated with the key.
|
|
9781
9836
|
*/
|
|
9782
9837
|
constructor(key, value) {
|
|
9783
|
-
|
|
9838
|
+
__publicField(this, "key");
|
|
9839
|
+
__publicField(this, "value");
|
|
9840
|
+
__publicField(this, "parent");
|
|
9841
|
+
__publicField(this, "_left");
|
|
9842
|
+
__publicField(this, "_right");
|
|
9843
|
+
__publicField(this, "_height", 0);
|
|
9844
|
+
__publicField(this, "_color", "BLACK");
|
|
9845
|
+
__publicField(this, "_count", 1);
|
|
9846
|
+
this.key = key;
|
|
9847
|
+
this.value = value;
|
|
9784
9848
|
}
|
|
9785
|
-
_left = void 0;
|
|
9786
9849
|
/**
|
|
9787
9850
|
* Gets the left child of the node.
|
|
9788
9851
|
* @remarks Time O(1), Space O(1)
|
|
@@ -9804,7 +9867,6 @@ var AVLTreeNode = class extends BSTNode {
|
|
|
9804
9867
|
}
|
|
9805
9868
|
this._left = v;
|
|
9806
9869
|
}
|
|
9807
|
-
_right = void 0;
|
|
9808
9870
|
/**
|
|
9809
9871
|
* Gets the right child of the node.
|
|
9810
9872
|
* @remarks Time O(1), Space O(1)
|
|
@@ -9826,11 +9888,81 @@ var AVLTreeNode = class extends BSTNode {
|
|
|
9826
9888
|
}
|
|
9827
9889
|
this._right = v;
|
|
9828
9890
|
}
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
|
|
9832
|
-
|
|
9891
|
+
/**
|
|
9892
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
9893
|
+
* @remarks Time O(1), Space O(1)
|
|
9894
|
+
*
|
|
9895
|
+
* @returns The height.
|
|
9896
|
+
*/
|
|
9897
|
+
get height() {
|
|
9898
|
+
return this._height;
|
|
9899
|
+
}
|
|
9900
|
+
/**
|
|
9901
|
+
* Sets the height of the node.
|
|
9902
|
+
* @remarks Time O(1), Space O(1)
|
|
9903
|
+
*
|
|
9904
|
+
* @param value - The new height.
|
|
9905
|
+
*/
|
|
9906
|
+
set height(value) {
|
|
9907
|
+
this._height = value;
|
|
9908
|
+
}
|
|
9909
|
+
/**
|
|
9910
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
9911
|
+
* @remarks Time O(1), Space O(1)
|
|
9912
|
+
*
|
|
9913
|
+
* @returns The node's color.
|
|
9914
|
+
*/
|
|
9915
|
+
get color() {
|
|
9916
|
+
return this._color;
|
|
9917
|
+
}
|
|
9918
|
+
/**
|
|
9919
|
+
* Sets the color of the node.
|
|
9920
|
+
* @remarks Time O(1), Space O(1)
|
|
9921
|
+
*
|
|
9922
|
+
* @param value - The new color.
|
|
9923
|
+
*/
|
|
9924
|
+
set color(value) {
|
|
9925
|
+
this._color = value;
|
|
9926
|
+
}
|
|
9927
|
+
/**
|
|
9928
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
9929
|
+
* @remarks Time O(1), Space O(1)
|
|
9930
|
+
*
|
|
9931
|
+
* @returns The subtree node count.
|
|
9932
|
+
*/
|
|
9933
|
+
get count() {
|
|
9934
|
+
return this._count;
|
|
9935
|
+
}
|
|
9936
|
+
/**
|
|
9937
|
+
* Sets the count of nodes in the subtree.
|
|
9938
|
+
* @remarks Time O(1), Space O(1)
|
|
9939
|
+
*
|
|
9940
|
+
* @param value - The new count.
|
|
9941
|
+
*/
|
|
9942
|
+
set count(value) {
|
|
9943
|
+
this._count = value;
|
|
9944
|
+
}
|
|
9945
|
+
/**
|
|
9946
|
+
* Gets the position of the node relative to its parent.
|
|
9947
|
+
* @remarks Time O(1), Space O(1)
|
|
9948
|
+
*
|
|
9949
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
9950
|
+
*/
|
|
9951
|
+
get familyPosition() {
|
|
9952
|
+
if (!this.parent) {
|
|
9953
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
9954
|
+
}
|
|
9955
|
+
if (this.parent.left === this) {
|
|
9956
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
9957
|
+
} else if (this.parent.right === this) {
|
|
9958
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
9959
|
+
}
|
|
9960
|
+
return "MAL_NODE";
|
|
9833
9961
|
}
|
|
9962
|
+
};
|
|
9963
|
+
__name(_AVLTreeNode, "AVLTreeNode");
|
|
9964
|
+
var AVLTreeNode = _AVLTreeNode;
|
|
9965
|
+
var _AVLTree = class _AVLTree extends BST {
|
|
9834
9966
|
/**
|
|
9835
9967
|
* Creates an instance of AVLTree.
|
|
9836
9968
|
* @remarks Time O(N log N) (from `addMany` with balanced add). Space O(N).
|
|
@@ -9850,7 +9982,7 @@ var AVLTree = class extends BST {
|
|
|
9850
9982
|
* @param [value] - The value for the new node.
|
|
9851
9983
|
* @returns The newly created AVLTreeNode.
|
|
9852
9984
|
*/
|
|
9853
|
-
|
|
9985
|
+
createNode(key, value) {
|
|
9854
9986
|
return new AVLTreeNode(key, this._isMapMode ? void 0 : value);
|
|
9855
9987
|
}
|
|
9856
9988
|
/**
|
|
@@ -9953,7 +10085,7 @@ var AVLTree = class extends BST {
|
|
|
9953
10085
|
*/
|
|
9954
10086
|
_createInstance(options) {
|
|
9955
10087
|
const Ctor = this.constructor;
|
|
9956
|
-
return new Ctor([], { ...this._snapshotOptions(), ...options
|
|
10088
|
+
return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
9957
10089
|
}
|
|
9958
10090
|
/**
|
|
9959
10091
|
* (Protected) Creates a new instance of the same AVLTree constructor, potentially with different generic types.
|
|
@@ -9966,7 +10098,7 @@ var AVLTree = class extends BST {
|
|
|
9966
10098
|
*/
|
|
9967
10099
|
_createLike(iter = [], options) {
|
|
9968
10100
|
const Ctor = this.constructor;
|
|
9969
|
-
return new Ctor(iter, { ...this._snapshotOptions(), ...options
|
|
10101
|
+
return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
9970
10102
|
}
|
|
9971
10103
|
/**
|
|
9972
10104
|
* (Protected) Swaps properties of two nodes, including height.
|
|
@@ -9981,7 +10113,7 @@ var AVLTree = class extends BST {
|
|
|
9981
10113
|
const destNodeEnsured = this.ensureNode(destNode);
|
|
9982
10114
|
if (srcNodeEnsured && destNodeEnsured) {
|
|
9983
10115
|
const { key, value, height } = destNodeEnsured;
|
|
9984
|
-
const tempNode = this.
|
|
10116
|
+
const tempNode = this.createNode(key, value);
|
|
9985
10117
|
if (tempNode) {
|
|
9986
10118
|
tempNode.height = height;
|
|
9987
10119
|
destNodeEnsured.key = srcNodeEnsured.key;
|
|
@@ -10035,7 +10167,7 @@ var AVLTree = class extends BST {
|
|
|
10035
10167
|
if (A === this.root) {
|
|
10036
10168
|
if (B) this._setRoot(B);
|
|
10037
10169
|
} else {
|
|
10038
|
-
if (parentOfA
|
|
10170
|
+
if ((parentOfA == null ? void 0 : parentOfA.left) === A) {
|
|
10039
10171
|
parentOfA.left = B;
|
|
10040
10172
|
} else {
|
|
10041
10173
|
if (parentOfA) parentOfA.right = B;
|
|
@@ -10218,13 +10350,11 @@ var AVLTree = class extends BST {
|
|
|
10218
10350
|
return super._replaceNode(oldNode, newNode);
|
|
10219
10351
|
}
|
|
10220
10352
|
};
|
|
10353
|
+
__name(_AVLTree, "AVLTree");
|
|
10354
|
+
var AVLTree = _AVLTree;
|
|
10221
10355
|
|
|
10222
10356
|
// src/data-structures/binary-tree/red-black-tree.ts
|
|
10223
|
-
var
|
|
10224
|
-
static {
|
|
10225
|
-
__name(this, "RedBlackTreeNode");
|
|
10226
|
-
}
|
|
10227
|
-
parent = void 0;
|
|
10357
|
+
var _RedBlackTreeNode = class _RedBlackTreeNode {
|
|
10228
10358
|
/**
|
|
10229
10359
|
* Create a Red-Black Tree and optionally bulk-insert items.
|
|
10230
10360
|
* @remarks Time O(n log n), Space O(n)
|
|
@@ -10234,10 +10364,18 @@ var RedBlackTreeNode = class extends BSTNode {
|
|
|
10234
10364
|
* @returns New RedBlackTree instance.
|
|
10235
10365
|
*/
|
|
10236
10366
|
constructor(key, value, color = "BLACK") {
|
|
10237
|
-
|
|
10238
|
-
this
|
|
10367
|
+
__publicField(this, "key");
|
|
10368
|
+
__publicField(this, "value");
|
|
10369
|
+
__publicField(this, "parent");
|
|
10370
|
+
__publicField(this, "_left");
|
|
10371
|
+
__publicField(this, "_right");
|
|
10372
|
+
__publicField(this, "_height", 0);
|
|
10373
|
+
__publicField(this, "_color", "BLACK");
|
|
10374
|
+
__publicField(this, "_count", 1);
|
|
10375
|
+
this.key = key;
|
|
10376
|
+
this.value = value;
|
|
10377
|
+
this.color = color;
|
|
10239
10378
|
}
|
|
10240
|
-
_left = void 0;
|
|
10241
10379
|
/**
|
|
10242
10380
|
* Get the left child pointer.
|
|
10243
10381
|
* @remarks Time O(1), Space O(1)
|
|
@@ -10258,7 +10396,6 @@ var RedBlackTreeNode = class extends BSTNode {
|
|
|
10258
10396
|
}
|
|
10259
10397
|
this._left = v;
|
|
10260
10398
|
}
|
|
10261
|
-
_right = void 0;
|
|
10262
10399
|
/**
|
|
10263
10400
|
* Get the right child pointer.
|
|
10264
10401
|
* @remarks Time O(1), Space O(1)
|
|
@@ -10279,36 +10416,106 @@ var RedBlackTreeNode = class extends BSTNode {
|
|
|
10279
10416
|
}
|
|
10280
10417
|
this._right = v;
|
|
10281
10418
|
}
|
|
10282
|
-
};
|
|
10283
|
-
var RedBlackTree = class extends BST {
|
|
10284
|
-
static {
|
|
10285
|
-
__name(this, "RedBlackTree");
|
|
10286
|
-
}
|
|
10287
|
-
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
10288
|
-
super([], options);
|
|
10289
|
-
this._root = this.NIL;
|
|
10290
|
-
if (keysNodesEntriesOrRaws) {
|
|
10291
|
-
this.addMany(keysNodesEntriesOrRaws);
|
|
10292
|
-
}
|
|
10293
|
-
}
|
|
10294
|
-
_root;
|
|
10295
10419
|
/**
|
|
10296
|
-
*
|
|
10420
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
10297
10421
|
* @remarks Time O(1), Space O(1)
|
|
10298
|
-
*
|
|
10422
|
+
*
|
|
10423
|
+
* @returns The height.
|
|
10299
10424
|
*/
|
|
10300
|
-
get
|
|
10301
|
-
return this.
|
|
10425
|
+
get height() {
|
|
10426
|
+
return this._height;
|
|
10302
10427
|
}
|
|
10303
10428
|
/**
|
|
10304
|
-
*
|
|
10429
|
+
* Sets the height of the node.
|
|
10305
10430
|
* @remarks Time O(1), Space O(1)
|
|
10306
|
-
*
|
|
10307
|
-
* @param
|
|
10431
|
+
*
|
|
10432
|
+
* @param value - The new height.
|
|
10433
|
+
*/
|
|
10434
|
+
set height(value) {
|
|
10435
|
+
this._height = value;
|
|
10436
|
+
}
|
|
10437
|
+
/**
|
|
10438
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
10439
|
+
* @remarks Time O(1), Space O(1)
|
|
10440
|
+
*
|
|
10441
|
+
* @returns The node's color.
|
|
10442
|
+
*/
|
|
10443
|
+
get color() {
|
|
10444
|
+
return this._color;
|
|
10445
|
+
}
|
|
10446
|
+
/**
|
|
10447
|
+
* Sets the color of the node.
|
|
10448
|
+
* @remarks Time O(1), Space O(1)
|
|
10449
|
+
*
|
|
10450
|
+
* @param value - The new color.
|
|
10451
|
+
*/
|
|
10452
|
+
set color(value) {
|
|
10453
|
+
this._color = value;
|
|
10454
|
+
}
|
|
10455
|
+
/**
|
|
10456
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
10457
|
+
* @remarks Time O(1), Space O(1)
|
|
10458
|
+
*
|
|
10459
|
+
* @returns The subtree node count.
|
|
10460
|
+
*/
|
|
10461
|
+
get count() {
|
|
10462
|
+
return this._count;
|
|
10463
|
+
}
|
|
10464
|
+
/**
|
|
10465
|
+
* Sets the count of nodes in the subtree.
|
|
10466
|
+
* @remarks Time O(1), Space O(1)
|
|
10467
|
+
*
|
|
10468
|
+
* @param value - The new count.
|
|
10469
|
+
*/
|
|
10470
|
+
set count(value) {
|
|
10471
|
+
this._count = value;
|
|
10472
|
+
}
|
|
10473
|
+
/**
|
|
10474
|
+
* Gets the position of the node relative to its parent.
|
|
10475
|
+
* @remarks Time O(1), Space O(1)
|
|
10476
|
+
*
|
|
10477
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
10478
|
+
*/
|
|
10479
|
+
get familyPosition() {
|
|
10480
|
+
if (!this.parent) {
|
|
10481
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
10482
|
+
}
|
|
10483
|
+
if (this.parent.left === this) {
|
|
10484
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
10485
|
+
} else if (this.parent.right === this) {
|
|
10486
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
10487
|
+
}
|
|
10488
|
+
return "MAL_NODE";
|
|
10489
|
+
}
|
|
10490
|
+
};
|
|
10491
|
+
__name(_RedBlackTreeNode, "RedBlackTreeNode");
|
|
10492
|
+
var RedBlackTreeNode = _RedBlackTreeNode;
|
|
10493
|
+
var _RedBlackTree = class _RedBlackTree extends BST {
|
|
10494
|
+
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
10495
|
+
super([], options);
|
|
10496
|
+
__publicField(this, "_root");
|
|
10497
|
+
this._root = this.NIL;
|
|
10498
|
+
if (keysNodesEntriesOrRaws) {
|
|
10499
|
+
this.addMany(keysNodesEntriesOrRaws);
|
|
10500
|
+
}
|
|
10501
|
+
}
|
|
10502
|
+
/**
|
|
10503
|
+
* Get the current root node.
|
|
10504
|
+
* @remarks Time O(1), Space O(1)
|
|
10505
|
+
* @returns Root node, or undefined.
|
|
10506
|
+
*/
|
|
10507
|
+
get root() {
|
|
10508
|
+
return this._root;
|
|
10509
|
+
}
|
|
10510
|
+
/**
|
|
10511
|
+
* Create a red-black node for the given key/value (value ignored in map mode).
|
|
10512
|
+
* @remarks Time O(1), Space O(1)
|
|
10513
|
+
* @param key - See parameter type for details.
|
|
10514
|
+
* @param [value] - See parameter type for details.
|
|
10308
10515
|
* @param color - See parameter type for details.
|
|
10309
10516
|
* @returns A new RedBlackTreeNode instance.
|
|
10310
10517
|
*/
|
|
10311
|
-
|
|
10518
|
+
createNode(key, value, color = "BLACK") {
|
|
10312
10519
|
return new RedBlackTreeNode(key, this._isMapMode ? void 0 : value, color);
|
|
10313
10520
|
}
|
|
10314
10521
|
/**
|
|
@@ -10436,11 +10643,11 @@ var RedBlackTree = class extends BST {
|
|
|
10436
10643
|
}
|
|
10437
10644
|
_createInstance(options) {
|
|
10438
10645
|
const Ctor = this.constructor;
|
|
10439
|
-
return new Ctor([], { ...this._snapshotOptions(), ...options
|
|
10646
|
+
return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
10440
10647
|
}
|
|
10441
10648
|
_createLike(iter = [], options) {
|
|
10442
10649
|
const Ctor = this.constructor;
|
|
10443
|
-
return new Ctor(iter, { ...this._snapshotOptions(), ...options
|
|
10650
|
+
return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
10444
10651
|
}
|
|
10445
10652
|
_setRoot(v) {
|
|
10446
10653
|
if (v) {
|
|
@@ -10459,15 +10666,16 @@ var RedBlackTree = class extends BST {
|
|
|
10459
10666
|
* @returns Status string: 'CREATED' or 'UPDATED'.
|
|
10460
10667
|
*/
|
|
10461
10668
|
_insert(node) {
|
|
10462
|
-
|
|
10669
|
+
var _a, _b, _c;
|
|
10670
|
+
let current = (_a = this.root) != null ? _a : this.NIL;
|
|
10463
10671
|
let parent = void 0;
|
|
10464
|
-
while (this.
|
|
10672
|
+
while (current !== this.NIL) {
|
|
10465
10673
|
parent = current;
|
|
10466
10674
|
const compared = this._compare(node.key, current.key);
|
|
10467
10675
|
if (compared < 0) {
|
|
10468
|
-
current = current.left
|
|
10676
|
+
current = (_b = current.left) != null ? _b : this.NIL;
|
|
10469
10677
|
} else if (compared > 0) {
|
|
10470
|
-
current = current.right
|
|
10678
|
+
current = (_c = current.right) != null ? _c : this.NIL;
|
|
10471
10679
|
} else {
|
|
10472
10680
|
this._replaceNode(current, node);
|
|
10473
10681
|
return "UPDATED";
|
|
@@ -10513,10 +10721,11 @@ var RedBlackTree = class extends BST {
|
|
|
10513
10721
|
* @returns void
|
|
10514
10722
|
*/
|
|
10515
10723
|
_insertFixup(z) {
|
|
10516
|
-
|
|
10517
|
-
|
|
10724
|
+
var _a, _b, _c, _d, _e;
|
|
10725
|
+
while (((_a = z == null ? void 0 : z.parent) == null ? void 0 : _a.color) === "RED") {
|
|
10726
|
+
if (z.parent === ((_b = z.parent.parent) == null ? void 0 : _b.left)) {
|
|
10518
10727
|
const y = z.parent.parent.right;
|
|
10519
|
-
if (y
|
|
10728
|
+
if ((y == null ? void 0 : y.color) === "RED") {
|
|
10520
10729
|
z.parent.color = "BLACK";
|
|
10521
10730
|
y.color = "BLACK";
|
|
10522
10731
|
z.parent.parent.color = "RED";
|
|
@@ -10526,15 +10735,15 @@ var RedBlackTree = class extends BST {
|
|
|
10526
10735
|
z = z.parent;
|
|
10527
10736
|
this._leftRotate(z);
|
|
10528
10737
|
}
|
|
10529
|
-
if (z &&
|
|
10738
|
+
if (z && z.parent && z.parent.parent) {
|
|
10530
10739
|
z.parent.color = "BLACK";
|
|
10531
10740
|
z.parent.parent.color = "RED";
|
|
10532
10741
|
this._rightRotate(z.parent.parent);
|
|
10533
10742
|
}
|
|
10534
10743
|
}
|
|
10535
10744
|
} else {
|
|
10536
|
-
const y = z
|
|
10537
|
-
if (y
|
|
10745
|
+
const y = (_e = (_d = (_c = z == null ? void 0 : z.parent) == null ? void 0 : _c.parent) == null ? void 0 : _d.left) != null ? _e : void 0;
|
|
10746
|
+
if ((y == null ? void 0 : y.color) === "RED") {
|
|
10538
10747
|
z.parent.color = "BLACK";
|
|
10539
10748
|
y.color = "BLACK";
|
|
10540
10749
|
z.parent.parent.color = "RED";
|
|
@@ -10544,7 +10753,7 @@ var RedBlackTree = class extends BST {
|
|
|
10544
10753
|
z = z.parent;
|
|
10545
10754
|
this._rightRotate(z);
|
|
10546
10755
|
}
|
|
10547
|
-
if (z &&
|
|
10756
|
+
if (z && z.parent && z.parent.parent) {
|
|
10548
10757
|
z.parent.color = "BLACK";
|
|
10549
10758
|
z.parent.parent.color = "RED";
|
|
10550
10759
|
this._leftRotate(z.parent.parent);
|
|
@@ -10561,6 +10770,7 @@ var RedBlackTree = class extends BST {
|
|
|
10561
10770
|
* @returns void
|
|
10562
10771
|
*/
|
|
10563
10772
|
_deleteFixup(node) {
|
|
10773
|
+
var _a, _b, _c, _d;
|
|
10564
10774
|
if (!node || node === this.root || node.color === "BLACK") {
|
|
10565
10775
|
if (node) {
|
|
10566
10776
|
node.color = "BLACK";
|
|
@@ -10574,17 +10784,17 @@ var RedBlackTree = class extends BST {
|
|
|
10574
10784
|
}
|
|
10575
10785
|
if (node === parent.left) {
|
|
10576
10786
|
let sibling = parent.right;
|
|
10577
|
-
if (sibling
|
|
10787
|
+
if ((sibling == null ? void 0 : sibling.color) === "RED") {
|
|
10578
10788
|
sibling.color = "BLACK";
|
|
10579
10789
|
parent.color = "RED";
|
|
10580
10790
|
this._leftRotate(parent);
|
|
10581
10791
|
sibling = parent.right;
|
|
10582
10792
|
}
|
|
10583
|
-
if ((sibling
|
|
10793
|
+
if (((_b = (_a = sibling == null ? void 0 : sibling.left) == null ? void 0 : _a.color) != null ? _b : "BLACK") === "BLACK") {
|
|
10584
10794
|
if (sibling) sibling.color = "RED";
|
|
10585
10795
|
node = parent;
|
|
10586
10796
|
} else {
|
|
10587
|
-
if (sibling
|
|
10797
|
+
if (sibling == null ? void 0 : sibling.left) sibling.left.color = "BLACK";
|
|
10588
10798
|
if (sibling) sibling.color = parent.color;
|
|
10589
10799
|
parent.color = "BLACK";
|
|
10590
10800
|
this._rightRotate(parent);
|
|
@@ -10592,17 +10802,17 @@ var RedBlackTree = class extends BST {
|
|
|
10592
10802
|
}
|
|
10593
10803
|
} else {
|
|
10594
10804
|
let sibling = parent.left;
|
|
10595
|
-
if (sibling
|
|
10805
|
+
if ((sibling == null ? void 0 : sibling.color) === "RED") {
|
|
10596
10806
|
sibling.color = "BLACK";
|
|
10597
10807
|
if (parent) parent.color = "RED";
|
|
10598
10808
|
this._rightRotate(parent);
|
|
10599
10809
|
if (parent) sibling = parent.left;
|
|
10600
10810
|
}
|
|
10601
|
-
if ((sibling
|
|
10811
|
+
if (((_d = (_c = sibling == null ? void 0 : sibling.right) == null ? void 0 : _c.color) != null ? _d : "BLACK") === "BLACK") {
|
|
10602
10812
|
if (sibling) sibling.color = "RED";
|
|
10603
10813
|
node = parent;
|
|
10604
10814
|
} else {
|
|
10605
|
-
if (sibling
|
|
10815
|
+
if (sibling == null ? void 0 : sibling.right) sibling.right.color = "BLACK";
|
|
10606
10816
|
if (sibling) sibling.color = parent.color;
|
|
10607
10817
|
if (parent) parent.color = "BLACK";
|
|
10608
10818
|
this._leftRotate(parent);
|
|
@@ -10626,7 +10836,7 @@ var RedBlackTree = class extends BST {
|
|
|
10626
10836
|
}
|
|
10627
10837
|
const y = x.right;
|
|
10628
10838
|
x.right = y.left;
|
|
10629
|
-
if (
|
|
10839
|
+
if (y.left && y.left !== this.NIL) {
|
|
10630
10840
|
y.left.parent = x;
|
|
10631
10841
|
}
|
|
10632
10842
|
y.parent = x.parent;
|
|
@@ -10652,7 +10862,7 @@ var RedBlackTree = class extends BST {
|
|
|
10652
10862
|
}
|
|
10653
10863
|
const x = y.left;
|
|
10654
10864
|
y.left = x.right;
|
|
10655
|
-
if (
|
|
10865
|
+
if (x.right && x.right !== this.NIL) {
|
|
10656
10866
|
x.right.parent = y;
|
|
10657
10867
|
}
|
|
10658
10868
|
x.parent = y.parent;
|
|
@@ -10667,13 +10877,11 @@ var RedBlackTree = class extends BST {
|
|
|
10667
10877
|
y.parent = x;
|
|
10668
10878
|
}
|
|
10669
10879
|
};
|
|
10880
|
+
__name(_RedBlackTree, "RedBlackTree");
|
|
10881
|
+
var RedBlackTree = _RedBlackTree;
|
|
10670
10882
|
|
|
10671
10883
|
// src/data-structures/binary-tree/avl-tree-multi-map.ts
|
|
10672
|
-
var
|
|
10673
|
-
static {
|
|
10674
|
-
__name(this, "AVLTreeMultiMapNode");
|
|
10675
|
-
}
|
|
10676
|
-
parent = void 0;
|
|
10884
|
+
var _AVLTreeMultiMapNode = class _AVLTreeMultiMapNode {
|
|
10677
10885
|
/**
|
|
10678
10886
|
* Create an AVLTreeMultiMap node with a value bucket.
|
|
10679
10887
|
* @remarks Time O(1), Space O(1)
|
|
@@ -10681,10 +10889,18 @@ var AVLTreeMultiMapNode = class extends AVLTreeNode {
|
|
|
10681
10889
|
* @param value - Initial array of values.
|
|
10682
10890
|
* @returns New AVLTreeMultiMapNode instance.
|
|
10683
10891
|
*/
|
|
10684
|
-
constructor(key, value) {
|
|
10685
|
-
|
|
10892
|
+
constructor(key, value = []) {
|
|
10893
|
+
__publicField(this, "key");
|
|
10894
|
+
__publicField(this, "value");
|
|
10895
|
+
__publicField(this, "parent");
|
|
10896
|
+
__publicField(this, "_left");
|
|
10897
|
+
__publicField(this, "_right");
|
|
10898
|
+
__publicField(this, "_height", 0);
|
|
10899
|
+
__publicField(this, "_color", "BLACK");
|
|
10900
|
+
__publicField(this, "_count", 1);
|
|
10901
|
+
this.key = key;
|
|
10902
|
+
this.value = value;
|
|
10686
10903
|
}
|
|
10687
|
-
_left = void 0;
|
|
10688
10904
|
/**
|
|
10689
10905
|
* Get the left child pointer.
|
|
10690
10906
|
* @remarks Time O(1), Space O(1)
|
|
@@ -10705,7 +10921,6 @@ var AVLTreeMultiMapNode = class extends AVLTreeNode {
|
|
|
10705
10921
|
}
|
|
10706
10922
|
this._left = v;
|
|
10707
10923
|
}
|
|
10708
|
-
_right = void 0;
|
|
10709
10924
|
/**
|
|
10710
10925
|
* Get the right child pointer.
|
|
10711
10926
|
* @remarks Time O(1), Space O(1)
|
|
@@ -10726,11 +10941,81 @@ var AVLTreeMultiMapNode = class extends AVLTreeNode {
|
|
|
10726
10941
|
}
|
|
10727
10942
|
this._right = v;
|
|
10728
10943
|
}
|
|
10729
|
-
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
|
|
10944
|
+
/**
|
|
10945
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
10946
|
+
* @remarks Time O(1), Space O(1)
|
|
10947
|
+
*
|
|
10948
|
+
* @returns The height.
|
|
10949
|
+
*/
|
|
10950
|
+
get height() {
|
|
10951
|
+
return this._height;
|
|
10733
10952
|
}
|
|
10953
|
+
/**
|
|
10954
|
+
* Sets the height of the node.
|
|
10955
|
+
* @remarks Time O(1), Space O(1)
|
|
10956
|
+
*
|
|
10957
|
+
* @param value - The new height.
|
|
10958
|
+
*/
|
|
10959
|
+
set height(value) {
|
|
10960
|
+
this._height = value;
|
|
10961
|
+
}
|
|
10962
|
+
/**
|
|
10963
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
10964
|
+
* @remarks Time O(1), Space O(1)
|
|
10965
|
+
*
|
|
10966
|
+
* @returns The node's color.
|
|
10967
|
+
*/
|
|
10968
|
+
get color() {
|
|
10969
|
+
return this._color;
|
|
10970
|
+
}
|
|
10971
|
+
/**
|
|
10972
|
+
* Sets the color of the node.
|
|
10973
|
+
* @remarks Time O(1), Space O(1)
|
|
10974
|
+
*
|
|
10975
|
+
* @param value - The new color.
|
|
10976
|
+
*/
|
|
10977
|
+
set color(value) {
|
|
10978
|
+
this._color = value;
|
|
10979
|
+
}
|
|
10980
|
+
/**
|
|
10981
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
10982
|
+
* @remarks Time O(1), Space O(1)
|
|
10983
|
+
*
|
|
10984
|
+
* @returns The subtree node count.
|
|
10985
|
+
*/
|
|
10986
|
+
get count() {
|
|
10987
|
+
return this._count;
|
|
10988
|
+
}
|
|
10989
|
+
/**
|
|
10990
|
+
* Sets the count of nodes in the subtree.
|
|
10991
|
+
* @remarks Time O(1), Space O(1)
|
|
10992
|
+
*
|
|
10993
|
+
* @param value - The new count.
|
|
10994
|
+
*/
|
|
10995
|
+
set count(value) {
|
|
10996
|
+
this._count = value;
|
|
10997
|
+
}
|
|
10998
|
+
/**
|
|
10999
|
+
* Gets the position of the node relative to its parent.
|
|
11000
|
+
* @remarks Time O(1), Space O(1)
|
|
11001
|
+
*
|
|
11002
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
11003
|
+
*/
|
|
11004
|
+
get familyPosition() {
|
|
11005
|
+
if (!this.parent) {
|
|
11006
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
11007
|
+
}
|
|
11008
|
+
if (this.parent.left === this) {
|
|
11009
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
11010
|
+
} else if (this.parent.right === this) {
|
|
11011
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
11012
|
+
}
|
|
11013
|
+
return "MAL_NODE";
|
|
11014
|
+
}
|
|
11015
|
+
};
|
|
11016
|
+
__name(_AVLTreeMultiMapNode, "AVLTreeMultiMapNode");
|
|
11017
|
+
var AVLTreeMultiMapNode = _AVLTreeMultiMapNode;
|
|
11018
|
+
var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
10734
11019
|
/**
|
|
10735
11020
|
* Create an AVLTreeMultiMap and optionally bulk-insert items.
|
|
10736
11021
|
* @remarks Time O(N log N), Space O(N)
|
|
@@ -10744,9 +11029,19 @@ var AVLTreeMultiMap = class extends AVLTree {
|
|
|
10744
11029
|
this.addMany(keysNodesEntriesOrRaws);
|
|
10745
11030
|
}
|
|
10746
11031
|
}
|
|
10747
|
-
|
|
11032
|
+
createNode(key, value = []) {
|
|
10748
11033
|
return new AVLTreeMultiMapNode(key, this._isMapMode ? [] : value);
|
|
10749
11034
|
}
|
|
11035
|
+
/**
|
|
11036
|
+
* Checks if the given item is a `AVLTreeMultiMapNode` instance.
|
|
11037
|
+
* @remarks Time O(1), Space O(1)
|
|
11038
|
+
*
|
|
11039
|
+
* @param keyNodeOrEntry - The item to check.
|
|
11040
|
+
* @returns True if it's a AVLTreeMultiMapNode, false otherwise.
|
|
11041
|
+
*/
|
|
11042
|
+
isNode(keyNodeOrEntry) {
|
|
11043
|
+
return keyNodeOrEntry instanceof AVLTreeMultiMapNode;
|
|
11044
|
+
}
|
|
10750
11045
|
/**
|
|
10751
11046
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
10752
11047
|
* @remarks Time O(log N + M), Space O(1)
|
|
@@ -10868,8 +11163,9 @@ var AVLTreeMultiMap = class extends AVLTree {
|
|
|
10868
11163
|
* @returns An empty like-kind instance.
|
|
10869
11164
|
*/
|
|
10870
11165
|
_createInstance(options) {
|
|
11166
|
+
var _a, _b;
|
|
10871
11167
|
const Ctor = this.constructor;
|
|
10872
|
-
return new Ctor([], { ...this._snapshotOptions
|
|
11168
|
+
return new Ctor([], { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
|
|
10873
11169
|
}
|
|
10874
11170
|
/**
|
|
10875
11171
|
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
@@ -10882,17 +11178,16 @@ var AVLTreeMultiMap = class extends AVLTree {
|
|
|
10882
11178
|
* @returns A like-kind AVLTree built from the iterable.
|
|
10883
11179
|
*/
|
|
10884
11180
|
_createLike(iter = [], options) {
|
|
11181
|
+
var _a, _b;
|
|
10885
11182
|
const Ctor = this.constructor;
|
|
10886
|
-
return new Ctor(iter, { ...this._snapshotOptions
|
|
11183
|
+
return new Ctor(iter, { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
|
|
10887
11184
|
}
|
|
10888
11185
|
};
|
|
11186
|
+
__name(_AVLTreeMultiMap, "AVLTreeMultiMap");
|
|
11187
|
+
var AVLTreeMultiMap = _AVLTreeMultiMap;
|
|
10889
11188
|
|
|
10890
11189
|
// src/data-structures/binary-tree/tree-multi-map.ts
|
|
10891
|
-
var
|
|
10892
|
-
static {
|
|
10893
|
-
__name(this, "TreeMultiMapNode");
|
|
10894
|
-
}
|
|
10895
|
-
parent = void 0;
|
|
11190
|
+
var _TreeMultiMapNode = class _TreeMultiMapNode {
|
|
10896
11191
|
/**
|
|
10897
11192
|
* Create a TreeMultiMap node with an optional value bucket.
|
|
10898
11193
|
* @remarks Time O(1), Space O(1)
|
|
@@ -10900,10 +11195,19 @@ var TreeMultiMapNode = class extends RedBlackTreeNode {
|
|
|
10900
11195
|
* @param [value] - Initial array of values.
|
|
10901
11196
|
* @returns New TreeMultiMapNode instance.
|
|
10902
11197
|
*/
|
|
10903
|
-
constructor(key, value) {
|
|
10904
|
-
|
|
11198
|
+
constructor(key, value = [], color = "BLACK") {
|
|
11199
|
+
__publicField(this, "key");
|
|
11200
|
+
__publicField(this, "value");
|
|
11201
|
+
__publicField(this, "parent");
|
|
11202
|
+
__publicField(this, "_left");
|
|
11203
|
+
__publicField(this, "_right");
|
|
11204
|
+
__publicField(this, "_height", 0);
|
|
11205
|
+
__publicField(this, "_color", "BLACK");
|
|
11206
|
+
__publicField(this, "_count", 1);
|
|
11207
|
+
this.key = key;
|
|
11208
|
+
this.value = value;
|
|
11209
|
+
this.color = color;
|
|
10905
11210
|
}
|
|
10906
|
-
_left = void 0;
|
|
10907
11211
|
/**
|
|
10908
11212
|
* Get the left child pointer.
|
|
10909
11213
|
* @remarks Time O(1), Space O(1)
|
|
@@ -10924,7 +11228,6 @@ var TreeMultiMapNode = class extends RedBlackTreeNode {
|
|
|
10924
11228
|
}
|
|
10925
11229
|
this._left = v;
|
|
10926
11230
|
}
|
|
10927
|
-
_right = void 0;
|
|
10928
11231
|
/**
|
|
10929
11232
|
* Get the right child pointer.
|
|
10930
11233
|
* @remarks Time O(1), Space O(1)
|
|
@@ -10945,11 +11248,81 @@ var TreeMultiMapNode = class extends RedBlackTreeNode {
|
|
|
10945
11248
|
}
|
|
10946
11249
|
this._right = v;
|
|
10947
11250
|
}
|
|
10948
|
-
|
|
10949
|
-
|
|
10950
|
-
|
|
10951
|
-
|
|
11251
|
+
/**
|
|
11252
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
11253
|
+
* @remarks Time O(1), Space O(1)
|
|
11254
|
+
*
|
|
11255
|
+
* @returns The height.
|
|
11256
|
+
*/
|
|
11257
|
+
get height() {
|
|
11258
|
+
return this._height;
|
|
10952
11259
|
}
|
|
11260
|
+
/**
|
|
11261
|
+
* Sets the height of the node.
|
|
11262
|
+
* @remarks Time O(1), Space O(1)
|
|
11263
|
+
*
|
|
11264
|
+
* @param value - The new height.
|
|
11265
|
+
*/
|
|
11266
|
+
set height(value) {
|
|
11267
|
+
this._height = value;
|
|
11268
|
+
}
|
|
11269
|
+
/**
|
|
11270
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
11271
|
+
* @remarks Time O(1), Space O(1)
|
|
11272
|
+
*
|
|
11273
|
+
* @returns The node's color.
|
|
11274
|
+
*/
|
|
11275
|
+
get color() {
|
|
11276
|
+
return this._color;
|
|
11277
|
+
}
|
|
11278
|
+
/**
|
|
11279
|
+
* Sets the color of the node.
|
|
11280
|
+
* @remarks Time O(1), Space O(1)
|
|
11281
|
+
*
|
|
11282
|
+
* @param value - The new color.
|
|
11283
|
+
*/
|
|
11284
|
+
set color(value) {
|
|
11285
|
+
this._color = value;
|
|
11286
|
+
}
|
|
11287
|
+
/**
|
|
11288
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
11289
|
+
* @remarks Time O(1), Space O(1)
|
|
11290
|
+
*
|
|
11291
|
+
* @returns The subtree node count.
|
|
11292
|
+
*/
|
|
11293
|
+
get count() {
|
|
11294
|
+
return this._count;
|
|
11295
|
+
}
|
|
11296
|
+
/**
|
|
11297
|
+
* Sets the count of nodes in the subtree.
|
|
11298
|
+
* @remarks Time O(1), Space O(1)
|
|
11299
|
+
*
|
|
11300
|
+
* @param value - The new count.
|
|
11301
|
+
*/
|
|
11302
|
+
set count(value) {
|
|
11303
|
+
this._count = value;
|
|
11304
|
+
}
|
|
11305
|
+
/**
|
|
11306
|
+
* Gets the position of the node relative to its parent.
|
|
11307
|
+
* @remarks Time O(1), Space O(1)
|
|
11308
|
+
*
|
|
11309
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
11310
|
+
*/
|
|
11311
|
+
get familyPosition() {
|
|
11312
|
+
if (!this.parent) {
|
|
11313
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
11314
|
+
}
|
|
11315
|
+
if (this.parent.left === this) {
|
|
11316
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
11317
|
+
} else if (this.parent.right === this) {
|
|
11318
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
11319
|
+
}
|
|
11320
|
+
return "MAL_NODE";
|
|
11321
|
+
}
|
|
11322
|
+
};
|
|
11323
|
+
__name(_TreeMultiMapNode, "TreeMultiMapNode");
|
|
11324
|
+
var TreeMultiMapNode = _TreeMultiMapNode;
|
|
11325
|
+
var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
10953
11326
|
/**
|
|
10954
11327
|
* Create a TreeMultiMap and optionally bulk-insert items.
|
|
10955
11328
|
* @remarks Time O(N log N), Space O(N)
|
|
@@ -10963,9 +11336,19 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
10963
11336
|
this.addMany(keysNodesEntriesOrRaws);
|
|
10964
11337
|
}
|
|
10965
11338
|
}
|
|
10966
|
-
|
|
11339
|
+
createNode(key, value = []) {
|
|
10967
11340
|
return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
|
|
10968
11341
|
}
|
|
11342
|
+
/**
|
|
11343
|
+
* Checks if the given item is a `TreeMultiMapNode` instance.
|
|
11344
|
+
* @remarks Time O(1), Space O(1)
|
|
11345
|
+
*
|
|
11346
|
+
* @param keyNodeOrEntry - The item to check.
|
|
11347
|
+
* @returns True if it's a TreeMultiMapNode, false otherwise.
|
|
11348
|
+
*/
|
|
11349
|
+
isNode(keyNodeOrEntry) {
|
|
11350
|
+
return keyNodeOrEntry instanceof TreeMultiMapNode;
|
|
11351
|
+
}
|
|
10969
11352
|
/**
|
|
10970
11353
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
10971
11354
|
* @remarks Time O(log N + M), Space O(1)
|
|
@@ -11059,8 +11442,9 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
11059
11442
|
* @returns An empty like-kind instance.
|
|
11060
11443
|
*/
|
|
11061
11444
|
_createInstance(options) {
|
|
11445
|
+
var _a, _b;
|
|
11062
11446
|
const Ctor = this.constructor;
|
|
11063
|
-
return new Ctor([], { ...this._snapshotOptions
|
|
11447
|
+
return new Ctor([], { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
|
|
11064
11448
|
}
|
|
11065
11449
|
/**
|
|
11066
11450
|
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
@@ -11073,17 +11457,16 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
11073
11457
|
* @returns A like-kind RedBlackTree built from the iterable.
|
|
11074
11458
|
*/
|
|
11075
11459
|
_createLike(iter = [], options) {
|
|
11460
|
+
var _a, _b;
|
|
11076
11461
|
const Ctor = this.constructor;
|
|
11077
|
-
return new Ctor(iter, { ...this._snapshotOptions
|
|
11462
|
+
return new Ctor(iter, { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
|
|
11078
11463
|
}
|
|
11079
11464
|
};
|
|
11465
|
+
__name(_TreeMultiMap, "TreeMultiMap");
|
|
11466
|
+
var TreeMultiMap = _TreeMultiMap;
|
|
11080
11467
|
|
|
11081
11468
|
// src/data-structures/binary-tree/tree-counter.ts
|
|
11082
|
-
var
|
|
11083
|
-
static {
|
|
11084
|
-
__name(this, "TreeCounterNode");
|
|
11085
|
-
}
|
|
11086
|
-
parent = void 0;
|
|
11469
|
+
var _TreeCounterNode = class _TreeCounterNode {
|
|
11087
11470
|
/**
|
|
11088
11471
|
* Create a tree counter node.
|
|
11089
11472
|
* @remarks Time O(1), Space O(1)
|
|
@@ -11094,10 +11477,19 @@ var TreeCounterNode = class extends RedBlackTreeNode {
|
|
|
11094
11477
|
* @returns New TreeCounterNode instance.
|
|
11095
11478
|
*/
|
|
11096
11479
|
constructor(key, value, count = 1, color = "BLACK") {
|
|
11097
|
-
|
|
11480
|
+
__publicField(this, "key");
|
|
11481
|
+
__publicField(this, "value");
|
|
11482
|
+
__publicField(this, "parent");
|
|
11483
|
+
__publicField(this, "_left");
|
|
11484
|
+
__publicField(this, "_right");
|
|
11485
|
+
__publicField(this, "_height", 0);
|
|
11486
|
+
__publicField(this, "_color", "BLACK");
|
|
11487
|
+
__publicField(this, "_count", 1);
|
|
11488
|
+
this.key = key;
|
|
11489
|
+
this.value = value;
|
|
11490
|
+
this.color = color;
|
|
11098
11491
|
this.count = count;
|
|
11099
11492
|
}
|
|
11100
|
-
_left = void 0;
|
|
11101
11493
|
/**
|
|
11102
11494
|
* Get the left child pointer.
|
|
11103
11495
|
* @remarks Time O(1), Space O(1)
|
|
@@ -11118,7 +11510,6 @@ var TreeCounterNode = class extends RedBlackTreeNode {
|
|
|
11118
11510
|
}
|
|
11119
11511
|
this._left = v;
|
|
11120
11512
|
}
|
|
11121
|
-
_right = void 0;
|
|
11122
11513
|
/**
|
|
11123
11514
|
* Get the right child pointer.
|
|
11124
11515
|
* @remarks Time O(1), Space O(1)
|
|
@@ -11139,11 +11530,81 @@ var TreeCounterNode = class extends RedBlackTreeNode {
|
|
|
11139
11530
|
}
|
|
11140
11531
|
this._right = v;
|
|
11141
11532
|
}
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
|
|
11145
|
-
|
|
11533
|
+
/**
|
|
11534
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
11535
|
+
* @remarks Time O(1), Space O(1)
|
|
11536
|
+
*
|
|
11537
|
+
* @returns The height.
|
|
11538
|
+
*/
|
|
11539
|
+
get height() {
|
|
11540
|
+
return this._height;
|
|
11541
|
+
}
|
|
11542
|
+
/**
|
|
11543
|
+
* Sets the height of the node.
|
|
11544
|
+
* @remarks Time O(1), Space O(1)
|
|
11545
|
+
*
|
|
11546
|
+
* @param value - The new height.
|
|
11547
|
+
*/
|
|
11548
|
+
set height(value) {
|
|
11549
|
+
this._height = value;
|
|
11550
|
+
}
|
|
11551
|
+
/**
|
|
11552
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
11553
|
+
* @remarks Time O(1), Space O(1)
|
|
11554
|
+
*
|
|
11555
|
+
* @returns The node's color.
|
|
11556
|
+
*/
|
|
11557
|
+
get color() {
|
|
11558
|
+
return this._color;
|
|
11559
|
+
}
|
|
11560
|
+
/**
|
|
11561
|
+
* Sets the color of the node.
|
|
11562
|
+
* @remarks Time O(1), Space O(1)
|
|
11563
|
+
*
|
|
11564
|
+
* @param value - The new color.
|
|
11565
|
+
*/
|
|
11566
|
+
set color(value) {
|
|
11567
|
+
this._color = value;
|
|
11568
|
+
}
|
|
11569
|
+
/**
|
|
11570
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
11571
|
+
* @remarks Time O(1), Space O(1)
|
|
11572
|
+
*
|
|
11573
|
+
* @returns The subtree node count.
|
|
11574
|
+
*/
|
|
11575
|
+
get count() {
|
|
11576
|
+
return this._count;
|
|
11577
|
+
}
|
|
11578
|
+
/**
|
|
11579
|
+
* Sets the count of nodes in the subtree.
|
|
11580
|
+
* @remarks Time O(1), Space O(1)
|
|
11581
|
+
*
|
|
11582
|
+
* @param value - The new count.
|
|
11583
|
+
*/
|
|
11584
|
+
set count(value) {
|
|
11585
|
+
this._count = value;
|
|
11586
|
+
}
|
|
11587
|
+
/**
|
|
11588
|
+
* Gets the position of the node relative to its parent.
|
|
11589
|
+
* @remarks Time O(1), Space O(1)
|
|
11590
|
+
*
|
|
11591
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
11592
|
+
*/
|
|
11593
|
+
get familyPosition() {
|
|
11594
|
+
if (!this.parent) {
|
|
11595
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
11596
|
+
}
|
|
11597
|
+
if (this.parent.left === this) {
|
|
11598
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
11599
|
+
} else if (this.parent.right === this) {
|
|
11600
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
11601
|
+
}
|
|
11602
|
+
return "MAL_NODE";
|
|
11146
11603
|
}
|
|
11604
|
+
};
|
|
11605
|
+
__name(_TreeCounterNode, "TreeCounterNode");
|
|
11606
|
+
var TreeCounterNode = _TreeCounterNode;
|
|
11607
|
+
var _TreeCounter = class _TreeCounter extends RedBlackTree {
|
|
11147
11608
|
/**
|
|
11148
11609
|
* Create a TreeCounter and optionally bulk-insert items.
|
|
11149
11610
|
* @remarks Time O(N log N), Space O(N)
|
|
@@ -11153,9 +11614,9 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
11153
11614
|
*/
|
|
11154
11615
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11155
11616
|
super([], options);
|
|
11617
|
+
__publicField(this, "_count", 0);
|
|
11156
11618
|
if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
|
|
11157
11619
|
}
|
|
11158
|
-
_count = 0;
|
|
11159
11620
|
/**
|
|
11160
11621
|
* Get the total aggregate count across all nodes.
|
|
11161
11622
|
* @remarks Time O(1), Space O(1)
|
|
@@ -11174,7 +11635,7 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
11174
11635
|
this.dfs((node) => sum += node ? node.count : 0);
|
|
11175
11636
|
return sum;
|
|
11176
11637
|
}
|
|
11177
|
-
|
|
11638
|
+
createNode(key, value, color = "BLACK", count) {
|
|
11178
11639
|
return new TreeCounterNode(key, this._isMapMode ? void 0 : value, count, color);
|
|
11179
11640
|
}
|
|
11180
11641
|
/**
|
|
@@ -11195,7 +11656,7 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
11195
11656
|
*/
|
|
11196
11657
|
add(keyNodeOrEntry, value, count = 1) {
|
|
11197
11658
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
11198
|
-
const orgCount = newNode
|
|
11659
|
+
const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
11199
11660
|
const isSuccessAdded = super.add(newNode, newValue);
|
|
11200
11661
|
if (isSuccessAdded) {
|
|
11201
11662
|
this._count += orgCount;
|
|
@@ -11375,7 +11836,7 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
11375
11836
|
*/
|
|
11376
11837
|
_createInstance(options) {
|
|
11377
11838
|
const Ctor = this.constructor;
|
|
11378
|
-
return new Ctor([], { ...this._snapshotOptions(), ...options
|
|
11839
|
+
return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
11379
11840
|
}
|
|
11380
11841
|
/**
|
|
11381
11842
|
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
@@ -11391,7 +11852,7 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
11391
11852
|
const Ctor = this.constructor;
|
|
11392
11853
|
return new Ctor(iter, {
|
|
11393
11854
|
...this._snapshotOptions(),
|
|
11394
|
-
...options
|
|
11855
|
+
...options != null ? options : {}
|
|
11395
11856
|
});
|
|
11396
11857
|
}
|
|
11397
11858
|
/**
|
|
@@ -11408,10 +11869,10 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
11408
11869
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
11409
11870
|
const [key, entryValue] = keyNodeOrEntry;
|
|
11410
11871
|
if (key === void 0 || key === null) return [void 0, void 0];
|
|
11411
|
-
const finalValue = value
|
|
11412
|
-
return [this.
|
|
11872
|
+
const finalValue = value != null ? value : entryValue;
|
|
11873
|
+
return [this.createNode(key, finalValue, "BLACK", count), finalValue];
|
|
11413
11874
|
}
|
|
11414
|
-
return [this.
|
|
11875
|
+
return [this.createNode(keyNodeOrEntry, value, "BLACK", count), value];
|
|
11415
11876
|
}
|
|
11416
11877
|
/**
|
|
11417
11878
|
* (Protected) Swap keys/values/counters between the source and destination nodes.
|
|
@@ -11425,7 +11886,7 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
11425
11886
|
destNode = this.ensureNode(destNode);
|
|
11426
11887
|
if (srcNode && destNode) {
|
|
11427
11888
|
const { key, value, count, color } = destNode;
|
|
11428
|
-
const tempNode = this.
|
|
11889
|
+
const tempNode = this.createNode(key, value, color, count);
|
|
11429
11890
|
if (tempNode) {
|
|
11430
11891
|
tempNode.color = color;
|
|
11431
11892
|
destNode.key = srcNode.key;
|
|
@@ -11453,13 +11914,11 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
11453
11914
|
return super._replaceNode(oldNode, newNode);
|
|
11454
11915
|
}
|
|
11455
11916
|
};
|
|
11917
|
+
__name(_TreeCounter, "TreeCounter");
|
|
11918
|
+
var TreeCounter = _TreeCounter;
|
|
11456
11919
|
|
|
11457
11920
|
// src/data-structures/binary-tree/avl-tree-counter.ts
|
|
11458
|
-
var
|
|
11459
|
-
static {
|
|
11460
|
-
__name(this, "AVLTreeCounterNode");
|
|
11461
|
-
}
|
|
11462
|
-
parent = void 0;
|
|
11921
|
+
var _AVLTreeCounterNode = class _AVLTreeCounterNode {
|
|
11463
11922
|
/**
|
|
11464
11923
|
* Create an AVL counter node.
|
|
11465
11924
|
* @remarks Time O(1), Space O(1)
|
|
@@ -11469,10 +11928,18 @@ var AVLTreeCounterNode = class extends AVLTreeNode {
|
|
|
11469
11928
|
* @returns New AVLTreeCounterNode instance.
|
|
11470
11929
|
*/
|
|
11471
11930
|
constructor(key, value, count = 1) {
|
|
11472
|
-
|
|
11931
|
+
__publicField(this, "key");
|
|
11932
|
+
__publicField(this, "value");
|
|
11933
|
+
__publicField(this, "parent");
|
|
11934
|
+
__publicField(this, "_left");
|
|
11935
|
+
__publicField(this, "_right");
|
|
11936
|
+
__publicField(this, "_height", 0);
|
|
11937
|
+
__publicField(this, "_color", "BLACK");
|
|
11938
|
+
__publicField(this, "_count", 1);
|
|
11939
|
+
this.key = key;
|
|
11940
|
+
this.value = value;
|
|
11473
11941
|
this.count = count;
|
|
11474
11942
|
}
|
|
11475
|
-
_left = void 0;
|
|
11476
11943
|
/**
|
|
11477
11944
|
* Get the left child pointer.
|
|
11478
11945
|
* @remarks Time O(1), Space O(1)
|
|
@@ -11493,7 +11960,6 @@ var AVLTreeCounterNode = class extends AVLTreeNode {
|
|
|
11493
11960
|
}
|
|
11494
11961
|
this._left = v;
|
|
11495
11962
|
}
|
|
11496
|
-
_right = void 0;
|
|
11497
11963
|
/**
|
|
11498
11964
|
* Get the right child pointer.
|
|
11499
11965
|
* @remarks Time O(1), Space O(1)
|
|
@@ -11514,11 +11980,81 @@ var AVLTreeCounterNode = class extends AVLTreeNode {
|
|
|
11514
11980
|
}
|
|
11515
11981
|
this._right = v;
|
|
11516
11982
|
}
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
|
|
11983
|
+
/**
|
|
11984
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
11985
|
+
* @remarks Time O(1), Space O(1)
|
|
11986
|
+
*
|
|
11987
|
+
* @returns The height.
|
|
11988
|
+
*/
|
|
11989
|
+
get height() {
|
|
11990
|
+
return this._height;
|
|
11991
|
+
}
|
|
11992
|
+
/**
|
|
11993
|
+
* Sets the height of the node.
|
|
11994
|
+
* @remarks Time O(1), Space O(1)
|
|
11995
|
+
*
|
|
11996
|
+
* @param value - The new height.
|
|
11997
|
+
*/
|
|
11998
|
+
set height(value) {
|
|
11999
|
+
this._height = value;
|
|
12000
|
+
}
|
|
12001
|
+
/**
|
|
12002
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
12003
|
+
* @remarks Time O(1), Space O(1)
|
|
12004
|
+
*
|
|
12005
|
+
* @returns The node's color.
|
|
12006
|
+
*/
|
|
12007
|
+
get color() {
|
|
12008
|
+
return this._color;
|
|
12009
|
+
}
|
|
12010
|
+
/**
|
|
12011
|
+
* Sets the color of the node.
|
|
12012
|
+
* @remarks Time O(1), Space O(1)
|
|
12013
|
+
*
|
|
12014
|
+
* @param value - The new color.
|
|
12015
|
+
*/
|
|
12016
|
+
set color(value) {
|
|
12017
|
+
this._color = value;
|
|
12018
|
+
}
|
|
12019
|
+
/**
|
|
12020
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
12021
|
+
* @remarks Time O(1), Space O(1)
|
|
12022
|
+
*
|
|
12023
|
+
* @returns The subtree node count.
|
|
12024
|
+
*/
|
|
12025
|
+
get count() {
|
|
12026
|
+
return this._count;
|
|
11521
12027
|
}
|
|
12028
|
+
/**
|
|
12029
|
+
* Sets the count of nodes in the subtree.
|
|
12030
|
+
* @remarks Time O(1), Space O(1)
|
|
12031
|
+
*
|
|
12032
|
+
* @param value - The new count.
|
|
12033
|
+
*/
|
|
12034
|
+
set count(value) {
|
|
12035
|
+
this._count = value;
|
|
12036
|
+
}
|
|
12037
|
+
/**
|
|
12038
|
+
* Gets the position of the node relative to its parent.
|
|
12039
|
+
* @remarks Time O(1), Space O(1)
|
|
12040
|
+
*
|
|
12041
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
12042
|
+
*/
|
|
12043
|
+
get familyPosition() {
|
|
12044
|
+
if (!this.parent) {
|
|
12045
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
12046
|
+
}
|
|
12047
|
+
if (this.parent.left === this) {
|
|
12048
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
12049
|
+
} else if (this.parent.right === this) {
|
|
12050
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
12051
|
+
}
|
|
12052
|
+
return "MAL_NODE";
|
|
12053
|
+
}
|
|
12054
|
+
};
|
|
12055
|
+
__name(_AVLTreeCounterNode, "AVLTreeCounterNode");
|
|
12056
|
+
var AVLTreeCounterNode = _AVLTreeCounterNode;
|
|
12057
|
+
var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
11522
12058
|
/**
|
|
11523
12059
|
* Create a AVLTreeCounter instance
|
|
11524
12060
|
* @remarks Time O(n), Space O(n)
|
|
@@ -11528,9 +12064,9 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
11528
12064
|
*/
|
|
11529
12065
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11530
12066
|
super([], options);
|
|
12067
|
+
__publicField(this, "_count", 0);
|
|
11531
12068
|
if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
|
|
11532
12069
|
}
|
|
11533
|
-
_count = 0;
|
|
11534
12070
|
get count() {
|
|
11535
12071
|
return this._count;
|
|
11536
12072
|
}
|
|
@@ -11544,7 +12080,7 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
11544
12080
|
this.dfs((node) => sum += node.count);
|
|
11545
12081
|
return sum;
|
|
11546
12082
|
}
|
|
11547
|
-
|
|
12083
|
+
createNode(key, value, count) {
|
|
11548
12084
|
return new AVLTreeCounterNode(key, this._isMapMode ? void 0 : value, count);
|
|
11549
12085
|
}
|
|
11550
12086
|
/**
|
|
@@ -11566,7 +12102,7 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
11566
12102
|
add(keyNodeOrEntry, value, count = 1) {
|
|
11567
12103
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
11568
12104
|
if (newNode === void 0) return false;
|
|
11569
|
-
const orgNodeCount = newNode
|
|
12105
|
+
const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
11570
12106
|
const inserted = super.add(newNode, newValue);
|
|
11571
12107
|
if (inserted) {
|
|
11572
12108
|
this._count += orgNodeCount;
|
|
@@ -11581,11 +12117,12 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
11581
12117
|
* @returns Array of deletion results including deleted node and a rebalance hint when present.
|
|
11582
12118
|
*/
|
|
11583
12119
|
delete(keyNodeOrEntry, ignoreCount = false) {
|
|
12120
|
+
var _a;
|
|
11584
12121
|
const deletedResult = [];
|
|
11585
12122
|
if (!this.root) return deletedResult;
|
|
11586
|
-
const curr = this.getNode(keyNodeOrEntry)
|
|
12123
|
+
const curr = (_a = this.getNode(keyNodeOrEntry)) != null ? _a : void 0;
|
|
11587
12124
|
if (!curr) return deletedResult;
|
|
11588
|
-
const parent = curr
|
|
12125
|
+
const parent = (curr == null ? void 0 : curr.parent) ? curr.parent : void 0;
|
|
11589
12126
|
let needBalanced = void 0, orgCurrent = curr;
|
|
11590
12127
|
if (curr.count > 1 && !ignoreCount) {
|
|
11591
12128
|
curr.count--;
|
|
@@ -11712,7 +12249,7 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
11712
12249
|
*/
|
|
11713
12250
|
_createInstance(options) {
|
|
11714
12251
|
const Ctor = this.constructor;
|
|
11715
|
-
return new Ctor([], { ...this._snapshotOptions(), ...options
|
|
12252
|
+
return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
11716
12253
|
}
|
|
11717
12254
|
/**
|
|
11718
12255
|
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
@@ -11726,7 +12263,7 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
11726
12263
|
*/
|
|
11727
12264
|
_createLike(iter = [], options) {
|
|
11728
12265
|
const Ctor = this.constructor;
|
|
11729
|
-
return new Ctor(iter, { ...this._snapshotOptions(), ...options
|
|
12266
|
+
return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
|
|
11730
12267
|
}
|
|
11731
12268
|
/**
|
|
11732
12269
|
* (Protected) Normalize input into a node plus its effective value and count.
|
|
@@ -11742,10 +12279,10 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
11742
12279
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
11743
12280
|
const [key, entryValue] = keyNodeOrEntry;
|
|
11744
12281
|
if (key === void 0 || key === null) return [void 0, void 0];
|
|
11745
|
-
const finalValue = value
|
|
11746
|
-
return [this.
|
|
12282
|
+
const finalValue = value != null ? value : entryValue;
|
|
12283
|
+
return [this.createNode(key, finalValue, count), finalValue];
|
|
11747
12284
|
}
|
|
11748
|
-
return [this.
|
|
12285
|
+
return [this.createNode(keyNodeOrEntry, value, count), value];
|
|
11749
12286
|
}
|
|
11750
12287
|
/**
|
|
11751
12288
|
* (Protected) Swap keys/values/counters between the source and destination nodes.
|
|
@@ -11759,7 +12296,7 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
11759
12296
|
destNode = this.ensureNode(destNode);
|
|
11760
12297
|
if (srcNode && destNode) {
|
|
11761
12298
|
const { key, value, count, height } = destNode;
|
|
11762
|
-
const tempNode = this.
|
|
12299
|
+
const tempNode = this.createNode(key, value, count);
|
|
11763
12300
|
if (tempNode) {
|
|
11764
12301
|
tempNode.height = height;
|
|
11765
12302
|
destNode.key = srcNode.key;
|
|
@@ -11787,22 +12324,20 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
11787
12324
|
return super._replaceNode(oldNode, newNode);
|
|
11788
12325
|
}
|
|
11789
12326
|
};
|
|
12327
|
+
__name(_AVLTreeCounter, "AVLTreeCounter");
|
|
12328
|
+
var AVLTreeCounter = _AVLTreeCounter;
|
|
11790
12329
|
|
|
11791
12330
|
// src/data-structures/priority-queue/priority-queue.ts
|
|
11792
|
-
var
|
|
11793
|
-
static {
|
|
11794
|
-
__name(this, "PriorityQueue");
|
|
11795
|
-
}
|
|
12331
|
+
var _PriorityQueue = class _PriorityQueue extends Heap {
|
|
11796
12332
|
constructor(elements = [], options) {
|
|
11797
12333
|
super(elements, options);
|
|
11798
12334
|
}
|
|
11799
12335
|
};
|
|
12336
|
+
__name(_PriorityQueue, "PriorityQueue");
|
|
12337
|
+
var PriorityQueue = _PriorityQueue;
|
|
11800
12338
|
|
|
11801
12339
|
// src/data-structures/priority-queue/min-priority-queue.ts
|
|
11802
|
-
var
|
|
11803
|
-
static {
|
|
11804
|
-
__name(this, "MinPriorityQueue");
|
|
11805
|
-
}
|
|
12340
|
+
var _MinPriorityQueue = class _MinPriorityQueue extends PriorityQueue {
|
|
11806
12341
|
/**
|
|
11807
12342
|
* Creates a min-priority queue.
|
|
11808
12343
|
* @param elements Optional initial elements to insert.
|
|
@@ -11813,12 +12348,11 @@ var MinPriorityQueue = class extends PriorityQueue {
|
|
|
11813
12348
|
super(elements, options);
|
|
11814
12349
|
}
|
|
11815
12350
|
};
|
|
12351
|
+
__name(_MinPriorityQueue, "MinPriorityQueue");
|
|
12352
|
+
var MinPriorityQueue = _MinPriorityQueue;
|
|
11816
12353
|
|
|
11817
12354
|
// src/data-structures/priority-queue/max-priority-queue.ts
|
|
11818
|
-
var
|
|
11819
|
-
static {
|
|
11820
|
-
__name(this, "MaxPriorityQueue");
|
|
11821
|
-
}
|
|
12355
|
+
var _MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
|
|
11822
12356
|
/**
|
|
11823
12357
|
* Creates a max-priority queue.
|
|
11824
12358
|
* @param elements Optional initial elements to insert.
|
|
@@ -11842,12 +12376,11 @@ var MaxPriorityQueue = class extends PriorityQueue {
|
|
|
11842
12376
|
});
|
|
11843
12377
|
}
|
|
11844
12378
|
};
|
|
12379
|
+
__name(_MaxPriorityQueue, "MaxPriorityQueue");
|
|
12380
|
+
var MaxPriorityQueue = _MaxPriorityQueue;
|
|
11845
12381
|
|
|
11846
12382
|
// src/data-structures/matrix/matrix.ts
|
|
11847
|
-
var
|
|
11848
|
-
static {
|
|
11849
|
-
__name(this, "Matrix");
|
|
11850
|
-
}
|
|
12383
|
+
var _Matrix = class _Matrix {
|
|
11851
12384
|
/**
|
|
11852
12385
|
* The constructor function initializes a matrix object with the provided data and options, or with
|
|
11853
12386
|
* default values if no options are provided.
|
|
@@ -11856,18 +12389,22 @@ var Matrix = class _Matrix {
|
|
|
11856
12389
|
* properties:
|
|
11857
12390
|
*/
|
|
11858
12391
|
constructor(data, options) {
|
|
12392
|
+
__publicField(this, "_rows", 0);
|
|
12393
|
+
__publicField(this, "_cols", 0);
|
|
12394
|
+
__publicField(this, "_data");
|
|
12395
|
+
var _a, _b, _c;
|
|
11859
12396
|
if (options) {
|
|
11860
12397
|
const { rows, cols, addFn, subtractFn, multiplyFn } = options;
|
|
11861
12398
|
if (typeof rows === "number" && rows > 0) this._rows = rows;
|
|
11862
12399
|
else this._rows = data.length;
|
|
11863
12400
|
if (typeof cols === "number" && cols > 0) this._cols = cols;
|
|
11864
|
-
else this._cols = data[0]
|
|
12401
|
+
else this._cols = ((_a = data[0]) == null ? void 0 : _a.length) || 0;
|
|
11865
12402
|
if (addFn) this._addFn = addFn;
|
|
11866
12403
|
if (subtractFn) this._subtractFn = subtractFn;
|
|
11867
12404
|
if (multiplyFn) this._multiplyFn = multiplyFn;
|
|
11868
12405
|
} else {
|
|
11869
12406
|
this._rows = data.length;
|
|
11870
|
-
this._cols = data[0]
|
|
12407
|
+
this._cols = (_c = (_b = data[0]) == null ? void 0 : _b.length) != null ? _c : 0;
|
|
11871
12408
|
}
|
|
11872
12409
|
if (data.length > 0) {
|
|
11873
12410
|
this._data = data;
|
|
@@ -11878,7 +12415,6 @@ var Matrix = class _Matrix {
|
|
|
11878
12415
|
}
|
|
11879
12416
|
}
|
|
11880
12417
|
}
|
|
11881
|
-
_rows = 0;
|
|
11882
12418
|
/**
|
|
11883
12419
|
* The function returns the number of rows.
|
|
11884
12420
|
* @returns The number of rows.
|
|
@@ -11886,7 +12422,6 @@ var Matrix = class _Matrix {
|
|
|
11886
12422
|
get rows() {
|
|
11887
12423
|
return this._rows;
|
|
11888
12424
|
}
|
|
11889
|
-
_cols = 0;
|
|
11890
12425
|
/**
|
|
11891
12426
|
* The function returns the value of the protected variable _cols.
|
|
11892
12427
|
* @returns The number of columns.
|
|
@@ -11894,7 +12429,6 @@ var Matrix = class _Matrix {
|
|
|
11894
12429
|
get cols() {
|
|
11895
12430
|
return this._cols;
|
|
11896
12431
|
}
|
|
11897
|
-
_data;
|
|
11898
12432
|
/**
|
|
11899
12433
|
* The function returns a two-dimensional array of numbers.
|
|
11900
12434
|
* @returns The data property, which is a two-dimensional array of numbers.
|
|
@@ -12093,6 +12627,7 @@ var Matrix = class _Matrix {
|
|
|
12093
12627
|
* @returns a Matrix object, which represents the inverse of the original matrix.
|
|
12094
12628
|
*/
|
|
12095
12629
|
inverse() {
|
|
12630
|
+
var _a;
|
|
12096
12631
|
if (this.rows !== this.cols) {
|
|
12097
12632
|
throw new Error("Matrix must be square for inversion.");
|
|
12098
12633
|
}
|
|
@@ -12119,7 +12654,7 @@ var Matrix = class _Matrix {
|
|
|
12119
12654
|
throw new Error("Matrix is singular, and its inverse does not exist.");
|
|
12120
12655
|
}
|
|
12121
12656
|
augmentedMatrix._swapRows(i, pivotRow);
|
|
12122
|
-
const pivotElement = augmentedMatrix.get(i, i)
|
|
12657
|
+
const pivotElement = (_a = augmentedMatrix.get(i, i)) != null ? _a : 1;
|
|
12123
12658
|
if (pivotElement === 0) {
|
|
12124
12659
|
throw new Error("Matrix is singular, and its inverse does not exist (division by zero).");
|
|
12125
12660
|
}
|
|
@@ -12262,14 +12797,11 @@ var Matrix = class _Matrix {
|
|
|
12262
12797
|
}
|
|
12263
12798
|
}
|
|
12264
12799
|
};
|
|
12800
|
+
__name(_Matrix, "Matrix");
|
|
12801
|
+
var Matrix = _Matrix;
|
|
12265
12802
|
|
|
12266
12803
|
// src/data-structures/matrix/navigator.ts
|
|
12267
|
-
var
|
|
12268
|
-
static {
|
|
12269
|
-
__name(this, "Character");
|
|
12270
|
-
}
|
|
12271
|
-
direction;
|
|
12272
|
-
turn;
|
|
12804
|
+
var _Character = class _Character {
|
|
12273
12805
|
/**
|
|
12274
12806
|
* The constructor function takes in a direction and turning object and sets the direction and turn properties of the
|
|
12275
12807
|
* Character class.
|
|
@@ -12279,25 +12811,26 @@ var Character = class _Character {
|
|
|
12279
12811
|
* turning direction. It is used to determine the new direction when the character turns.
|
|
12280
12812
|
*/
|
|
12281
12813
|
constructor(direction, turning) {
|
|
12814
|
+
__publicField(this, "direction");
|
|
12815
|
+
__publicField(this, "turn");
|
|
12282
12816
|
this.direction = direction;
|
|
12283
12817
|
this.turn = () => new _Character(turning[direction], turning);
|
|
12284
12818
|
}
|
|
12285
12819
|
};
|
|
12286
|
-
|
|
12287
|
-
|
|
12288
|
-
|
|
12289
|
-
}
|
|
12290
|
-
onMove;
|
|
12291
|
-
_matrix;
|
|
12292
|
-
_cur;
|
|
12293
|
-
_character;
|
|
12294
|
-
_VISITED;
|
|
12820
|
+
__name(_Character, "Character");
|
|
12821
|
+
var Character = _Character;
|
|
12822
|
+
var _Navigator = class _Navigator {
|
|
12295
12823
|
/**
|
|
12296
12824
|
* The constructor initializes the Navigator object with the given parameters and sets the current position as visited
|
|
12297
12825
|
* in the matrix.
|
|
12298
12826
|
* @param - - `matrix`: a 2D array representing the grid or map
|
|
12299
12827
|
*/
|
|
12300
12828
|
constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }) {
|
|
12829
|
+
__publicField(this, "onMove");
|
|
12830
|
+
__publicField(this, "_matrix");
|
|
12831
|
+
__publicField(this, "_cur");
|
|
12832
|
+
__publicField(this, "_character");
|
|
12833
|
+
__publicField(this, "_VISITED");
|
|
12301
12834
|
this._matrix = matrix;
|
|
12302
12835
|
this._cur = cur;
|
|
12303
12836
|
this._character = new Character(charDir, turning);
|
|
@@ -12375,23 +12908,24 @@ var Navigator = class {
|
|
|
12375
12908
|
if (this.onMove) this.onMove(this._cur);
|
|
12376
12909
|
}
|
|
12377
12910
|
};
|
|
12911
|
+
__name(_Navigator, "Navigator");
|
|
12912
|
+
var Navigator = _Navigator;
|
|
12378
12913
|
|
|
12379
12914
|
// src/data-structures/trie/trie.ts
|
|
12380
|
-
var
|
|
12381
|
-
static {
|
|
12382
|
-
__name(this, "TrieNode");
|
|
12383
|
-
}
|
|
12915
|
+
var _TrieNode = class _TrieNode {
|
|
12384
12916
|
/**
|
|
12385
12917
|
* Create a Trie node with a character key.
|
|
12386
12918
|
* @remarks Time O(1), Space O(1)
|
|
12387
12919
|
* @returns New TrieNode instance.
|
|
12388
12920
|
*/
|
|
12389
12921
|
constructor(key) {
|
|
12922
|
+
__publicField(this, "_key");
|
|
12923
|
+
__publicField(this, "_children");
|
|
12924
|
+
__publicField(this, "_isEnd");
|
|
12390
12925
|
this._key = key;
|
|
12391
12926
|
this._isEnd = false;
|
|
12392
12927
|
this._children = /* @__PURE__ */ new Map();
|
|
12393
12928
|
}
|
|
12394
|
-
_key;
|
|
12395
12929
|
/**
|
|
12396
12930
|
* Get the character key of this node.
|
|
12397
12931
|
* @remarks Time O(1), Space O(1)
|
|
@@ -12409,7 +12943,6 @@ var TrieNode = class {
|
|
|
12409
12943
|
set key(value) {
|
|
12410
12944
|
this._key = value;
|
|
12411
12945
|
}
|
|
12412
|
-
_children;
|
|
12413
12946
|
/**
|
|
12414
12947
|
* Get the child map of this node.
|
|
12415
12948
|
* @remarks Time O(1), Space O(1)
|
|
@@ -12427,7 +12960,6 @@ var TrieNode = class {
|
|
|
12427
12960
|
set children(value) {
|
|
12428
12961
|
this._children = value;
|
|
12429
12962
|
}
|
|
12430
|
-
_isEnd;
|
|
12431
12963
|
/**
|
|
12432
12964
|
* Check whether this node marks the end of a word.
|
|
12433
12965
|
* @remarks Time O(1), Space O(1)
|
|
@@ -12446,10 +12978,9 @@ var TrieNode = class {
|
|
|
12446
12978
|
this._isEnd = value;
|
|
12447
12979
|
}
|
|
12448
12980
|
};
|
|
12449
|
-
|
|
12450
|
-
|
|
12451
|
-
|
|
12452
|
-
}
|
|
12981
|
+
__name(_TrieNode, "TrieNode");
|
|
12982
|
+
var TrieNode = _TrieNode;
|
|
12983
|
+
var _Trie = class _Trie extends IterableElementBase {
|
|
12453
12984
|
/**
|
|
12454
12985
|
* Create a Trie and optionally bulk-insert words.
|
|
12455
12986
|
* @remarks Time O(totalChars), Space O(totalChars)
|
|
@@ -12459,6 +12990,9 @@ var Trie = class extends IterableElementBase {
|
|
|
12459
12990
|
*/
|
|
12460
12991
|
constructor(words = [], options) {
|
|
12461
12992
|
super(options);
|
|
12993
|
+
__publicField(this, "_size", 0);
|
|
12994
|
+
__publicField(this, "_caseSensitive", true);
|
|
12995
|
+
__publicField(this, "_root", new TrieNode(""));
|
|
12462
12996
|
if (options) {
|
|
12463
12997
|
const { caseSensitive } = options;
|
|
12464
12998
|
if (caseSensitive !== void 0) this._caseSensitive = caseSensitive;
|
|
@@ -12467,7 +13001,6 @@ var Trie = class extends IterableElementBase {
|
|
|
12467
13001
|
this.addMany(words);
|
|
12468
13002
|
}
|
|
12469
13003
|
}
|
|
12470
|
-
_size = 0;
|
|
12471
13004
|
/**
|
|
12472
13005
|
* Get the number of stored words.
|
|
12473
13006
|
* @remarks Time O(1), Space O(1)
|
|
@@ -12476,7 +13009,6 @@ var Trie = class extends IterableElementBase {
|
|
|
12476
13009
|
get size() {
|
|
12477
13010
|
return this._size;
|
|
12478
13011
|
}
|
|
12479
|
-
_caseSensitive = true;
|
|
12480
13012
|
/**
|
|
12481
13013
|
* Get whether comparisons are case-sensitive.
|
|
12482
13014
|
* @remarks Time O(1), Space O(1)
|
|
@@ -12485,7 +13017,6 @@ var Trie = class extends IterableElementBase {
|
|
|
12485
13017
|
get caseSensitive() {
|
|
12486
13018
|
return this._caseSensitive;
|
|
12487
13019
|
}
|
|
12488
|
-
_root = new TrieNode("");
|
|
12489
13020
|
/**
|
|
12490
13021
|
* Get the root node.
|
|
12491
13022
|
* @remarks Time O(1), Space O(1)
|
|
@@ -12815,7 +13346,7 @@ var Trie = class extends IterableElementBase {
|
|
|
12815
13346
|
const next = new Ctor([], {
|
|
12816
13347
|
toElementFn: this.toElementFn,
|
|
12817
13348
|
caseSensitive: this.caseSensitive,
|
|
12818
|
-
...options
|
|
13349
|
+
...options != null ? options : {}
|
|
12819
13350
|
});
|
|
12820
13351
|
return next;
|
|
12821
13352
|
}
|
|
@@ -12871,12 +13402,11 @@ var Trie = class extends IterableElementBase {
|
|
|
12871
13402
|
return str;
|
|
12872
13403
|
}
|
|
12873
13404
|
};
|
|
13405
|
+
__name(_Trie, "Trie");
|
|
13406
|
+
var Trie = _Trie;
|
|
12874
13407
|
|
|
12875
13408
|
// src/data-structures/tree/tree.ts
|
|
12876
|
-
var
|
|
12877
|
-
static {
|
|
12878
|
-
__name(this, "TreeNode");
|
|
12879
|
-
}
|
|
13409
|
+
var _TreeNode = class _TreeNode {
|
|
12880
13410
|
/**
|
|
12881
13411
|
* The constructor function initializes a TreeNode object with a key, optional value, and optional
|
|
12882
13412
|
* children.
|
|
@@ -12888,11 +13418,13 @@ var TreeNode = class _TreeNode {
|
|
|
12888
13418
|
* default value is an empty array.
|
|
12889
13419
|
*/
|
|
12890
13420
|
constructor(key, value, children) {
|
|
13421
|
+
__publicField(this, "_key");
|
|
13422
|
+
__publicField(this, "_value");
|
|
13423
|
+
__publicField(this, "_children");
|
|
12891
13424
|
this._key = key;
|
|
12892
13425
|
this._value = value || void 0;
|
|
12893
13426
|
if (children) this._children = children;
|
|
12894
13427
|
}
|
|
12895
|
-
_key;
|
|
12896
13428
|
/**
|
|
12897
13429
|
* The function returns the value of the protected variable _key.
|
|
12898
13430
|
* @returns The value of the `_key` property, which is a string.
|
|
@@ -12908,7 +13440,6 @@ var TreeNode = class _TreeNode {
|
|
|
12908
13440
|
set key(value) {
|
|
12909
13441
|
this._key = value;
|
|
12910
13442
|
}
|
|
12911
|
-
_value;
|
|
12912
13443
|
/**
|
|
12913
13444
|
* The function returns the value stored in a variable, or undefined if the variable is empty.
|
|
12914
13445
|
* @returns The value of the variable `_value` is being returned.
|
|
@@ -12924,7 +13455,6 @@ var TreeNode = class _TreeNode {
|
|
|
12924
13455
|
set value(value) {
|
|
12925
13456
|
this._value = value;
|
|
12926
13457
|
}
|
|
12927
|
-
_children;
|
|
12928
13458
|
/**
|
|
12929
13459
|
* The function returns an array of TreeNode objects or undefined.
|
|
12930
13460
|
* @returns The `children` property is being returned. It is of type `TreeNode<V>[] | undefined`,
|
|
@@ -12980,6 +13510,8 @@ var TreeNode = class _TreeNode {
|
|
|
12980
13510
|
return maxDepth;
|
|
12981
13511
|
}
|
|
12982
13512
|
};
|
|
13513
|
+
__name(_TreeNode, "TreeNode");
|
|
13514
|
+
var TreeNode = _TreeNode;
|
|
12983
13515
|
/**
|
|
12984
13516
|
* data-structure-typed
|
|
12985
13517
|
*
|
|
@@ -13009,5 +13541,5 @@ var TreeNode = class _TreeNode {
|
|
|
13009
13541
|
*/
|
|
13010
13542
|
|
|
13011
13543
|
export { AVLTree, AVLTreeCounter, AVLTreeCounterNode, AVLTreeMultiMap, AVLTreeMultiMapNode, AVLTreeNode, AbstractEdge, AbstractGraph, AbstractVertex, BST, BSTNode, BinaryIndexedTree, BinaryTree, BinaryTreeNode, Character, DFSOperation, Deque, DirectedEdge, DirectedGraph, DirectedVertex, DoublyLinkedList, DoublyLinkedListNode, FibonacciHeap, FibonacciHeapNode, HashMap, Heap, IterableElementBase, IterableEntryBase, LinkedHashMap, LinkedListQueue, MapEdge, MapGraph, MapVertex, Matrix, MaxHeap, MaxPriorityQueue, MinHeap, MinPriorityQueue, Navigator, PriorityQueue, Queue, Range, RedBlackTree, RedBlackTreeNode, SegmentTree, SegmentTreeNode, SinglyLinkedList, SinglyLinkedListNode, SkipList, SkipListNode, Stack, TreeCounter, TreeCounterNode, TreeMultiMap, TreeMultiMapNode, TreeNode, Trie, TrieNode, UndirectedEdge, UndirectedGraph, UndirectedVertex, arrayRemove, asyncTrampoline, calcMinUnitsRequired, getMSB, isComparable, isTrampolineThunk, isWeakKey, makeAsyncTrampoline, makeTrampoline, makeTrampolineThunk, rangeCheck, roundFixed, throwRangeError, toBinaryString, trampoline, uuidV4 };
|
|
13012
|
-
//# sourceMappingURL=index.
|
|
13013
|
-
//# sourceMappingURL=index.
|
|
13544
|
+
//# sourceMappingURL=index.mjs.map
|
|
13545
|
+
//# sourceMappingURL=index.mjs.map
|