data-structure-typed 1.18.5 → 1.18.6

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.
Files changed (135) hide show
  1. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +333 -0
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1455 -0
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +3 -2
  4. package/dist/data-structures/binary-tree/avl-tree.js +2 -2
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +6 -334
  6. package/dist/data-structures/binary-tree/binary-tree.js +26 -1436
  7. package/dist/data-structures/binary-tree/bst.d.ts +5 -12
  8. package/dist/data-structures/binary-tree/bst.js +31 -36
  9. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  10. package/dist/data-structures/binary-tree/index.js +1 -0
  11. package/dist/data-structures/binary-tree/rb-tree.js +2 -6
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +8 -23
  13. package/dist/data-structures/binary-tree/tree-multiset.js +26 -29
  14. package/dist/data-structures/graph/directed-graph.d.ts +2 -4
  15. package/dist/data-structures/graph/directed-graph.js +3 -7
  16. package/dist/data-structures/graph/undirected-graph.d.ts +13 -11
  17. package/dist/data-structures/graph/undirected-graph.js +14 -14
  18. package/dist/data-structures/interfaces/binary-tree.d.ts +1 -2
  19. package/dist/data-structures/types/abstract-binary-tree.d.ts +32 -0
  20. package/dist/data-structures/types/abstract-binary-tree.js +21 -0
  21. package/dist/data-structures/types/avl-tree.d.ts +2 -4
  22. package/dist/data-structures/types/binary-tree.d.ts +2 -10
  23. package/dist/data-structures/types/bst.d.ts +10 -5
  24. package/dist/data-structures/types/bst.js +7 -0
  25. package/dist/data-structures/types/helpers.d.ts +8 -0
  26. package/dist/data-structures/types/helpers.js +2 -0
  27. package/dist/data-structures/types/index.d.ts +3 -0
  28. package/dist/data-structures/types/index.js +3 -0
  29. package/dist/data-structures/types/rb-tree.d.ts +6 -0
  30. package/dist/data-structures/types/rb-tree.js +8 -0
  31. package/dist/data-structures/types/tree-multiset.d.ts +5 -3
  32. package/docs/assets/search.js +1 -1
  33. package/docs/classes/AVLTree.html +152 -152
  34. package/docs/classes/AVLTreeNode.html +38 -27
  35. package/docs/classes/AaTree.html +18 -7
  36. package/docs/classes/AbstractBinaryTree.html +2023 -0
  37. package/docs/classes/AbstractBinaryTreeNode.html +491 -0
  38. package/docs/classes/AbstractEdge.html +28 -17
  39. package/docs/classes/AbstractGraph.html +52 -41
  40. package/docs/classes/AbstractVertex.html +25 -14
  41. package/docs/classes/ArrayDeque.html +31 -20
  42. package/docs/classes/BST.html +140 -134
  43. package/docs/classes/BSTNode.html +40 -28
  44. package/docs/classes/BTree.html +18 -7
  45. package/docs/classes/BinaryIndexedTree.html +26 -15
  46. package/docs/classes/BinaryTree.html +447 -446
  47. package/docs/classes/BinaryTreeNode.html +107 -135
  48. package/docs/classes/Character.html +21 -10
  49. package/docs/classes/CoordinateMap.html +26 -15
  50. package/docs/classes/CoordinateSet.html +25 -14
  51. package/docs/classes/Deque.html +51 -40
  52. package/docs/classes/DirectedEdge.html +32 -21
  53. package/docs/classes/DirectedGraph.html +73 -147
  54. package/docs/classes/DirectedVertex.html +23 -12
  55. package/docs/classes/DoublyLinkedList.html +54 -43
  56. package/docs/classes/DoublyLinkedListNode.html +28 -17
  57. package/docs/classes/HashTable.html +18 -7
  58. package/docs/classes/Heap.html +32 -21
  59. package/docs/classes/HeapItem.html +25 -14
  60. package/docs/classes/Matrix2D.html +33 -22
  61. package/docs/classes/MatrixNTI2D.html +21 -10
  62. package/docs/classes/MaxHeap.html +32 -21
  63. package/docs/classes/MaxPriorityQueue.html +51 -40
  64. package/docs/classes/MinHeap.html +32 -21
  65. package/docs/classes/MinPriorityQueue.html +51 -40
  66. package/docs/classes/Navigator.html +27 -16
  67. package/docs/classes/ObjectDeque.html +42 -31
  68. package/docs/classes/Pair.html +18 -7
  69. package/docs/classes/PriorityQueue.html +49 -38
  70. package/docs/classes/Queue.html +31 -20
  71. package/docs/classes/SegmentTree.html +34 -23
  72. package/docs/classes/SegmentTreeNode.html +37 -26
  73. package/docs/classes/SinglyLinkedList.html +51 -40
  74. package/docs/classes/SinglyLinkedListNode.html +25 -14
  75. package/docs/classes/SkipLinkedList.html +18 -7
  76. package/docs/classes/SplayTree.html +18 -7
  77. package/docs/classes/Stack.html +29 -18
  78. package/docs/classes/TreeMap.html +18 -7
  79. package/docs/classes/TreeMultiSet.html +180 -173
  80. package/docs/classes/TreeMultiSetNode.html +450 -0
  81. package/docs/classes/TreeNode.html +33 -22
  82. package/docs/classes/TreeSet.html +18 -7
  83. package/docs/classes/Trie.html +30 -19
  84. package/docs/classes/TrieNode.html +28 -17
  85. package/docs/classes/TwoThreeTree.html +18 -7
  86. package/docs/classes/UndirectedEdge.html +29 -18
  87. package/docs/classes/UndirectedGraph.html +80 -142
  88. package/docs/classes/UndirectedVertex.html +23 -12
  89. package/docs/classes/Vector2D.html +45 -34
  90. package/docs/enums/CP.html +24 -13
  91. package/docs/enums/FamilyPosition.html +36 -25
  92. package/docs/enums/LoopType.html +30 -19
  93. package/docs/enums/RBColor.html +168 -0
  94. package/docs/enums/TopologicalProperty.html +21 -10
  95. package/docs/index.html +17 -6
  96. package/docs/interfaces/IBinaryTree.html +20 -8
  97. package/docs/interfaces/IBinaryTreeNode.html +41 -28
  98. package/docs/interfaces/IDirectedGraph.html +24 -13
  99. package/docs/interfaces/IGraph.html +37 -26
  100. package/docs/interfaces/IUNDirectedGraph.html +18 -7
  101. package/docs/modules.html +34 -12
  102. package/docs/types/{AVLTreeDeleted.html → AVLTreeOptions.html} +23 -21
  103. package/docs/types/AbstractBinaryTreeOptions.html +150 -0
  104. package/docs/types/AbstractRecursiveBinaryTreeNode.html +146 -0
  105. package/docs/types/{ResultsByProperty.html → AbstractResultByProperty.html} +23 -12
  106. package/docs/types/{TreeMultiSetDeletedResult.html → AbstractResultsByProperty.html} +23 -19
  107. package/docs/types/BSTComparator.html +18 -7
  108. package/docs/types/BSTOptions.html +146 -0
  109. package/docs/types/BinaryTreeDeletedResult.html +153 -0
  110. package/docs/types/BinaryTreeNodeId.html +18 -7
  111. package/docs/types/BinaryTreeNodePropertyName.html +18 -7
  112. package/docs/types/{BinaryTreeDeleted.html → BinaryTreeOptions.html} +23 -21
  113. package/docs/types/DFSOrderPattern.html +18 -7
  114. package/docs/types/DijkstraResult.html +18 -7
  115. package/docs/types/Direction.html +18 -7
  116. package/docs/types/EdgeId.html +18 -7
  117. package/docs/types/HeapOptions.html +18 -7
  118. package/docs/types/IdObject.html +151 -0
  119. package/docs/types/{ResultByProperty.html → KeyValObject.html} +27 -16
  120. package/docs/types/NavigatorParams.html +18 -7
  121. package/docs/types/NodeOrPropertyName.html +18 -7
  122. package/docs/types/PriorityQueueComparator.html +18 -7
  123. package/docs/types/PriorityQueueDFSOrderPattern.html +18 -7
  124. package/docs/types/PriorityQueueOptions.html +18 -7
  125. package/docs/types/{BSTDeletedResult.html → RBTreeOptions.html} +23 -21
  126. package/docs/types/RecursiveAVLTreeNode.html +18 -7
  127. package/docs/types/RecursiveBSTNode.html +18 -7
  128. package/docs/types/RecursiveBinaryTreeNode.html +18 -7
  129. package/docs/types/RecursiveTreeMultiSetNode.html +146 -0
  130. package/docs/types/SegmentTreeNodeVal.html +18 -7
  131. package/docs/types/TopologicalStatus.html +18 -7
  132. package/docs/types/TreeMultiSetOptions.html +146 -0
  133. package/docs/types/Turning.html +18 -7
  134. package/docs/types/VertexId.html +18 -7
  135. package/package.json +1 -1
