directed-graph-typed 1.39.6 → 1.41.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.
Files changed (96) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.js +0 -1
  2. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
  3. package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -11
  4. package/dist/data-structures/binary-tree/binary-tree.d.ts +13 -20
  5. package/dist/data-structures/binary-tree/binary-tree.js +30 -31
  6. package/dist/data-structures/binary-tree/bst.d.ts +2 -2
  7. package/dist/data-structures/binary-tree/bst.js +4 -4
  8. package/dist/data-structures/binary-tree/rb-tree.d.ts +95 -11
  9. package/dist/data-structures/binary-tree/rb-tree.js +379 -18
  10. package/dist/data-structures/binary-tree/segment-tree.d.ts +10 -26
  11. package/dist/data-structures/binary-tree/segment-tree.js +10 -58
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  13. package/dist/data-structures/binary-tree/tree-multiset.js +6 -6
  14. package/dist/data-structures/graph/abstract-graph.d.ts +5 -24
  15. package/dist/data-structures/graph/abstract-graph.js +4 -43
  16. package/dist/data-structures/graph/directed-graph.d.ts +4 -10
  17. package/dist/data-structures/graph/directed-graph.js +2 -20
  18. package/dist/data-structures/graph/map-graph.d.ts +4 -10
  19. package/dist/data-structures/graph/map-graph.js +2 -20
  20. package/dist/data-structures/graph/undirected-graph.d.ts +1 -8
  21. package/dist/data-structures/graph/undirected-graph.js +1 -14
  22. package/dist/data-structures/hash/coordinate-map.d.ts +0 -1
  23. package/dist/data-structures/hash/coordinate-map.js +0 -3
  24. package/dist/data-structures/hash/coordinate-set.d.ts +0 -1
  25. package/dist/data-structures/hash/coordinate-set.js +0 -3
  26. package/dist/data-structures/hash/hash-map.d.ts +8 -14
  27. package/dist/data-structures/hash/hash-map.js +4 -22
  28. package/dist/data-structures/hash/hash-table.d.ts +6 -9
  29. package/dist/data-structures/hash/hash-table.js +0 -9
  30. package/dist/data-structures/heap/heap.d.ts +12 -6
  31. package/dist/data-structures/heap/heap.js +40 -22
  32. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +6 -14
  33. package/dist/data-structures/linked-list/doubly-linked-list.js +18 -42
  34. package/dist/data-structures/linked-list/singly-linked-list.d.ts +5 -11
  35. package/dist/data-structures/linked-list/singly-linked-list.js +17 -35
  36. package/dist/data-structures/linked-list/skip-linked-list.d.ts +29 -10
  37. package/dist/data-structures/linked-list/skip-linked-list.js +62 -17
  38. package/dist/data-structures/matrix/matrix.d.ts +1 -1
  39. package/dist/data-structures/matrix/matrix2d.d.ts +1 -1
  40. package/dist/data-structures/matrix/navigator.d.ts +4 -4
  41. package/dist/data-structures/queue/deque.d.ts +8 -12
  42. package/dist/data-structures/queue/deque.js +31 -43
  43. package/dist/data-structures/queue/queue.d.ts +20 -5
  44. package/dist/data-structures/queue/queue.js +35 -18
  45. package/dist/data-structures/stack/stack.d.ts +2 -1
  46. package/dist/data-structures/stack/stack.js +10 -7
  47. package/dist/data-structures/tree/tree.d.ts +3 -9
  48. package/dist/data-structures/tree/tree.js +3 -21
  49. package/dist/data-structures/trie/trie.d.ts +6 -12
  50. package/dist/data-structures/trie/trie.js +6 -24
  51. package/dist/interfaces/binary-tree.d.ts +1 -1
  52. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  53. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -7
  54. package/dist/types/data-structures/binary-tree/rb-tree.js +11 -6
  55. package/package.json +2 -2
  56. package/src/data-structures/binary-tree/avl-tree.ts +2 -4
  57. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -15
  58. package/src/data-structures/binary-tree/binary-tree.ts +40 -43
  59. package/src/data-structures/binary-tree/bst.ts +9 -10
  60. package/src/data-structures/binary-tree/rb-tree.ts +415 -355
  61. package/src/data-structures/binary-tree/segment-tree.ts +16 -83
  62. package/src/data-structures/binary-tree/tree-multiset.ts +8 -9
  63. package/src/data-structures/graph/abstract-graph.ts +21 -67
  64. package/src/data-structures/graph/directed-graph.ts +13 -39
  65. package/src/data-structures/graph/map-graph.ts +7 -32
  66. package/src/data-structures/graph/undirected-graph.ts +9 -26
  67. package/src/data-structures/hash/coordinate-map.ts +0 -4
  68. package/src/data-structures/hash/coordinate-set.ts +0 -4
  69. package/src/data-structures/hash/hash-map.ts +13 -37
  70. package/src/data-structures/hash/hash-table.ts +6 -18
  71. package/src/data-structures/hash/tree-map.ts +2 -1
  72. package/src/data-structures/hash/tree-set.ts +2 -1
  73. package/src/data-structures/heap/heap.ts +58 -30
  74. package/src/data-structures/heap/max-heap.ts +1 -1
  75. package/src/data-structures/heap/min-heap.ts +1 -1
  76. package/src/data-structures/linked-list/doubly-linked-list.ts +26 -60
  77. package/src/data-structures/linked-list/singly-linked-list.ts +24 -49
  78. package/src/data-structures/linked-list/skip-linked-list.ts +73 -25
  79. package/src/data-structures/matrix/matrix.ts +2 -2
  80. package/src/data-structures/matrix/matrix2d.ts +1 -1
  81. package/src/data-structures/matrix/navigator.ts +4 -4
  82. package/src/data-structures/matrix/vector2d.ts +2 -1
  83. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  84. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  85. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  86. package/src/data-structures/queue/deque.ts +38 -53
  87. package/src/data-structures/queue/queue.ts +38 -20
  88. package/src/data-structures/stack/stack.ts +13 -9
  89. package/src/data-structures/tree/tree.ts +7 -33
  90. package/src/data-structures/trie/trie.ts +14 -40
  91. package/src/interfaces/binary-tree.ts +1 -1
  92. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  93. package/src/types/data-structures/binary-tree/rb-tree.ts +6 -6
  94. package/src/types/data-structures/matrix/navigator.ts +1 -1
  95. package/src/types/utils/utils.ts +1 -1
  96. package/src/types/utils/validate-type.ts +2 -2
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
+ // import {BinaryTreeOptions} from './binary-tree';
3
+ // import {RBTreeNode} from '../../../data-structures';
2
4
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RBColor = void 0;
4
- var RBColor;
5
- (function (RBColor) {
6
- RBColor["RED"] = "RED";
7
- RBColor["BLACK"] = "BLACK";
8
- })(RBColor = exports.RBColor || (exports.RBColor = {}));
5
+ exports.RBTNColor = void 0;
6
+ var RBTNColor;
7
+ (function (RBTNColor) {
8
+ RBTNColor[RBTNColor["RED"] = 1] = "RED";
9
+ RBTNColor[RBTNColor["BLACK"] = 0] = "BLACK";
10
+ })(RBTNColor = exports.RBTNColor || (exports.RBTNColor = {}));
11
+ // export type RBTreeNodeNested<T> = RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
12
+ //
13
+ // export type RBTreeOptions = BinaryTreeOptions & {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directed-graph-typed",
3
- "version": "1.39.6",
3
+ "version": "1.41.0",
4
4
  "description": "Directed Graph. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -146,6 +146,6 @@
