priority-queue-typed 1.48.4 → 1.48.6
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.
- package/dist/data-structures/base/iterable-base.d.ts +6 -6
- package/dist/data-structures/base/iterable-base.js +3 -3
- package/dist/data-structures/binary-tree/avl-tree.d.ts +5 -3
- package/dist/data-structures/binary-tree/avl-tree.js +6 -4
- package/dist/data-structures/binary-tree/binary-tree.d.ts +24 -22
- package/dist/data-structures/binary-tree/binary-tree.js +35 -22
- package/dist/data-structures/binary-tree/bst.d.ts +30 -22
- package/dist/data-structures/binary-tree/bst.js +38 -26
- package/dist/data-structures/binary-tree/rb-tree.d.ts +19 -13
- package/dist/data-structures/binary-tree/rb-tree.js +20 -14
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +21 -14
- package/dist/data-structures/binary-tree/tree-multimap.js +25 -18
- package/dist/data-structures/graph/abstract-graph.d.ts +52 -52
- package/dist/data-structures/graph/abstract-graph.js +78 -78
- package/dist/data-structures/graph/directed-graph.d.ts +47 -47
- package/dist/data-structures/graph/directed-graph.js +56 -56
- package/dist/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/data-structures/graph/map-graph.js +8 -8
- package/dist/data-structures/graph/undirected-graph.d.ts +29 -29
- package/dist/data-structures/graph/undirected-graph.js +57 -57
- package/dist/data-structures/hash/hash-map.d.ts +8 -8
- package/dist/data-structures/hash/hash-map.js +2 -2
- package/dist/interfaces/binary-tree.d.ts +2 -2
- package/dist/types/data-structures/base/base.d.ts +3 -3
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +6 -6
- package/src/data-structures/binary-tree/avl-tree.ts +7 -4
- package/src/data-structures/binary-tree/binary-tree.ts +47 -27
- package/src/data-structures/binary-tree/bst.ts +52 -32
- package/src/data-structures/binary-tree/rb-tree.ts +20 -14
- package/src/data-structures/binary-tree/tree-multimap.ts +26 -18
- package/src/data-structures/graph/abstract-graph.ts +82 -82
- package/src/data-structures/graph/directed-graph.ts +56 -56
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +59 -59
- package/src/data-structures/hash/hash-map.ts +8 -8
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/types/data-structures/base/base.ts +3 -3
|
@@ -28,7 +28,7 @@ export class DirectedEdge<E = any> extends AbstractEdge<E> {
|
|
|
28
28
|
dest: VertexKey;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* The constructor function initializes the source and destination
|
|
31
|
+
* The constructor function initializes the source and destination vertexMap of an edge, along with an optional weight
|
|
32
32
|
* and value.
|
|
33
33
|
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
34
34
|
* a graph.
|
|
@@ -80,7 +80,7 @@ export class DirectedGraph<
|
|
|
80
80
|
/**
|
|
81
81
|
* The function creates a new vertex with an optional value and returns it.
|
|
82
82
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
83
|
-
* could be a number or a string depending on how you want to identify your
|
|
83
|
+
* could be a number or a string depending on how you want to identify your vertexMap.
|
|
84
84
|
* @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
85
85
|
* it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
|
|
86
86
|
* assigned the same value as the 'key' parameter
|
|
@@ -96,7 +96,7 @@ export class DirectedGraph<
|
|
|
96
96
|
*/
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* The function creates a directed edge between two
|
|
99
|
+
* The function creates a directed edge between two vertexMap with an optional weight and value.
|
|
100
100
|
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
101
101
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
102
102
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
@@ -110,23 +110,23 @@ export class DirectedGraph<
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
|
-
* Time Complexity: O(|V|) where |V| is the number of
|
|
113
|
+
* Time Complexity: O(|V|) where |V| is the number of vertexMap
|
|
114
114
|
* Space Complexity: O(1)
|
|
115
115
|
*/
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
|
-
* Time Complexity: O(|V|) where |V| is the number of
|
|
118
|
+
* Time Complexity: O(|V|) where |V| is the number of vertexMap
|
|
119
119
|
* Space Complexity: O(1)
|
|
120
120
|
*
|
|
121
|
-
* The `getEdge` function retrieves an edge between two
|
|
121
|
+
* The `getEdge` function retrieves an edge between two vertexMap based on their source and destination IDs.
|
|
122
122
|
* @param {VO | VertexKey | undefined} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
123
123
|
* @param {VO | VertexKey | undefined} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
124
124
|
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `undefined` if the
|
|
125
125
|
* destination is not specified.
|
|
126
|
-
* @returns the first edge found between the source and destination
|
|
126
|
+
* @returns the first edge found between the source and destination vertexMap, or undefined if no such edge is found.
|
|
127
127
|
*/
|
|
128
128
|
getEdge(srcOrKey: VO | VertexKey | undefined, destOrKey: VO | VertexKey | undefined): EO | undefined {
|
|
129
|
-
let
|
|
129
|
+
let edgeMap: EO[] = [];
|
|
130
130
|
|
|
131
131
|
if (srcOrKey !== undefined && destOrKey !== undefined) {
|
|
132
132
|
const src: VO | undefined = this._getVertex(srcOrKey);
|
|
@@ -135,24 +135,24 @@ export class DirectedGraph<
|
|
|
135
135
|
if (src && dest) {
|
|
136
136
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
137
137
|
if (srcOutEdges) {
|
|
138
|
-
|
|
138
|
+
edgeMap = srcOutEdges.filter(edge => edge.dest === dest.key);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
return
|
|
143
|
+
return edgeMap[0] || undefined;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
147
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
148
148
|
* Space Complexity: O(1)
|
|
149
149
|
*/
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
152
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
153
153
|
* Space Complexity: O(1)
|
|
154
154
|
*
|
|
155
|
-
* The function removes an edge between two
|
|
155
|
+
* The function removes an edge between two vertexMap in a graph and returns the removed edge.
|
|
156
156
|
* @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
|
|
157
157
|
* @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
158
158
|
* @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
|
|
@@ -178,13 +178,13 @@ export class DirectedGraph<
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
/**
|
|
181
|
-
* Time Complexity: O(E) where E is the number of
|
|
181
|
+
* Time Complexity: O(E) where E is the number of edgeMap
|
|
182
182
|
* Space Complexity: O(1)
|
|
183
183
|
*/
|
|
184
184
|
|
|
185
185
|
|
|
186
186
|
/**
|
|
187
|
-
* Time Complexity: O(E) where E is the number of
|
|
187
|
+
* Time Complexity: O(E) where E is the number of edgeMap
|
|
188
188
|
* Space Complexity: O(1)
|
|
189
189
|
*
|
|
190
190
|
* The `deleteEdge` function removes an edge from a graph and returns the removed edge.
|
|
@@ -256,24 +256,24 @@ export class DirectedGraph<
|
|
|
256
256
|
this._inEdgeMap.delete(vertex)
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
return this.
|
|
259
|
+
return this._vertexMap.delete(vertexKey);
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
/**
|
|
263
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
263
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
264
264
|
* Space Complexity: O(1)
|
|
265
265
|
*/
|
|
266
266
|
|
|
267
267
|
/**
|
|
268
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
268
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
269
269
|
* Space Complexity: O(1)
|
|
270
270
|
*
|
|
271
|
-
* The function removes
|
|
271
|
+
* The function removes edgeMap between two vertexMap and returns the removed edgeMap.
|
|
272
272
|
* @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
|
|
273
273
|
* unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
|
|
274
274
|
* @param {VertexKey | VO} v2 - The parameter `v2` represents either a `VertexKey` or a `VO` object. It is used to specify
|
|
275
275
|
* the second vertex in the edge that needs to be removed.
|
|
276
|
-
* @returns an array of removed
|
|
276
|
+
* @returns an array of removed edgeMap (EO[]).
|
|
277
277
|
*/
|
|
278
278
|
deleteEdgesBetween(v1: VertexKey | VO, v2: VertexKey | VO): EO[] {
|
|
279
279
|
const removed: EO[] = [];
|
|
@@ -298,10 +298,10 @@ export class DirectedGraph<
|
|
|
298
298
|
* Time Complexity: O(1)
|
|
299
299
|
* Space Complexity: O(1)
|
|
300
300
|
*
|
|
301
|
-
* The function `incomingEdgesOf` returns an array of incoming
|
|
301
|
+
* The function `incomingEdgesOf` returns an array of incoming edgeMap for a given vertex or vertex ID.
|
|
302
302
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
303
303
|
* (`VertexKey`).
|
|
304
|
-
* @returns The method `incomingEdgesOf` returns an array of
|
|
304
|
+
* @returns The method `incomingEdgesOf` returns an array of edgeMap (`EO[]`).
|
|
305
305
|
*/
|
|
306
306
|
incomingEdgesOf(vertexOrKey: VO | VertexKey): EO[] {
|
|
307
307
|
const target = this._getVertex(vertexOrKey);
|
|
@@ -320,10 +320,10 @@ export class DirectedGraph<
|
|
|
320
320
|
* Time Complexity: O(1)
|
|
321
321
|
* Space Complexity: O(1)
|
|
322
322
|
*
|
|
323
|
-
* The function `outgoingEdgesOf` returns an array of outgoing
|
|
323
|
+
* The function `outgoingEdgesOf` returns an array of outgoing edgeMap from a given vertex or vertex ID.
|
|
324
324
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
|
|
325
325
|
* (`VertexKey`).
|
|
326
|
-
* @returns The method `outgoingEdgesOf` returns an array of
|
|
326
|
+
* @returns The method `outgoingEdgesOf` returns an array of edgeMap (`EO[]`).
|
|
327
327
|
*/
|
|
328
328
|
outgoingEdgesOf(vertexOrKey: VO | VertexKey): EO[] {
|
|
329
329
|
const target = this._getVertex(vertexOrKey);
|
|
@@ -359,9 +359,9 @@ export class DirectedGraph<
|
|
|
359
359
|
* Time Complexity: O(1)
|
|
360
360
|
* Space Complexity: O(1)
|
|
361
361
|
*
|
|
362
|
-
* The function "inDegreeOf" returns the number of incoming
|
|
362
|
+
* The function "inDegreeOf" returns the number of incoming edgeMap for a given vertex.
|
|
363
363
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
364
|
-
* @returns The number of incoming
|
|
364
|
+
* @returns The number of incoming edgeMap of the specified vertex or vertex ID.
|
|
365
365
|
*/
|
|
366
366
|
inDegreeOf(vertexOrKey: VertexKey | VO): number {
|
|
367
367
|
return this.incomingEdgesOf(vertexOrKey).length;
|
|
@@ -376,9 +376,9 @@ export class DirectedGraph<
|
|
|
376
376
|
* Time Complexity: O(1)
|
|
377
377
|
* Space Complexity: O(1)
|
|
378
378
|
*
|
|
379
|
-
* The function `outDegreeOf` returns the number of outgoing
|
|
379
|
+
* The function `outDegreeOf` returns the number of outgoing edgeMap from a given vertex.
|
|
380
380
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
381
|
-
* @returns The number of outgoing
|
|
381
|
+
* @returns The number of outgoing edgeMap from the specified vertex or vertex ID.
|
|
382
382
|
*/
|
|
383
383
|
outDegreeOf(vertexOrKey: VertexKey | VO): number {
|
|
384
384
|
return this.outgoingEdgesOf(vertexOrKey).length;
|
|
@@ -393,9 +393,9 @@ export class DirectedGraph<
|
|
|
393
393
|
* Time Complexity: O(1)
|
|
394
394
|
* Space Complexity: O(1)
|
|
395
395
|
*
|
|
396
|
-
* The function "edgesOf" returns an array of both outgoing and incoming
|
|
396
|
+
* The function "edgesOf" returns an array of both outgoing and incoming edgeMap of a given vertex or vertex ID.
|
|
397
397
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
398
|
-
* @returns The function `edgesOf` returns an array of
|
|
398
|
+
* @returns The function `edgesOf` returns an array of edgeMap.
|
|
399
399
|
*/
|
|
400
400
|
edgesOf(vertexOrKey: VertexKey | VO): EO[] {
|
|
401
401
|
return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
|
|
@@ -436,18 +436,18 @@ export class DirectedGraph<
|
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
/**
|
|
439
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
439
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
440
440
|
* Space Complexity: O(1)
|
|
441
441
|
*/
|
|
442
442
|
|
|
443
443
|
/**
|
|
444
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
444
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
445
445
|
* Space Complexity: O(1)
|
|
446
446
|
*
|
|
447
|
-
* The function `getDestinations` returns an array of destination
|
|
447
|
+
* The function `getDestinations` returns an array of destination vertexMap connected to a given vertex.
|
|
448
448
|
* @param {VO | VertexKey | undefined} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
449
449
|
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `undefined`.
|
|
450
|
-
* @returns an array of
|
|
450
|
+
* @returns an array of vertexMap (VO[]).
|
|
451
451
|
*/
|
|
452
452
|
getDestinations(vertex: VO | VertexKey | undefined): VO[] {
|
|
453
453
|
if (vertex === undefined) {
|
|
@@ -465,27 +465,27 @@ export class DirectedGraph<
|
|
|
465
465
|
}
|
|
466
466
|
|
|
467
467
|
/**
|
|
468
|
-
* Time Complexity: O(|V| + |E|) where |V| is the number of
|
|
468
|
+
* Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
|
|
469
469
|
* Space Complexity: O(|V|)
|
|
470
470
|
*/
|
|
471
471
|
|
|
472
472
|
/**
|
|
473
|
-
* Time Complexity: O(|V| + |E|) where |V| is the number of
|
|
473
|
+
* Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
|
|
474
474
|
* Space Complexity: O(|V|)
|
|
475
475
|
*
|
|
476
|
-
* The `topologicalSort` function performs a topological sort on a graph and returns an array of
|
|
476
|
+
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertexMap or vertex IDs
|
|
477
477
|
* in the sorted order, or undefined if the graph contains a cycle.
|
|
478
478
|
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
479
|
-
* property to use for sorting the
|
|
480
|
-
* specified, the
|
|
481
|
-
* @returns an array of
|
|
479
|
+
* property to use for sorting the vertexMap. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
|
|
480
|
+
* specified, the vertexMap themselves will be used for sorting. If 'key' is specified, the ids of
|
|
481
|
+
* @returns an array of vertexMap or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
|
|
482
482
|
*/
|
|
483
483
|
topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | undefined {
|
|
484
484
|
propertyName = propertyName ?? 'key';
|
|
485
485
|
// When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
|
|
486
486
|
// When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
|
|
487
487
|
const statusMap: Map<VO | VertexKey, TopologicalStatus> = new Map<VO | VertexKey, TopologicalStatus>();
|
|
488
|
-
for (const entry of this.
|
|
488
|
+
for (const entry of this.vertexMap) {
|
|
489
489
|
statusMap.set(entry[1], 0);
|
|
490
490
|
}
|
|
491
491
|
|
|
@@ -506,7 +506,7 @@ export class DirectedGraph<
|
|
|
506
506
|
sorted.push(cur);
|
|
507
507
|
};
|
|
508
508
|
|
|
509
|
-
for (const entry of this.
|
|
509
|
+
for (const entry of this.vertexMap) {
|
|
510
510
|
if (statusMap.get(entry[1]) === 0) {
|
|
511
511
|
dfs(entry[1]);
|
|
512
512
|
}
|
|
@@ -519,38 +519,38 @@ export class DirectedGraph<
|
|
|
519
519
|
}
|
|
520
520
|
|
|
521
521
|
/**
|
|
522
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
522
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
523
523
|
* Space Complexity: O(|E|)
|
|
524
524
|
*/
|
|
525
525
|
|
|
526
526
|
/**
|
|
527
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
527
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
528
528
|
* Space Complexity: O(|E|)
|
|
529
529
|
*
|
|
530
|
-
* The `edgeSet` function returns an array of all the
|
|
531
|
-
* @returns The `edgeSet()` method returns an array of
|
|
530
|
+
* The `edgeSet` function returns an array of all the edgeMap in the graph.
|
|
531
|
+
* @returns The `edgeSet()` method returns an array of edgeMap (`EO[]`).
|
|
532
532
|
*/
|
|
533
533
|
edgeSet(): EO[] {
|
|
534
|
-
let
|
|
534
|
+
let edgeMap: EO[] = [];
|
|
535
535
|
this._outEdgeMap.forEach(outEdges => {
|
|
536
|
-
|
|
536
|
+
edgeMap = [...edgeMap, ...outEdges];
|
|
537
537
|
});
|
|
538
|
-
return
|
|
538
|
+
return edgeMap;
|
|
539
539
|
}
|
|
540
540
|
|
|
541
541
|
/**
|
|
542
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
542
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
543
543
|
* Space Complexity: O(1)
|
|
544
544
|
*/
|
|
545
545
|
|
|
546
546
|
/**
|
|
547
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
547
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
548
548
|
* Space Complexity: O(1)
|
|
549
549
|
*
|
|
550
|
-
* The function `getNeighbors` returns an array of neighboring
|
|
550
|
+
* The function `getNeighbors` returns an array of neighboring vertexMap of a given vertex or vertex ID in a graph.
|
|
551
551
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
552
552
|
* (`VertexKey`).
|
|
553
|
-
* @returns an array of
|
|
553
|
+
* @returns an array of vertexMap (VO[]).
|
|
554
554
|
*/
|
|
555
555
|
getNeighbors(vertexOrKey: VO | VertexKey): VO[] {
|
|
556
556
|
const neighbors: VO[] = [];
|
|
@@ -577,10 +577,10 @@ export class DirectedGraph<
|
|
|
577
577
|
* Time Complexity: O(1)
|
|
578
578
|
* Space Complexity: O(1)
|
|
579
579
|
*
|
|
580
|
-
* The function "getEndsOfEdge" returns the source and destination
|
|
580
|
+
* The function "getEndsOfEdge" returns the source and destination vertexMap of an edge if it exists in the graph,
|
|
581
581
|
* otherwise it returns undefined.
|
|
582
582
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
|
|
583
|
-
* @returns The function `getEndsOfEdge` returns an array containing two
|
|
583
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
|
|
584
584
|
* graph. If the edge does not exist, it returns `undefined`.
|
|
585
585
|
*/
|
|
586
586
|
getEndsOfEdge(edge: EO): [VO, VO] | undefined {
|
|
@@ -605,7 +605,7 @@ export class DirectedGraph<
|
|
|
605
605
|
* Time Complexity: O(1)
|
|
606
606
|
* Space Complexity: O(1)
|
|
607
607
|
*
|
|
608
|
-
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination
|
|
608
|
+
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertexMap exist.
|
|
609
609
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
610
610
|
* needs to be added to the graph.
|
|
611
611
|
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
@@ -47,24 +47,24 @@ export class MapGraph<
|
|
|
47
47
|
EO extends MapEdge<E> = MapEdge<E>
|
|
48
48
|
> extends DirectedGraph<V, E, VO, EO> {
|
|
49
49
|
/**
|
|
50
|
-
* The constructor function initializes the
|
|
51
|
-
* @param {MapGraphCoordinate}
|
|
50
|
+
* The constructor function initializes the originCoord and bottomRight properties of a MapGraphCoordinate object.
|
|
51
|
+
* @param {MapGraphCoordinate} originCoord - The `originCoord` parameter is a `MapGraphCoordinate` object that represents the
|
|
52
52
|
* starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
|
|
53
53
|
* graph.
|
|
54
54
|
* @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
|
|
55
55
|
* `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
|
|
56
56
|
* it will default to `undefined`.
|
|
57
57
|
*/
|
|
58
|
-
constructor(
|
|
58
|
+
constructor(originCoord: MapGraphCoordinate, bottomRight?: MapGraphCoordinate) {
|
|
59
59
|
super();
|
|
60
|
-
this.
|
|
60
|
+
this._originCoord = originCoord;
|
|
61
61
|
this._bottomRight = bottomRight;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
protected
|
|
64
|
+
protected _originCoord: MapGraphCoordinate = [0, 0];
|
|
65
65
|
|
|
66
|
-
get
|
|
67
|
-
return this.
|
|
66
|
+
get originCoord(): MapGraphCoordinate {
|
|
67
|
+
return this._originCoord;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
protected _bottomRight: MapGraphCoordinate | undefined;
|
|
@@ -84,7 +84,7 @@ export class MapGraph<
|
|
|
84
84
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
85
85
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
86
86
|
*/
|
|
87
|
-
override createVertex(key: VertexKey, value?: V, lat: number = this.
|
|
87
|
+
override createVertex(key: VertexKey, value?: V, lat: number = this.originCoord[0], long: number = this.originCoord[1]): VO {
|
|
88
88
|
return new MapVertex(key, value, lat, long) as VO;
|
|
89
89
|
}
|
|
90
90
|
|