heap-typed 1.47.6 → 1.47.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 (56) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +40 -22
  2. package/dist/data-structures/binary-tree/avl-tree.js +45 -36
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +105 -113
  4. package/dist/data-structures/binary-tree/binary-tree.js +133 -119
  5. package/dist/data-structures/binary-tree/bst.d.ts +53 -44
  6. package/dist/data-structures/binary-tree/bst.js +137 -154
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +48 -15
  8. package/dist/data-structures/binary-tree/rb-tree.js +70 -33
  9. package/dist/data-structures/binary-tree/segment-tree.d.ts +6 -6
  10. package/dist/data-structures/binary-tree/segment-tree.js +7 -7
  11. package/dist/data-structures/binary-tree/tree-multimap.d.ts +26 -37
  12. package/dist/data-structures/binary-tree/tree-multimap.js +58 -137
  13. package/dist/data-structures/graph/abstract-graph.d.ts +17 -17
  14. package/dist/data-structures/graph/abstract-graph.js +30 -30
  15. package/dist/data-structures/graph/directed-graph.d.ts +24 -24
  16. package/dist/data-structures/graph/directed-graph.js +28 -28
  17. package/dist/data-structures/graph/undirected-graph.d.ts +14 -14
  18. package/dist/data-structures/graph/undirected-graph.js +18 -18
  19. package/dist/data-structures/hash/hash-map.d.ts +2 -6
  20. package/dist/data-structures/hash/hash-map.js +5 -8
  21. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
  22. package/dist/data-structures/linked-list/doubly-linked-list.js +33 -33
  23. package/dist/data-structures/linked-list/singly-linked-list.d.ts +21 -21
  24. package/dist/data-structures/linked-list/singly-linked-list.js +27 -27
  25. package/dist/data-structures/linked-list/skip-linked-list.js +4 -4
  26. package/dist/data-structures/queue/queue.d.ts +13 -13
  27. package/dist/data-structures/queue/queue.js +13 -13
  28. package/dist/data-structures/stack/stack.d.ts +6 -6
  29. package/dist/data-structures/stack/stack.js +7 -7
  30. package/dist/data-structures/trie/trie.d.ts +3 -0
  31. package/dist/data-structures/trie/trie.js +19 -4
  32. package/dist/interfaces/binary-tree.d.ts +3 -3
  33. package/dist/types/common.d.ts +6 -1
  34. package/dist/types/data-structures/graph/abstract-graph.d.ts +2 -2
  35. package/dist/types/data-structures/hash/hash-map.d.ts +1 -2
  36. package/package.json +2 -2
  37. package/src/data-structures/binary-tree/avl-tree.ts +59 -39
  38. package/src/data-structures/binary-tree/binary-tree.ts +192 -180
  39. package/src/data-structures/binary-tree/bst.ts +157 -154
  40. package/src/data-structures/binary-tree/rb-tree.ts +78 -37
  41. package/src/data-structures/binary-tree/segment-tree.ts +10 -10
  42. package/src/data-structures/binary-tree/tree-multimap.ts +67 -145
  43. package/src/data-structures/graph/abstract-graph.ts +46 -46
  44. package/src/data-structures/graph/directed-graph.ts +40 -40
  45. package/src/data-structures/graph/undirected-graph.ts +26 -26
  46. package/src/data-structures/hash/hash-map.ts +8 -8
  47. package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
  48. package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
  49. package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
  50. package/src/data-structures/queue/queue.ts +13 -13
  51. package/src/data-structures/stack/stack.ts +9 -9
  52. package/src/data-structures/trie/trie.ts +23 -4
  53. package/src/interfaces/binary-tree.ts +3 -3
  54. package/src/types/common.ts +11 -1
  55. package/src/types/data-structures/graph/abstract-graph.ts +2 -2
  56. package/src/types/data-structures/hash/hash-map.ts +1 -2
@@ -74,13 +74,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
74
74
  * Space Complexity: O(1)
75
75
  *
76
76
  * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
77
- * @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
78
- * @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
79
- * destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
77
+ * @param {VO | VertexKey | undefined} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
78
+ * @param {VO | VertexKey | undefined} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
79
+ * destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `undefined` if the
80
80
  * destination is not specified.
