heap-typed 1.52.6 → 1.52.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/constants/index.d.ts +4 -0
  2. package/dist/constants/index.js +8 -0
  3. package/dist/data-structures/base/iterable-element-base.d.ts +8 -1
  4. package/dist/data-structures/base/iterable-element-base.js +10 -1
  5. package/dist/data-structures/base/iterable-entry-base.d.ts +8 -1
  6. package/dist/data-structures/base/iterable-entry-base.js +10 -10
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +23 -24
  10. package/dist/data-structures/binary-tree/avl-tree.js +71 -64
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -2
  12. package/dist/data-structures/binary-tree/binary-tree.d.ts +534 -402
  13. package/dist/data-structures/binary-tree/binary-tree.js +668 -597
  14. package/dist/data-structures/binary-tree/bst.d.ts +72 -65
  15. package/dist/data-structures/binary-tree/bst.js +115 -113
  16. package/dist/data-structures/binary-tree/rb-tree.d.ts +21 -24
  17. package/dist/data-structures/binary-tree/rb-tree.js +40 -39
  18. package/dist/data-structures/binary-tree/segment-tree.d.ts +2 -2
  19. package/dist/data-structures/binary-tree/segment-tree.js +2 -2
  20. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
  21. package/dist/data-structures/binary-tree/tree-multi-map.js +44 -43
  22. package/dist/data-structures/graph/abstract-graph.d.ts +2 -2
  23. package/dist/data-structures/graph/abstract-graph.js +7 -4
  24. package/dist/data-structures/graph/directed-graph.d.ts +2 -2
  25. package/dist/data-structures/graph/directed-graph.js +4 -2
  26. package/dist/data-structures/graph/undirected-graph.d.ts +2 -2
  27. package/dist/data-structures/hash/hash-map.d.ts +2 -2
  28. package/dist/data-structures/hash/hash-map.js +1 -1
  29. package/dist/data-structures/heap/heap.js +3 -3
  30. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  31. package/dist/data-structures/linked-list/doubly-linked-list.js +7 -7
  32. package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  33. package/dist/data-structures/linked-list/singly-linked-list.js +6 -6
  34. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  35. package/dist/data-structures/matrix/matrix.d.ts +2 -2
  36. package/dist/data-structures/matrix/navigator.d.ts +2 -2
  37. package/dist/data-structures/matrix/navigator.js +4 -2
  38. package/dist/data-structures/queue/deque.d.ts +3 -3
  39. package/dist/data-structures/queue/deque.js +29 -29
  40. package/dist/data-structures/queue/queue.d.ts +1 -1
  41. package/dist/data-structures/stack/stack.d.ts +2 -2
  42. package/dist/data-structures/trie/trie.d.ts +2 -2
  43. package/dist/data-structures/trie/trie.js +1 -1
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +1 -0
  46. package/dist/interfaces/binary-tree.d.ts +2 -2
  47. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
  48. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -6
  49. package/package.json +2 -2
  50. package/src/constants/index.ts +4 -0
  51. package/src/data-structures/base/iterable-element-base.ts +11 -1
  52. package/src/data-structures/base/iterable-entry-base.ts +11 -19
  53. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
  54. package/src/data-structures/binary-tree/avl-tree.ts +69 -71
  55. package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
  56. package/src/data-structures/binary-tree/binary-tree.ts +697 -725
  57. package/src/data-structures/binary-tree/bst.ts +123 -129
  58. package/src/data-structures/binary-tree/rb-tree.ts +44 -46
  59. package/src/data-structures/binary-tree/segment-tree.ts +2 -2
  60. package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
  61. package/src/data-structures/graph/abstract-graph.ts +6 -6
  62. package/src/data-structures/graph/directed-graph.ts +4 -4
  63. package/src/data-structures/graph/undirected-graph.ts +2 -2
  64. package/src/data-structures/hash/hash-map.ts +3 -3
  65. package/src/data-structures/heap/heap.ts +3 -3
  66. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
  67. package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
  68. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  69. package/src/data-structures/matrix/matrix.ts +2 -2
  70. package/src/data-structures/matrix/navigator.ts +4 -4
  71. package/src/data-structures/queue/deque.ts +31 -31
  72. package/src/data-structures/queue/queue.ts +1 -1
  73. package/src/data-structures/stack/stack.ts +2 -2
  74. package/src/data-structures/trie/trie.ts +3 -3
  75. package/src/index.ts +2 -1
  76. package/src/interfaces/binary-tree.ts +3 -3
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
@@ -1,14 +1,15 @@
1
1
  import type {
2
2
  BinaryTreeDeleteResult,
3
- BTNCallback,
4
3
  BTNKeyOrNodeOrEntry,
4
+ BTNPredicate,
5
5
  CRUD,
6
+ OptBSTN,
6
7
  RBTNColor,
7
8
  RBTreeOptions,
8
9
  RedBlackTreeNested,
9
- RedBlackTreeNodeNested
10
+ RedBlackTreeNodeNested,
11
+ BTNEntry
10
12
  } from '../../types';
