data-structure-typed 1.48.4 → 1.48.5

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 (83) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -6
  3. package/dist/cjs/data-structures/base/iterable-base.js +3 -3
  4. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +5 -3
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -4
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +18 -15
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js +16 -13
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/bst.d.ts +15 -11
  12. package/dist/cjs/data-structures/binary-tree/bst.js +17 -13
  13. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +19 -13
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js +20 -14
  16. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +21 -14
  18. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +25 -18
  19. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +52 -52
  21. package/dist/cjs/data-structures/graph/abstract-graph.js +78 -78
  22. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/directed-graph.d.ts +47 -47
  24. package/dist/cjs/data-structures/graph/directed-graph.js +56 -56
  25. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/map-graph.d.ts +5 -5
  27. package/dist/cjs/data-structures/graph/map-graph.js +8 -8
  28. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +29 -29
  30. package/dist/cjs/data-structures/graph/undirected-graph.js +57 -57
  31. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  32. package/dist/cjs/data-structures/hash/hash-map.d.ts +8 -8
  33. package/dist/cjs/data-structures/hash/hash-map.js +2 -2
  34. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  35. package/dist/cjs/interfaces/binary-tree.d.ts +1 -1
  36. package/dist/cjs/types/data-structures/base/base.d.ts +3 -3
  37. package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -6
  38. package/dist/mjs/data-structures/base/iterable-base.js +1 -1
  39. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +5 -3
  40. package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -4
  41. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +18 -15
  42. package/dist/mjs/data-structures/binary-tree/binary-tree.js +17 -14
  43. package/dist/mjs/data-structures/binary-tree/bst.d.ts +15 -11
  44. package/dist/mjs/data-structures/binary-tree/bst.js +17 -13
  45. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +19 -13
  46. package/dist/mjs/data-structures/binary-tree/rb-tree.js +20 -14
  47. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +21 -14
  48. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +25 -18
  49. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +52 -52
  50. package/dist/mjs/data-structures/graph/abstract-graph.js +79 -79
  51. package/dist/mjs/data-structures/graph/directed-graph.d.ts +47 -47
  52. package/dist/mjs/data-structures/graph/directed-graph.js +56 -56
  53. package/dist/mjs/data-structures/graph/map-graph.d.ts +5 -5
  54. package/dist/mjs/data-structures/graph/map-graph.js +8 -8
  55. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +29 -29
  56. package/dist/mjs/data-structures/graph/undirected-graph.js +59 -59
  57. package/dist/mjs/data-structures/hash/hash-map.d.ts +8 -8
  58. package/dist/mjs/data-structures/hash/hash-map.js +3 -3
  59. package/dist/mjs/interfaces/binary-tree.d.ts +1 -1
  60. package/dist/mjs/types/data-structures/base/base.d.ts +3 -3
  61. package/dist/umd/data-structure-typed.js +302 -280
  62. package/dist/umd/data-structure-typed.min.js +2 -2
  63. package/dist/umd/data-structure-typed.min.js.map +1 -1
  64. package/package.json +1 -1
  65. package/src/data-structures/base/iterable-base.ts +6 -6
  66. package/src/data-structures/binary-tree/avl-tree.ts +8 -5
  67. package/src/data-structures/binary-tree/binary-tree.ts +23 -19
  68. package/src/data-structures/binary-tree/bst.ts +19 -14
  69. package/src/data-structures/binary-tree/rb-tree.ts +20 -14
  70. package/src/data-structures/binary-tree/tree-multimap.ts +27 -19
  71. package/src/data-structures/graph/abstract-graph.ts +82 -82
  72. package/src/data-structures/graph/directed-graph.ts +56 -56
  73. package/src/data-structures/graph/map-graph.ts +8 -8
  74. package/src/data-structures/graph/undirected-graph.ts +59 -59
  75. package/src/data-structures/hash/hash-map.ts +8 -8
  76. package/src/interfaces/binary-tree.ts +1 -1
  77. package/src/types/data-structures/base/base.ts +3 -3
  78. package/test/integration/bst.test.ts +1 -1
  79. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -1
  80. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +3 -3
  81. package/test/unit/data-structures/graph/directed-graph.test.ts +15 -15
  82. package/test/unit/data-structures/graph/map-graph.test.ts +3 -3
  83. package/test/unit/data-structures/graph/undirected-graph.test.ts +12 -12