81
- * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
81
+ * @returns the first edge found between the source and destination vertices, or undefined if no such edge is found.
82
82
  */
83
- getEdge(srcOrKey: VO | VertexKey | null, destOrKey: VO | VertexKey | null): EO | null;
83
+ getEdge(srcOrKey: VO | VertexKey | undefined, destOrKey: VO | VertexKey | undefined): EO | undefined;
84
84
  /**
85
85
  * Time Complexity: O(|E|) where |E| is the number of edges
86
86
  * Space Complexity: O(1)
@@ -92,9 +92,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
92
92
  * The function removes an edge between two vertices in a graph and returns the removed edge.
93
93
  * @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
94
94
  * @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
95
- * @returns the removed edge (EO) if it exists, or null if either the source or destination vertex does not exist.
95
+ * @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
96
96
  */
97
- deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | null;
97
+ deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
98
98
  /**
99
99
  * Time Complexity: O(|E|) where |E| is the number of edges
100
100
  * Space Complexity: O(1)
@@ -103,12 +103,12 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
103
103
  * Time Complexity: O(|E|) where |E| is the number of edges
104
104
  * Space Complexity: O(1)
105
105
  *
106
- * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
106
+ * The function removes an edge from a graph and returns the removed edge, or undefined if the edge was not found.
107
107
  * @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
108
108
  * and `dest`, which represent the source and destination vertices of the edge, respectively.
109
- * @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `null` if the edge does not exist.
109
+ * @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `undefined` if the edge does not exist.
110
110
  */
111
- deleteEdge(edge: EO): EO | null;
111
+ deleteEdge(edge: EO): EO | undefined;
112
112
  /**
113
113
  * Time Complexity: O(|E|) where |E| is the number of edges
114
114
  * Space Complexity: O(1)
@@ -213,11 +213,11 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
213
213
  * Time Complexity: O(1)
214
214
  * Space Complexity: O(1)
215
215
  *
216
- * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
216
+ * The function "getEdgeSrc" returns the source vertex of an edge, or undefined if the edge does not exist.
217
217
  * @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
218
- * @returns either a vertex object (VO) or null.
218
+ * @returns either a vertex object (VO) or undefined.
219
219
  */
220
- getEdgeSrc(e: EO): VO | null;
220
+ getEdgeSrc(e: EO): VO | undefined;
221
221
  /**
222
222
  * Time Complexity: O(1)
223
223
  * Space Complexity: O(1)
@@ -228,9 +228,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
228
228
  *
229
229
  * The function "getEdgeDest" returns the destination vertex of an edge.
230
230
  * @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
231
- * @returns either a vertex object of type VO or null.
231
+ * @returns either a vertex object of type VO or undefined.
232
232
  */
233
- getEdgeDest(e: EO): VO | null;
233
+ getEdgeDest(e: EO): VO | undefined;
234
234
  /**
235
235
  * Time Complexity: O(|E|) where |E| is the number of edges
236
236
  * Space Complexity: O(1)
@@ -240,11 +240,11 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
240
240
  * Space Complexity: O(1)
241
241
  *
242
242
  * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
243
- * @param {VO | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
244
- * find the destinations. It can be either a `VO` object, a `VertexKey` value, or `null`.
243
+ * @param {VO | VertexKey | undefined} vertex - The `vertex` parameter represents the starting vertex from which we want to
244
+ * find the destinations. It can be either a `VO` object, a `VertexKey` value, or `undefined`.
245
245
  * @returns an array of vertices (VO[]).
246
246
  */
247
- getDestinations(vertex: VO | VertexKey | null): VO[];
247
+ getDestinations(vertex: VO | VertexKey | undefined): VO[];
248
248
  /**
249
249
  * Time Complexity: O(|V| + |E|) where |V| is the number of vertices and |E| is the number of edges
250
250
  * Space Complexity: O(|V|)
@@ -254,13 +254,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
254
254
  * Space Complexity: O(|V|)
255
255
  *
256
256
  * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
257
- * in the sorted order, or null if the graph contains a cycle.
257
+ * in the sorted order, or undefined if the graph contains a cycle.
258
258
  * @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
259
259
  * property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
260
260
  * specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
261
- * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
261
+ * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
262
262
  */