11
- import { BTNEntry } from '../../types';
12
13
  import { BST, BSTNode } from './bst';
13
14
  import { IBinaryTree } from '../../interfaces';
14
15
 
@@ -64,7 +65,7 @@ export class RedBlackTree<
64
65
  {
65
66
  /**
66
67
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
67
- * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
68
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
68
69
  * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
69
70
  * initialize the RBTree with the provided elements.
70
71
  * @param [options] - The `options` parameter is an optional object that can be passed to the
@@ -73,15 +74,15 @@ export class RedBlackTree<
73
74
  * depend on the implementation
74
75
  */
75
76
  constructor(
76
- keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
77
+ keysOrNodesOrEntriesOrRaws: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
77
78
  options?: RBTreeOptions<K, V, R>
78
79
  ) {
79
80
  super([], options);
80
81
 
81
82
  this._root = this.NIL;
82
83
 
83
- if (keysOrNodesOrEntriesOrRawElements) {
84
- this.addMany(keysOrNodesOrEntriesOrRawElements);
84
+ if (keysOrNodesOrEntriesOrRaws) {
85
+ this.addMany(keysOrNodesOrEntriesOrRaws);
85
86
  }
86
87
  }
87
88
 
@@ -122,6 +123,8 @@ export class RedBlackTree<
122
123
  override createTree(options?: RBTreeOptions<K, V, R>): TREE {
123
124
  return new RedBlackTree<K, V, R, NODE, TREE>([], {
124
125
  iterationType: this.iterationType,
126
+ comparator: this._comparator,
127
+ toEntryFn: this._toEntryFn,
125
128
  ...options
126
129
  }) as TREE;
127
130
  }
@@ -131,15 +134,13 @@ export class RedBlackTree<
131
134
  * Space Complexity: O(1)
132
135
  *
133
136
  * The function checks if the input is an instance of the RedBlackTreeNode class.
134
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
135
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
136
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
137
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
138
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
139
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
137
140
  * an instance of the `RedBlackTreeNode` class.
138
141
  */
139
- override isNode(
140
- keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
141
- ): keyOrNodeOrEntryOrRawElement is NODE {
142
- return keyOrNodeOrEntryOrRawElement instanceof RedBlackTreeNode;
142
+ override isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE {
143
+ return keyOrNodeOrEntryOrRaw instanceof RedBlackTreeNode;
143
144
  }
144
145
 
145
146
  // /**
@@ -153,27 +154,27 @@ export class RedBlackTree<
153
154
  // *
154
155
  // * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
155
156
  // * valid, otherwise it returns undefined.
156
- // * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
157
- // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
157
+ // * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRaw - The key, value, or entry to convert.
158
+ // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRaw` is a key).
158
159
  // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
159
160
  // */
160
- // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
161
+ // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): NODE | undefined {
161
162
  //
162
- // if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
163
- // if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
163
+ // if (keyOrNodeOrEntryOrRaw === null || keyOrNodeOrEntryOrRaw === undefined) return;
164
+ // if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
164
165
  //
165
- // if (this.toEntryFn) {
166
- // const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
166
+ // if (this._toEntryFn) {
167
+ // const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw as R);
167
168
  // if (this.isKey(key)) return this.createNode(key, entryValue ?? value, 'RED');
168
169
  // }
169
170
  //
170
- // if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
171
- // const [key, value] = keyOrNodeOrEntryOrRawElement;
171
+ // if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
172
+ // const [key, value] = keyOrNodeOrEntryOrRaw;
172
173
  // if (key === undefined || key === null) return;
173
174
  // else return this.createNode(key, value, 'RED');
174
175
  // }
175
176
  //
176
- // if (this.isKey(keyOrNodeOrEntryOrRawElement)) return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'RED');
177
+ // if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, 'RED');
177
178
  //
178
179
  // return ;
179
180
  // }
@@ -196,8 +197,8 @@ export class RedBlackTree<
196
197
  *
197
198
  * The function adds a new node to a binary search tree and returns true if the node was successfully
198
199
  * added.
199
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
200
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
200
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
201
+ * `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
201
202
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
202
203
  * the key in the data structure. It represents the value that you want to add or update in the data
203
204
  * structure.
@@ -205,8 +206,8 @@ export class RedBlackTree<
205
206
  * the method returns true. If the node already exists and its value is updated, the method also
206
207
  * returns true. If the node cannot be added or updated, the method returns false.
207
208
  */
208
- override add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
209
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
209
+ override add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): boolean {
210
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value);
210
211
  if (!this.isRealNode(newNode)) return false;
211
212
 
212
213
  const insertStatus = this._insert(newNode);
@@ -227,26 +228,23 @@ export class RedBlackTree<
227
228
  * Time Complexity: O(log n)
228
229
  * Space Complexity: O(1)
229
230
  *
230
- * The function overrides the delete method of a binary tree data structure, allowing for the
231
- * deletion of a node and maintaining the balance of the tree.
232
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
233
- * that identifies the node to be deleted from the binary tree. It can be of any type that is
234
- * returned by the callback function `C`. It can also be `null` or `undefined` if there is no node to
235
- * delete.
236
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
237
- * equality of nodes in the binary tree. It is optional and has a default value of
238
- * `this._DEFAULT_CALLBACK`. The type of the `callback` parameter is `C`, which is a generic type
239
- * that extends the `BTNCallback
240
- * @returns an array of BinaryTreeDeleteResult<NODE> objects.
231
+ * The function overrides the delete method in a binary tree data structure to remove a node based on
232
+ * a given predicate and maintain the binary search tree properties.
233
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
234
+ * parameter in the `override delete` method is used to specify the condition or key based on which a
235
+ * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
236
+ * function that determines which node(s) should be deleted.
237
+ * @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
238
+ * objects. Each object in the array contains information about the deleted node and whether
239
+ * balancing is needed.
241
240
  */
242
- override delete<C extends BTNCallback<NODE>>(
243
- identifier: ReturnType<C> | null | undefined,
244
- callback: C = this._DEFAULT_CALLBACK as C
245
- ): BinaryTreeDeleteResult<NODE>[] {
246
- if (identifier === null) return [];
241
+ override delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[] {
242
+ if (predicate === null) return [];
243
+
247
244
  const results: BinaryTreeDeleteResult<NODE>[] = [];
248
- callback = this._ensureCallback(identifier, callback);
249
- const nodeToDelete = this.isRealNode(identifier) ? identifier : this.getNode(identifier, callback);
245
+ let nodeToDelete: OptBSTN<NODE>;
246
+ if (this._isPredicated(predicate)) nodeToDelete = this.getNode(predicate);
247
+ else nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
250
248
 
251
249
  if (!nodeToDelete) {
252
250
  return results;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
 
@@ -1,22 +1,23 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type {
9
9
  BinaryTreeDeleteResult,
10
10
  BSTNKeyOrNode,
11
- BTNCallback,
12
11
  BTNKeyOrNodeOrEntry,
12
+ BTNPredicate,
13
13
  IterationType,
14
+ OptBSTN,
14
15
  RBTNColor,
15
16
  TreeMultiMapNested,
16
17
  TreeMultiMapNodeNested,
17
- TreeMultiMapOptions
18
+ TreeMultiMapOptions,
19
+ BTNEntry
18
20
  } from '../../types';
19
- import { BTNEntry } from '../../types';
20
21
  import { IBinaryTree } from '../../interfaces';
21
22
  import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
22
23
 
@@ -74,7 +75,7 @@ export class TreeMultiMap<
74
75
  {
75
76
  /**
76
77
  * The constructor function initializes a TreeMultiMap object with optional initial data.
77
- * @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
78
+ * @param keysOrNodesOrEntriesOrRaws - The parameter `keysOrNodesOrEntriesOrRaws` is an
78
79
  * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
79
80
  * TreeMultiMap with initial data.
80
81
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
@@ -82,11 +83,11 @@ export class TreeMultiMap<
82
83
  * `compareValues`, which are functions used to compare keys and values respectively.
83
84
  */
84
85
  constructor(
85
- keysOrNodesOrEntriesOrRawElements: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
86
+ keysOrNodesOrEntriesOrRaws: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
86
87
  options?: TreeMultiMapOptions<K, V, R>
87
88
  ) {
88
89
  super([], options);
89
- if (keysOrNodesOrEntriesOrRawElements) this.addMany(keysOrNodesOrEntriesOrRawElements);
90
+ if (keysOrNodesOrEntriesOrRaws) this.addMany(keysOrNodesOrEntriesOrRaws);
90
91
  }
91
92
 
92
93
  protected _count = 0;
@@ -142,6 +143,8 @@ export class TreeMultiMap<
142
143
  override createTree(options?: TreeMultiMapOptions<K, V, R>): TREE {
143
144
  return new TreeMultiMap<K, V, R, NODE, TREE>([], {
144
145
  iterationType: this.iterationType,
146
+ comparator: this._comparator,
147
+ toEntryFn: this._toEntryFn,
145
148
  ...options
146
149
  }) as TREE;
147
150
  }
@@ -149,8 +152,8 @@ export class TreeMultiMap<
149
152
  /**
150
153
  * The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
151
154
  * node based on the input.
152
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
153
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
155
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
156
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
154
157
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
155
158
  * associated with the key in the node. It is used when creating a new node or updating the value of
156
159
  * an existing node.
@@ -159,42 +162,39 @@ export class TreeMultiMap<
159
162
  * @returns either a NODE object or undefined.
160
163
  */
161
164
  override keyValueOrEntryOrRawElementToNode(
162
- keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
165
+ keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
163
166
  value?: V,
164
167
  count = 1
165
168
  ): NODE | undefined {
166
- if (keyOrNodeOrEntryOrRawElement === undefined || keyOrNodeOrEntryOrRawElement === null) return;
169
+ if (keyOrNodeOrEntryOrRaw === undefined || keyOrNodeOrEntryOrRaw === null) return;
167
170
 
168
- if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
171
+ if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
169
172
 
170
- if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
171
- const [key, entryValue] = keyOrNodeOrEntryOrRawElement;
173
+ if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
174
+ const [key, entryValue] = keyOrNodeOrEntryOrRaw;
172
175
  if (key === undefined || key === null) return;
173
176
  if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'BLACK', count);
174
177
  }
175
178
 
176
- if (this.toEntryFn) {
177
- const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
179
+ if (this._toEntryFn) {
180
+ const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw as R);
178
181
  if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'BLACK', count);
179
182
  }
180
183
 
181
- if (this.isKey(keyOrNodeOrEntryOrRawElement))
182
- return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'BLACK', count);
184
+ if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, 'BLACK', count);
183
185
 
184
186
  return;
185
187
  }
186
188
 
187
189
  /**
188
190
  * The function checks if the input is an instance of the TreeMultiMapNode class.
189
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
190
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
191
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
191
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
192
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
193
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
192
194
  * an instance of the `TreeMultiMapNode` class.
193
195
  */
194
- override isNode(
195
- keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
196
- ): keyOrNodeOrEntryOrRawElement is NODE {
197
- return keyOrNodeOrEntryOrRawElement instanceof TreeMultiMapNode;
196
+ override isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE {
197
+ return keyOrNodeOrEntryOrRaw instanceof TreeMultiMapNode;
198
198
  }
199
199
 
200
200
  /**
@@ -203,8 +203,8 @@ export class TreeMultiMap<
203
203
  *
204
204
  * The function overrides the add method of a class and adds a new node to a data structure, updating
205
205
  * the count and returning a boolean indicating success.
206
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
207
- * `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
206
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
207
+ * `keyOrNodeOrEntryOrRaw` parameter can accept one of the following types:
208
208
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
209
209
  * data structure. It is an optional parameter, so it can be omitted if not needed.
210
210
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
@@ -213,8 +213,8 @@ export class TreeMultiMap<
213
213
  * @returns The method is returning a boolean value. It returns true if the addition of the new node
214
214
  * was successful, and false otherwise.
215
215
  */
216
- override add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count = 1): boolean {
217
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
216
+ override add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count = 1): boolean {
217
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
218
218
  const orgCount = newNode?.count || 0;
219
219
  const isSuccessAdded = super.add(newNode);
220
220
 
@@ -230,30 +230,29 @@ export class TreeMultiMap<
230
230
  * Time Complexity: O(log n)
231
231
  * Space Complexity: O(1)
232
232
  *
233
- * The function `delete` is used to remove a node from a binary tree and fix the tree if necessary.
234
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value or
235
- * key that is used to identify the node that needs to be deleted from the binary tree. It can be of
236
- * any type that is returned by the callback function `C`. It can also be `null` or `undefined` if
237
- * the node to be deleted
238
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
239
- * equality of nodes in the binary tree. It is optional and has a default value of
240
- * `this._DEFAULT_CALLBACK`. The `callback` function is used to compare nodes when searching for a
241
- * specific node or when performing other operations on the
242
- * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
243
- * being deleted. If set to true, the count of the node will not be taken into account when deleting
244
- * it. If set to false, the count of the node will be decremented by 1 before deleting it.
245
- * @returns an array of BinaryTreeDeleteResult<NODE> objects.
233
+ * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
234
+ * structure, handling cases where nodes have children and maintaining balance in the tree.
235
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
236
+ * parameter in the `delete` method is used to specify the condition or key based on which a node
237
+ * should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
238
+ * function.
239
+ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
240
+ * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
241
+ * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
242
+ * `ignoreCount` is `false
243
+ * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
246
244
  */
247
- override delete<C extends BTNCallback<NODE>>(
248
- identifier: ReturnType<C> | null | undefined,
249
- callback: C = this._DEFAULT_CALLBACK as C,
245
+ override delete(
246
+ predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>,
250
247
  ignoreCount = false
251
248
  ): BinaryTreeDeleteResult<NODE>[] {
252
- if (identifier === null) return [];
249
+ if (predicate === null) return [];
250
+
253
251
  const results: BinaryTreeDeleteResult<NODE>[] = [];
254
- callback = this._ensureCallback(identifier, callback);
255
252
 
256
- const nodeToDelete = this.isRealNode(identifier) ? identifier : this.getNode(identifier, callback);
253
+ let nodeToDelete: OptBSTN<NODE>;
254
+ if (this._isPredicated(predicate)) nodeToDelete = this.getNode(predicate);
255
+ else nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
257
256
 
258
257
  if (!nodeToDelete) {
259
258
  return results;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { DijkstraResult, EntryCallback, VertexKey } from '../../types';
@@ -564,7 +564,7 @@ export abstract class AbstractGraph<
564
564
  }
565
565
  }
566
566
 
567
- getMinDist &&
567
+ if (getMinDist)
568
568
  distMap.forEach((d, v) => {
569
569
  if (v !== srcVertex) {
570
570
  if (d < minDist) {
@@ -574,7 +574,7 @@ export abstract class AbstractGraph<
574
574
  }
575
575
  });
576
576
 
577
- genPaths && getPaths(minDest);
577
+ if (genPaths) getPaths(minDest);
578
578
 
579
579
  return { distMap, preMap, seen, paths, minDist, minPath };
580
580
  }
@@ -761,7 +761,7 @@ export abstract class AbstractGraph<
761
761
  if (sWeight !== undefined && dWeight !== undefined) {
762
762
  if (distMap.get(s) !== Infinity && sWeight + weight < dWeight) {
763
763
  distMap.set(d, sWeight + weight);
764
- genPath && preMap.set(d, s);
764
+ if (genPath) preMap.set(d, s);
765
765
  }
766
766
  }
767
767
  }
@@ -900,7 +900,7 @@ export abstract class AbstractGraph<
900
900
  currentPath.push(vertex.key);
901
901
 
902
902
  for (const neighbor of this.getNeighbors(vertex)) {
903
- neighbor && dfs(neighbor, currentPath, visited);
903
+ if (neighbor) dfs(neighbor, currentPath, visited);
904
904
  }
905
905
 
906
906
  visited.delete(vertex);
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { TopologicalStatus, VertexKey } from '../../types';
@@ -260,8 +260,8 @@ export class DirectedGraph<
260
260
  const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2);
261
261
  const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1);
262
262
 
263
- v1ToV2 && removed.push(v1ToV2);
264
- v2ToV1 && removed.push(v2ToV1);
263
+ if (v1ToV2) removed.push(v1ToV2);
264
+ if (v2ToV1) removed.push(v2ToV1);
265
265
  }
266
266
 
267
267
  return removed;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { VertexKey } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type {
@@ -111,7 +111,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
111
111
  * @returns A boolean value indicating whether the size of the object is 0 or not.
112
112
  */
113
113
  isEmpty(): boolean {
114
- return this.size === 0;
114
+ return this._size === 0;
115
115
  }
116
116
 
117
117
  /**
@@ -626,7 +626,7 @@ export class FibonacciHeap<E> {
626
626
  * @returns The top element or undefined if the heap is empty.
627
627
  */
628
628
  pop(): E | undefined {
629
- if (this.size === 0) return undefined;
629
+ if (this._size === 0) return undefined;
630
630
 
631
631
  const z = this.min!;
632
632
  if (z.child) {
@@ -770,7 +770,7 @@ export class FibonacciHeap<E> {
770
770
  * @protected
771
771
  */
772
772
  protected _consolidate(): void {
773
- const A: (FibonacciHeapNode<E> | undefined)[] = new Array(this.size);
773
+ const A: (FibonacciHeapNode<E> | undefined)[] = new Array(this._size);
774
774
  const elements = this.consumeLinkedList(this.root);
775
775
  let x: FibonacciHeapNode<E> | undefined,
776
776
  y: FibonacciHeapNode<E> | undefined,
@@ -798,7 +798,7 @@ export class FibonacciHeap<E> {
798
798
  A[d] = x;
799
799
  }
800
800
 
801
- for (let i = 0; i < this.size; i++) {
801
+ for (let i = 0; i < this._size; i++) {
802
802
  if (A[i] && this.comparator(A[i]!.element, this.min!.element) <= 0) {
803
803
  this._min = A[i]!;
804
804
  }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { DoublyLinkedListOptions, ElementCallback } from '../../types';
@@ -267,7 +267,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
267
267
  * or the linked list is empty, it will return undefined.
268
268
  */
269
269
  at(index: number): E | undefined {
270
- if (index < 0 || index >= this.size) return undefined;
270
+ if (index < 0 || index >= this._size) return undefined;
271
271
  let current = this.head;
272
272
  for (let i = 0; i < index; i++) {
273
273
  current = current!.next;
@@ -287,7 +287,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
287
287
  * valid range of the linked list, otherwise it returns `undefined`.
288
288
  */
289
289
  getNodeAt(index: number): DoublyLinkedListNode<E> | undefined {
290
- if (index < 0 || index >= this.size) return undefined;
290
+ if (index < 0 || index >= this._size) return undefined;
291
291
  let current = this.head;
292
292
  for (let i = 0; i < index; i++) {
293
293
  current = current!.next;
@@ -331,12 +331,12 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
331
331
  * if the index is out of bounds.
332
332
  */
333
333
  addAt(index: number, value: E): boolean {
334
- if (index < 0 || index > this.size) return false;
334
+ if (index < 0 || index > this._size) return false;
335
335
  if (index === 0) {
336
336
  this.unshift(value);
337
337
  return true;
338
338
  }
339
- if (index === this.size) {
339
+ if (index === this._size) {
340
340
  this.push(value);
341
341
  return true;
342
342
  }
@@ -442,12 +442,12 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
442
442
  * bounds.
443
443
  */
444
444
  deleteAt(index: number): boolean {
445
- if (index < 0 || index >= this.size) return false;
445
+ if (index < 0 || index >= this._size) return false;
446
446
  if (index === 0) {
447
447
  this.shift();
448
448
  return true;
449
449
  }
450
- if (index === this.size - 1) {
450
+ if (index === this._size - 1) {
451
451
  this.pop();
452
452
  return true;
453
453
  }
@@ -505,7 +505,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
505
505
  * @returns A boolean value is being returned.
506
506
  */
507
507
  isEmpty(): boolean {
508
- return this.size === 0;
508
+ return this._size === 0;
509
509
  }
510
510
 
511
511
  /**
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { ElementCallback, SinglyLinkedListOptions } from '../../types';
@@ -237,7 +237,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
237
237
  * `undefined` if the index is out of bounds.
238
238
  */
239
239
  at(index: number): E | undefined {
240
- if (index < 0 || index >= this.size) return undefined;
240
+ if (index < 0 || index >= this._size) return undefined;
241
241
  let current = this.head;
242
242
  for (let i = 0; i < index; i++) {
243
243
  current = current!.next;
@@ -274,12 +274,12 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
274
274
  * bounds.
275
275
  */
276
276
  deleteAt(index: number): boolean {
277
- if (index < 0 || index >= this.size) return false;
277
+ if (index < 0 || index >= this._size) return false;
278
278
  if (index === 0) {
279
279
  this.shift();
280
280
  return true;
281
281
  }
282
- if (index === this.size - 1) {
282
+ if (index === this._size - 1) {
283
283
  this.pop();
284
284
  return true;
285
285
  }
@@ -348,12 +348,12 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
348
348
  * if the index is out of bounds.
349
349
  */
350
350
  addAt(index: number, value: E): boolean {
351
- if (index < 0 || index > this.size) return false;
351
+ if (index < 0 || index > this._size) return false;
352
352
  if (index === 0) {
353
353
  this.unshift(value);
354
354
  return true;
355
355
  }
356
- if (index === this.size) {
356
+ if (index === this._size) {
357
357
  this.push(value);
358
358
  return true;
359
359
  }
@@ -372,7 +372,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
372
372
  * @returns A boolean value indicating whether the length of the object is equal to 0.
373
373
  */
374
374
  isEmpty(): boolean {
375
- return this.size === 0;
375
+ return this._size === 0;
376
376
  }
377
377
 
378
378
  /**