bst-typed 1.52.6 → 1.52.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 (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 +591 -402
  13. package/dist/data-structures/binary-tree/binary-tree.js +690 -604
  14. package/dist/data-structures/binary-tree/bst.d.ts +72 -65
  15. package/dist/data-structures/binary-tree/bst.js +122 -125
  16. package/dist/data-structures/binary-tree/rb-tree.d.ts +21 -24
  17. package/dist/data-structures/binary-tree/rb-tree.js +42 -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 +27 -31
  21. package/dist/data-structures/binary-tree/tree-multi-map.js +45 -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 +46 -50
  54. package/src/data-structures/binary-tree/avl-tree.ts +68 -71
  55. package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
  56. package/src/data-structures/binary-tree/binary-tree.ts +716 -748
  57. package/src/data-structures/binary-tree/bst.ts +137 -146
  58. package/src/data-structures/binary-tree/rb-tree.ts +46 -46
  59. package/src/data-structures/binary-tree/segment-tree.ts +2 -2
  60. package/src/data-structures/binary-tree/tree-multi-map.ts +49 -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,14 @@
1
1
  import type {
2
2
  BinaryTreeDeleteResult,
3
- BTNCallback,
4
3
  BTNKeyOrNodeOrEntry,
5
4
  CRUD,
5
+ OptBSTN,
6
6
  RBTNColor,
7
7
  RBTreeOptions,
8
8
  RedBlackTreeNested,
9
- RedBlackTreeNodeNested
9
+ RedBlackTreeNodeNested,
10
+ BTNEntry
10
11
  } from '../../types';
11
- import { BTNEntry } from '../../types';
12
12
  import { BST, BSTNode } from './bst';
13
13
  import { IBinaryTree } from '../../interfaces';
14
14
 
@@ -64,7 +64,7 @@ export class RedBlackTree<
64
64
  {
65
65
  /**
66
66
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
67
- * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
67
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
68
68
  * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
69
69
  * initialize the RBTree with the provided elements.
70
70
  * @param [options] - The `options` parameter is an optional object that can be passed to the
@@ -73,15 +73,15 @@ export class RedBlackTree<
73
73
  * depend on the implementation
74
74
  */
75
75
  constructor(
76
- keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
76
+ keysOrNodesOrEntriesOrRaws: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
77
77
  options?: RBTreeOptions<K, V, R>
78
78
  ) {
79
79
  super([], options);
80
80
 
81
81
  this._root = this.NIL;
82
82
 
83
- if (keysOrNodesOrEntriesOrRawElements) {
84
- this.addMany(keysOrNodesOrEntriesOrRawElements);
83
+ if (keysOrNodesOrEntriesOrRaws) {
84
+ this.addMany(keysOrNodesOrEntriesOrRaws);
85
85
  }
86
86
  }
87
87
 
@@ -122,6 +122,8 @@ export class RedBlackTree<
122
122
  override createTree(options?: RBTreeOptions<K, V, R>): TREE {
123
123
  return new RedBlackTree<K, V, R, NODE, TREE>([], {
124
124
  iterationType: this.iterationType,
125
+ comparator: this._comparator,
126
+ toEntryFn: this._toEntryFn,
125
127
  ...options
126
128
  }) as TREE;
127
129
  }
@@ -131,15 +133,13 @@ export class RedBlackTree<
131
133
  * Space Complexity: O(1)
132
134
  *
133
135
  * 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
136
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
137
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
138
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
137
139
  * an instance of the `RedBlackTreeNode` class.
138
140
  */
139
- override isNode(
140
- keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
141
- ): keyOrNodeOrEntryOrRawElement is NODE {
142
- return keyOrNodeOrEntryOrRawElement instanceof RedBlackTreeNode;
141
+ override isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE {
142
+ return keyOrNodeOrEntryOrRaw instanceof RedBlackTreeNode;
143
143
  }
144
144
 
145
145
  // /**
@@ -153,27 +153,27 @@ export class RedBlackTree<
153
153
  // *
154
154
  // * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
155
155
  // * 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).
156
+ // * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRaw - The key, value, or entry to convert.
157
+ // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRaw` is a key).
158
158
  // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
159
159
  // */
160
- // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
160
+ // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): NODE | undefined {
161
161
  //
162
- // if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
163
- // if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
162
+ // if (keyOrNodeOrEntryOrRaw === null || keyOrNodeOrEntryOrRaw === undefined) return;
163
+ // if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
164
164
  //
165
- // if (this.toEntryFn) {
166
- // const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
165
+ // if (this._toEntryFn) {
166
+ // const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw as R);
167
167
  // if (this.isKey(key)) return this.createNode(key, entryValue ?? value, 'RED');
168
168
  // }
169
169
  //
170
- // if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
171
- // const [key, value] = keyOrNodeOrEntryOrRawElement;
170
+ // if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
171
+ // const [key, value] = keyOrNodeOrEntryOrRaw;
172
172
  // if (key === undefined || key === null) return;
173
173
  // else return this.createNode(key, value, 'RED');
174
174
  // }
175
175
  //
176
- // if (this.isKey(keyOrNodeOrEntryOrRawElement)) return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'RED');
176
+ // if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, 'RED');
177
177
  //
178
178
  // return ;
179
179
  // }
@@ -196,8 +196,8 @@ export class RedBlackTree<
196
196
  *
197
197
  * The function adds a new node to a binary search tree and returns true if the node was successfully
198
198
  * 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>`.
199
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
200
+ * `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
201
201
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
202
202
  * the key in the data structure. It represents the value that you want to add or update in the data
203
203
  * structure.
@@ -205,8 +205,8 @@ export class RedBlackTree<
205
205
  * the method returns true. If the node already exists and its value is updated, the method also
206
206
  * returns true. If the node cannot be added or updated, the method returns false.
207
207
  */
208
- override add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
209
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
208
+ override add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): boolean {
209
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value);
210
210
  if (!this.isRealNode(newNode)) return false;
211
211
 
212
212
  const insertStatus = this._insert(newNode);
@@ -227,26 +227,26 @@ export class RedBlackTree<
227
227
  * Time Complexity: O(log n)
228
228
  * Space Complexity: O(1)
229
229
  *
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.
230
+ * The function overrides the delete method in a binary tree data structure to remove a node based on
231
+ * a given predicate and maintain the binary search tree properties.
232
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
233
+ * parameter in the `override delete` method is used to specify the condition or key based on which a
234
+ * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
235
+ * function that determines which node(s) should be deleted.
236
+ * @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
237
+ * objects. Each object in the array contains information about the deleted node and whether
238
+ * balancing is needed.
241
239
  */
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 [];
240
+ override delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[] {
241
+ if (keyOrNodeOrEntryOrRaw === null) return [];
242
+
247
243
  const results: BinaryTreeDeleteResult<NODE>[] = [];
248
- callback = this._ensureCallback(identifier, callback);
249
- const nodeToDelete = this.isRealNode(identifier) ? identifier : this.getNode(identifier, callback);
244
+ let nodeToDelete: OptBSTN<NODE>;
245
+ if (this._isPredicated(keyOrNodeOrEntryOrRaw)) nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw);
246
+ else
247
+ nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw)
248
+ ? keyOrNodeOrEntryOrRaw
249
+ : this.getNode(keyOrNodeOrEntryOrRaw);
250
250
 
251
251
  if (!nodeToDelete) {
252
252
  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,22 @@
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,
13
12
  IterationType,
13
+ OptBSTN,
14
14
  RBTNColor,
15
15
  TreeMultiMapNested,
16
16
  TreeMultiMapNodeNested,
17
- TreeMultiMapOptions
17
+ TreeMultiMapOptions,
18
+ BTNEntry
18
19
  } from '../../types';
19
- import { BTNEntry } from '../../types';
20
20
  import { IBinaryTree } from '../../interfaces';
21
21
  import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
22
22
 
@@ -74,7 +74,7 @@ export class TreeMultiMap<
74
74
  {
75
75
  /**
76
76
  * The constructor function initializes a TreeMultiMap object with optional initial data.
77
- * @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
77
+ * @param keysOrNodesOrEntriesOrRaws - The parameter `keysOrNodesOrEntriesOrRaws` is an
78
78
  * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
79
79
  * TreeMultiMap with initial data.
80
80
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
@@ -82,11 +82,11 @@ export class TreeMultiMap<
82
82
  * `compareValues`, which are functions used to compare keys and values respectively.
83
83
  */
84
84
  constructor(
85
- keysOrNodesOrEntriesOrRawElements: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
85
+ keysOrNodesOrEntriesOrRaws: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
86
86
  options?: TreeMultiMapOptions<K, V, R>
87
87
  ) {
88
88
  super([], options);
89
- if (keysOrNodesOrEntriesOrRawElements) this.addMany(keysOrNodesOrEntriesOrRawElements);
89
+ if (keysOrNodesOrEntriesOrRaws) this.addMany(keysOrNodesOrEntriesOrRaws);
90
90
  }
91
91
 
92
92
  protected _count = 0;
@@ -142,6 +142,8 @@ export class TreeMultiMap<
142
142
  override createTree(options?: TreeMultiMapOptions<K, V, R>): TREE {
143
143
  return new TreeMultiMap<K, V, R, NODE, TREE>([], {
144
144
  iterationType: this.iterationType,
145
+ comparator: this._comparator,
146
+ toEntryFn: this._toEntryFn,
145
147
  ...options
146
148
  }) as TREE;
147
149
  }
@@ -149,8 +151,8 @@ export class TreeMultiMap<
149
151
  /**
150
152
  * The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
151
153
  * 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>`.
154
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
155
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
154
156
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
155
157
  * associated with the key in the node. It is used when creating a new node or updating the value of
156
158
  * an existing node.
@@ -159,42 +161,39 @@ export class TreeMultiMap<
159
161
  * @returns either a NODE object or undefined.
160
162
  */
161
163
  override keyValueOrEntryOrRawElementToNode(
162
- keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
164
+ keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
163
165
  value?: V,
164
166
  count = 1
165
167
  ): NODE | undefined {
166
- if (keyOrNodeOrEntryOrRawElement === undefined || keyOrNodeOrEntryOrRawElement === null) return;
168
+ if (keyOrNodeOrEntryOrRaw === undefined || keyOrNodeOrEntryOrRaw === null) return;
167
169
 
168
- if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
170
+ if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
169
171
 
170
- if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
171
- const [key, entryValue] = keyOrNodeOrEntryOrRawElement;
172
+ if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
173
+ const [key, entryValue] = keyOrNodeOrEntryOrRaw;
172
174
  if (key === undefined || key === null) return;
173
175
  if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'BLACK', count);
174
176
  }
175
177
 
176
- if (this.toEntryFn) {
177
- const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
178
+ if (this._toEntryFn) {
179
+ const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw as R);
178
180
  if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'BLACK', count);
179
181
  }
180
182
 
181
- if (this.isKey(keyOrNodeOrEntryOrRawElement))
182
- return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'BLACK', count);
183
+ if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, 'BLACK', count);
183
184
 
