data-structure-typed 1.34.6 → 1.34.8
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/README.md +74 -35
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +70 -70
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.js +8 -8
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +4 -4
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.js +59 -59
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/rb-tree.js +4 -4
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.js +39 -39
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/graph/abstract-graph.js +49 -49
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.js +33 -33
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/map-graph.js +4 -4
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.js +14 -14
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/tree/tree.js +5 -5
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +71 -71
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +110 -110
- package/lib/data-structures/binary-tree/avl-tree.d.ts +10 -10
- package/lib/data-structures/binary-tree/avl-tree.js +13 -13
- package/lib/data-structures/binary-tree/binary-tree.d.ts +6 -6
- package/lib/data-structures/binary-tree/binary-tree.js +7 -7
- package/lib/data-structures/binary-tree/bst.d.ts +34 -34
- package/lib/data-structures/binary-tree/bst.js +80 -80
- package/lib/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/lib/data-structures/binary-tree/rb-tree.js +4 -4
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +27 -27
- package/lib/data-structures/binary-tree/tree-multiset.js +55 -55
- package/lib/data-structures/graph/abstract-graph.d.ts +60 -60
- package/lib/data-structures/graph/abstract-graph.js +81 -81
- package/lib/data-structures/graph/directed-graph.d.ts +51 -51
- package/lib/data-structures/graph/directed-graph.js +63 -63
- package/lib/data-structures/graph/map-graph.d.ts +13 -13
- package/lib/data-structures/graph/map-graph.js +12 -12
- package/lib/data-structures/graph/undirected-graph.d.ts +30 -30
- package/lib/data-structures/graph/undirected-graph.js +32 -32
- package/lib/data-structures/heap/heap.d.ts +1 -1
- package/lib/data-structures/tree/tree.d.ts +4 -4
- package/lib/data-structures/tree/tree.js +6 -6
- package/lib/interfaces/abstract-binary-tree.d.ts +24 -24
- package/lib/interfaces/abstract-graph.d.ts +13 -13
- package/lib/interfaces/avl-tree.d.ts +3 -3
- package/lib/interfaces/bst.d.ts +8 -8
- package/lib/interfaces/directed-graph.d.ts +5 -5
- package/lib/interfaces/rb-tree.d.ts +2 -2
- package/lib/interfaces/undirected-graph.d.ts +2 -2
- package/lib/types/data-structures/abstract-binary-tree.d.ts +3 -3
- package/lib/types/data-structures/abstract-graph.d.ts +2 -2
- package/lib/types/data-structures/bst.d.ts +2 -2
- package/lib/types/data-structures/tree-multiset.d.ts +1 -1
- package/lib/types/utils/validate-type.d.ts +8 -8
- package/package.json +1 -1
- package/scripts/rename_clear_files.sh +29 -0
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +147 -147
- package/src/data-structures/binary-tree/avl-tree.ts +14 -14
- package/src/data-structures/binary-tree/binary-tree.ts +8 -8
- package/src/data-structures/binary-tree/bst.ts +98 -90
- package/src/data-structures/binary-tree/rb-tree.ts +9 -9
- package/src/data-structures/binary-tree/tree-multiset.ts +62 -62
- package/src/data-structures/graph/abstract-graph.ts +109 -104
- package/src/data-structures/graph/directed-graph.ts +77 -77
- package/src/data-structures/graph/map-graph.ts +20 -15
- package/src/data-structures/graph/undirected-graph.ts +39 -39
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/tree/tree.ts +7 -7
- package/src/interfaces/abstract-binary-tree.ts +24 -24
- package/src/interfaces/abstract-graph.ts +13 -13
- package/src/interfaces/avl-tree.ts +3 -3
- package/src/interfaces/bst.ts +8 -8
- package/src/interfaces/directed-graph.ts +5 -5
- package/src/interfaces/rb-tree.ts +2 -2
- package/src/interfaces/undirected-graph.ts +2 -2
- package/src/types/data-structures/abstract-binary-tree.ts +3 -3
- package/src/types/data-structures/abstract-graph.ts +2 -2
- package/src/types/data-structures/bst.ts +2 -2
- package/src/types/data-structures/tree-multiset.ts +1 -1
- package/src/types/utils/validate-type.ts +10 -10
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +24 -24
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/bst.test.ts +71 -71
- package/test/unit/data-structures/binary-tree/overall.test.ts +19 -19
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +72 -72
- package/test/unit/data-structures/graph/directed-graph.test.ts +8 -8
- package/test/unit/data-structures/graph/map-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/overall.test.ts +2 -2
- package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
- package/test/unit/data-structures/tree/tree.test.ts +2 -2
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
|
|
|
8
8
|
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
9
9
|
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
|
|
10
10
|
|
|
11
|
-
## [v1.34.
|
|
11
|
+
## [v1.34.8](https://github.com/zrwusa/data-structure-typed/compare/v1.34.1...main) (upcoming)
|
|
12
12
|
|
|
13
13
|
## [v1.34.1](https://github.com/zrwusa/data-structure-typed/compare/v1.33.4...v1.34.1) (6 October 2023)
|
|
14
14
|
|
package/README.md
CHANGED
|
@@ -6,13 +6,15 @@ Do you envy C++ with [std](), Python with [collections](), and Java with [java.u
|
|
|
6
6
|
|
|
7
7
|
Now you can use this library in Node.js and browser environments in CommonJS(require export.modules = ), ESModule(import export), Typescript(import export), UMD(var Queue = dataStructureTyped.Queue)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-

|
|
13
|
-

|
|
14
|
-

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
15
12
|

|
|
13
|
+

|
|
14
|
+

|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
|
|
16
18
|
|
|
17
19
|
[//]: # ()
|
|
18
20
|
|
|
@@ -424,6 +426,7 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D
|
|
|
424
426
|
|
|
425
427
|
### Standard library data structure comparison
|
|
426
428
|
|
|
429
|
+
|
|
427
430
|
<table>
|
|
428
431
|
<thead>
|
|
429
432
|
<tr>
|
|
@@ -449,6 +452,13 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D
|
|
|
449
452
|
<td>LinkedList<E></td>
|
|
450
453
|
<td>deque</td>
|
|
451
454
|
</tr>
|
|
455
|
+
<tr>
|
|
456
|
+
<td>Singly Linked List</td>
|
|
457
|
+
<td>SinglyLinkedList<E></td>
|
|
458
|
+
<td>-</td>
|
|
459
|
+
<td>-</td>
|
|
460
|
+
<td>-</td>
|
|
461
|
+
</tr>
|
|
452
462
|
<tr>
|
|
453
463
|
<td>Set</td>
|
|
454
464
|
<td>Set<E></td>
|
|
@@ -464,19 +474,13 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D
|
|
|
464
474
|
<td>dict</td>
|
|
465
475
|
</tr>
|
|
466
476
|
<tr>
|
|
467
|
-
<td>
|
|
477
|
+
<td>Ordered Dictionary</td>
|
|
478
|
+
<td>Map<K, V></td>
|
|
468
479
|
<td>-</td>
|
|
469
|
-
<td>unordered_set<T></td>
|
|
470
|
-
<td>HashSet<E></td>
|
|
471
480
|
<td>-</td>
|
|
481
|
+
<td>OrderedDict</td>
|
|
472
482
|
</tr>
|
|
473
|
-
|
|
474
|
-
<td>Unordered Map</td>
|
|
475
|
-
<td>HashMap<K, V></td>
|
|
476
|
-
<td>unordered_map<K, V></td>
|
|
477
|
-
<td>HashMap<K, V></td>
|
|
478
|
-
<td>defaultdict</td>
|
|
479
|
-
</tr>
|
|
483
|
+
|
|
480
484
|
<tr>
|
|
481
485
|
<td>Queue</td>
|
|
482
486
|
<td>Queue<E></td>
|
|
@@ -491,6 +495,13 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D
|
|
|
491
495
|
<td>PriorityQueue<E></td>
|
|
492
496
|
<td>-</td>
|
|
493
497
|
</tr>
|
|
498
|
+
<tr>
|
|
499
|
+
<td>Heap</td>
|
|
500
|
+
<td>Heap<V></td>
|
|
501
|
+
<td>priority_queue<T></td>
|
|
502
|
+
<td>PriorityQueue<E></td>
|
|
503
|
+
<td>heapq</td>
|
|
504
|
+
</tr>
|
|
494
505
|
<tr>
|
|
495
506
|
<td>Stack</td>
|
|
496
507
|
<td>Stack<E></td>
|
|
@@ -499,19 +510,26 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D
|
|
|
499
510
|
<td>-</td>
|
|
500
511
|
</tr>
|
|
501
512
|
<tr>
|
|
502
|
-
<td>
|
|
503
|
-
<td
|
|
504
|
-
<td>
|
|
513
|
+
<td>Deque</td>
|
|
514
|
+
<td>Deque<E></td>
|
|
515
|
+
<td>deque<T></td>
|
|
505
516
|
<td>-</td>
|
|
506
517
|
<td>-</td>
|
|
507
518
|
</tr>
|
|
508
519
|
<tr>
|
|
509
|
-
<td>
|
|
510
|
-
<td>
|
|
511
|
-
<td
|
|
520
|
+
<td>Trie</td>
|
|
521
|
+
<td>Trie</td>
|
|
522
|
+
<td>-</td>
|
|
512
523
|
<td>-</td>
|
|
513
524
|
<td>-</td>
|
|
514
525
|
</tr>
|
|
526
|
+
<tr>
|
|
527
|
+
<td>Unordered Map</td>
|
|
528
|
+
<td>HashMap<K, V></td>
|
|
529
|
+
<td>unordered_map<K, V></td>
|
|
530
|
+
<td>HashMap<K, V></td>
|
|
531
|
+
<td>defaultdict</td>
|
|
532
|
+
</tr>
|
|
515
533
|
<tr>
|
|
516
534
|
<td>Multiset</td>
|
|
517
535
|
<td>-</td>
|
|
@@ -527,18 +545,39 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D
|
|
|
527
545
|
<td>-</td>
|
|
528
546
|
</tr>
|
|
529
547
|
<tr>
|
|
530
|
-
<td>
|
|
548
|
+
<td>Binary Tree</td>
|
|
549
|
+
<td>BinaryTree<K, V></td>
|
|
550
|
+
<td>-</td>
|
|
531
551
|
<td>-</td>
|
|
532
|
-
<td>unordered_multiset</td>
|
|
533
|
-
<td>Counter</td>
|
|
534
552
|
<td>-</td>
|
|
535
553
|
</tr>
|
|
536
554
|
<tr>
|
|
537
|
-
<td>
|
|
538
|
-
<td>
|
|
555
|
+
<td>Binary Search Tree</td>
|
|
556
|
+
<td>BST<K, V></td>
|
|
539
557
|
<td>-</td>
|
|
540
558
|
<td>-</td>
|
|
541
|
-
<td
|
|
559
|
+
<td>-</td>
|
|
560
|
+
</tr>
|
|
561
|
+
<tr>
|
|
562
|
+
<td>Directed Graph</td>
|
|
563
|
+
<td>DirectedGraph<V, E></td>
|
|
564
|
+
<td>-</td>
|
|
565
|
+
<td>-</td>
|
|
566
|
+
<td>-</td>
|
|
567
|
+
</tr>
|
|
568
|
+
<tr>
|
|
569
|
+
<td>Undirected Graph</td>
|
|
570
|
+
<td>UndirectedGraph<V, E></td>
|
|
571
|
+
<td>-</td>
|
|
572
|
+
<td>-</td>
|
|
573
|
+
<td>-</td>
|
|
574
|
+
</tr>
|
|
575
|
+
<tr>
|
|
576
|
+
<td>Unordered Multiset</td>
|
|
577
|
+
<td>-</td>
|
|
578
|
+
<td>unordered_multiset</td>
|
|
579
|
+
<td>-</td>
|
|
580
|
+
<td>Counter</td>
|
|
542
581
|
</tr>
|
|
543
582
|
<tr>
|
|
544
583
|
<td>Linked Hash Set</td>
|
|
@@ -576,24 +615,24 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D
|
|
|
576
615
|
<td>-</td>
|
|
577
616
|
</tr>
|
|
578
617
|
<tr>
|
|
579
|
-
<td>
|
|
580
|
-
<td>-</td>
|
|
618
|
+
<td>Unordered Multimap</td>
|
|
581
619
|
<td>-</td>
|
|
620
|
+
<td>unordered_multimap<K, V></td>
|
|
582
621
|
<td>-</td>
|
|
583
622
|
<td>-</td>
|
|
584
623
|
</tr>
|
|
585
624
|
<tr>
|
|
586
|
-
<td>
|
|
625
|
+
<td>Bitset</td>
|
|
587
626
|
<td>-</td>
|
|
588
|
-
<td>
|
|
627
|
+
<td>bitset<N></td>
|
|
589
628
|
<td>-</td>
|
|
590
629
|
<td>-</td>
|
|
591
630
|
</tr>
|
|
592
631
|
<tr>
|
|
593
|
-
<td>Unordered
|
|
594
|
-
<td>unordered_multimap<K, V></td>
|
|
595
|
-
<td>-</td>
|
|
632
|
+
<td>Unordered Set</td>
|
|
596
633
|
<td>-</td>
|
|
634
|
+
<td>unordered_set<T></td>
|
|
635
|
+
<td>HashSet<E></td>
|
|
597
636
|
<td>-</td>
|
|
598
637
|
</tr>
|
|
599
638
|
</tbody>
|
|
@@ -20,17 +20,17 @@ exports.AbstractBinaryTree = exports.AbstractBinaryTreeNode = void 0;
|
|
|
20
20
|
var utils_1 = require("../../utils");
|
|
21
21
|
var types_1 = require("../../types");
|
|
22
22
|
var AbstractBinaryTreeNode = (function () {
|
|
23
|
-
function AbstractBinaryTreeNode(
|
|
23
|
+
function AbstractBinaryTreeNode(key, val) {
|
|
24
24
|
this._height = 0;
|
|
25
|
-
this.
|
|
25
|
+
this._key = key;
|
|
26
26
|
this._val = val;
|
|
27
27
|
}
|
|
28
|
-
Object.defineProperty(AbstractBinaryTreeNode.prototype, "
|
|
28
|
+
Object.defineProperty(AbstractBinaryTreeNode.prototype, "key", {
|
|
29
29
|
get: function () {
|
|
30
|
-
return this.
|
|
30
|
+
return this._key;
|
|
31
31
|
},
|
|
32
32
|
set: function (v) {
|
|
33
|
-
this.
|
|
33
|
+
this._key = v;
|
|
34
34
|
},
|
|
35
35
|
enumerable: false,
|
|
36
36
|
configurable: true
|
|
@@ -135,7 +135,7 @@ var AbstractBinaryTree = (function () {
|
|
|
135
135
|
this._root = null;
|
|
136
136
|
this._size = 0;
|
|
137
137
|
this._loopType = types_1.LoopType.ITERATIVE;
|
|
138
|
-
this.
|
|
138
|
+
this._visitedKey = [];
|
|
139
139
|
this._visitedVal = [];
|
|
140
140
|
this._visitedNode = [];
|
|
141
141
|
if (options !== undefined) {
|
|
@@ -165,9 +165,9 @@ var AbstractBinaryTree = (function () {
|
|
|
165
165
|
enumerable: false,
|
|
166
166
|
configurable: true
|
|
167
167
|
});
|
|
168
|
-
Object.defineProperty(AbstractBinaryTree.prototype, "
|
|
168
|
+
Object.defineProperty(AbstractBinaryTree.prototype, "visitedKey", {
|
|
169
169
|
get: function () {
|
|
170
|
-
return this.
|
|
170
|
+
return this._visitedKey;
|
|
171
171
|
},
|
|
172
172
|
enumerable: false,
|
|
173
173
|
configurable: true
|
|
@@ -187,14 +187,14 @@ var AbstractBinaryTree = (function () {
|
|
|
187
187
|
configurable: true
|
|
188
188
|
});
|
|
189
189
|
AbstractBinaryTree.prototype.swapLocation = function (srcNode, destNode) {
|
|
190
|
-
var
|
|
191
|
-
var tempNode = this.createNode(
|
|
190
|
+
var key = destNode.key, val = destNode.val, height = destNode.height;
|
|
191
|
+
var tempNode = this.createNode(key, val);
|
|
192
192
|
if (tempNode) {
|
|
193
193
|
tempNode.height = height;
|
|
194
|
-
destNode.
|
|
194
|
+
destNode.key = srcNode.key;
|
|
195
195
|
destNode.val = srcNode.val;
|
|
196
196
|
destNode.height = srcNode.height;
|
|
197
|
-
srcNode.
|
|
197
|
+
srcNode.key = tempNode.key;
|
|
198
198
|
srcNode.val = tempNode.val;
|
|
199
199
|
srcNode.height = tempNode.height;
|
|
200
200
|
}
|
|
@@ -208,14 +208,14 @@ var AbstractBinaryTree = (function () {
|
|
|
208
208
|
AbstractBinaryTree.prototype.isEmpty = function () {
|
|
209
209
|
return this.size === 0;
|
|
210
210
|
};
|
|
211
|
-
AbstractBinaryTree.prototype.add = function (
|
|
211
|
+
AbstractBinaryTree.prototype.add = function (keyOrNode, val) {
|
|
212
212
|
var _this = this;
|
|
213
213
|
var _bfs = function (root, newNode) {
|
|
214
214
|
var queue = [root];
|
|
215
215
|
while (queue.length > 0) {
|
|
216
216
|
var cur = queue.shift();
|
|
217
217
|
if (cur) {
|
|
218
|
-
if (newNode && cur.
|
|
218
|
+
if (newNode && cur.key === newNode.key)
|
|
219
219
|
return;
|
|
220
220
|
var inserted_1 = _this._addTo(newNode, cur);
|
|
221
221
|
if (inserted_1 !== undefined)
|
|
@@ -231,19 +231,19 @@ var AbstractBinaryTree = (function () {
|
|
|
231
231
|
return;
|
|
232
232
|
};
|
|
233
233
|
var inserted, needInsert;
|
|
234
|
-
if (
|
|
234
|
+
if (keyOrNode === null) {
|
|
235
235
|
needInsert = null;
|
|
236
236
|
}
|
|
237
|
-
else if (typeof
|
|
238
|
-
needInsert = this.createNode(
|
|
237
|
+
else if (typeof keyOrNode === 'number') {
|
|
238
|
+
needInsert = this.createNode(keyOrNode, val);
|
|
239
239
|
}
|
|
240
|
-
else if (
|
|
241
|
-
needInsert =
|
|
240
|
+
else if (keyOrNode instanceof AbstractBinaryTreeNode) {
|
|
241
|
+
needInsert = keyOrNode;
|
|
242
242
|
}
|
|
243
243
|
else {
|
|
244
244
|
return;
|
|
245
245
|
}
|
|
246
|
-
var existNode =
|
|
246
|
+
var existNode = keyOrNode ? this.get(keyOrNode, 'key') : undefined;
|
|
247
247
|
if (this.root) {
|
|
248
248
|
if (existNode) {
|
|
249
249
|
existNode.val = val;
|
|
@@ -268,17 +268,17 @@ var AbstractBinaryTree = (function () {
|
|
|
268
268
|
AbstractBinaryTree.prototype.addMany = function (idsOrNodes, data) {
|
|
269
269
|
var inserted = [];
|
|
270
270
|
for (var i = 0; i < idsOrNodes.length; i++) {
|
|
271
|
-
var
|
|
272
|
-
if (
|
|
273
|
-
inserted.push(this.add(
|
|
271
|
+
var keyOrNode = idsOrNodes[i];
|
|
272
|
+
if (keyOrNode instanceof AbstractBinaryTreeNode) {
|
|
273
|
+
inserted.push(this.add(keyOrNode.key, keyOrNode.val));
|
|
274
274
|
continue;
|
|
275
275
|
}
|
|
276
|
-
if (
|
|
276
|
+
if (keyOrNode === null) {
|
|
277
277
|
inserted.push(this.add(null));
|
|
278
278
|
continue;
|
|
279
279
|
}
|
|
280
280
|
var val = data === null || data === void 0 ? void 0 : data[i];
|
|
281
|
-
inserted.push(this.add(
|
|
281
|
+
inserted.push(this.add(keyOrNode, val));
|
|
282
282
|
}
|
|
283
283
|
return inserted;
|
|
284
284
|
};
|
|
@@ -286,11 +286,11 @@ var AbstractBinaryTree = (function () {
|
|
|
286
286
|
this.clear();
|
|
287
287
|
return idsOrNodes.length === this.addMany(idsOrNodes, data).length;
|
|
288
288
|
};
|
|
289
|
-
AbstractBinaryTree.prototype.remove = function (
|
|
289
|
+
AbstractBinaryTree.prototype.remove = function (nodeOrKey) {
|
|
290
290
|
var bstDeletedResult = [];
|
|
291
291
|
if (!this.root)
|
|
292
292
|
return bstDeletedResult;
|
|
293
|
-
var curr = typeof
|
|
293
|
+
var curr = typeof nodeOrKey === 'number' ? this.get(nodeOrKey) : nodeOrKey;
|
|
294
294
|
if (!curr)
|
|
295
295
|
return bstDeletedResult;
|
|
296
296
|
var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
|
|
@@ -331,7 +331,7 @@ var AbstractBinaryTree = (function () {
|
|
|
331
331
|
};
|
|
332
332
|
AbstractBinaryTree.prototype.getDepth = function (beginRoot) {
|
|
333
333
|
if (typeof beginRoot === 'number')
|
|
334
|
-
beginRoot = this.get(beginRoot, '
|
|
334
|
+
beginRoot = this.get(beginRoot, 'key');
|
|
335
335
|
var depth = 0;
|
|
336
336
|
while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {
|
|
337
337
|
depth++;
|
|
@@ -342,7 +342,7 @@ var AbstractBinaryTree = (function () {
|
|
|
342
342
|
AbstractBinaryTree.prototype.getHeight = function (beginRoot) {
|
|
343
343
|
beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
|
|
344
344
|
if (typeof beginRoot === 'number')
|
|
345
|
-
beginRoot = this.get(beginRoot, '
|
|
345
|
+
beginRoot = this.get(beginRoot, 'key');
|
|
346
346
|
if (!beginRoot)
|
|
347
347
|
return -1;
|
|
348
348
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
@@ -426,7 +426,7 @@ var AbstractBinaryTree = (function () {
|
|
|
426
426
|
var _this = this;
|
|
427
427
|
if (!this.root)
|
|
428
428
|
return [];
|
|
429
|
-
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : '
|
|
429
|
+
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
430
430
|
var result = [];
|
|
431
431
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
432
432
|
var _traverse_1 = function (cur) {
|
|
@@ -454,12 +454,12 @@ var AbstractBinaryTree = (function () {
|
|
|
454
454
|
return result;
|
|
455
455
|
};
|
|
456
456
|
AbstractBinaryTree.prototype.has = function (nodeProperty, propertyName) {
|
|
457
|
-
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : '
|
|
457
|
+
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
458
458
|
return this.getNodes(nodeProperty, propertyName).length > 0;
|
|
459
459
|
};
|
|
460
460
|
AbstractBinaryTree.prototype.get = function (nodeProperty, propertyName) {
|
|
461
461
|
var _a;
|
|
462
|
-
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : '
|
|
462
|
+
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
463
463
|
return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
|
|
464
464
|
};
|
|
465
465
|
AbstractBinaryTree.prototype.getPathToRoot = function (node, isReverse) {
|
|
@@ -474,7 +474,7 @@ var AbstractBinaryTree = (function () {
|
|
|
474
474
|
};
|
|
475
475
|
AbstractBinaryTree.prototype.getLeftMost = function (beginRoot) {
|
|
476
476
|
if (typeof beginRoot === 'number')
|
|
477
|
-
beginRoot = this.get(beginRoot, '
|
|
477
|
+
beginRoot = this.get(beginRoot, 'key');
|
|
478
478
|
beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
|
|
479
479
|
if (!beginRoot)
|
|
480
480
|
return beginRoot;
|
|
@@ -523,9 +523,9 @@ var AbstractBinaryTree = (function () {
|
|
|
523
523
|
var dfs_1 = function (cur, min, max) {
|
|
524
524
|
if (!cur)
|
|
525
525
|
return true;
|
|
526
|
-
if (cur.
|
|
526
|
+
if (cur.key <= min || cur.key >= max)
|
|
527
527
|
return false;
|
|
528
|
-
return dfs_1(cur.left, min, cur.
|
|
528
|
+
return dfs_1(cur.left, min, cur.key) && dfs_1(cur.right, cur.key, max);
|
|
529
529
|
};
|
|
530
530
|
return dfs_1(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
|
|
531
531
|
}
|
|
@@ -538,9 +538,9 @@ var AbstractBinaryTree = (function () {
|
|
|
538
538
|
curr = curr.left;
|
|
539
539
|
}
|
|
540
540
|
curr = stack.pop();
|
|
541
|
-
if (!curr || prev >= curr.
|
|
541
|
+
if (!curr || prev >= curr.key)
|
|
542
542
|
return false;
|
|
543
|
-
prev = curr.
|
|
543
|
+
prev = curr.key;
|
|
544
544
|
curr = curr.right;
|
|
545
545
|
}
|
|
546
546
|
return true;
|
|
@@ -574,23 +574,23 @@ var AbstractBinaryTree = (function () {
|
|
|
574
574
|
}
|
|
575
575
|
};
|
|
576
576
|
AbstractBinaryTree.prototype.subTreeSum = function (subTreeRoot, propertyName) {
|
|
577
|
-
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : '
|
|
577
|
+
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
578
578
|
if (typeof subTreeRoot === 'number')
|
|
579
|
-
subTreeRoot = this.get(subTreeRoot, '
|
|
579
|
+
subTreeRoot = this.get(subTreeRoot, 'key');
|
|
580
580
|
if (!subTreeRoot)
|
|
581
581
|
return 0;
|
|
582
582
|
var sum = 0;
|
|
583
583
|
var _sumByProperty = function (cur) {
|
|
584
584
|
var needSum;
|
|
585
585
|
switch (propertyName) {
|
|
586
|
-
case '
|
|
587
|
-
needSum = cur.
|
|
586
|
+
case 'key':
|
|
587
|
+
needSum = cur.key;
|
|
588
588
|
break;
|
|
589
589
|
case 'val':
|
|
590
590
|
needSum = typeof cur.val === 'number' ? cur.val : 0;
|
|
591
591
|
break;
|
|
592
592
|
default:
|
|
593
|
-
needSum = cur.
|
|
593
|
+
needSum = cur.key;
|
|
594
594
|
break;
|
|
595
595
|
}
|
|
596
596
|
return needSum;
|
|
@@ -615,18 +615,18 @@ var AbstractBinaryTree = (function () {
|
|
|
615
615
|
return sum;
|
|
616
616
|
};
|
|
617
617
|
AbstractBinaryTree.prototype.subTreeAdd = function (subTreeRoot, delta, propertyName) {
|
|
618
|
-
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : '
|
|
618
|
+
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
619
619
|
if (typeof subTreeRoot === 'number')
|
|
620
|
-
subTreeRoot = this.get(subTreeRoot, '
|
|
620
|
+
subTreeRoot = this.get(subTreeRoot, 'key');
|
|
621
621
|
if (!subTreeRoot)
|
|
622
622
|
return false;
|
|
623
623
|
var _addByProperty = function (cur) {
|
|
624
624
|
switch (propertyName) {
|
|
625
|
-
case '
|
|
626
|
-
cur.
|
|
625
|
+
case 'key':
|
|
626
|
+
cur.key += delta;
|
|
627
627
|
break;
|
|
628
628
|
default:
|
|
629
|
-
cur.
|
|
629
|
+
cur.key += delta;
|
|
630
630
|
break;
|
|
631
631
|
}
|
|
632
632
|
};
|
|
@@ -650,7 +650,7 @@ var AbstractBinaryTree = (function () {
|
|
|
650
650
|
return true;
|
|
651
651
|
};
|
|
652
652
|
AbstractBinaryTree.prototype.BFS = function (nodeOrPropertyName) {
|
|
653
|
-
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : '
|
|
653
|
+
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
|
|
654
654
|
this._clearResults();
|
|
655
655
|
var queue = [this.root];
|
|
656
656
|
while (queue.length !== 0) {
|
|
@@ -668,7 +668,7 @@ var AbstractBinaryTree = (function () {
|
|
|
668
668
|
AbstractBinaryTree.prototype.DFS = function (pattern, nodeOrPropertyName) {
|
|
669
669
|
var _this = this;
|
|
670
670
|
pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
|
|
671
|
-
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : '
|
|
671
|
+
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
|
|
672
672
|
this._clearResults();
|
|
673
673
|
var _traverse = function (node) {
|
|
674
674
|
switch (pattern) {
|
|
@@ -700,7 +700,7 @@ var AbstractBinaryTree = (function () {
|
|
|
700
700
|
};
|
|
701
701
|
AbstractBinaryTree.prototype.DFSIterative = function (pattern, nodeOrPropertyName) {
|
|
702
702
|
pattern = pattern || 'in';
|
|
703
|
-
nodeOrPropertyName = nodeOrPropertyName || '
|
|
703
|
+
nodeOrPropertyName = nodeOrPropertyName || 'key';
|
|
704
704
|
this._clearResults();
|
|
705
705
|
if (!this.root)
|
|
706
706
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
@@ -740,7 +740,7 @@ var AbstractBinaryTree = (function () {
|
|
|
740
740
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
741
741
|
};
|
|
742
742
|
AbstractBinaryTree.prototype.levelIterative = function (node, nodeOrPropertyName) {
|
|
743
|
-
nodeOrPropertyName = nodeOrPropertyName || '
|
|
743
|
+
nodeOrPropertyName = nodeOrPropertyName || 'key';
|
|
744
744
|
node = node || this.root;
|
|
745
745
|
if (!node)
|
|
746
746
|
return [];
|
|
@@ -761,15 +761,15 @@ var AbstractBinaryTree = (function () {
|
|
|
761
761
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
762
762
|
};
|
|
763
763
|
AbstractBinaryTree.prototype.listLevels = function (node, nodeOrPropertyName) {
|
|
764
|
-
nodeOrPropertyName = nodeOrPropertyName || '
|
|
764
|
+
nodeOrPropertyName = nodeOrPropertyName || 'key';
|
|
765
765
|
node = node || this.root;
|
|
766
766
|
if (!node)
|
|
767
767
|
return [];
|
|
768
768
|
var levelsNodes = [];
|
|
769
769
|
var collectByProperty = function (node, level) {
|
|
770
770
|
switch (nodeOrPropertyName) {
|
|
771
|
-
case '
|
|
772
|
-
levelsNodes[level].push(node.
|
|
771
|
+
case 'key':
|
|
772
|
+
levelsNodes[level].push(node.key);
|
|
773
773
|
break;
|
|
774
774
|
case 'val':
|
|
775
775
|
levelsNodes[level].push(node.val);
|
|
@@ -778,7 +778,7 @@ var AbstractBinaryTree = (function () {
|
|
|
778
778
|
levelsNodes[level].push(node);
|
|
779
779
|
break;
|
|
780
780
|
default:
|
|
781
|
-
levelsNodes[level].push(node.
|
|
781
|
+
levelsNodes[level].push(node.key);
|
|
782
782
|
break;
|
|
783
783
|
}
|
|
784
784
|
};
|
|
@@ -829,7 +829,7 @@ var AbstractBinaryTree = (function () {
|
|
|
829
829
|
if (this.root === null)
|
|
830
830
|
return [];
|
|
831
831
|
pattern = pattern || 'in';
|
|
832
|
-
nodeOrPropertyName = nodeOrPropertyName || '
|
|
832
|
+
nodeOrPropertyName = nodeOrPropertyName || 'key';
|
|
833
833
|
this._clearResults();
|
|
834
834
|
var cur = this.root;
|
|
835
835
|
var _reverseEdge = function (node) {
|
|
@@ -938,8 +938,8 @@ var AbstractBinaryTree = (function () {
|
|
|
938
938
|
AbstractBinaryTree.prototype._setLoopType = function (value) {
|
|
939
939
|
this._loopType = value;
|
|
940
940
|
};
|
|
941
|
-
AbstractBinaryTree.prototype.
|
|
942
|
-
this.
|
|
941
|
+
AbstractBinaryTree.prototype._setVisitedKey = function (value) {
|
|
942
|
+
this._visitedKey = value;
|
|
943
943
|
};
|
|
944
944
|
AbstractBinaryTree.prototype._setVisitedVal = function (value) {
|
|
945
945
|
this._visitedVal = value;
|
|
@@ -957,14 +957,14 @@ var AbstractBinaryTree = (function () {
|
|
|
957
957
|
this._size = v;
|
|
958
958
|
};
|
|
959
959
|
AbstractBinaryTree.prototype._clearResults = function () {
|
|
960
|
-
this.
|
|
960
|
+
this._visitedKey = [];
|
|
961
961
|
this._visitedVal = [];
|
|
962
962
|
this._visitedNode = [];
|
|
963
963
|
};
|
|
964
964
|
AbstractBinaryTree.prototype._pushByPropertyNameStopOrNot = function (cur, result, nodeProperty, propertyName, onlyOne) {
|
|
965
965
|
switch (propertyName) {
|
|
966
|
-
case '
|
|
967
|
-
if (cur.
|
|
966
|
+
case 'key':
|
|
967
|
+
if (cur.key === nodeProperty) {
|
|
968
968
|
result.push(cur);
|
|
969
969
|
return !!onlyOne;
|
|
970
970
|
}
|
|
@@ -976,7 +976,7 @@ var AbstractBinaryTree = (function () {
|
|
|
976
976
|
}
|
|
977
977
|
break;
|
|
978
978
|
default:
|
|
979
|
-
if (cur.
|
|
979
|
+
if (cur.key === nodeProperty) {
|
|
980
980
|
result.push(cur);
|
|
981
981
|
return !!onlyOne;
|
|
982
982
|
}
|
|
@@ -984,10 +984,10 @@ var AbstractBinaryTree = (function () {
|
|
|
984
984
|
}
|
|
985
985
|
};
|
|
986
986
|
AbstractBinaryTree.prototype._accumulatedByPropertyName = function (node, nodeOrPropertyName) {
|
|
987
|
-
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : '
|
|
987
|
+
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
|
|
988
988
|
switch (nodeOrPropertyName) {
|
|
989
|
-
case '
|
|
990
|
-
this.
|
|
989
|
+
case 'key':
|
|
990
|
+
this._visitedKey.push(node.key);
|
|
991
991
|
break;
|
|
992
992
|
case 'val':
|
|
993
993
|
this._visitedVal.push(node.val);
|
|
@@ -996,21 +996,21 @@ var AbstractBinaryTree = (function () {
|
|
|
996
996
|
this._visitedNode.push(node);
|
|
997
997
|
break;
|
|
998
998
|
default:
|
|
999
|
-
this.
|
|
999
|
+
this._visitedKey.push(node.key);
|
|
1000
1000
|
break;
|
|
1001
1001
|
}
|
|
1002
1002
|
};
|
|
1003
1003
|
AbstractBinaryTree.prototype._getResultByPropertyName = function (nodeOrPropertyName) {
|
|
1004
|
-
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : '
|
|
1004
|
+
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
|
|
1005
1005
|
switch (nodeOrPropertyName) {
|
|
1006
|
-
case '
|
|
1007
|
-
return this.
|
|
1006
|
+
case 'key':
|
|
1007
|
+
return this._visitedKey;
|
|
1008
1008
|
case 'val':
|
|
1009
1009
|
return this._visitedVal;
|
|
1010
1010
|
case 'node':
|
|
1011
1011
|
return this._visitedNode;
|
|
1012
1012
|
default:
|
|
1013
|
-
return this.
|
|
1013
|
+
return this._visitedKey;
|
|
1014
1014
|
}
|
|
1015
1015
|
};
|
|
1016
1016
|
return AbstractBinaryTree;
|