@@ -24,7 +24,7 @@ export class UndirectedVertex<V = any> extends AbstractVertex<V> {
24
24
  }
25
25
 
26
26
  export class UndirectedEdge<E = number> extends AbstractEdge<E> {
27
- vertices: [VertexKey, VertexKey];
27
+ vertexMap: [VertexKey, VertexKey];
28
28
 
29
29
  /**
30
30
  * The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
@@ -38,7 +38,7 @@ export class UndirectedEdge<E = number> extends AbstractEdge<E> {
38
38
  */
39
39
  constructor(v1: VertexKey, v2: VertexKey, weight?: number, value?: E) {
40
40
  super(weight, value);
41
- this.vertices = [v1, v2];
41
+ this.vertexMap = [v1, v2];
42
42
  }
43
43
  }
44
44
 
@@ -51,17 +51,17 @@ export class UndirectedGraph<
51
51
  extends AbstractGraph<V, E, VO, EO>
52
52
  implements IGraph<V, E, VO, EO> {
53
53
  /**
54
- * The constructor initializes a new Map object to store edges.
54
+ * The constructor initializes a new Map object to store edgeMap.
55
55
  */
56
56
  constructor() {
57
57
  super();
58
- this._edges = new Map<VO, EO[]>();
58
+ this._edgeMap = new Map<VO, EO[]>();
59
59
  }
60
60
 
61
- protected _edges: Map<VO, EO[]>;
61
+ protected _edgeMap: Map<VO, EO[]>;
62
62
 
63
- get edges(): Map<VO, EO[]> {
64
- return this._edges;
63
+ get edgeMap(): Map<VO, EO[]> {
64
+ return this._edgeMap;
65
65
  }
66
66
 
67
67
  /**
@@ -78,7 +78,7 @@ export class UndirectedGraph<
78
78
  }
79
79
 
80
80
  /**
81
- * The function creates an undirected edge between two vertices with an optional weight and value.
81
+ * The function creates an undirected edge between two vertexMap with an optional weight and value.
82
82
  * @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
83
83
  * @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
84
84
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
@@ -92,15 +92,15 @@ export class UndirectedGraph<
92
92
  }
93
93
 
94
94
  /**
95
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
95
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
96
96
  * Space Complexity: O(1)
97
97
  */
98
98
 
99
99
  /**
100
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
100
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
101
101
  * Space Complexity: O(1)
102
102
  *
103
- * The function `getEdge` returns the first edge that connects two vertices, or undefined if no such edge exists.
103
+ * The function `getEdge` returns the first edge that connects two vertexMap, or undefined if no such edge exists.
104
104
  * @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
105
105
  * object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
106
106
  * @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
@@ -108,34 +108,34 @@ export class UndirectedGraph<
108
108
  * @returns an edge (EO) or undefined.
109
109
  */
110
110
  getEdge(v1: VO | VertexKey | undefined, v2: VO | VertexKey | undefined): EO | undefined {
111
- let edges: EO[] | undefined = [];
111
+ let edgeMap: EO[] | undefined = [];
112
112
 
113
113
  if (v1 !== undefined && v2 !== undefined) {
114
114
  const vertex1: VO | undefined = this._getVertex(v1);
115
115
  const vertex2: VO | undefined = this._getVertex(v2);
116
116
 
117
117
  if (vertex1 && vertex2) {
118
- edges = this._edges.get(vertex1)?.filter(e => e.vertices.includes(vertex2.key));
118
+ edgeMap = this._edgeMap.get(vertex1)?.filter(e => e.vertexMap.includes(vertex2.key));
119
119
  }
120
120
  }
121
121
 
122
- return edges ? edges[0] || undefined : undefined;
122
+ return edgeMap ? edgeMap[0] || undefined : undefined;
123
123
  }
124
124
 
125
125
  /**
126
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
126
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
127
127
  * Space Complexity: O(1)
128
128
  */
129
129
 
130
130
  /**
131
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
131
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
132
132
  * Space Complexity: O(1)
133
133
  *
134
- * The function removes an edge between two vertices in a graph and returns the removed edge.
134
+ * The function removes an edge between two vertexMap in a graph and returns the removed edge.
135
135
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
136
136
  * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
137
137
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
138
- * @returns the removed edge (EO) if it exists, or undefined if either of the vertices (VO) does not exist.
138
+ * @returns the removed edge (EO) if it exists, or undefined if either of the vertexMap (VO) does not exist.
139
139
  */
140
140
  deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | undefined {
141
141
  const vertex1: VO | undefined = this._getVertex(v1);
@@ -145,29 +145,29 @@ export class UndirectedGraph<
145
145
  return undefined;
146
146
  }
147
147
 
148
- const v1Edges = this._edges.get(vertex1);
148
+ const v1Edges = this._edgeMap.get(vertex1);
149
149
  let removed: EO | undefined = undefined;
150
150
  if (v1Edges) {
151
- removed = arrayRemove<EO>(v1Edges, (e: EO) => e.vertices.includes(vertex2.key))[0] || undefined;
151
+ removed = arrayRemove<EO>(v1Edges, (e: EO) => e.vertexMap.includes(vertex2.key))[0] || undefined;
152
152
  }
153
- const v2Edges = this._edges.get(vertex2);
153
+ const v2Edges = this._edgeMap.get(vertex2);
154
154
  if (v2Edges) {
155
- arrayRemove<EO>(v2Edges, (e: EO) => e.vertices.includes(vertex1.key));
155
+ arrayRemove<EO>(v2Edges, (e: EO) => e.vertexMap.includes(vertex1.key));
156
156
  }
157
157
  return removed;
158
158
  }
159
159
 
160
160
  /**
161
- * Time Complexity: O(E), where E is the number of edges incident to the given vertex.
161
+ * Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
162
162
  * Space Complexity: O(1)
163
163
  */
164
164
 
165
165
 
166
166
  /**
167
- * Time Complexity: O(E), where E is the number of edges incident to the given vertex.
167
+ * Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
168
168
  * Space Complexity: O(1)
169
169
  *
170
- * The function `deleteEdge` deletes an edge between two vertices in a graph.
170
+ * The function `deleteEdge` deletes an edge between two vertexMap in a graph.
171
171
  * @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
172
172
  * either an edge object or a vertex key.
173
173
  * @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
@@ -186,8 +186,8 @@ export class UndirectedGraph<
186
186
  return;
187
187
  }
188
188
  } else {
189
- oneSide = this._getVertex(edgeOrOneSideVertexKey.vertices[0]);
190
- otherSide = this._getVertex(edgeOrOneSideVertexKey.vertices[1]);
189
+ oneSide = this._getVertex(edgeOrOneSideVertexKey.vertexMap[0]);
190
+ otherSide = this._getVertex(edgeOrOneSideVertexKey.vertexMap[1]);
191
191
  }
192
192
 
193
193
  if (oneSide && otherSide) {
@@ -227,19 +227,19 @@ export class UndirectedGraph<
227
227
 
228
228
  if (vertex) {
229
229
  neighbors.forEach(neighbor => {
230
- const neighborEdges = this._edges.get(neighbor);
230
+ const neighborEdges = this._edgeMap.get(neighbor);
231
231
  if (neighborEdges) {
232
232
  const restEdges = neighborEdges.filter(edge => {
233
- return !edge.vertices.includes(vertexKey);
233
+ return !edge.vertexMap.includes(vertexKey);
234
234
  });
235
- this._edges.set(neighbor, restEdges);
235
+ this._edgeMap.set(neighbor, restEdges);
236
236
  }
237
237
  })
238
- this._edges.delete(vertex);
238
+ this._edgeMap.delete(vertex);
239
239
 
240
240
  }
241
241
 
242
- return this._vertices.delete(vertexKey);
242
+ return this._vertexMap.delete(vertexKey);
243
243
  }
244
244
 
245
245
  /**
@@ -251,16 +251,16 @@ export class UndirectedGraph<
251
251
  * Time Complexity: O(1)
252
252
  * Space Complexity: O(1)
253
253
  *
254
- * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
254
+ * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edgeMap connected to that
255
255
  * vertex.
256
256
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
257
257
  * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
258
- * edges connected to that vertex.
258
+ * edgeMap connected to that vertex.
259
259
  */
260
260
  degreeOf(vertexOrKey: VertexKey | VO): number {
261
261
  const vertex = this._getVertex(vertexOrKey);
262
262
  if (vertex) {
263
- return this._edges.get(vertex)?.length || 0;
263
+ return this._edgeMap.get(vertex)?.length || 0;
264
264
  } else {
265
265
  return 0;
266
266
  }
@@ -275,36 +275,36 @@ export class UndirectedGraph<
275
275
  * Time Complexity: O(1)
276
276
  * Space Complexity: O(1)
277
277
  *
278
- * The function returns the edges of a given vertex or vertex ID.
278
+ * The function returns the edgeMap of a given vertex or vertex ID.
279
279
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
280
280
  * unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
281
- * @returns an array of edges.
281
+ * @returns an array of edgeMap.
282
282
  */
283
283
  edgesOf(vertexOrKey: VertexKey | VO): EO[] {
284
284
  const vertex = this._getVertex(vertexOrKey);
285
285
  if (vertex) {
286
- return this._edges.get(vertex) || [];
286
+ return this._edgeMap.get(vertex) || [];
287
287
  } else {
288
288
  return [];
289
289
  }
290
290
  }
291
291
 
292
292
  /**
293
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
293
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
294
294
  * Space Complexity: O(|E|)
295
295
  */
296
296
 
297
297
  /**
298
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
298
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
299
299
  * Space Complexity: O(|E|)
300
300
  *
301
- * The function "edgeSet" returns an array of unique edges from a set of edges.
301
+ * The function "edgeSet" returns an array of unique edgeMap from a set of edgeMap.
302
302
  * @returns The method `edgeSet()` returns an array of type `EO[]`.
303
303
  */
304
304
  edgeSet(): EO[] {
305
305
  const edgeSet: Set<EO> = new Set();
306
- this._edges.forEach(edges => {
307
- edges.forEach(edge => {
306
+ this._edgeMap.forEach(edgeMap => {
307
+ edgeMap.forEach(edge => {
308
308
  edgeSet.add(edge);
309
309
  });
310
310
  });
@@ -312,18 +312,18 @@ export class UndirectedGraph<
312
312
  }
313
313
 
314
314
  /**
315
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
315
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
316
316
  * Space Complexity: O(|E|)
317
317
  */
318
318
 
319
319
  /**
320
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
320
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
321
321
  * Space Complexity: O(|E|)
322
322
  *
323
- * The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
323
+ * The function "getNeighbors" returns an array of neighboring vertexMap for a given vertex or vertex ID.
324
324
  * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
325
325
  * (`VertexKey`).
326
- * @returns an array of vertices (VO[]).
326
+ * @returns an array of vertexMap (VO[]).
327
327
  */
328
328
  getNeighbors(vertexOrKey: VO | VertexKey): VO[] {
329
329
  const neighbors: VO[] = [];
@@ -331,7 +331,7 @@ export class UndirectedGraph<
331
331
  if (vertex) {
332
332
  const neighborEdges = this.edgesOf(vertex);
333
333
  for (const edge of neighborEdges) {
334
- const neighbor = this._getVertex(edge.vertices.filter(e => e !== vertex.key)[0]);
334
+ const neighbor = this._getVertex(edge.vertexMap.filter(e => e !== vertex.key)[0]);
335
335
  if (neighbor) {
336
336
  neighbors.push(neighbor);
337
337
  }
@@ -349,18 +349,18 @@ export class UndirectedGraph<
349
349
  * Time Complexity: O(1)
350
350
  * Space Complexity: O(1)
351
351
  *
352
- * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
352
+ * The function "getEndsOfEdge" returns the vertexMap at the ends of an edge if the edge exists in the graph, otherwise
353
353
  * it returns undefined.
354
354
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
355
- * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
355
+ * @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
356
356
  * graph. If the edge does not exist, it returns `undefined`.
357
357
  */
358
358
  getEndsOfEdge(edge: EO): [VO, VO] | undefined {
359
- if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
359
+ if (!this.hasEdge(edge.vertexMap[0], edge.vertexMap[1])) {
360
360
  return undefined;
361
361
  }
362
- const v1 = this._getVertex(edge.vertices[0]);
363
- const v2 = this._getVertex(edge.vertices[1]);
362
+ const v1 = this._getVertex(edge.vertexMap[0]);
363
+ const v2 = this._getVertex(edge.vertexMap[1]);
364
364
  if (v1 && v2) {
365
365
  return [v1, v2];
366
366
  } else {
@@ -377,20 +377,20 @@ export class UndirectedGraph<
377
377
  * Time Complexity: O(1)
378
378
  * Space Complexity: O(1)
379
379
  *
380
- * The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
380
+ * The function adds an edge to the graph by updating the adjacency list with the vertexMap of the edge.
381
381
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
382
382
  * @returns a boolean value.
383
383
  */
384
384
  protected _addEdgeOnly(edge: EO): boolean {
385
- for (const end of edge.vertices) {
385
+ for (const end of edge.vertexMap) {
386
386
  const endVertex = this._getVertex(end);
387
387
  if (endVertex === undefined) return false;
388
388
  if (endVertex) {
389
- const edges = this._edges.get(endVertex);
390
- if (edges) {
391
- edges.push(edge);
389
+ const edgeMap = this._edgeMap.get(endVertex);
390
+ if (edgeMap) {
391
+ edgeMap.push(edge);
392
392
  } else {
393
- this._edges.set(endVertex, [edge]);
393
+ this._edgeMap.set(endVertex, [edge]);
394
394
  }
395
395
  }
396
396
  }
@@ -7,10 +7,10 @@
7
7
  */
8
8
 
9
9
  import { isWeakKey, rangeCheck } from '../../utils';
10
- import { HashMapLinkedNode, HashMapOptions, HashMapStoreItem, PairCallback } from '../../types';
11
- import { IterablePairBase } from "../base";
10
+ import { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem } from '../../types';
11
+ import { IterableEntryBase } from "../base";
12
12
 
13
- export class HashMap<K = any, V = any> extends IterablePairBase<K, V> {
13
+ export class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
14
14
  protected _store: { [key: string]: HashMapStoreItem<K, V> } = {};
15
15
  protected _objMap: Map<object, V> = new Map();
16
16
 
@@ -165,7 +165,7 @@ export class HashMap<K = any, V = any> extends IterablePairBase<K, V> {
165
165
  * @returns The `map` method is returning a new `HashMap` object with the transformed values based on
166
166
  * the provided callback function.
167
167
  */
168
- map<U>(callbackfn: PairCallback<K, V, U>, thisArg?: any): HashMap<K, U> {
168
+ map<U>(callbackfn: EntryCallback<K, V, U>, thisArg?: any): HashMap<K, U> {
169
169
  const resultMap = new HashMap<K, U>();
170
170
  let index = 0;
171
171
  for (const [key, value] of this) {
@@ -195,7 +195,7 @@ export class HashMap<K = any, V = any> extends IterablePairBase<K, V> {
195
195
  * @returns The `filter` method is returning a new `HashMap` object that contains the key-value pairs
196
196
  * from the original `HashMap` that pass the provided `predicate` function.
197
197
  */
198
- filter(predicate: PairCallback<K, V, boolean>, thisArg?: any): HashMap<K, V> {
198
+ filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): HashMap<K, V> {
199
199
  const filteredMap = new HashMap<K, V>();
200
200
  let index = 0;
201
201
  for (const [key, value] of this) {
@@ -248,7 +248,7 @@ export class HashMap<K = any, V = any> extends IterablePairBase<K, V> {
248
248
  }
249
249
  }
250
250
 
251
- export class LinkedHashMap<K = any, V = any> extends IterablePairBase<K, V> {
251
+ export class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K, V> {
252
252
 
253
253
  protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>> = {};
254
254
  protected _objMap = new WeakMap<object, HashMapLinkedNode<K, V | undefined>>();
@@ -567,7 +567,7 @@ export class LinkedHashMap<K = any, V = any> extends IterablePairBase<K, V> {
567
567
  * @returns a new `LinkedHashMap` object that contains the key-value pairs from the original
568
568
  * `LinkedHashMap` object that satisfy the given predicate function.
569
569
  */
570
- filter(predicate: PairCallback<K, V, boolean>, thisArg?: any): LinkedHashMap<K, V> {
570
+ filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): LinkedHashMap<K, V> {
571
571
  const filteredMap = new LinkedHashMap<K, V>();
572
572
  let index = 0;
573
573
  for (const [key, value] of this) {
@@ -601,7 +601,7 @@ export class LinkedHashMap<K = any, V = any> extends IterablePairBase<K, V> {
601
601
  * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
602
602
  * function.
603
603
  */
604
- map<NV>(callback: PairCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV> {
604
+ map<NV>(callback: EntryCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV> {
605
605
  const mappedMap = new LinkedHashMap<K, NV>();
606
606
  let index = 0;
607
607
  for (const [key, value] of this) {
@@ -13,7 +13,7 @@ export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V,
13
13
 
14
14
  createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
15
15
 
16
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, count?: number): N | null | undefined;
16
+ add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
17
17
 
18
18
  addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>): (N | null | undefined)[];
19
19
 
@@ -1,6 +1,6 @@
1
- import { IterableElementBase, IterablePairBase } from "../../../data-structures";
1
+ import { IterableElementBase, IterableEntryBase } from "../../../data-structures";
2
2
 
3
- export type PairCallback<K, V, R> = (value: V, key: K, index: number, container: IterablePairBase<K, V>) => R;
3
+ export type EntryCallback<K, V, R> = (value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
4
4
  export type ElementCallback<V, R> = (element: V, index: number, container: IterableElementBase<V>) => R;
5
- export type ReducePairCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, container: IterablePairBase<K, V>) => R;
5
+ export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
6
6
  export type ReduceElementCallback<V, R> = (accumulator: R, element: V, index: number, container: IterableElementBase<V>) => R;
@@ -183,7 +183,7 @@ describe('Individual package BST operations test', () => {
183
183
  });
184
184
 
185
185
  it('should perform various operations on a Binary Search Tree with object values', () => {
186
- const objBST = new BST<number,{ key: number; keyA: number }>();
186
+ const objBST = new BST<number, { key: number; keyA: number }>();
187
187
  expect(objBST).toBeInstanceOf(BST);
188
188
  objBST.add([11, { key: 11, keyA: 11 }]);
189
189
  objBST.add([3, { key: 3, keyA: 3 }]);
@@ -569,7 +569,7 @@ describe('BinaryTree iterative methods test', () => {
569
569
  beforeEach(() => {
570
570
  binaryTree = new BinaryTree();
571
571
  binaryTree.add([1, 'a']);
572
- binaryTree.add([2, 'b']);
572
+ binaryTree.add(2, 'b');
573
573
  binaryTree.add([3, 'c']);
574
574
  });
575
575
 
@@ -605,9 +605,9 @@ describe('TreeMultimap iterative methods test', () => {
605
605
  let treeMM: TreeMultimap<number, string>;
606
606
  beforeEach(() => {
607
607
  treeMM = new TreeMultimap<number, string>();
608
- treeMM.add([1, 'a'], 10);
609
- treeMM.add([2, 'b'], 10);
610
- treeMM.add([3, 'c'], 1);
608
+ treeMM.add(1, 'a', 10);
609
+ treeMM.add([2, 'b'], undefined, 10);
610
+ treeMM.add([3, 'c'], undefined, 1);
611
611
  });
612
612
 
613
613
  test('The node obtained by get Node should match the node type', () => {
@@ -7,7 +7,7 @@ describe('DirectedGraph Operation Test', () => {
7
7
  graph = new DirectedGraph();
8
8
  });
9
9
 
10
- it('should add vertices', () => {
10
+ it('should add vertexMap', () => {
11
11
  const vertex1 = new DirectedVertex('A');
12
12
  const vertex2 = new DirectedVertex('B');
13
13
 
@@ -155,7 +155,7 @@ describe('Inherit from DirectedGraph and perform operations', () => {
155
155
  myGraph = new MyDirectedGraph();
156
156
  });
157
157
 
158
- it('Add vertices', () => {
158
+ it('Add vertexMap', () => {
159
159
  myGraph.addVertex(1, 'data1');
160
160
  myGraph.addVertex(2, 'data2');
161
161
  myGraph.addVertex(3, 'data3');
@@ -204,7 +204,7 @@ describe('Inherit from DirectedGraph and perform operations', () => {
204
204
  expect(true).toBeTruthy();
205
205
  });
206
206
 
207
- it('Remove edge between vertices', () => {
207
+ it('Remove edge between vertexMap', () => {
208
208
  myGraph.addVertex(1, 'data1');
209
209
  myGraph.addVertex(2, 'data2');
210
210
  myGraph.addEdge(1, 2, 10, 'edge-data1-2');
@@ -232,14 +232,14 @@ describe('Inherit from DirectedGraph and perform operations', () => {
232
232
  }
233
233
  });
234
234
 
235
- it('Minimum path between vertices', () => {
235
+ it('Minimum path between vertexMap', () => {
236
236
  myGraph.addVertex(new MyVertex(1, 'data1'));
237
237
  myGraph.addVertex(new MyVertex(2, 'data2'));
238
238
  myGraph.addEdge(new MyEdge(1, 2, 10, 'edge-data1-2'));
239
239
  });
240
240
 
241
- it('All paths between vertices', () => {
242
- // Add vertices and edges as needed for this test
241
+ it('All paths between vertexMap', () => {
242
+ // Add vertexMap and edges as needed for this test
243
243
  myGraph.addVertex(new MyVertex(1, 'data1'));
244
244
  myGraph.addVertex(new MyVertex(2, 'data2'));
245
245
  myGraph.addEdge(new MyEdge(1, 2, 10, 'edge-data1-2'));
@@ -598,41 +598,41 @@ describe('cycles, strongly connected components, bridges, articular points in Di
598
598
 
599
599
  describe('DirectedGraph iterative Methods', () => {
600
600
  let graph: DirectedGraph<string>;
601
- let vertices: string[];
601
+ let vertexMap: string[];
602
602
 
603
603
  beforeEach(() => {
604
604
  graph = new DirectedGraph();
605
- vertices = ['A', 'B', 'C', 'D'];
606
- vertices.forEach(vertex => graph.addVertex(vertex));
605
+ vertexMap = ['A', 'B', 'C', 'D'];
606
+ vertexMap.forEach(vertex => graph.addVertex(vertex));
607
607
  });
608
608
 
609
- test('[Symbol.iterator] should iterate over all vertices', () => {
609
+ test('[Symbol.iterator] should iterate over all vertexMap', () => {
610
610
  const iteratedVertices = [];
611
611
  for (const vertex of graph) {
612
612
  iteratedVertices.push(vertex[0]);
613
613
  }
614
- expect(iteratedVertices).toEqual(vertices);
614
+ expect(iteratedVertices).toEqual(vertexMap);
615
615
  });
616
616
 
617
617
  test('forEach should apply a function to each vertex', () => {
618
618
  const result: VertexKey[] = [];
619
619
  graph.forEach((value, key) => key && result.push(key));
620
- expect(result).toEqual(vertices);
620
+ expect(result).toEqual(vertexMap);
621
621
  });
622
622
 
623
- test('filter should return vertices that satisfy the condition', () => {
623
+ test('filter should return vertexMap that satisfy the condition', () => {
624
624
  const filtered = graph.filter((value, vertex) => vertex === 'A' || vertex === 'B');
625
625
  expect(filtered).toEqual([["A", undefined], ["B", undefined]]);
626
626
  });
627
627
 
628
628
  test('map should apply a function to each vertex and return a new array', () => {
629
629
  const mapped = graph.map((value, vertex) => vertex + '_mapped');
630
- expect(mapped).toEqual(vertices.map(v => v + '_mapped'));
630
+ expect(mapped).toEqual(vertexMap.map(v => v + '_mapped'));
631
631
  });
632
632
 
633
633
  test('reduce should accumulate a value based on each vertex', () => {
634
634
  const concatenated = graph.reduce((acc, value, key) => acc + key, '');
635
- expect(concatenated).toBe(vertices.join(''));
635
+ expect(concatenated).toBe(vertexMap.join(''));
636
636
  });
637
637
 
638
638
  test('Removing an edge of a DirectedGraph should not delete additional edges', () => {
@@ -52,8 +52,8 @@ describe('MapGraph', () => {
52
52
  mapGraph = new MapGraph<string, string>([0, 0], [100, 100]);
53
53
  });
54
54
 
55
- // Test adding vertices to the graph
56
- it('should add vertices to the graph', () => {
55
+ // Test adding vertexMap to the graph
56
+ it('should add vertexMap to the graph', () => {
57
57
  const locationA = new MapVertex('A', 'Location A', 10, 20);
58
58
  const locationB = new MapVertex('B', 'Location B', 30, 40);
59
59
 
@@ -88,7 +88,7 @@ describe('MapGraph', () => {
88
88
  const edgeAB = new MapEdge('A', 'B', 50, 'Edge from A to B');
89
89
  const edgeBC = new MapEdge('B', 'C', 60, 'Edge from B to C');
90
90
 
91
- expect(mapGraph.origin).toEqual([0, 0]);
91
+ expect(mapGraph.originCoord).toEqual([0, 0]);
92
92
  expect(mapGraph.bottomRight).toEqual([100, 100]);
93
93
 
94
94
  mapGraph.addVertex(locationA);
@@ -17,7 +17,7 @@ describe('UndirectedGraph Operation Test', () => {
17
17
  expect(graph.getEndsOfEdge(new UndirectedEdge('c', 'd'))).toBe(undefined);
18
18
  });
19
19
 
20
- it('should add vertices', () => {
20
+ it('should add vertexMap', () => {
21
21
  const vertex1 = new UndirectedVertex('A');
22
22
  const vertex2 = new UndirectedVertex('B');
23
23
 
@@ -76,8 +76,8 @@ describe('UndirectedGraph', () => {
76
76
  undirectedGraph = new UndirectedGraph<string, string>();
77
77
  });
78
78
 
79
- // Test adding vertices to the graph
80
- it('should add vertices to the graph', () => {
79
+ // Test adding vertexMap to the graph
80
+ it('should add vertexMap to the graph', () => {
81
81
  const vertexA = new UndirectedVertex('A', 'Location A');
82
82
  const vertexB = new UndirectedVertex('B', 'Location B');
83
83
 
@@ -130,8 +130,8 @@ describe('UndirectedGraph', () => {
130
130
  const edgeAB = new UndirectedEdge('A', 'B', 3, 'Edge between A and B');
131
131
  const edgeBC = new UndirectedEdge('B', 'C', 4, 'Edge between B and C');
132
132
 
133
- edgeAB.vertices = edgeAB.vertices;
134
- expect(undirectedGraph.edges.size).toBe(0);
133
+ edgeAB.vertexMap = edgeAB.vertexMap;
134
+ expect(undirectedGraph.edgeMap.size).toBe(0);
135
135
  undirectedGraph.addVertex(vertexA);
136
136
  undirectedGraph.addVertex(vertexB);
137
137
  undirectedGraph.addVertex(vertexC);
@@ -181,10 +181,10 @@ describe('UndirectedGraph', () => {
181
181
  dg.addVertex('hey')
182
182
  dg.addEdge('hello', 'hi')
183
183
  dg.addEdge('hello', 'hey')
184
- expect(dg.getEdge('hello', 'hi')?.vertices[0]).toBe('hello')
185
- expect(dg.getEdge('hello', 'hi')?.vertices[1]).toBe('hi')
186
- expect(dg.getEdge('hello', 'hey')?.vertices[0]).toBe('hello')
187
- expect(dg.getEdge('hello', 'hey')?.vertices[1]).toBe('hey')
184
+ expect(dg.getEdge('hello', 'hi')?.vertexMap[0]).toBe('hello')
185
+ expect(dg.getEdge('hello', 'hi')?.vertexMap[1]).toBe('hi')
186
+ expect(dg.getEdge('hello', 'hey')?.vertexMap[0]).toBe('hello')
187
+ expect(dg.getEdge('hello', 'hey')?.vertexMap[1]).toBe('hey')
188
188
  dg.deleteEdge('hello', 'hi')
189
189
  expect(dg.getEdge('hello', 'hi')).toBe(undefined)
190
190
  expect(dg.getEdge('hello', 'hey')).toBeInstanceOf(UndirectedEdge)
@@ -200,13 +200,13 @@ describe('UndirectedGraph', () => {
200
200
  dg.addEdge('hello', 'earth')
201
201
  dg.addEdge('world', 'earth')
202
202
 
203
- expect(dg.getEdge('hello', 'world')?.vertices[0]).toBe('hello');
203
+ expect(dg.getEdge('hello', 'world')?.vertexMap[0]).toBe('hello');
204
204
  expect(dg.edgeSet().length).toBe(3)
205
- expect(dg.edgeSet()[0].vertices).toEqual(['hello', 'world'])
205
+ expect(dg.edgeSet()[0].vertexMap).toEqual(['hello', 'world'])
206
206
 
207
207
  dg.deleteVertex('hello')
208
208
  expect(dg.edgeSet().length).toBe(1)
209
- expect(dg.edgeSet()?.[0].vertices[0]).toBe('world')
209
+ expect(dg.edgeSet()?.[0].vertexMap[0]).toBe('world')
210
210
 
211
211
  expect(dg.getEdge('hello', 'world')).toBe(undefined);
212
212
  })