directed-graph-typed 1.51.8 → 1.52.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 (106) hide show
  1. package/dist/data-structures/base/index.d.ts +2 -1
  2. package/dist/data-structures/base/index.js +2 -1
  3. package/dist/data-structures/base/iterable-element-base.d.ts +171 -0
  4. package/dist/data-structures/base/iterable-element-base.js +225 -0
  5. package/dist/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  6. package/dist/data-structures/base/{iterable-base.js → iterable-entry-base.js} +12 -189
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
  10. package/dist/data-structures/binary-tree/avl-tree.js +78 -59
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -226
  12. package/dist/data-structures/binary-tree/binary-tree.js +475 -363
  13. package/dist/data-structures/binary-tree/bst.d.ts +192 -202
  14. package/dist/data-structures/binary-tree/bst.js +207 -249
  15. package/dist/data-structures/binary-tree/rb-tree.d.ts +73 -74
  16. package/dist/data-structures/binary-tree/rb-tree.js +107 -98
  17. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
  18. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
  19. package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
  20. package/dist/data-structures/graph/abstract-graph.js +10 -15
  21. package/dist/data-structures/hash/hash-map.d.ts +33 -40
  22. package/dist/data-structures/hash/hash-map.js +40 -55
  23. package/dist/data-structures/heap/heap.d.ts +43 -114
  24. package/dist/data-structures/heap/heap.js +59 -127
  25. package/dist/data-structures/heap/max-heap.d.ts +50 -4
  26. package/dist/data-structures/heap/max-heap.js +76 -10
  27. package/dist/data-structures/heap/min-heap.d.ts +51 -5
  28. package/dist/data-structures/heap/min-heap.js +68 -11
  29. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  30. package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
  31. package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  32. package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
  33. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  34. package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
  35. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  36. package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
  37. package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
  38. package/dist/data-structures/priority-queue/priority-queue.js +70 -1
  39. package/dist/data-structures/queue/deque.d.ts +21 -20
  40. package/dist/data-structures/queue/deque.js +29 -23
  41. package/dist/data-structures/queue/queue.d.ts +8 -28
  42. package/dist/data-structures/queue/queue.js +15 -31
  43. package/dist/data-structures/stack/stack.d.ts +17 -22
  44. package/dist/data-structures/stack/stack.js +25 -24
  45. package/dist/data-structures/trie/trie.d.ts +19 -14
  46. package/dist/data-structures/trie/trie.js +27 -16
  47. package/dist/interfaces/binary-tree.d.ts +7 -7
  48. package/dist/types/common.d.ts +1 -2
  49. package/dist/types/data-structures/base/base.d.ts +5 -2
  50. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
  51. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
  52. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  53. package/dist/types/data-structures/binary-tree/bst.d.ts +4 -5
  54. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
  55. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  56. package/dist/types/data-structures/heap/heap.d.ts +3 -2
  57. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  58. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  59. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  60. package/dist/types/data-structures/queue/deque.d.ts +3 -2
  61. package/dist/types/data-structures/queue/queue.d.ts +2 -1
  62. package/dist/types/data-structures/stack/stack.d.ts +2 -1
  63. package/dist/types/data-structures/trie/trie.d.ts +3 -2
  64. package/dist/utils/utils.js +3 -5
  65. package/package.json +2 -2
  66. package/src/data-structures/base/index.ts +2 -1
  67. package/src/data-structures/base/iterable-element-base.ts +250 -0
  68. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  69. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +144 -95
  70. package/src/data-structures/binary-tree/avl-tree.ts +96 -69
  71. package/src/data-structures/binary-tree/binary-tree.ts +535 -403
  72. package/src/data-structures/binary-tree/bst.ts +247 -277
  73. package/src/data-structures/binary-tree/rb-tree.ts +123 -103
  74. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
  75. package/src/data-structures/graph/abstract-graph.ts +10 -10
  76. package/src/data-structures/hash/hash-map.ts +46 -53
  77. package/src/data-structures/heap/heap.ts +71 -152
  78. package/src/data-structures/heap/max-heap.ts +88 -13
  79. package/src/data-structures/heap/min-heap.ts +78 -15
  80. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  81. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  82. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  83. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  84. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  85. package/src/data-structures/queue/deque.ts +37 -26
  86. package/src/data-structures/queue/queue.ts +23 -36
  87. package/src/data-structures/stack/stack.ts +31 -26
  88. package/src/data-structures/trie/trie.ts +35 -20
  89. package/src/interfaces/binary-tree.ts +9 -9
  90. package/src/types/common.ts +1 -2
  91. package/src/types/data-structures/base/base.ts +14 -6
  92. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
  93. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
  94. package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
  95. package/src/types/data-structures/binary-tree/bst.ts +4 -5
  96. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
  97. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
  98. package/src/types/data-structures/heap/heap.ts +4 -1
  99. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  100. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  101. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  102. package/src/types/data-structures/queue/deque.ts +3 -1
  103. package/src/types/data-structures/queue/queue.ts +3 -1
  104. package/src/types/data-structures/stack/stack.ts +3 -1
  105. package/src/types/data-structures/trie/trie.ts +3 -1
  106. package/src/utils/utils.ts +3 -3