263
- topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | null;
263
+ topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | undefined;
264
264
  /**
265
265
  * Time Complexity: O(|E|) where |E| is the number of edges
266
266
  * Space Complexity: O(|E|)
@@ -296,12 +296,12 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
296
296
  * Space Complexity: O(1)
297
297
  *
298
298
  * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
299
- * otherwise it returns null.
299
+ * otherwise it returns undefined.
300
300
  * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
301
301
  * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
302
- * graph. If the edge does not exist, it returns `null`.
302
+ * graph. If the edge does not exist, it returns `undefined`.
303
303
  */
304
- getEndsOfEdge(edge: EO): [VO, VO] | null;
304
+ getEndsOfEdge(edge: EO): [VO, VO] | undefined;
305
305
  /**
306
306
  * Time Complexity: O(1)
307
307
  * Space Complexity: O(1)
@@ -99,15 +99,15 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
99
99
  * Space Complexity: O(1)
100
100
  *
101
101
  * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
102
- * @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
103
- * @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
104
- * destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
102
+ * @param {VO | VertexKey | undefined} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
103
+ * @param {VO | VertexKey | undefined} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
104
+ * destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `undefined` if the
105
105
  * destination is not specified.
106
- * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
106
+ * @returns the first edge found between the source and destination vertices, or undefined if no such edge is found.
107
107
  */
108
108
  getEdge(srcOrKey, destOrKey) {
109
109
  let edges = [];
110
- if (srcOrKey !== null && destOrKey !== null) {
110
+ if (srcOrKey !== undefined && destOrKey !== undefined) {
111
111
  const src = this._getVertex(srcOrKey);
112
112
  const dest = this._getVertex(destOrKey);
113
113
  if (src && dest) {
@@ -117,7 +117,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
117
117
  }
118
118
  }
119
119
  }
120
- return edges[0] || null;
120
+ return edges[0] || undefined;
121
121
  }
122
122
  /**
123
123
  * Time Complexity: O(|E|) where |E| is the number of edges
@@ -130,14 +130,14 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
130
130
  * The function removes an edge between two vertices in a graph and returns the removed edge.
131
131
  * @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
132
132
  * @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
133
- * @returns the removed edge (EO) if it exists, or null if either the source or destination vertex does not exist.
133
+ * @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
134
134
  */
135
135
  deleteEdgeSrcToDest(srcOrKey, destOrKey) {
136
136
  const src = this._getVertex(srcOrKey);
137
137
  const dest = this._getVertex(destOrKey);
138
- let removed = null;
138
+ let removed = undefined;
139
139
  if (!src || !dest) {
140
- return null;
140
+ return undefined;
141
141
  }
142
142
  const srcOutEdges = this._outEdgeMap.get(src);
143
143
  if (srcOutEdges) {
@@ -145,7 +145,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
145
145
  }
146
146
  const destInEdges = this._inEdgeMap.get(dest);
147
147
  if (destInEdges) {
148
- removed = (0, utils_1.arrayRemove)(destInEdges, (edge) => edge.src === src.key)[0] || null;
148
+ removed = (0, utils_1.arrayRemove)(destInEdges, (edge) => edge.src === src.key)[0] || undefined;
149
149
  }
150
150
  return removed;
151
151
  }
@@ -157,13 +157,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
157
157
  * Time Complexity: O(|E|) where |E| is the number of edges
158
158
  * Space Complexity: O(1)
159
159
  *
160
- * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
160
+ * The function removes an edge from a graph and returns the removed edge, or undefined if the edge was not found.
161
161
  * @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
162
162
  * and `dest`, which represent the source and destination vertices of the edge, respectively.
163
- * @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `null` if the edge does not exist.
163
+ * @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `undefined` if the edge does not exist.
164
164
  */