@@ -5,14 +5,10 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult, RecursiveBSTNode } from '../types';
9
- import { BinaryTree, BinaryTreeNode, LoopType } from './binary-tree';
8
+ import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, RecursiveBSTNode } from '../types';
9
+ import { BinaryTreeDeletedResult, BSTOptions, CP } from '../types';
10
+ import { BinaryTree, BinaryTreeNode } from './binary-tree';
10
11
  import { IBinaryTree, IBinaryTreeNode } from '../interfaces';
11
- export declare enum CP {
12
- lt = -1,
13
- eq = 0,
14
- gt = 1
15
- }
16
12
  export declare class BSTNode<T, FAMILY extends BSTNode<T, FAMILY> = RecursiveBSTNode<T>> extends BinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
17
13
  }
18
14
  export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BinaryTree<N> implements IBinaryTree<N> {
@@ -20,10 +16,7 @@ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> exten
20
16
  * The constructor function accepts an optional options object and sets the comparator property if provided.
21
17
  * @param [options] - An optional object that can contain the following properties:
22
18
  */
23
- constructor(options?: {
24
- comparator?: BSTComparator;
25
- loopType?: LoopType;
26
- });
19
+ constructor(options?: BSTOptions);
27
20
  _createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
28
21
  /**
29
22
  * The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
@@ -67,7 +60,7 @@ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> exten
67
60
  * set to false or not provided, the count of the node will be taken into account and the
68
61
  * @returns an array of `BSTDeletedResult<N>` objects.
69
62
  */
70
- remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<N>[];
63
+ remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
71
64
  /**
72
65
  * The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
73
66
  * option to specify the property name and whether to return only one node.
@@ -31,14 +31,9 @@ var __read = (this && this.__read) || function (o, n) {
31
31
  return ar;
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.BST = exports.BSTNode = exports.CP = void 0;
34
+ exports.BST = exports.BSTNode = void 0;
35
+ var types_1 = require("../types");
35
36
  var binary_tree_1 = require("./binary-tree");
36
- var CP;
37
- (function (CP) {
38
- CP[CP["lt"] = -1] = "lt";
39
- CP[CP["eq"] = 0] = "eq";
40
- CP[CP["gt"] = 1] = "gt";
41
- })(CP || (exports.CP = CP = {}));
42
37
  var BSTNode = /** @class */ (function (_super) {
43
38
  __extends(BSTNode, _super);
44
39
  function BSTNode() {
@@ -95,7 +90,7 @@ var BST = /** @class */ (function (_super) {
95
90
  var traversing = true;
96
91
  while (traversing) {
97
92
  if (cur !== null && newNode !== null) {
98
- if (this._compare(cur.id, id) === CP.eq) {
93
+ if (this._compare(cur.id, id) === types_1.CP.eq) {
99
94
  if (newNode) {
100
95
  cur.count += newNode.count;
101
96
  this._setCount(this.count + newNode.count);
@@ -105,12 +100,12 @@ var BST = /** @class */ (function (_super) {
105
100
  traversing = false;
106
101
  inserted = cur;
107
102
  }
108
- else if (this._compare(cur.id, id) === CP.gt) {
103
+ else if (this._compare(cur.id, id) === types_1.CP.gt) {
109
104
  // Traverse left of the node
110
105
  if (cur.left === undefined) {
111
106
  if (newNode) {
112
107
  newNode.parent = cur;
113
- newNode.familyPosition = binary_tree_1.FamilyPosition.left;
108
+ newNode.familyPosition = types_1.FamilyPosition.LEFT;
114
109
  }
115
110
  //Add to the left of the current node
116
111
  cur.left = newNode;
@@ -125,12 +120,12 @@ var BST = /** @class */ (function (_super) {
125
120
  cur = cur.left;
126
121
  }
127
122
  }
128
- else if (this._compare(cur.id, id) === CP.lt) {
123
+ else if (this._compare(cur.id, id) === types_1.CP.lt) {
129
124
  // Traverse right of the node
130
125
  if (cur.right === undefined) {
131
126
  if (newNode) {
132
127
  newNode.parent = cur;
133
- newNode.familyPosition = binary_tree_1.FamilyPosition.right;
128
+ newNode.familyPosition = types_1.FamilyPosition.RIGHT;
134
129
  }
135
130
  //Add to the right of the current node
136
131
  cur.right = newNode;
@@ -177,9 +172,9 @@ var BST = /** @class */ (function (_super) {
177
172
  */
178
173
  BST.prototype.lastKey = function () {
179
174
  var _a, _b, _c, _d, _e, _f;
180
- if (this._compare(0, 1) === CP.lt)
175
+ if (this._compare(0, 1) === types_1.CP.lt)
181
176
  return (_b = (_a = this.getRightMost()) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 0;
182
- else if (this._compare(0, 1) === CP.gt)
177
+ else if (this._compare(0, 1) === types_1.CP.gt)
183
178
  return (_d = (_c = this.getLeftMost()) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : 0;
184
179
  else
185
180
  return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : 0;
@@ -215,10 +210,10 @@ var BST = /** @class */ (function (_super) {
215
210
  }
216
211
  else {
217
212
  switch (curr.familyPosition) {
218
- case binary_tree_1.FamilyPosition.left:
213
+ case types_1.FamilyPosition.LEFT:
219
214
  parent.left = curr.right;
220
215
  break;
221
- case binary_tree_1.FamilyPosition.right:
216
+ case types_1.FamilyPosition.RIGHT:
222
217
  parent.right = curr.right;
223
218
  break;
224
219
  }
@@ -264,16 +259,16 @@ var BST = /** @class */ (function (_super) {
264
259
  if (!this.root)
265
260
  return [];
266
261
  var result = [];
267
- if (this.loopType === binary_tree_1.LoopType.recursive) {
262
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
268
263
  var _traverse_1 = function (cur) {
269
264
  if (_this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
270
265
  return;
271
266
  if (!cur.left && !cur.right)
272
267
  return;
273
268
  if (propertyName === 'id') {
274
- if (_this._compare(cur.id, nodeProperty) === CP.gt)
269
+ if (_this._compare(cur.id, nodeProperty) === types_1.CP.gt)
275
270
  cur.left && _traverse_1(cur.left);
276
- if (_this._compare(cur.id, nodeProperty) === CP.lt)
271
+ if (_this._compare(cur.id, nodeProperty) === types_1.CP.lt)
277
272
  cur.right && _traverse_1(cur.right);
278
273
  }
279
274
  else {
@@ -291,9 +286,9 @@ var BST = /** @class */ (function (_super) {
291
286
  if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
292
287
  return result;
293
288
  if (propertyName === 'id') {
294
- if (this._compare(cur.id, nodeProperty) === CP.gt)
289
+ if (this._compare(cur.id, nodeProperty) === types_1.CP.gt)
295
290
  cur.left && queue.push(cur.left);
296
- if (this._compare(cur.id, nodeProperty) === CP.lt)
291
+ if (this._compare(cur.id, nodeProperty) === types_1.CP.lt)
297
292
  cur.right && queue.push(cur.right);
298
293
  }
299
294
  else {
@@ -337,15 +332,15 @@ var BST = /** @class */ (function (_super) {
337
332
  return needSum;
338
333
  };
339
334
  var sum = 0;
340
- if (this.loopType === binary_tree_1.LoopType.recursive) {
335
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
341
336
  var _traverse_2 = function (cur) {
342
337
  var compared = _this._compare(cur.id, id);
343
- if (compared === CP.eq) {
338
+ if (compared === types_1.CP.eq) {
344
339
  if (cur.right)
345
340
  sum += _this.subTreeSum(cur.right, propertyName);
346
341
  return;
347
342
  }
348
- else if (compared === CP.lt) {
343
+ else if (compared === types_1.CP.lt) {
349
344
  if (cur.left)
350
345
  sum += _this.subTreeSum(cur.left, propertyName);
351
346
  sum += getSumByPropertyName(cur);
@@ -369,12 +364,12 @@ var BST = /** @class */ (function (_super) {
369
364
  var cur = queue.shift();
370
365
  if (cur) {
371
366
  var compared = this._compare(cur.id, id);
372
- if (compared === CP.eq) {
367
+ if (compared === types_1.CP.eq) {
373
368
  if (cur.right)
374
369
  sum += this.subTreeSum(cur.right, propertyName);
375
370
  return sum;
376
371
  }
377
- else if (compared === CP.lt) { // todo maybe a bug
372
+ else if (compared === types_1.CP.lt) { // todo maybe a bug
378
373
  if (cur.left)
379
374
  sum += this.subTreeSum(cur.left, propertyName);
380
375
  sum += getSumByPropertyName(cur);
@@ -424,15 +419,15 @@ var BST = /** @class */ (function (_super) {
424
419
  break;
425
420
  }
426
421
  };
427
- if (this.loopType === binary_tree_1.LoopType.recursive) {
422
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
428
423
  var _traverse_3 = function (cur) {
429
424
  var compared = _this._compare(cur.id, node.id);
430
425
  _sumByPropertyName(cur);
431
426
  if (!cur.left && !cur.right)
432
427
  return;
433
- if (cur.left && compared === CP.gt)
428
+ if (cur.left && compared === types_1.CP.gt)
434
429
  _traverse_3(cur.left);
435
- else if (cur.right && compared === CP.gt)
430
+ else if (cur.right && compared === types_1.CP.gt)
436
431
  _traverse_3(cur.right);
437
432
  };
438
433
  _traverse_3(this.root);
@@ -445,9 +440,9 @@ var BST = /** @class */ (function (_super) {
445
440
  if (cur) {
446
441
  var compared = this._compare(cur.id, node.id);
447
442
  _sumByPropertyName(cur);
448
- if (cur.left && compared === CP.gt)
443
+ if (cur.left && compared === types_1.CP.gt)
449
444
  queue.push(cur.left);
450
- else if (cur.right && compared === CP.gt)
445
+ else if (cur.right && compared === types_1.CP.gt)
451
446
  queue.push(cur.right);
452
447
  }
453
448
  }
@@ -465,7 +460,7 @@ var BST = /** @class */ (function (_super) {
465
460
  this.clear();
466
461
  if (sorted.length < 1)
467
462
  return false;
468
- if (this.loopType === binary_tree_1.LoopType.recursive) {
463
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
469
464
  var buildBalanceBST_1 = function (l, r) {
470
465
  if (l > r)
471
466
  return;
@@ -506,7 +501,7 @@ var BST = /** @class */ (function (_super) {
506
501
  if (!this.root)
507
502
  return true;
508
503
  var balanced = true;
509
- if (this.loopType === binary_tree_1.LoopType.recursive) {
504
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
510
505
  var _height_1 = function (cur) {
511
506
  if (!cur)
512
507
  return 0;
@@ -558,11 +553,11 @@ var BST = /** @class */ (function (_super) {
558
553
  BST.prototype._compare = function (a, b) {
559
554
  var compared = this._comparator(a, b);
560
555
  if (compared > 0)
561
- return CP.gt;
556
+ return types_1.CP.gt;
562
557
  else if (compared < 0)
563
- return CP.lt;
558
+ return types_1.CP.lt;
564
559
  else
565
- return CP.eq;
560
+ return types_1.CP.eq;
566
561
  };
567
562
  return BST;
568
563
  }(binary_tree_1.BinaryTree));
@@ -1,3 +1,4 @@
1
+ export * from './abstract-binary-tree';
1
2
  export * from './binary-tree';
2
3
  export * from './bst';
3
4
  export * from './binary-indexed-tree';
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./abstract-binary-tree"), exports);
17
18
  __exportStar(require("./binary-tree"), exports);
18
19
  __exportStar(require("./bst"), exports);
19
20
  __exportStar(require("./binary-indexed-tree"), exports);
@@ -16,11 +16,7 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  var binary_tree_1 = require("./binary-tree");
19
- var RBColor;
20
- (function (RBColor) {
21
- RBColor[RBColor["Red"] = 0] = "Red";
22
- RBColor[RBColor["Black"] = 1] = "Black";
23
- })(RBColor || (RBColor = {}));
19
+ var types_1 = require("../types");
24
20
  var RBNode = /** @class */ (function (_super) {
25
21
  __extends(RBNode, _super);
26
22
  // override createNode(id: BinaryTreeNodeId, val: T | null, count?: number): RBNode<T> | null {
@@ -28,7 +24,7 @@ var RBNode = /** @class */ (function (_super) {
28
24
  // }
29
25
  function RBNode(id, val, count) {
30
26
  var _this = _super.call(this, id, val, count) || this;
31
- _this._color = RBColor.Red;
27
+ _this._color = types_1.RBColor.RED;
32
28
  return _this;
33
29
  }
34
30
  Object.defineProperty(RBNode.prototype, "color", {
@@ -6,9 +6,15 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { BinaryTreeNodeId, TreeMultiSetDeletedResult } from '../types';
10
- import { IBinaryTree } from '../interfaces';
9
+ import type { BinaryTreeNodeId, RecursiveTreeMultiSetNode, TreeMultiSetOptions } from '../types';
10
+ import { IBinaryTree, IBinaryTreeNode } from '../interfaces';
11
+ export declare class TreeMultiSetNode<T, FAMILY extends TreeMultiSetNode<T, FAMILY> = RecursiveTreeMultiSetNode<T>> extends BSTNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
12
+ }
13
+ /**
14
+ * The only distinction between a TreeMultiSet and a BST lies in the ability of the former to store duplicate nodes through the utilization of counters.
15
+ */
11
16
  export declare class TreeMultiSet<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BST<N> implements IBinaryTree<N> {
17
+ constructor(options?: TreeMultiSetOptions);
12
18
  /**
13
19
  * The function creates a new BSTNode with the given id, value, and count.
14
20
  * @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
@@ -19,25 +25,4 @@ export declare class TreeMultiSet<N extends BSTNode<N['val'], N> = BSTNode<numbe
19
25
  * @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
20
26
  */
21
27
  _createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N;
22
- /**
23
- * The function overrides the add method of the BinarySearchTree class in TypeScript.
24
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
25
- * @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
26
- * can be of type `N` (the generic type) or `null`.
27
- * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
28
- * of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
29
- * @returns The `add` method is returning a `BSTNode<N>` object or `null`.
30
- */
31
- add(id: BinaryTreeNodeId, val: N | null, count?: number): N | null;
32
- /**
33
- * The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
34
- * method.
35
- * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
36
- * removed from the tree.
37
- * @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean value that
38
- * determines whether to update the left sum of all nodes in the tree after removing a node. If `isUpdateAllLeftSum` is
39
- * set to `true`, the left sum of all nodes will be recalculated. If it
40
- * @returns The method is returning an array of TreeMultiSetDeletedResult objects.
41
- */
42
- remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<N>[];
43
28
  }
@@ -14,8 +14,19 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.TreeMultiSet = void 0;
29
+ exports.TreeMultiSet = exports.TreeMultiSetNode = void 0;
19
30
  /**
20
31
  * data-structure-typed
21
32
  *
@@ -24,10 +35,21 @@ exports.TreeMultiSet = void 0;
24
35
  * @license MIT License
25
36
  */
26
37
  var bst_1 = require("./bst");
38
+ var TreeMultiSetNode = /** @class */ (function (_super) {
39
+ __extends(TreeMultiSetNode, _super);
40
+ function TreeMultiSetNode() {
41
+ return _super !== null && _super.apply(this, arguments) || this;
42
+ }
43
+ return TreeMultiSetNode;
44
+ }(bst_1.BSTNode));
45
+ exports.TreeMultiSetNode = TreeMultiSetNode;
46
+ /**
47
+ * The only distinction between a TreeMultiSet and a BST lies in the ability of the former to store duplicate nodes through the utilization of counters.
48
+ */
27
49
  var TreeMultiSet = /** @class */ (function (_super) {
28
50
  __extends(TreeMultiSet, _super);
29
- function TreeMultiSet() {
30
- return _super !== null && _super.apply(this, arguments) || this;
51
+ function TreeMultiSet(options) {
52
+ return _super.call(this, __assign(__assign({}, options), { isDuplicatedVal: true })) || this;
31
53
  }
32
54
  /**
33
55
  * The function creates a new BSTNode with the given id, value, and count.
@@ -39,34 +61,9 @@ var TreeMultiSet = /** @class */ (function (_super) {
39
61
  * @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
40
62
  */
41
63
  TreeMultiSet.prototype._createNode = function (id, val, count) {
42
- var node = new bst_1.BSTNode(id, val, count);
64
+ var node = new TreeMultiSetNode(id, val, count);
43
65
  return node;
44
66
  };
45
- /**
46
- * The function overrides the add method of the BinarySearchTree class in TypeScript.
47
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
48
- * @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
49
- * can be of type `N` (the generic type) or `null`.
50
- * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
51
- * of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
52
- * @returns The `add` method is returning a `BSTNode<N>` object or `null`.
53
- */
54
- TreeMultiSet.prototype.add = function (id, val, count) {
55
- return _super.prototype.add.call(this, id, val, count);
56
- };
57
- /**
58
- * The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
59
- * method.
60
- * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
61
- * removed from the tree.
62
- * @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean value that
63
- * determines whether to update the left sum of all nodes in the tree after removing a node. If `isUpdateAllLeftSum` is
64
- * set to `true`, the left sum of all nodes will be recalculated. If it
65
- * @returns The method is returning an array of TreeMultiSetDeletedResult objects.
66
- */
67
- TreeMultiSet.prototype.remove = function (id, isUpdateAllLeftSum) {
68
- return _super.prototype.remove.call(this, id, isUpdateAllLeftSum);
69
- };
70
67
  return TreeMultiSet;
71
68
  }(bst_1.BST));
72
69
  exports.TreeMultiSet = TreeMultiSet;
@@ -32,10 +32,8 @@ export declare class DirectedEdge<T = number> extends AbstractEdge<T> {
32
32
  get dest(): VertexId;
33
33
  set dest(v: VertexId);
34
34
  }
35
- export declare class DirectedGraph<V extends DirectedVertex<any>, E extends DirectedEdge<any>> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
36
- private readonly _vertexConstructor;
37
- private readonly _edgeConstructor;
38
- constructor(vertexConstructor: new (id: VertexId, val?: V['val']) => V, edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E);
35
+ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVertex, E extends DirectedEdge<any> = DirectedEdge> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
36
+ constructor();
39
37
  private _outEdgeMap;
40
38
  get outEdgeMap(): Map<V, E[]>;
41
39
  private _inEdgeMap;
@@ -122,12 +122,10 @@ exports.DirectedEdge = DirectedEdge;
122
122
  // Strongly connected, One direction connected, Weakly connected
123
123
  var DirectedGraph = /** @class */ (function (_super) {
124
124
  __extends(DirectedGraph, _super);
125
- function DirectedGraph(vertexConstructor, edgeConstructor) {
125
+ function DirectedGraph() {
126
126
  var _this = _super.call(this) || this;
127
127
  _this._outEdgeMap = new Map();
128
128
  _this._inEdgeMap = new Map();
129
- _this._vertexConstructor = vertexConstructor;
130
- _this._edgeConstructor = edgeConstructor;
131
129
  return _this;
132
130
  }
133
131
  Object.defineProperty(DirectedGraph.prototype, "outEdgeMap", {
@@ -151,7 +149,7 @@ var DirectedGraph = /** @class */ (function (_super) {
151
149
  * @param val
152
150
  */
153
151
  DirectedGraph.prototype._createVertex = function (id, val) {
154
- return new this._vertexConstructor(id, val);
152
+ return new DirectedVertex(id, val !== null && val !== void 0 ? val : id);
155
153
  };
156
154
  /**
157
155
  * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
@@ -162,9 +160,7 @@ var DirectedGraph = /** @class */ (function (_super) {
162
160
  * @param val
163
161
  */
164
162
  DirectedGraph.prototype._createEdge = function (src, dest, weight, val) {
165
- if (weight === undefined || weight === null)
166
- weight = 1;
167
- return new this._edgeConstructor(src, dest, weight, val);
163
+ return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1, val);
168
164
  };
169
165
  /**
170
166
  * The function `getEdge` returns the directed edge between two vertices, given their source and destination.
@@ -26,10 +26,8 @@ export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
26
26
  get vertices(): [VertexId, VertexId];
27
27
  set vertices(v: [VertexId, VertexId]);
28
28
  }
29
- export declare class UndirectedGraph<V extends UndirectedVertex<any>, E extends UndirectedEdge<any>> extends AbstractGraph<V, E> {
30
- private readonly _vertexConstructor;
31
- private readonly _edgeConstructor;
32
- constructor(vertexConstructor: new (id: VertexId, val?: V['val']) => V, edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E);
29
+ export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> {
30
+ constructor();
33
31
  protected _edges: Map<V, E[]>;
34
32
  get edges(): Map<V, E[]>;
35
33
  /**
@@ -40,14 +38,18 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any>, E extends
40
38
  */
41
39
  _createVertex(id: VertexId, val?: V['val']): V;
42
40
  /**
43
- * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
44
- * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
45
- * @param src
46
- * @param dest
47
- * @param weight
48
- * @param val
41
+ * The function _createEdge creates an undirected edge between two vertices with an optional weight and value.
42
+ * @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge. It is of type `VertexId`, which
43
+ * could be a unique identifier or label for the vertex.
44
+ * @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge. It is of type `VertexId`, which
45
+ * is typically a unique identifier for a vertex in a graph.
46
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
47
+ * weight is provided, the default value is 1.
48
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
49
+ * is used to store additional information or data associated with the edge.
50
+ * @returns an instance of the UndirectedEdge class, casted as type E.
49
51
  */
50
- _createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
52
+ _createEdge(v1: VertexId, v2: VertexId, weight?: number, val?: E['val']): E;
51
53
  /**
52
54
  * The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
53
55
  * exists.
@@ -108,10 +108,8 @@ var UndirectedEdge = /** @class */ (function (_super) {
108
108
  exports.UndirectedEdge = UndirectedEdge;
109
109
  var UndirectedGraph = /** @class */ (function (_super) {
110
110
  __extends(UndirectedGraph, _super);
111
- function UndirectedGraph(vertexConstructor, edgeConstructor) {
111
+ function UndirectedGraph() {
112
112
  var _this = _super.call(this) || this;
113
- _this._vertexConstructor = vertexConstructor;
114
- _this._edgeConstructor = edgeConstructor;
115
113
  _this._edges = new Map();
116
114
  return _this;
117
115
  }
@@ -129,20 +127,22 @@ var UndirectedGraph = /** @class */ (function (_super) {
129
127
  * @param val
130
128
  */
131
129
  UndirectedGraph.prototype._createVertex = function (id, val) {
132
- return new this._vertexConstructor(id, val);
130
+ return new UndirectedVertex(id, val !== null && val !== void 0 ? val : id);
133
131
  };
134
132
  /**
135
- * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
136
- * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
137
- * @param src
138
- * @param dest
139
- * @param weight
140
- * @param val
133
+ * The function _createEdge creates an undirected edge between two vertices with an optional weight and value.
134
+ * @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge. It is of type `VertexId`, which
135
+ * could be a unique identifier or label for the vertex.
136
+ * @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge. It is of type `VertexId`, which
137
+ * is typically a unique identifier for a vertex in a graph.
138
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
139
+ * weight is provided, the default value is 1.
140
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
141
+ * is used to store additional information or data associated with the edge.
142
+ * @returns an instance of the UndirectedEdge class, casted as type E.
141
143
  */
142
- UndirectedGraph.prototype._createEdge = function (src, dest, weight, val) {
143
- if (weight === undefined || weight === null)
144
- weight = 1;
145
- return new this._edgeConstructor(src, dest, weight, val);
144
+ UndirectedGraph.prototype._createEdge = function (v1, v2, weight, val) {
145
+ return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, val);
146
146
  };
147
147
  /**
148
148
  * The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
@@ -1,5 +1,4 @@
1
- import { BinaryTreeNodeId } from '../types';
2
- import { FamilyPosition } from '../binary-tree';
1
+ import { BinaryTreeNodeId, FamilyPosition } from '../types';
3
2
  export interface IBinaryTreeNode<T, FAMILY extends IBinaryTreeNode<T, FAMILY>> {
4
3
  _createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
5
4
  get id(): BinaryTreeNodeId;
@@ -0,0 +1,32 @@
1
+ import { AbstractBinaryTreeNode } from '../binary-tree';
2
+ /**
3
+ * Enum representing different loop types.
4
+ *
5
+ * - `iterative`: Indicates the iterative loop type (with loops that use iterations).
6
+ * - `recursive`: Indicates the recursive loop type (with loops that call themselves).
7
+ */
8
+ export declare enum LoopType {
9
+ ITERATIVE = "ITERATIVE",
10
+ RECURSIVE = "RECURSIVE"
11
+ }
12
+ export declare enum FamilyPosition {
13
+ ROOT = 0,
14
+ LEFT = 1,
15
+ RIGHT = 2
16
+ }
17
+ export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
18
+ export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
19
+ export type DFSOrderPattern = 'in' | 'pre' | 'post';
20
+ export type BinaryTreeNodeId = number;
21
+ export type BinaryTreeDeletedResult<N> = {
22
+ deleted: N | null | undefined;
23
+ needBalanced: N | null;
24
+ };
25
+ export type AbstractResultByProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeId;
26
+ export type AbstractResultsByProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = AbstractResultByProperty<N>[];
27
+ export type AbstractRecursiveBinaryTreeNode<T> = AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
28
+ export type AbstractBinaryTreeOptions = {
29
+ loopType?: LoopType;
30
+ autoIncrementId?: boolean;
31
+ isDuplicatedVal?: boolean;
32
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FamilyPosition = exports.LoopType = void 0;
4
+ /**
5
+ * Enum representing different loop types.
6
+ *
7
+ * - `iterative`: Indicates the iterative loop type (with loops that use iterations).
8
+ * - `recursive`: Indicates the recursive loop type (with loops that call themselves).
9
+ */
10
+ var LoopType;
11
+ (function (LoopType) {
12
+ LoopType["ITERATIVE"] = "ITERATIVE";
13
+ LoopType["RECURSIVE"] = "RECURSIVE";
14
+ })(LoopType || (exports.LoopType = LoopType = {}));
15
+ /* This enumeration defines the position of a node within a family tree composed of three associated nodes, where 'root' represents the root node of the family tree, 'left' represents the left child node, and 'right' represents the right child node. */
16
+ var FamilyPosition;
17
+ (function (FamilyPosition) {
18
+ FamilyPosition[FamilyPosition["ROOT"] = 0] = "ROOT";
19
+ FamilyPosition[FamilyPosition["LEFT"] = 1] = "LEFT";
20
+ FamilyPosition[FamilyPosition["RIGHT"] = 2] = "RIGHT";
21
+ })(FamilyPosition || (exports.FamilyPosition = FamilyPosition = {}));
@@ -1,6 +1,4 @@
1
1
  import { AVLTreeNode } from '../binary-tree';
2
- export type AVLTreeDeleted<N> = {
3
- deleted: N | null;
4
- needBalanced: N | null;
5
- };
2
+ import { BSTOptions } from './bst';
6
3
  export type RecursiveAVLTreeNode<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
+ export type AVLTreeOptions = BSTOptions & {};