184
185
  return;
185
186
  }
186
187
 
187
188
  /**
188
189
  * 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
190
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
191
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
192
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
192
193
  * an instance of the `TreeMultiMapNode` class.
193
194
  */
194
- override isNode(
195
- keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
196
- ): keyOrNodeOrEntryOrRawElement is NODE {
197
- return keyOrNodeOrEntryOrRawElement instanceof TreeMultiMapNode;
195
+ override isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE {
196
+ return keyOrNodeOrEntryOrRaw instanceof TreeMultiMapNode;
198
197
  }
199
198
 
200
199
  /**
@@ -203,8 +202,8 @@ export class TreeMultiMap<
203
202
  *
204
203
  * The function overrides the add method of a class and adds a new node to a data structure, updating
205
204
  * 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:
205
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
206
+ * `keyOrNodeOrEntryOrRaw` parameter can accept one of the following types:
208
207
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
209
208
  * data structure. It is an optional parameter, so it can be omitted if not needed.
210
209
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
@@ -213,8 +212,8 @@ export class TreeMultiMap<
213
212
  * @returns The method is returning a boolean value. It returns true if the addition of the new node
214
213
  * was successful, and false otherwise.
215
214
  */
216
- override add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count = 1): boolean {
217
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
215
+ override add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count = 1): boolean {
216
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
218
217
  const orgCount = newNode?.count || 0;
219
218
  const isSuccessAdded = super.add(newNode);
220
219
 
@@ -230,30 +229,31 @@ export class TreeMultiMap<
230
229
  * Time Complexity: O(log n)
231
230
  * Space Complexity: O(1)
232
231
  *
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.
232
+ * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
233
+ * structure, handling cases where nodes have children and maintaining balance in the tree.
234
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
235
+ * parameter in the `delete` method is used to specify the condition or key based on which a node
236
+ * should be deleted from the binary tree. It can be a key, a node, or an entry.
237
+ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
238
+ * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
239
+ * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
240
+ * `ignoreCount` is `false
241
+ * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
246
242
  */
247
- override delete<C extends BTNCallback<NODE>>(
248
- identifier: ReturnType<C> | null | undefined,
249
- callback: C = this._DEFAULT_CALLBACK as C,
243
+ override delete(
244
+ keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
250
245
  ignoreCount = false
251
246
  ): BinaryTreeDeleteResult<NODE>[] {
252
- if (identifier === null) return [];
247
+ if (keyOrNodeOrEntryOrRaw === null) return [];
248
+
253
249
  const results: BinaryTreeDeleteResult<NODE>[] = [];
254
- callback = this._ensureCallback(identifier, callback);
255
250
 
256
- const nodeToDelete = this.isRealNode(identifier) ? identifier : this.getNode(identifier, callback);
251
+ let nodeToDelete: OptBSTN<NODE>;
252
+ if (this._isPredicated(keyOrNodeOrEntryOrRaw)) nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw);
253
+ else
254
+ nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw)
255
+ ? keyOrNodeOrEntryOrRaw
256
+ : this.getNode(keyOrNodeOrEntryOrRaw);
257
257
 
258
258
  if (!nodeToDelete) {
259
259
  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
  /**