165
165
  deleteEdge(edge) {
166
- let removed = null;
166
+ let removed = undefined;
167
167
  const src = this._getVertex(edge.src);
168
168
  const dest = this._getVertex(edge.dest);
169
169
  if (src && dest) {
@@ -311,9 +311,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
311
311
  * Time Complexity: O(1)
312
312
  * Space Complexity: O(1)
313
313
  *
314
- * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
314
+ * The function "getEdgeSrc" returns the source vertex of an edge, or undefined if the edge does not exist.
315
315
  * @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
316
- * @returns either a vertex object (VO) or null.
316
+ * @returns either a vertex object (VO) or undefined.
317
317
  */
318
318
  getEdgeSrc(e) {
319
319
  return this._getVertex(e.src);
@@ -328,7 +328,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
328
328
  *
329
329
  * The function "getEdgeDest" returns the destination vertex of an edge.
330
330
  * @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
331
- * @returns either a vertex object of type VO or null.
331
+ * @returns either a vertex object of type VO or undefined.
332
332
  */
333
333
  getEdgeDest(e) {
334
334
  return this._getVertex(e.dest);
@@ -342,12 +342,12 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
342
342
  * Space Complexity: O(1)
343
343
  *
344
344
  * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
345
- * @param {VO | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
346
- * find the destinations. It can be either a `VO` object, a `VertexKey` value, or `null`.
345
+ * @param {VO | VertexKey | undefined} vertex - The `vertex` parameter represents the starting vertex from which we want to
346
+ * find the destinations. It can be either a `VO` object, a `VertexKey` value, or `undefined`.
347
347
  * @returns an array of vertices (VO[]).
348
348
  */
349
349
  getDestinations(vertex) {
350
- if (vertex === null) {
350
+ if (vertex === undefined) {
351
351
  return [];
352
352
  }
353
353
  const destinations = [];
@@ -369,11 +369,11 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
369
369
  * Space Complexity: O(|V|)
370
370
  *
371
371
  * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
372
- * in the sorted order, or null if the graph contains a cycle.
372
+ * in the sorted order, or undefined if the graph contains a cycle.
373
373
  * @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
374
374
  * property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
375
375
  * specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
376
- * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
376
+ * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
377
377
  */
378
378
  topologicalSort(propertyName) {
379
379
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
@@ -406,7 +406,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
406
406
  }
407
407
  }
408
408
  if (hasCycle)
409
- return null;
409
+ return undefined;
410
410
  if (propertyName === 'key')
411
411
  sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
412
412
  return sorted.reverse();
@@ -449,7 +449,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
449
449
  const outEdges = this.outgoingEdgesOf(vertex);
450
450
  for (const outEdge of outEdges) {
451
451
  const neighbor = this._getVertex(outEdge.dest);
452
- // TODO after no-non-null-assertion not ensure the logic
452
+ // TODO after no-non-undefined-assertion not ensure the logic
453
453
  if (neighbor) {
454
454
  neighbors.push(neighbor);
455
455
  }
@@ -466,14 +466,14 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
466
466
  * Space Complexity: O(1)
467
467
  *
468
468
  * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
469
- * otherwise it returns null.
469
+ * otherwise it returns undefined.
470
470
  * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
471
471
  * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
472
- * graph. If the edge does not exist, it returns `null`.
472
+ * graph. If the edge does not exist, it returns `undefined`.
473
473
  */
474
474
  getEndsOfEdge(edge) {
475
475
  if (!this.hasEdge(edge.src, edge.dest)) {
476
- return null;
476
+ return undefined;
477
477
  }
478
478
  const v1 = this._getVertex(edge.src);
479
479
  const v2 = this._getVertex(edge.dest);
@@ -481,7 +481,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
481
481
  return [v1, v2];
482
482
  }
483
483
  else {
484
- return null;
484
+ return undefined;
485
485
  }
486
486
  }
487
487
  /**
@@ -504,7 +504,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
504
504
  }
505
505
  const srcVertex = this._getVertex(edge.src);
506
506
  const destVertex = this._getVertex(edge.dest);
507
- // TODO after no-non-null-assertion not ensure the logic
507
+ // TODO after no-non-undefined-assertion not ensure the logic
508
508
  if (srcVertex && destVertex) {
509
509
  const srcOutEdges = this._outEdgeMap.get(srcVertex);
510
510
  if (srcOutEdges) {
@@ -61,14 +61,14 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
61
61
  * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
62
62
  * Space Complexity: O(1)
63
63
  *
64
- * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
65
- * @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
66
- * object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
67
- * @param {VO | VertexKey | null} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
68
- * object), `null`, or `VertexKey` (vertex ID).
69
- * @returns an edge (EO) or null.
64
+ * The function `getEdge` returns the first edge that connects two vertices, or undefined if no such edge exists.
65
+ * @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
66
+ * object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
67
+ * @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
68
+ * object), `undefined`, or `VertexKey` (vertex ID).
69
+ * @returns an edge (EO) or undefined.
70
70
  */
71
- getEdge(v1: VO | VertexKey | null, v2: VO | VertexKey | null): EO | null;
71
+ getEdge(v1: VO | VertexKey | undefined, v2: VO | VertexKey | undefined): EO | undefined;
72
72
  /**
73
73
  * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
74
74
  * Space Complexity: O(1)
@@ -81,9 +81,9 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
81
81
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
82
82
  * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
83
83
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
84
- * @returns the removed edge (EO) if it exists, or null if either of the vertices (VO) does not exist.
84
+ * @returns the removed edge (EO) if it exists, or undefined if either of the vertices (VO) does not exist.
85
85
  */
86
- deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | null;
86
+ deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | undefined;
87
87
  /**
88
88
  * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
89
89
  * Space Complexity: O(1)
@@ -94,9 +94,9 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
94
94
  *
95
95
  * The deleteEdge function removes an edge between two vertices in a graph.
96
96
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
97
- * @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
97
+ * @returns The method is returning either the removed edge (of type EO) or undefined if the edge was not found.
98
98
  */
99
- deleteEdge(edge: EO): EO | null;
99
+ deleteEdge(edge: EO): EO | undefined;
100
100
  /**
101
101
  * Time Complexity: O(1)
102
102
  * Space Complexity: O(1)
@@ -161,12 +161,12 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
161
161
  * Space Complexity: O(1)
162
162
  *
163
163
  * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
164
- * it returns null.
164
+ * it returns undefined.
165
165
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
166
166
  * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
167
- * graph. If the edge does not exist, it returns `null`.
167
+ * graph. If the edge does not exist, it returns `undefined`.
168
168
  */
169
- getEndsOfEdge(edge: EO): [VO, VO] | null;
169
+ getEndsOfEdge(edge: EO): [VO, VO] | undefined;
170
170
  /**
171
171
  * Time Complexity: O(1)
172
172
  * Space Complexity: O(1)
@@ -84,24 +84,24 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
84
84
  * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
85
85
  * Space Complexity: O(1)
86
86
  *
87
- * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
88
- * @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
89
- * object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
90
- * @param {VO | VertexKey | null} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
91
- * object), `null`, or `VertexKey` (vertex ID).
92
- * @returns an edge (EO) or null.
87
+ * The function `getEdge` returns the first edge that connects two vertices, or undefined if no such edge exists.
88
+ * @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
89
+ * object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
90
+ * @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
91
+ * object), `undefined`, or `VertexKey` (vertex ID).
92
+ * @returns an edge (EO) or undefined.
93
93
  */
94
94
  getEdge(v1, v2) {
95
95
  var _a;
96
96
  let edges = [];
97
- if (v1 !== null && v2 !== null) {
97
+ if (v1 !== undefined && v2 !== undefined) {
98
98
  const vertex1 = this._getVertex(v1);
99
99
  const vertex2 = this._getVertex(v2);
100
100
  if (vertex1 && vertex2) {
101
101
  edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.vertices.includes(vertex2.key));
102
102
  }
103
103
  }
104
- return edges ? edges[0] || null : null;
104
+ return edges ? edges[0] || undefined : undefined;
105
105
  }
106
106
  /**
107
107
  * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
@@ -115,18 +115,18 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
115
115
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
116
116
  * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
117
117
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
118
- * @returns the removed edge (EO) if it exists, or null if either of the vertices (VO) does not exist.
118
+ * @returns the removed edge (EO) if it exists, or undefined if either of the vertices (VO) does not exist.
119
119
  */
120
120
  deleteEdgeBetween(v1, v2) {
121
121
  const vertex1 = this._getVertex(v1);
122
122
  const vertex2 = this._getVertex(v2);
123
123
  if (!vertex1 || !vertex2) {
124
- return null;
124
+ return undefined;
125
125
  }
126
126
  const v1Edges = this._edges.get(vertex1);
127
- let removed = null;
127
+ let removed = undefined;
128
128
  if (v1Edges) {
129
- removed = (0, utils_1.arrayRemove)(v1Edges, (e) => e.vertices.includes(vertex2.key))[0] || null;
129
+ removed = (0, utils_1.arrayRemove)(v1Edges, (e) => e.vertices.includes(vertex2.key))[0] || undefined;
130
130
  }
131
131
  const v2Edges = this._edges.get(vertex2);
132
132
  if (v2Edges) {
@@ -144,7 +144,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
144
144
  *
145
145
  * The deleteEdge function removes an edge between two vertices in a graph.
146
146
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
147
- * @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
147
+ * @returns The method is returning either the removed edge (of type EO) or undefined if the edge was not found.
148
148
  */
149
149
  deleteEdge(edge) {
150
150
  return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
@@ -251,14 +251,14 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
251
251
  * Space Complexity: O(1)
252
252
  *
253
253
  * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
254
- * it returns null.
254
+ * it returns undefined.
255
255
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
256
256
  * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
257
- * graph. If the edge does not exist, it returns `null`.
257
+ * graph. If the edge does not exist, it returns `undefined`.
258
258
  */
259
259
  getEndsOfEdge(edge) {
260
260
  if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
261
- return null;
261
+ return undefined;
262
262
  }
263
263
  const v1 = this._getVertex(edge.vertices[0]);
264
264
  const v2 = this._getVertex(edge.vertices[1]);
@@ -266,7 +266,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
266
266
  return [v1, v2];
267
267
  }
268
268
  else {
269
- return null;
269
+ return undefined;
270
270
  }
271
271
  }
272
272
  /**
@@ -284,7 +284,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
284
284
  _addEdgeOnly(edge) {
285
285
  for (const end of edge.vertices) {
286
286
  const endVertex = this._getVertex(end);
287
- if (endVertex === null)
287
+ if (endVertex === undefined)
288
288
  return false;
289
289
  if (endVertex) {
290
290
  const edges = this._edges.get(endVertex);
@@ -14,12 +14,7 @@ export declare class HashMap<K = any, V = any> {
14
14
  protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
15
15
  protected _hashFn: (key: K) => string;
16
16
  protected _objHashFn: (key: K) => object;
17
- /**
18
- * The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs.
19
- * @param options - The `options` parameter is an object that contains the `elements` property. The
20
- * `elements` property is an iterable that contains key-value pairs represented as arrays `[K, V]`.
21
- */
22
- constructor(options?: HashMapOptions<K, V>);
17
+ constructor(elements?: Iterable<[K, V]>, options?: HashMapOptions<K>);
23
18
  protected _size: number;
24
19
  get size(): number;
25
20
  /**
@@ -172,6 +167,7 @@ export declare class HashMap<K = any, V = any> {
172
167
  * The above function is an iterator that yields key-value pairs from a linked list.
173
168
  */
174
169
  [Symbol.iterator](): Generator<[K, V], void, unknown>;
170
+ print(): void;
175
171
  /**
176
172
  * Time Complexity: O(1)
177
173
  * Space Complexity: O(1)
@@ -10,13 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.HashMap = void 0;
11
11
  const utils_1 = require("../../utils");
12
12
  class HashMap {
13
- /**
14
- * The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs.
15
- * @param options - The `options` parameter is an object that contains the `elements` property. The
16
- * `elements` property is an iterable that contains key-value pairs represented as arrays `[K, V]`.
17
- */
18
- constructor(options = {
19
- elements: [],
13
+ constructor(elements, options = {
20
14
  hashFn: (key) => String(key),
21
15
  objHashFn: (key) => key
22
16
  }) {
@@ -25,7 +19,7 @@ class HashMap {
25
19
  this._size = 0;
26
20
  this._sentinel = {};
27
21
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
28
- const { elements, hashFn, objHashFn } = options;
22
+ const { hashFn, objHashFn } = options;
29
23
  this._hashFn = hashFn;
30
24
  this._objHashFn = objHashFn;
31
25
  if (elements) {
@@ -347,6 +341,9 @@ class HashMap {
347
341
  node = node.next;
348
342
  }
349
343
  }
344
+ print() {
345
+ console.log([...this]);
346
+ }
350
347
  /**
351
348
  * Time Complexity: O(1)
352
349
  * Space Complexity: O(1)