146
146
  "typescript": "^4.9.5"
147
147
  },
148
148
  "dependencies": {
149
- "data-structure-typed": "^1.39.6"
149
+ "data-structure-typed": "^1.41.0"
150
150
  }
151
151
  }
@@ -21,8 +21,7 @@ export class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNeste
21
21
 
22
22
  export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>>
23
23
  extends BST<V, N>
24
- implements IBinaryTree<V, N>
25
- {
24
+ implements IBinaryTree<V, N> {
26
25
  /**
27
26
  * This is a constructor function for an AVL tree data structure in TypeScript.
28
27
  * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
@@ -56,7 +55,6 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
56
55
  * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
57
56
  */
58
57
  override add(keyOrNode: BTNKey | N | null, value?: V): N | null | undefined {
59
- // TODO support node as a param
60
58
  const inserted = super.add(keyOrNode, value);
61
59
  if (inserted) this._balancePath(inserted);
62
60
  return inserted;
@@ -162,7 +160,7 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
162
160
  // Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
163
161
  switch (
164
162
  this._balanceFactor(A) // second O(1)
165
- ) {
163
+ ) {
166
164
  case -2:
167
165
  if (A && A.left) {
168
166
  if (this._balanceFactor(A.left) <= 0) {
@@ -17,7 +17,7 @@ export class BinaryIndexedTree {
17
17
  * @param - - `frequency`: The default frequency value. It is optional and has a default
18
18
  * value of 0.
19
19
  */
20
- constructor({frequency = 0, max}: {frequency?: number; max: number}) {
20
+ constructor({frequency = 0, max}: { frequency?: number; max: number }) {
21
21
  this._freq = frequency;
22
22
  this._max = max;
23
23
  this._freqMap = {0: 0};
@@ -31,30 +31,18 @@ export class BinaryIndexedTree {
31
31
  return this._freqMap;
32
32
  }
33
33
 
34
- set freqMap(value: Record<number, number>) {
35
- this._freqMap = value;
36
- }
37
-
38
34
  protected _msb: number;
39
35
 
40
36
  get msb(): number {
41
37
  return this._msb;
42
38
  }
43
39
 
44
- set msb(value: number) {
45
- this._msb = value;
46
- }
47
-
48
40
  protected _negativeCount: number;
49
41
 
50
42
  get negativeCount(): number {
51
43
  return this._negativeCount;
52
44
  }
53
45
 
54
- set negativeCount(value: number) {
55
- this._negativeCount = value;
56
- }
57
-
58
46
  get freq(): number {
59
47
  return this._freq;
60
48
  }
@@ -232,9 +220,9 @@ export class BinaryIndexedTree {
232
220
  */
233
221
  protected _updateNegativeCount(freqCur: number, freqNew: number): void {
234
222
  if (freqCur < 0 && freqNew >= 0) {
235
- this.negativeCount--;
223
+ this._negativeCount--;
236
224
  } else if (freqCur >= 0 && freqNew < 0) {
237
- this.negativeCount++;
225
+ this._negativeCount++;
238
226
  }
239
227
  }
240
228
 
@@ -43,7 +43,7 @@ export class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = BinaryTree
43
43
  this.value = value;
44
44
  }
45
45
 
46
- private _left: N | null | undefined;
46
+ protected _left: N | null | undefined;
47
47
 
48
48
  /**
49
49
  * Get the left child node.
@@ -63,7 +63,7 @@ export class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = BinaryTree
63
63
  this._left = v;
64
64
  }
65
65
 
66
- private _right: N | null | undefined;
66
+ protected _right: N | null | undefined;
67
67
 
68
68
  /**
69
69
  * Get the right child node.
@@ -108,8 +108,9 @@ export class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = BinaryTree
108
108
  * @template N - The type of the binary tree's nodes.
109
109
  */
110
110
  export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>>
111
- implements IBinaryTree<V, N>
112
- {
111
+ implements IBinaryTree<V, N> {
112
+ iterationType: IterationType = IterationType.ITERATIVE;
113
+
113
114
  /**
114
115
  * Creates a new instance of BinaryTree.
115
116
  * @param {BinaryTreeOptions} [options] - The options for the binary tree.
@@ -117,28 +118,11 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
117
118
  constructor(options?: BinaryTreeOptions) {
118
119
  if (options !== undefined) {
119
120
  const {iterationType = IterationType.ITERATIVE} = options;
120
- this._iterationType = iterationType;
121
+ this.iterationType = iterationType;
121
122
  }
122
123
  }
123
124
 
124
- private _iterationType: IterationType = IterationType.ITERATIVE;
125
-
126
- /**
127
- * Get the iteration type used in the binary tree.
128
- */
129
- get iterationType(): IterationType {
130
- return this._iterationType;
131
- }
132
-
133
- /**
134
- * Set the iteration type for the binary tree.
135
- * @param {IterationType} v - The new iteration type to set.
136
- */
137
- set iterationType(v: IterationType) {
138
- this._iterationType = v;
139
- }
140
-
141
- private _root: N | null = null;
125
+ protected _root: N | null = null;
142
126
 
143
127
  /**
144
128
  * Get the root node of the binary tree.
@@ -147,7 +131,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
147
131
  return this._root;
148
132
  }
149
133
 
150
- private _size = 0;
134
+ protected _size = 0;
151
135
 
152
136
  /**
153
137
  * Get the number of nodes in the binary tree.
@@ -170,7 +154,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
170
154
  * Clear the binary tree, removing all nodes.
171
155
  */
172
156
  clear() {
173
- this._root = null;
157
+ this._setRoot(null);
174
158
  this._size = 0;
175
159
  }
176
160
 
@@ -229,9 +213,9 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
229
213
  } else {
230
214
  this._setRoot(needInsert);
231
215
  if (needInsert !== null) {
232
- this._setSize(1);
216
+ this._size = 1;
233
217
  } else {
234
- this._setSize(0);
218
+ this._size = 0;
235
219
  }
236
220
  inserted = this.root;
237
221
  }
@@ -339,7 +323,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
339
323
  }
340
324
  }
341
325
  }
342
- this._setSize(this.size - 1);
326
+ this._size = this.size - 1;
343
327
 
344
328
  bstDeletedResult.push({deleted: orgCurrent, needBalanced});
345
329
  return bstDeletedResult;
@@ -401,7 +385,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
401
385
  return -1;
402
386
  }
403
387
 
404
- const stack: {node: N; depth: number}[] = [{node: beginRoot, depth: 0}];
388
+ const stack: { node: N; depth: number }[] = [{node: beginRoot, depth: 0}];
405
389
  let maxHeight = 0;
406
390
 
407
391
  while (stack.length > 0) {
@@ -904,7 +888,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
904
888
  _traverse(beginRoot);
905
889
  } else {
906
890
  // 0: visit, 1: print
907
- const stack: {opt: 0 | 1; node: N | null | undefined}[] = [{opt: 0, node: beginRoot}];
891
+ const stack: { opt: 0 | 1; node: N | null | undefined }[] = [{opt: 0, node: beginRoot}];
908
892
 
909
893
  while (stack.length > 0) {
910
894
  const cur = stack.pop();
@@ -966,7 +950,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
966
950
  if (iterationType === IterationType.RECURSIVE) {
967
951
  const queue = new Queue<N>([beginRoot]);
968
952
 
969
- function traverse(level: number) {
953
+ const traverse = (level: number) => {
970
954
  if (queue.size === 0) return;
971
955
 
972
956
  const current = queue.shift()!;
@@ -1064,6 +1048,26 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1064
1048
  }
1065
1049
  }
1066
1050
 
1051
+ /**
1052
+ * The function `getSuccessor` returns the next node in a binary tree given a node `x`, or `null` if
1053
+ * `x` is the last node.
1054
+ * @param {N} x - N - a node in a binary tree
1055
+ * @returns The function `getSuccessor` returns a value of type `N` (the successor node), or `null`
1056
+ * if there is no successor, or `undefined` if the input `x` is `undefined`.
1057
+ */
1058
+ getSuccessor(x: N): N | null | undefined{
1059
+ if (x.right) {
1060
+ return this.getLeftMost(x.right);
1061
+ }
1062
+
1063
+ let y: N | null | undefined = x.parent;
1064
+ while (y && y && x === y.right) {
1065
+ x = y;
1066
+ y = y.parent;
1067
+ }
1068
+ return y;
1069
+ }
1070
+
1067
1071
  // --- start additional methods ---
1068
1072
 
1069
1073
  /**
@@ -1174,7 +1178,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1174
1178
  * @returns The `*[Symbol.iterator]` method returns a generator object that yields the keys of the
1175
1179
  * binary tree nodes in a specific order.
1176
1180
  */
1177
- *[Symbol.iterator](node = this.root): Generator<BTNKey, void, undefined> {
1181
+ * [Symbol.iterator](node = this.root): Generator<BTNKey, void, undefined> {
1178
1182
  if (!node) {
1179
1183
  return;
1180
1184
  }
@@ -1196,10 +1200,12 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1196
1200
  }
1197
1201
  } else {
1198
1202
  if (node.left) {
1203
+ // @ts-ignore
1199
1204
  yield* this[Symbol.iterator](node.left);
1200
1205
  }
1201
1206
  yield node.key;
1202
1207
  if (node.right) {
1208
+ // @ts-ignore
1203
1209
  yield* this[Symbol.iterator](node.right);
1204
1210
  }
1205
1211
  }
@@ -1244,13 +1250,13 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1244
1250
  if (parent.left === undefined) {
1245
1251
  parent.left = newNode;
1246
1252
  if (newNode) {
1247
- this._setSize(this.size + 1);
1253
+ this._size = this.size + 1;
1248
1254
  }
1249
1255
  return parent.left;
1250
1256
  } else if (parent.right === undefined) {
1251
1257
  parent.right = newNode;
1252
1258
  if (newNode) {
1253
- this._setSize(this.size + 1);
1259
+ this._size = this.size + 1;
1254
1260
  }
1255
1261
  return parent.right;
1256
1262
  } else {
@@ -1274,14 +1280,5 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1274
1280
  this._root = v;
1275
1281
  }
1276
1282
 
1277
- /**
1278
- * The function sets the value of the protected property "_size" to the given number.
1279
- * @param {number} v - The parameter "v" is a number that represents the size value that we want to
1280
- * set.
1281
- */
1282
- protected _setSize(v: number) {
1283
- this._size = v;
1284
- }
1285
-
1286
1283
  // --- end additional methods ---
1287
1284
  }
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type {BTNKey, BSTComparator, BSTNodeNested, BSTOptions, BTNCallback} from '../../types';
8
+ import type {BSTComparator, BSTNodeNested, BSTOptions, BTNCallback, BTNKey} from '../../types';
9
9
  import {CP, IterationType} from '../../types';
10
10
  import {BinaryTree, BinaryTreeNode} from './binary-tree';
11
11
  import {IBinaryTree} from '../../interfaces';
@@ -19,8 +19,7 @@ export class BSTNode<V = any, N extends BSTNode<V, N> = BSTNodeNested<V>> extend
19
19
 
20
20
  export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>>
21
21
  extends BinaryTree<V, N>
22
- implements IBinaryTree<V, N>
23
- {
22
+ implements IBinaryTree<V, N> {
24
23
  /**
25
24
  * The constructor function initializes a binary search tree object with an optional comparator
26
25
  * function.
@@ -72,7 +71,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
72
71
  }
73
72
  if (this.root === null) {
74
73
  this._setRoot(newNode);
75
- this._setSize(this.size + 1);
74
+ this._size = this.size + 1;
76
75
  inserted = this.root;
77
76
  } else {
78
77
  let cur = this.root;
@@ -94,7 +93,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
94
93
  }
95
94
  //Add to the left of the current node
96
95
  cur.left = newNode;
97
- this._setSize(this.size + 1);
96
+ this._size = this.size + 1;
98
97
  traversing = false;
99
98
  inserted = cur.left;
100
99
  } else {
@@ -109,7 +108,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
109
108
  }
110
109
  //Add to the right of the current node
111
110
  cur.right = newNode;
112
- this._setSize(this.size + 1);
111
+ this._size = this.size + 1;
113
112
  traversing = false;
114
113
  inserted = cur.right;
115
114
  } else {
@@ -128,7 +127,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
128
127
  /**
129
128
  * The `addMany` function is used to efficiently add multiple nodes to a binary search tree while
130
129
  * maintaining balance.
131
- * @param {[BTNKey | N, N['value']][]} keysOrNodes - The `arr` parameter in the `addMany` function
130
+ * @param {[BTNKey | N, V][]} keysOrNodes - The `arr` parameter in the `addMany` function
132
131
  * represents an array of keys or nodes that need to be added to the binary search tree. It can be an
133
132
  * array of `BTNKey` or `N` (which represents the node type in the binary search tree) or
134
133
  * `null
@@ -154,15 +153,15 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
154
153
  return super.addMany(keysOrNodes, data);
155
154
  }
156
155
  const inserted: (N | null | undefined)[] = [];
157
- const combinedArr: [BTNKey | N, N['value']][] = keysOrNodes.map((value, index) => [value, data?.[index]]);
156
+ const combinedArr: [BTNKey | N, V][] = keysOrNodes.map((value:(BTNKey | N), index) => [value, data?.[index]] as [BTNKey | N, V]);
158
157
  let sorted = [];
159
158
 
160
- function isNodeOrNullTuple(arr: [BTNKey | N, N['value']][]): arr is [N, N['value']][] {
159
+ function isNodeOrNullTuple(arr: [BTNKey | N, V][]): arr is [N, V][] {
161
160
  for (const [keyOrNode] of arr) if (keyOrNode instanceof BSTNode) return true;
162
161
  return false;
163
162
  }
164
163
 
165
- function isBinaryTreeKeyOrNullTuple(arr: [BTNKey | N, N['value']][]): arr is [BTNKey, N['value']][] {
164
+ function isBinaryTreeKeyOrNullTuple(arr: [BTNKey | N, V][]): arr is [BTNKey, V][] {
166
165
  for (const [keyOrNode] of arr) if (typeof keyOrNode === 'number') return true;
167
166
  return false;
168
167
  }