data-structure-typed 1.34.8 → 1.34.9

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 (126) hide show
  1. package/.eslintrc.js +1 -0
  2. package/CHANGELOG.md +1 -1
  3. package/CONTRIBUTING.md +0 -0
  4. package/README.md +8 -8
  5. package/dist/data-structures/binary-tree/aa-tree.js +2 -5
  6. package/dist/data-structures/binary-tree/aa-tree.js.map +1 -1
  7. package/dist/data-structures/binary-tree/abstract-binary-tree.js +280 -423
  8. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  9. package/dist/data-structures/binary-tree/avl-tree.js +63 -89
  10. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/data-structures/binary-tree/b-tree.js +2 -5
  12. package/dist/data-structures/binary-tree/b-tree.js.map +1 -1
  13. package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
  14. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  15. package/dist/data-structures/binary-tree/binary-tree.js +11 -30
  16. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  17. package/dist/data-structures/binary-tree/bst.js +127 -214
  18. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  19. package/dist/data-structures/binary-tree/rb-tree.js +19 -43
  20. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
  21. package/dist/data-structures/binary-tree/segment-tree.js +80 -122
  22. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
  23. package/dist/data-structures/binary-tree/splay-tree.js +2 -5
  24. package/dist/data-structures/binary-tree/splay-tree.js.map +1 -1
  25. package/dist/data-structures/binary-tree/tree-multiset.js +147 -218
  26. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  27. package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
  28. package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -1
  29. package/dist/data-structures/graph/abstract-graph.js +338 -572
  30. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  31. package/dist/data-structures/graph/directed-graph.js +145 -275
  32. package/dist/data-structures/graph/directed-graph.js.map +1 -1
  33. package/dist/data-structures/graph/map-graph.js +46 -87
  34. package/dist/data-structures/graph/map-graph.js.map +1 -1
  35. package/dist/data-structures/graph/undirected-graph.js +90 -179
  36. package/dist/data-structures/graph/undirected-graph.js.map +1 -1
  37. package/dist/data-structures/hash/coordinate-map.js +23 -45
  38. package/dist/data-structures/hash/coordinate-map.js.map +1 -1
  39. package/dist/data-structures/hash/coordinate-set.js +20 -42
  40. package/dist/data-structures/hash/coordinate-set.js.map +1 -1
  41. package/dist/data-structures/hash/hash-map.js +85 -247
  42. package/dist/data-structures/hash/hash-map.js.map +1 -1
  43. package/dist/data-structures/hash/hash-table.js +87 -128
  44. package/dist/data-structures/hash/hash-table.js.map +1 -1
  45. package/dist/data-structures/hash/pair.js +2 -5
  46. package/dist/data-structures/hash/pair.js.map +1 -1
  47. package/dist/data-structures/hash/tree-map.js +2 -5
  48. package/dist/data-structures/hash/tree-map.js.map +1 -1
  49. package/dist/data-structures/hash/tree-set.js +2 -5
  50. package/dist/data-structures/hash/tree-set.js.map +1 -1
  51. package/dist/data-structures/heap/heap.js +56 -80
  52. package/dist/data-structures/heap/heap.js.map +1 -1
  53. package/dist/data-structures/heap/max-heap.js +8 -26
  54. package/dist/data-structures/heap/max-heap.js.map +1 -1
  55. package/dist/data-structures/heap/min-heap.js +8 -26
  56. package/dist/data-structures/heap/min-heap.js.map +1 -1
  57. package/dist/data-structures/linked-list/doubly-linked-list.js +149 -218
  58. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  59. package/dist/data-structures/linked-list/singly-linked-list.js +119 -218
  60. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
  61. package/dist/data-structures/linked-list/skip-linked-list.js +50 -70
  62. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
  63. package/dist/data-structures/matrix/matrix.js +7 -8
  64. package/dist/data-structures/matrix/matrix.js.map +1 -1
  65. package/dist/data-structures/matrix/matrix2d.js +57 -70
  66. package/dist/data-structures/matrix/matrix2d.js.map +1 -1
  67. package/dist/data-structures/matrix/navigator.js +18 -37
  68. package/dist/data-structures/matrix/navigator.js.map +1 -1
  69. package/dist/data-structures/matrix/vector2d.js +63 -84
  70. package/dist/data-structures/matrix/vector2d.js.map +1 -1
  71. package/dist/data-structures/priority-queue/max-priority-queue.js +13 -41
  72. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  73. package/dist/data-structures/priority-queue/min-priority-queue.js +13 -41
  74. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  75. package/dist/data-structures/priority-queue/priority-queue.js +93 -139
  76. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
  77. package/dist/data-structures/queue/deque.js +82 -128
  78. package/dist/data-structures/queue/deque.js.map +1 -1
  79. package/dist/data-structures/queue/queue.js +57 -157
  80. package/dist/data-structures/queue/queue.js.map +1 -1
  81. package/dist/data-structures/stack/stack.js +21 -22
  82. package/dist/data-structures/stack/stack.js.map +1 -1
  83. package/dist/data-structures/tree/tree.js +32 -45
  84. package/dist/data-structures/tree/tree.js.map +1 -1
  85. package/dist/data-structures/trie/trie.js +93 -200
  86. package/dist/data-structures/trie/trie.js.map +1 -1
  87. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
  88. package/dist/utils/utils.js +22 -107
  89. package/dist/utils/utils.js.map +1 -1
  90. package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +79 -78
  91. package/lib/data-structures/binary-tree/abstract-binary-tree.js +61 -141
  92. package/lib/data-structures/binary-tree/avl-tree.d.ts +9 -0
  93. package/lib/data-structures/binary-tree/avl-tree.js +22 -0
  94. package/lib/data-structures/binary-tree/bst.d.ts +3 -3
  95. package/lib/data-structures/binary-tree/bst.js +12 -15
  96. package/lib/data-structures/binary-tree/tree-multiset.d.ts +16 -18
  97. package/lib/data-structures/binary-tree/tree-multiset.js +26 -36
  98. package/lib/data-structures/graph/abstract-graph.d.ts +2 -2
  99. package/lib/data-structures/graph/abstract-graph.js +5 -5
  100. package/lib/data-structures/priority-queue/priority-queue.d.ts +3 -3
  101. package/lib/data-structures/priority-queue/priority-queue.js +3 -3
  102. package/lib/interfaces/abstract-binary-tree.d.ts +23 -28
  103. package/lib/interfaces/avl-tree.d.ts +3 -1
  104. package/lib/interfaces/bst.d.ts +2 -1
  105. package/lib/types/data-structures/abstract-binary-tree.js +0 -1
  106. package/package.json +6 -6
  107. package/src/data-structures/binary-tree/abstract-binary-tree.ts +151 -203
  108. package/src/data-structures/binary-tree/avl-tree.ts +29 -0
  109. package/src/data-structures/binary-tree/bst.ts +12 -15
  110. package/src/data-structures/binary-tree/tree-multiset.ts +27 -39
  111. package/src/data-structures/graph/abstract-graph.ts +5 -5
  112. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  113. package/src/interfaces/abstract-binary-tree.ts +23 -36
  114. package/src/interfaces/avl-tree.ts +3 -1
  115. package/src/interfaces/bst.ts +1 -1
  116. package/src/types/data-structures/abstract-binary-tree.ts +0 -1
  117. package/test/integration/avl-tree.test.ts +24 -24
  118. package/test/integration/bst.test.ts +71 -71
  119. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  120. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -9
  121. package/test/unit/data-structures/binary-tree/bst.test.ts +8 -8
  122. package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
  123. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +9 -9
  124. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
  125. package/umd/bundle.min.js +1 -1
  126. package/umd/bundle.min.js.map +1 -1