@@ -9,7 +9,6 @@ import type {
9
9
  BinaryTreeDeleteResult,
10
10
  BSTNKeyOrNode,
11
11
  BTNCallback,
12
- Comparable,
13
12
  IterationType,
14
13
  KeyOrNodeOrEntry,
15
14
  RBTNColor,
@@ -17,11 +16,12 @@ import type {
17
16
  TreeMultiMapNodeNested,
18
17
  TreeMultiMapOptions
19
18
  } from '../../types';
19
+ import { BTNEntry } from '../../types';
20
20
  import { IBinaryTree } from '../../interfaces';
21
21
  import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
22
22
 
23
23
  export class TreeMultiMapNode<
24
- K extends Comparable,
24
+ K = any,
25
25
  V = any,
26
26
  NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>
27
27
  > extends RedBlackTreeNode<K, V, NODE> {
@@ -63,25 +63,29 @@ export class TreeMultiMapNode<
63
63
  }
64
64
 
65
65
  export class TreeMultiMap<
66
- K extends Comparable,
66
+ K = any,
67
67
  V = any,
68
+ R = BTNEntry<K, V>,
68
69
  NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>,
69
- TREE extends TreeMultiMap<K, V, NODE, TREE> = TreeMultiMap<K, V, NODE, TreeMultiMapNested<K, V, NODE>>
70
+ TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>
70
71
  >
71
- extends RedBlackTree<K, V, NODE, TREE>
72
- implements IBinaryTree<K, V, NODE, TREE> {
72
+ extends RedBlackTree<K, V, R, NODE, TREE>
73
+ implements IBinaryTree<K, V, R, NODE, TREE> {
73
74
  /**
74
- * The constructor function initializes a new instance of the TreeMultiMap class with optional
75
- * initial keys, nodes, or entries.
76
- * @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
77
- * contain keys, nodes, or entries. It is used to initialize the TreeMultiMap with the provided keys,
78
- * nodes, or entries.
79
- * @param [options] - The `options` parameter is an optional object that can be passed to the
80
- * constructor. It allows you to customize the behavior of the `TreeMultiMap` instance.
75
+ * The constructor function initializes a TreeMultiMap object with optional initial data.
76
+ * @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
77
+ * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
78
+ * TreeMultiMap with initial data.
79
+ * @param [options] - The `options` parameter is an optional object that can be used to customize the
80
+ * behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
81
+ * `compareValues`, which are functions used to compare keys and values respectively.
81
82
  */
82
- constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: TreeMultiMapOptions<K>) {
83
+ constructor(
84
+ keysOrNodesOrEntriesOrRawElements: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [],
85
+ options?: TreeMultiMapOptions<K, V, R>
86
+ ) {
83
87
  super([], options);
84
- if (keysOrNodesOrEntries) this.addMany(keysOrNodesOrEntries);
88
+ if (keysOrNodesOrEntriesOrRawElements) this.addMany(keysOrNodesOrEntriesOrRawElements);
85
89
  }
86
90
 
87
91
  protected _count = 0;
@@ -117,16 +121,15 @@ export class TreeMultiMap<
117
121
  /**
118
122
  * The function creates a new TreeMultiMapNode with the specified key, value, color, and count.
119
123
  * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
120
- * which is a generic type representing the key type of the node.
121
- * @param {V} [value] - The `value` parameter represents the value associated with the key in the
122
- * node. It is an optional parameter, which means it can be omitted when calling the `createNode`
123
- * function. If provided, it should be of type `V`.
124
+ * which is a generic type representing the type of keys in the tree.
125
+ * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
126
+ * associated with the key in the node. It is of type `V`, which can be any data type.
124
127
  * @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
125
128
  * a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
126
129
  * @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
127
130
  * the tree. It is an optional parameter and is used to keep track of the number of values associated
128
131
  * with a key in the tree.
129
- * @returns A new instance of the TreeMultiMapNode class is being returned.
132
+ * @returns A new instance of the TreeMultiMapNode class, casted as NODE.
130
133
  */
131
134
  override createNode(key: K, value?: V, color: RBTNColor = 'BLACK', count?: number): NODE {
132
135
  return new TreeMultiMapNode(key, value, count, color) as NODE;
@@ -135,64 +138,67 @@ export class TreeMultiMap<
135
138
  /**
136
139
  * The function creates a new instance of a TreeMultiMap with the specified options and returns it.
137
140
  * @param [options] - The `options` parameter is an optional object that contains additional
138
- * configuration options for creating the `TreeMultiMap`. It can include properties such as
139
- * `keyComparator`, `valueComparator`, `allowDuplicates`, etc.
141
+ * configuration options for creating the `TreeMultiMap`. It is of type `TreeMultiMapOptions<K, V,
142
+ * R>`.
140
143
  * @returns a new instance of the `TreeMultiMap` class, with the provided options merged with the
141
- * existing `iterationType` option. The returned value is casted as `TREE`.
144
+ * existing `iterationType` property. The returned value is casted as `TREE`.
142
145
  */
143
- override createTree(options?: TreeMultiMapOptions<K>): TREE {
144
- return new TreeMultiMap<K, V, NODE, TREE>([], {
146
+ override createTree(options?: TreeMultiMapOptions<K, V, R>): TREE {
147
+ return new TreeMultiMap<K, V, R, NODE, TREE>([], {
145
148
  iterationType: this.iterationType,
146
149
  ...options
147
150
  }) as TREE;
148
151
  }
149
152
 
150
153
  /**
151
- * The function `keyValueOrEntryToNode` takes a key, value, and count and returns a node if the input
152
- * is valid.
153
- * @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be of type `KeyOrNodeOrEntry<K, V,
154
- * NODE>`. It can accept three types of values:
155
- * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
156
- * value associated with a key in a key-value pair.
157
- * @param [count=1] - The count parameter is an optional parameter that specifies the number of times
158
- * the key-value pair should be added to the node. If not provided, it defaults to 1.
159
- * @returns a NODE object or undefined.
154
+ * The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
155
+ * node based on the input.
156
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
157
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
158
+ * @param {V} [value] - The `value` parameter is an optional value that represents the value
159
+ * associated with the key in the node. It is used when creating a new node or updating the value of
160
+ * an existing node.
161
+ * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
162
+ * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
163
+ * @returns either a NODE object or undefined.
160
164
  */
161
- override keyValueOrEntryToNode(
162
- keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>,
165
+ override keyValueOrEntryOrRawElementToNode(
166
+ keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>,
163
167
  value?: V,
164
168
  count = 1
165
169
  ): NODE | undefined {
166
- let node: NODE | undefined;
167
- if (keyOrNodeOrEntry === undefined || keyOrNodeOrEntry === null) {
168
- return;
169
- } else if (this.isNode(keyOrNodeOrEntry)) {
170
- node = keyOrNodeOrEntry;
171
- } else if (this.isEntry(keyOrNodeOrEntry)) {
172
- const [key, value] = keyOrNodeOrEntry;
173
- if (key === undefined || key === null) {
174
- return;
175
- } else {
176
- node = this.createNode(key, value, 'BLACK', count);
177
- }
178
- } else if (!this.isNode(keyOrNodeOrEntry)) {
179
- node = this.createNode(keyOrNodeOrEntry, value, 'BLACK', count);
180
- } else {
181
- return;
170
+ if (keyOrNodeOrEntryOrRawElement === undefined || keyOrNodeOrEntryOrRawElement === null) return;
171
+
172
+ if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
173
+
174
+ if (this.toEntryFn) {
175
+ const [key] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
176
+ if (key) return this.getNodeByKey(key);
182
177
  }
183
- return node;
178
+
179
+ if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
180
+ const [key, value] = keyOrNodeOrEntryOrRawElement;
181
+ if (key === undefined || key === null) return;
182
+ else return this.createNode(key, value, 'BLACK', count);
183
+ }
184
+
185
+ if (this.isKey(keyOrNodeOrEntryOrRawElement))
186
+ return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'BLACK', count);
187
+
188
+ return;
184
189
  }
185
190
 
186
191
  /**
187
- * The function "isNode" checks if a given key, node, or entry is an instance of the TreeMultiMapNode
188
- * class.
189
- * @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be of type `KeyOrNodeOrEntry<K, V,
190
- * NODE>`.
191
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntry` is an instance
192
- * of the `TreeMultiMapNode` class.
192
+ * The function checks if the input is an instance of the TreeMultiMapNode class.
193
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
194
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
195
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
196
+ * an instance of the `TreeMultiMapNode` class.
193
197
  */
194
- override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE {
195
- return keyOrNodeOrEntry instanceof TreeMultiMapNode;
198
+ override isNode(
199
+ keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>
200
+ ): keyOrNodeOrEntryOrRawElement is NODE {
201
+ return keyOrNodeOrEntryOrRawElement instanceof TreeMultiMapNode;
196
202
  }
197
203
 
198
204
  /**
@@ -204,17 +210,20 @@ export class TreeMultiMap<
204
210
  * Time Complexity: O(log n)
205
211
  * Space Complexity: O(1)
206
212
  *
207
- * The function overrides the add method in TypeScript and adds a new node to the data structure.
208
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can accept three types of values:
213
+ * The function overrides the add method of a class and adds a new node to a data structure, updating
214
+ * the count and returning a boolean indicating success.
215
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
216
+ * `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
209
217
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
210
- * data structure.
218
+ * data structure. It is an optional parameter, so it can be omitted if not needed.
211
219
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
212
- * be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
213
- * be added once. However, you can specify a different value for `count` if you want to add
214
- * @returns a boolean value.
220
+ * be added to the data structure. By default, it is set to 1, meaning that if no value is provided
221
+ * for `count`, the key-value pair will be added once.
222
+ * @returns The method is returning a boolean value. It returns true if the addition of the new node
223
+ * was successful, and false otherwise.
215
224
  */
216
- override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count = 1): boolean {
217
- const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value, count);
225
+ override add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count = 1): boolean {
226
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
218
227
  const orgCount = newNode?.count || 0;
219
228
  const isSuccessAdded = super.add(newNode);
220
229
 
@@ -235,20 +244,18 @@ export class TreeMultiMap<
235
244
  * Time Complexity: O(log n)
236
245
  * Space Complexity: O(1)
237
246
  *
238
- * The `delete` function in a TypeScript class is used to delete nodes from a binary tree based on a
239
- * given identifier, and it returns an array of results containing information about the deleted
240
- * nodes.
241
- * @param {ReturnType<C> | null | undefined} identifier - The identifier parameter is the value used
242
- * to identify the node to be deleted. It can be of any type that is returned by the callback
243
- * function. It can also be null or undefined if no node needs to be deleted.
244
- * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as
245
- * input and returns a value of type `ReturnType<C>`. It is used to determine if a node matches the
246
- * identifier for deletion. If no callback is provided, the `_DEFAULT_CALLBACK` function is
247
- * used
248
- * @param [ignoreCount=false] - A boolean value indicating whether to ignore the count of the target
249
- * node when performing deletion. If set to true, the count of the target node will not be considered
250
- * and the node will be deleted regardless of its count. If set to false (default), the count of the
251
- * target node will be decremented
247
+ * The function `delete` is used to remove a node from a binary tree and fix the tree if necessary.
248
+ * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value or
249
+ * key that is used to identify the node that needs to be deleted from the binary tree. It can be of
250
+ * any type that is returned by the callback function `C`. It can also be `null` or `undefined` if
251
+ * the node to be deleted
252
+ * @param {C} callback - The `callback` parameter is a function that is used to determine the
253
+ * equality of nodes in the binary tree. It is optional and has a default value of
254
+ * `this._DEFAULT_CALLBACK`. The `callback` function is used to compare nodes when searching for a
255
+ * specific node or when performing other operations on the
256
+ * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
257
+ * being deleted. If set to true, the count of the node will not be taken into account when deleting
258
+ * it. If set to false, the count of the node will be decremented by 1 before deleting it.
252
259
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
253
260
  */
254
261
  override delete<C extends BTNCallback<NODE>>(
@@ -372,10 +379,12 @@ export class TreeMultiMap<
372
379
  *
373
380
  * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
374
381
  * tree using either a recursive or iterative approach.
375
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
376
- * type of iteration to use when building the balanced binary search tree. It can have two possible
377
- * values:
378
- * @returns a boolean value.
382
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
383
+ * specifies the type of iteration to use when building the balanced binary search tree. It has a
384
+ * default value of `this.iterationType`, which means it will use the iteration type specified by the
385
+ * `iterationType` property of the current object.
386
+ * @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
387
+ * balancing operation is successful, and `false` if there are no nodes to balance.
379
388
  */
380
389
  override perfectlyBalance(iterationType: IterationType = this.iterationType): boolean {
381
390
  const sorted = this.dfs(node => node, 'IN'),
@@ -434,19 +443,27 @@ export class TreeMultiMap<
434
443
  }
435
444
 
436
445
  /**
437
- * The function swaps the properties of two nodes in a binary search tree.
438
- * @param srcNode - The source node that needs to be swapped with the destination node. It can be
439
- * either a key or a node object.
440
- * @param destNode - The `destNode` parameter is the node in the binary search tree where the
441
- * properties will be swapped with the `srcNode`.
446
+ * Time Complexity: O(1)
447
+ * Space Complexity: O(1)
448
+ */
449
+
450
+ /**
451
+ * Time Complexity: O(1)
452
+ * Space Complexity: O(1)
453
+ *
454
+ * The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
455
+ * in a binary search tree.
456
+ * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
457
+ * that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
458
+ * instance of the `BSTNKeyOrNode<K, NODE>` class.
459
+ * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
460
+ * node where the properties will be swapped with the source node.
442
461
  * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
443
- * If both `srcNode` and `destNode` are valid nodes, the method swaps their `key`, `value`, `count`,
444
- * and `color` properties. If the swapping is successful, the method returns the modified `destNode`.
445
- * If either `srcNode` or `destNode` is
462
+ * If either `srcNode` or `destNode` is undefined, it returns undefined.
446
463
  */
447
464
  protected override _swapProperties(
448
- srcNode: BSTNKeyOrNode<K, NODE>,
449
- destNode: BSTNKeyOrNode<K, NODE>
465
+ srcNode: R | BSTNKeyOrNode<K, NODE>,
466
+ destNode: R | BSTNKeyOrNode<K, NODE>
450
467
  ): NODE | undefined {
451
468
  srcNode = this.ensureNode(srcNode);
452
469
  destNode = this.ensureNode(destNode);
@@ -473,14 +490,22 @@ export class TreeMultiMap<
473
490
  }
474
491
 
475
492
  /**
493
+ * Time Complexity: O(1)
494
+ * Space Complexity: O(1)
495
+ */
496
+
497
+ /**
498
+ * Time Complexity: O(1)
499
+ * Space Complexity: O(1)
500
+ *
476
501
  * The function replaces an old node with a new node and updates the count property of the new node.
477
- * @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
478
- * needs to be replaced in the data structure.
479
- * @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
502
+ * @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace in the data
503
+ * structure.
504
+ * @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
480
505
  * @returns The method is returning the result of calling the `_replaceNode` method from the
481
- * superclass, after updating the `count` property of the `newNode` object.
506
+ * superclass, which is of type `NODE`.
482
507
  */
483
- protected _replaceNode(oldNode: NODE, newNode: NODE): NODE {
508
+ protected override _replaceNode(oldNode: NODE, newNode: NODE): NODE {
484
509
  newNode.count = oldNode.count + newNode.count;
485
510
  return super._replaceNode(oldNode, newNode);
486
511
  }
@@ -496,9 +496,9 @@ export abstract class AbstractGraph<
496
496
 
497
497
  /**
498
498
  * Dijkstra algorithm time: O(VE) space: O(VO + EO)
499
- * /
499
+ */
500
500
 
501
- /**
501
+ /**
502
502
  * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
503
503
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
504
504
  */
@@ -639,9 +639,9 @@ export abstract class AbstractGraph<
639
639
  * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edgeMap.
640
640
  * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
641
641
  *
642
- * /
642
+ */
643
643
 
644
- /**
644
+ /**
645
645
  * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
646
646
  * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
647
647
  */
@@ -777,9 +777,9 @@ export abstract class AbstractGraph<
777
777
  * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
778
778
  * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
779
779
  * one to rest pairs
780
- * /
780
+ */
781
781
 
782
- /**
782
+ /**
783
783
  * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
784
784
  * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
785
785
  *
@@ -887,9 +887,9 @@ export abstract class AbstractGraph<
887
887
 
888
888
  /**
889
889
  * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
890
- * /
890
+ */
891
891
 
892
- /**
892
+ /**
893
893
  * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
894
894
  * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
895
895
  */
@@ -907,9 +907,9 @@ export abstract class AbstractGraph<
907
907
  * Not support graph with negative weight cycle
908
908
  * all pairs
909
909
  * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
910
- * /
910
+ */
911
911
 
912
- /**
912
+ /**
913
913
  * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
914
914
  * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
915
915
  *