@@ -118,22 +118,22 @@ export class BST extends BinaryTree {
118
118
  /**
119
119
  * The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced
120
120
  * manner.
121
- * @param {[BinaryTreeNodeKey | N , N['val']][]} idsOrNodes - The `idsOrNodes` parameter in the `addMany` function is an array of
121
+ * @param {[BinaryTreeNodeKey | N , N['val']][]} keysOrNodes - The `keysOrNodes` parameter in the `addMany` function is an array of
122
122
  * `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
123
123
  * to the binary search tree.
124
124
  * @param {N['val'][]} data - The values of tree nodes
125
125
  * @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
126
126
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
127
127
  */
128
- addMany(idsOrNodes, data, isBalanceAdd = false) {
128
+ addMany(keysOrNodes, data, isBalanceAdd = false) {
129
129
  function hasNoNull(arr) {
130
130
  return arr.indexOf(null) === -1;
131
131
  }
132
- if (!isBalanceAdd || !hasNoNull(idsOrNodes)) {
133
- return super.addMany(idsOrNodes, data);
132
+ if (!isBalanceAdd || !hasNoNull(keysOrNodes)) {
133
+ return super.addMany(keysOrNodes, data);
134
134
  }
135
135
  const inserted = [];
136
- const combinedArr = idsOrNodes.map((value, index) => [value, data === null || data === void 0 ? void 0 : data[index]]);
136
+ const combinedArr = keysOrNodes.map((value, index) => [value, data === null || data === void 0 ? void 0 : data[index]]);
137
137
  let sorted = [];
138
138
  function isNodeOrNullTuple(arr) {
139
139
  for (const [keyOrNode] of arr)
@@ -155,7 +155,7 @@ export class BST extends BinaryTree {
155
155
  sorted = combinedArr.sort((a, b) => a[0] - b[0]);
156
156
  }
157
157
  else {
158
- throw new Error('Invalid input idsOrNodes');
158
+ throw new Error('Invalid input keysOrNodes');
159
159
  }
160
160
  sortedKeysOrNodes = sorted.map(([keyOrNode]) => keyOrNode);
161
161
  sortedData = sorted.map(([, val]) => val);
@@ -201,9 +201,8 @@ export class BST extends BinaryTree {
201
201
  * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
202
202
  * @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
203
203
  */
204
- get(nodeProperty, propertyName) {
204
+ get(nodeProperty, propertyName = 'key') {
205
205
  var _a;
206
- propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
207
206
  return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
208
207
  }
209
208
  /**
@@ -233,7 +232,7 @@ export class BST extends BinaryTree {
233
232
  * is set to `true`, the function will return an array with only one node (if
234
233
  * @returns an array of nodes (type N).
235
234
  */
236
- getNodes(nodeProperty, propertyName = 'key', onlyOne) {
235
+ getNodes(nodeProperty, propertyName = 'key', onlyOne = false) {
237
236
  if (!this.root)
238
237
  return [];
239
238
  const result = [];
@@ -288,8 +287,7 @@ export class BST extends BinaryTree {
288
287
  * @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
289
288
  * binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.
290
289
  */
291
- lesserSum(beginNode, propertyName) {
292
- propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
290
+ lesserSum(beginNode, propertyName = 'key') {
293
291
  if (typeof beginNode === 'number')
294
292
  beginNode = this.get(beginNode, 'key');
295
293
  if (!beginNode)
@@ -380,8 +378,7 @@ export class BST extends BinaryTree {
380
378
  * 'key'.
381
379
  * @returns a boolean value.
382
380
  */
383
- allGreaterNodesAdd(node, delta, propertyName) {
384
- propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
381
+ allGreaterNodesAdd(node, delta, propertyName = 'key') {
385
382
  if (typeof node === 'number')
386
383
  node = this.get(node, 'key');
387
384
  if (!node)
@@ -446,7 +443,7 @@ export class BST extends BinaryTree {
446
443
  * @returns The function `perfectlyBalance()` returns a boolean value.
447
444
  */
448
445
  perfectlyBalance() {
449
- const sorted = this.DFS('in', 'node'), n = sorted.length;
446
+ const sorted = this.dfs('in', 'node'), n = sorted.length;
450
447
  this.clear();
451
448
  if (sorted.length < 1)
452
449
  return false;
@@ -534,7 +531,7 @@ export class BST extends BinaryTree {
534
531
  /**
535
532
  * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
536
533
  * greater than, less than, or equal to the second ID.
537
- * @param {BinaryTreeNodeKey} a - a is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
534
+ * @param {BinaryTreeNodeKey} a - "a" is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
538
535
  * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
539
536
  * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
540
537
  * than), or CP.eq (equal).
@@ -11,19 +11,17 @@ import { ITreeMultiset, ITreeMultisetNode } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
12
12
  export declare class TreeMultisetNode<V = any, NEIGHBOR extends TreeMultisetNode<V, NEIGHBOR> = TreeMultisetNodeNested<V>> extends AVLTreeNode<V, NEIGHBOR> implements ITreeMultisetNode<V, NEIGHBOR> {
13
13
  /**
14
- * The constructor function initializes a BinaryTreeNode object with an key, value, and count.
14
+ * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
15
15
  * @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
16
16
  * of the binary tree node.
17
17
  * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value of the binary
18
18
  * tree node. If no value is provided, it will be `undefined`.
19
19
  * @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
20
20
  * occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
21
- * parameter when creating a new instance of the `BinaryTreeNode` class,
21
+ * parameter when creating a new instance of the `BinaryTreeNode` class.
22
22
  */
23
23
  constructor(key: BinaryTreeNodeKey, val?: V, count?: number);
24
- private _count;
25
- get count(): number;
26
- set count(v: number);
24
+ count: number;
27
25
  }
28
26
  /**
29
27
  * The only distinction between a TreeMultiset and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
@@ -80,14 +78,14 @@ export declare class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = Tree
80
78
  /**
81
79
  * The `addMany` function takes an array of node IDs or nodes and adds them to the tree multiset, returning an array of
82
80
  * the inserted nodes.
83
- * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
81
+ * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
84
82
  * objects, or null values.
85
83
  * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
86
84
  * the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()`
87
85
  * method. If provided, the `data` array should
88
86
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
89
87
  */
90
- addMany(idsOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[];
88
+ addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[];
91
89
  /**
92
90
  * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
93
91
  * constructs a balanced binary search tree using either a recursive or iterative approach.
@@ -146,7 +144,7 @@ export declare class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = Tree
146
144
  /**
147
145
  * The BFSCount function returns an array of counts from a breadth-first search of nodes.
148
146
  * @returns The BFSCount() function returns an array of numbers, specifically the count property of each node in the
149
- * BFS traversal.
147
+ * bfs traversal.
150
148
  */
151
149
  BFSCount(): number[];
152
150
  /**
@@ -165,24 +163,24 @@ export declare class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = Tree
165
163
  * traversal pattern for the Morris traversal algorithm. It can have one of three values: 'in', 'pre', or 'post'.
166
164
  * @returns The function `morrisCount` returns an array of numbers.
167
165
  */
168
- morrisCount(pattern?: 'in' | 'pre' | 'post'): number[];
166
+ morrisCount(pattern?: DFSOrderPattern): number[];
169
167
  /**
170
- * The function DFSIterativeCount performs an iterative depth-first search and returns an array of node counts based on
168
+ * The function dfsCountIterative performs an iterative depth-first search and returns an array of node counts based on
171
169
  * the specified traversal pattern.
172
170
  * @param {'in' | 'pre' | 'post'} [pattern] - The pattern parameter is a string that specifies the traversal order for
173
- * the Depth-First Search (DFS) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
174
- * @returns The DFSIterativeCount function returns an array of numbers, which represents the count property of each node
175
- * in the DFS traversal.
171
+ * the Depth-First Search (dfs) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
172
+ * @returns The dfsCountIterative function returns an array of numbers, which represents the count property of each node
173
+ * in the dfs traversal.
176
174
  */
177
- DFSIterativeCount(pattern?: 'in' | 'pre' | 'post'): number[];
175
+ dfsCountIterative(pattern?: DFSOrderPattern): number[];
178
176
  /**
179
- * The DFSCount function returns an array of counts for each node in a depth-first search traversal.
177
+ * The dfsCount function returns an array of counts for each node in a depth-first search traversal.
180
178
  * @param {DFSOrderPattern} [pattern] - The pattern parameter is an optional parameter that specifies the order in which
181
- * the Depth-First Search (DFS) algorithm should traverse the nodes. It can have one of the following values:
182
- * @returns The DFSCount function returns an array of numbers, specifically the count property of each node in the DFS
179
+ * the Depth-First Search (dfs) algorithm should traverse the nodes. It can have one of the following values:
180
+ * @returns The dfsCount function returns an array of numbers, specifically the count property of each node in the dfs
183
181
  * traversal.
184
182
  */
185
- DFSCount(pattern?: DFSOrderPattern): number[];
183
+ dfsCount(pattern?: DFSOrderPattern): number[];
186
184
  /**
187
185
  * The `lesserSumCount` function calculates the sum of the counts of all nodes in a binary tree that have a lesser
188
186
  * value than a given node.
@@ -2,24 +2,18 @@ import { CP, FamilyPosition, LoopType } from '../../types';
2
2
  import { AVLTree, AVLTreeNode } from './avl-tree';
3
3
  export class TreeMultisetNode extends AVLTreeNode {
4
4
  /**
5
- * The constructor function initializes a BinaryTreeNode object with an key, value, and count.
5
+ * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
6
6
  * @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
7
7
  * of the binary tree node.
8
8
  * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value of the binary
9
9
  * tree node. If no value is provided, it will be `undefined`.
10
10
  * @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
11
11
  * occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
12
- * parameter when creating a new instance of the `BinaryTreeNode` class,
12
+ * parameter when creating a new instance of the `BinaryTreeNode` class.
13
13
  */
14
14
  constructor(key, val, count = 1) {
15
15
  super(key, val);
16
- this._count = count;
17
- }
18
- get count() {
19
- return this._count;
20
- }
21
- set count(v) {
22
- this._count = v;
16
+ this.count = count;
23
17
  }
24
18
  }
25
19
  /**
@@ -33,7 +27,7 @@ export class TreeMultiset extends AVLTree {
33
27
  * TreeMultiset.
34
28
  */
35
29
  constructor(options) {
36
- super(Object.assign({}, options));
30
+ super(options);
37
31
  this._count = 0;
38
32
  }
39
33
  get count() {
@@ -84,8 +78,7 @@ export class TreeMultiset extends AVLTree {
84
78
  * value should be added to the binary tree. If the `count` parameter is not provided, it defaults to 1.
85
79
  * @returns The method `add` returns either the inserted node (`N`), `null`, or `undefined`.
86
80
  */
87
- add(keyOrNode, val, count) {
88
- count = count !== null && count !== void 0 ? count : 1;
81
+ add(keyOrNode, val, count = 1) {
89
82
  let inserted = undefined, newNode;
90
83
  if (keyOrNode instanceof TreeMultisetNode) {
91
84
  newNode = this.createNode(keyOrNode.key, keyOrNode.val, keyOrNode.count);
@@ -199,17 +192,17 @@ export class TreeMultiset extends AVLTree {
199
192
  /**
200
193
  * The `addMany` function takes an array of node IDs or nodes and adds them to the tree multiset, returning an array of
201
194
  * the inserted nodes.
202
- * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
195
+ * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
203
196
  * objects, or null values.
204
197
  * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
205
198
  * the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()`
206
199
  * method. If provided, the `data` array should
207
200
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
208
201
  */
209
- addMany(idsOrNodes, data) {
202
+ addMany(keysOrNodes, data) {
210
203
  const inserted = [];
211
- for (let i = 0; i < idsOrNodes.length; i++) {
212
- const keyOrNode = idsOrNodes[i];
204
+ for (let i = 0; i < keysOrNodes.length; i++) {
205
+ const keyOrNode = keysOrNodes[i];
213
206
  if (keyOrNode instanceof TreeMultisetNode) {
214
207
  inserted.push(this.add(keyOrNode.key, keyOrNode.val, keyOrNode.count));
215
208
  continue;
@@ -228,7 +221,7 @@ export class TreeMultiset extends AVLTree {
228
221
  * @returns The function `perfectlyBalance()` returns a boolean value.
229
222
  */
230
223
  perfectlyBalance() {
231
- const sorted = this.DFS('in', 'node'), n = sorted.length;
224
+ const sorted = this.dfs('in', 'node'), n = sorted.length;
232
225
  if (sorted.length < 1)
233
226
  return false;
234
227
  this.clear();
@@ -272,7 +265,7 @@ export class TreeMultiset extends AVLTree {
272
265
  * not be taken into account when removing it. If `ignoreCount` is set to `false
273
266
  * @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
274
267
  */
275
- remove(nodeOrKey, ignoreCount) {
268
+ remove(nodeOrKey, ignoreCount = false) {
276
269
  const bstDeletedResult = [];
277
270
  if (!this.root)
278
271
  return bstDeletedResult;
@@ -442,7 +435,7 @@ export class TreeMultiset extends AVLTree {
442
435
  * to `true`, the function will return only one node. If `onlyOne`
443
436
  * @returns an array of nodes that match the given nodeProperty.
444
437
  */
445
- getNodesByCount(nodeProperty, onlyOne) {
438
+ getNodesByCount(nodeProperty, onlyOne = false) {
446
439
  if (!this.root)
447
440
  return [];
448
441
  const result = [];
@@ -480,10 +473,10 @@ export class TreeMultiset extends AVLTree {
480
473
  /**
481
474
  * The BFSCount function returns an array of counts from a breadth-first search of nodes.
482
475
  * @returns The BFSCount() function returns an array of numbers, specifically the count property of each node in the
483
- * BFS traversal.
476
+ * bfs traversal.
484
477
  */
485
478
  BFSCount() {
486
- const nodes = super.BFS('node');
479
+ const nodes = super.bfs('node');
487
480
  return nodes.map(node => node.count);
488
481
  }
489
482
  /**
@@ -505,34 +498,31 @@ export class TreeMultiset extends AVLTree {
505
498
  * traversal pattern for the Morris traversal algorithm. It can have one of three values: 'in', 'pre', or 'post'.
506
499
  * @returns The function `morrisCount` returns an array of numbers.
507
500
  */
508
- morrisCount(pattern) {
509
- pattern = pattern || 'in';
501
+ morrisCount(pattern = 'in') {
510
502
  const nodes = super.morris(pattern, 'node');
511
503
  return nodes.map(node => node.count);
512
504
  }
513
505
  /**
514
- * The function DFSIterativeCount performs an iterative depth-first search and returns an array of node counts based on
506
+ * The function dfsCountIterative performs an iterative depth-first search and returns an array of node counts based on
515
507
  * the specified traversal pattern.
516
508
  * @param {'in' | 'pre' | 'post'} [pattern] - The pattern parameter is a string that specifies the traversal order for
517
- * the Depth-First Search (DFS) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
518
- * @returns The DFSIterativeCount function returns an array of numbers, which represents the count property of each node
519
- * in the DFS traversal.
509
+ * the Depth-First Search (dfs) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
510
+ * @returns The dfsCountIterative function returns an array of numbers, which represents the count property of each node
511
+ * in the dfs traversal.
520
512
  */
521
- DFSIterativeCount(pattern) {
522
- pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
523
- const nodes = super.DFSIterative(pattern, 'node');
513
+ dfsCountIterative(pattern = 'in') {
514
+ const nodes = super.dfsIterative(pattern, 'node');
524
515
  return nodes.map(node => node.count);
525
516
  }
526
517
  /**
527
- * The DFSCount function returns an array of counts for each node in a depth-first search traversal.
518
+ * The dfsCount function returns an array of counts for each node in a depth-first search traversal.
528
519
  * @param {DFSOrderPattern} [pattern] - The pattern parameter is an optional parameter that specifies the order in which
529
- * the Depth-First Search (DFS) algorithm should traverse the nodes. It can have one of the following values:
530
- * @returns The DFSCount function returns an array of numbers, specifically the count property of each node in the DFS
520
+ * the Depth-First Search (dfs) algorithm should traverse the nodes. It can have one of the following values:
521
+ * @returns The dfsCount function returns an array of numbers, specifically the count property of each node in the dfs
531
522
  * traversal.
532
523
  */
533
- DFSCount(pattern) {
534
- pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
535
- const nodes = super.DFS(pattern, 'node');
524
+ dfsCount(pattern = 'in') {
525
+ const nodes = super.dfs(pattern, 'node');
536
526
  return nodes.map(node => node.count);
537
527
  }
538
528
  /**
@@ -288,7 +288,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
288
288
  predecessor: (V | null)[][];
289
289
  };
290
290
  /**
291
- * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
291
+ * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
292
292
  * Tarjan can find cycles in directed or undirected graph
293
293
  * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
294
294
  * Tarjan solve the bi-connected components of undirected graphs;
@@ -296,7 +296,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
296
296
  * /
297
297
 
298
298
  /**
299
- * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
299
+ * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
300
300
  * Tarjan can find cycles in directed or undirected graph
301
301
  * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
302
302
  * Tarjan solve the bi-connected components of undirected graphs;
@@ -775,7 +775,7 @@ export class AbstractGraph {
775
775
  return { costs, predecessor };
776
776
  }
777
777
  /**
778
- * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
778
+ * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
779
779
  * Tarjan can find cycles in directed or undirected graph
780
780
  * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
781
781
  * Tarjan solve the bi-connected components of undirected graphs;
@@ -783,7 +783,7 @@ export class AbstractGraph {
783
783
  * /
784
784
 
785
785
  /**
786
- * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
786
+ * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
787
787
  * Tarjan can find cycles in directed or undirected graph
788
788
  * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
789
789
  * Tarjan solve the bi-connected components of undirected graphs;
@@ -804,8 +804,8 @@ export class AbstractGraph {
804
804
  * @returns The function `tarjan` returns an object with the following properties:
805
805
  */
806
806
  tarjan(needArticulationPoints, needBridges, needSCCs, needCycles) {
807
- // !! in undirected graph we will not let child visit parent when DFS
808
- // !! articulation point(in DFS search tree not in graph): (cur !== root && cur.has(child)) && (low(child) >= dfn(cur)) || (cur === root && cur.children() >= 2)
807
+ // !! in undirected graph we will not let child visit parent when dfs
808
+ // !! articulation point(in dfs search tree not in graph): (cur !== root && cur.has(child)) && (low(child) >= dfn(cur)) || (cur === root && cur.children() >= 2)
809
809
  // !! bridge: low(child) > dfn(cur)
810
810
  const defaultConfig = false;
811
811
  if (needArticulationPoints === undefined)
@@ -832,7 +832,7 @@ export class AbstractGraph {
832
832
  dfnMap.set(cur, dfn);
833
833
  lowMap.set(cur, dfn);
834
834
  const neighbors = this.getNeighbors(cur);
835
- let childCount = 0; // child in DFS tree not child in graph
835
+ let childCount = 0; // child in dfs tree not child in graph
836
836
  for (const neighbor of neighbors) {
837
837
  if (neighbor !== parent) {
838
838
  if (dfnMap.get(neighbor) === -1) {
@@ -104,13 +104,13 @@ export declare class PriorityQueue<E = any> {
104
104
  */
105
105
  sort(): E[];
106
106
  /**
107
- * The DFS function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
107
+ * The dfs function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
108
108
  * based on the specified traversal order.
109
109
  * @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
110
- * the nodes should be visited during the Depth-First Search (DFS) traversal. It can have one of the following values:
110
+ * the nodes should be visited during the Depth-First Search (dfs) traversal. It can have one of the following values:
111
111
  * @returns an array of type `(E | null)[]`.
112
112
  */
113
- DFS(dfsMode: PriorityQueueDFSOrderPattern): (E | null)[];
113
+ dfs(dfsMode: PriorityQueueDFSOrderPattern): (E | null)[];
114
114
  protected _setNodes(value: E[]): void;
115
115
  protected readonly _comparator: PriorityQueueComparator<E>;
116
116
  /**
@@ -174,13 +174,13 @@ export class PriorityQueue {
174
174
  return visitedNode;
175
175
  }
176
176
  /**
177
- * The DFS function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
177
+ * The dfs function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
178
178
  * based on the specified traversal order.
179
179
  * @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
180
- * the nodes should be visited during the Depth-First Search (DFS) traversal. It can have one of the following values:
180
+ * the nodes should be visited during the Depth-First Search (dfs) traversal. It can have one of the following values:
181
181
  * @returns an array of type `(E | null)[]`.
182
182
  */
183
- DFS(dfsMode) {
183
+ dfs(dfsMode) {
184
184
  const visitedNode = [];
185
185
  const traverse = (cur) => {
186
186
  var _a, _b, _c;
@@ -1,19 +1,14 @@
1
1
  import { AbstractBinaryTreeNodeProperties, AbstractBinaryTreeNodeProperty, BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodePropertyName, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName } from '../types';
2
2
  import { AbstractBinaryTreeNode } from '../data-structures';
3
3
  export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
4
- get key(): BinaryTreeNodeKey;
5
- set key(v: BinaryTreeNodeKey);
6
- get val(): T | undefined;
7
- set val(v: T | undefined);
4
+ key: BinaryTreeNodeKey;
5
+ val: T | undefined;
8
6
  get left(): NEIGHBOR | null | undefined;
9
7
  set left(v: NEIGHBOR | null | undefined);
10
8
  get right(): NEIGHBOR | null | undefined;
11
9
  set right(v: NEIGHBOR | null | undefined);
12
- get parent(): NEIGHBOR | null | undefined;
13
- set parent(v: NEIGHBOR | null | undefined);
10
+ parent: NEIGHBOR | null | undefined;
14
11
  get familyPosition(): FamilyPosition;
15
- get height(): number;
16
- set height(v: number);
17
12
  }
18
13
  export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
19
14
  createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N | null;
@@ -27,8 +22,8 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
27
22
  clear(): void;
28
23
  isEmpty(): boolean;
29
24
  add(key: BinaryTreeNodeKey | N, val?: N['val']): N | null | undefined;
30
- addMany(idsOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N['val'][]): (N | null | undefined)[];
31
- fill(idsOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N[] | Array<N['val']>): boolean;
25
+ addMany(keysOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N['val'][]): (N | null | undefined)[];
26
+ refill(keysOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N[] | Array<N['val']>): boolean;
32
27
  remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
33
28
  getDepth(node: N): number;
34
29
  getHeight(beginRoot?: N | null): number;
@@ -49,24 +44,24 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
49
44
  getSubTreeSize(subTreeRoot: N | null | undefined): number;
50
45
  subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
51
46
  subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
52
- BFS(): BinaryTreeNodeKey[];
53
- BFS(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
54
- BFS(nodeOrPropertyName: 'val'): N['val'][];
55
- BFS(nodeOrPropertyName: 'node'): N[];
56
- BFS(nodeOrPropertyName: 'count'): number[];
57
- BFS(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
58
- DFS(): BinaryTreeNodeKey[];
59
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
60
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
61
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
62
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
63
- DFS(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
64
- DFSIterative(): BinaryTreeNodeKey[];
65
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
66
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
67
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
68
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
69
- DFSIterative(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
47
+ bfs(): BinaryTreeNodeKey[];
48
+ bfs(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
49
+ bfs(nodeOrPropertyName: 'val'): N['val'][];
50
+ bfs(nodeOrPropertyName: 'node'): N[];
51
+ bfs(nodeOrPropertyName: 'count'): number[];
52
+ bfs(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
53
+ dfs(): BinaryTreeNodeKey[];
54
+ dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
55
+ dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
56
+ dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
57
+ dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
58
+ dfs(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
59
+ dfsIterative(): BinaryTreeNodeKey[];
60
+ dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
61
+ dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
62
+ dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
63
+ dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
64
+ dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
70
65
  levelIterative(node: N | null): BinaryTreeNodeKey[];
71
66
  levelIterative(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
72
67
  levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
@@ -1,7 +1,9 @@
1
1
  import { AVLTreeNode } from '../data-structures';
2
2
  import { IBST, IBSTNode } from './bst';
3
3
  import { BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../types';
4
- export type IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>;
4
+ export interface IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
5
+ height: number;
6
+ }
5
7
  export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
6
8
  add(key: BinaryTreeNodeKey, val?: N['val'] | null): N | null | undefined;
7
9
  remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
@@ -1,7 +1,8 @@
1
1
  import { BSTNode } from '../data-structures';
2
2
  import { IBinaryTree, IBinaryTreeNode } from './binary-tree';
3
3
  import { BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodePropertyName } from '../types';
4
- export type IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> = IBinaryTreeNode<T, NEIGHBOR>;
4
+ export interface IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> extends IBinaryTreeNode<T, NEIGHBOR> {
5
+ }
5
6
  export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
6
7
  createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
7
8
  add(key: BinaryTreeNodeKey, val?: N['val'] | null, count?: number): N | null | undefined;
@@ -9,7 +9,6 @@ export var LoopType;
9
9
  LoopType["ITERATIVE"] = "ITERATIVE";
10
10
  LoopType["RECURSIVE"] = "RECURSIVE";
11
11
  })(LoopType || (LoopType = {}));
12
- /* 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. */
13
12
  export var FamilyPosition;
14
13
  (function (FamilyPosition) {
15
14
  FamilyPosition["ROOT"] = "ROOT";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.34.8",
3
+ "version": "1.34.9",
4
4
  "description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.",
5
5
  "main": "dist/index.js",
6
6
  "module": "lib/index.js",
@@ -23,7 +23,7 @@
23
23
  "fix:test": "npm run lint:test && npm run format:test",
24
24
  "fix": "npm run fix:src && npm run fix:test",
25
25
  "update:test-deps": "npm i avl-tree-typed binary-tree-typed bst-typed heap-typed --save-dev",
26
- "update-all:test-deps": "npm i avl-tree-typed binary-tree-typed bst-typed deque-typed directed-graph-typed doubly-linked-list-typed graph-typed heap-typed linked-list-typed max-heap-typed max-priority-queue-typed min-heap-typed min-priority-queue-typed priority-queue-typed singly-linked-list-typed stack-typed tree-multiset-typed trie-typed undirected-graph-typed queue-typed --save-dev",
26
+ "install:individuals": "npm i avl-tree-typed binary-tree-typed bst-typed deque-typed directed-graph-typed doubly-linked-list-typed graph-typed heap-typed linked-list-typed max-heap-typed max-priority-queue-typed min-heap-typed min-priority-queue-typed priority-queue-typed singly-linked-list-typed stack-typed tree-multiset-typed trie-typed undirected-graph-typed queue-typed --save-dev",
27
27
  "test": "jest",
28
28
  "check:deps": "dependency-cruiser src",
29
29
  "changelog": "auto-changelog",
@@ -50,17 +50,17 @@
50
50
  "@typescript-eslint/eslint-plugin": "^6.7.4",
51
51
  "@typescript-eslint/parser": "^6.7.4",
52
52
  "auto-changelog": "^2.4.0",
53
- "avl-tree-typed": "^1.34.1",
53
+ "avl-tree-typed": "^1.34.8",
54
54
  "benchmark": "^2.1.4",
55
- "binary-tree-typed": "^1.34.1",
56
- "bst-typed": "^1.34.1",
55
+ "binary-tree-typed": "^1.34.8",
56
+ "bst-typed": "^1.34.8",
57
57
  "dependency-cruiser": "^14.1.0",
58
58
  "eslint": "^8.50.0",
59
59
  "eslint-config-prettier": "^9.0.0",
60
60
  "eslint-import-resolver-alias": "^1.1.2",
61
61
  "eslint-import-resolver-typescript": "^3.6.1",
62
62
  "eslint-plugin-import": "^2.28.1",
63
- "heap-typed": "^1.34.1",
63
+ "heap-typed": "^1.34.8",
64
64
  "istanbul-badges-readme": "^1.8.5",
65
65
  "jest": "^29.7.0",
66
66
  "prettier": "^3.0.3",