min-heap-typed 1.39.4 → 1.39.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/binary-tree/avl-tree.d.ts +6 -6
- package/dist/data-structures/binary-tree/avl-tree.js +13 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +7 -7
- package/dist/data-structures/binary-tree/binary-tree.js +17 -17
- package/dist/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/data-structures/binary-tree/bst.js +13 -13
- package/dist/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/data-structures/binary-tree/rb-tree.js +4 -4
- package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -7
- package/dist/data-structures/binary-tree/segment-tree.js +16 -16
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/data-structures/binary-tree/tree-multiset.js +18 -18
- package/dist/data-structures/graph/abstract-graph.d.ts +96 -96
- package/dist/data-structures/graph/abstract-graph.js +64 -64
- package/dist/data-structures/graph/directed-graph.d.ts +68 -68
- package/dist/data-structures/graph/directed-graph.js +48 -48
- package/dist/data-structures/graph/map-graph.d.ts +13 -13
- package/dist/data-structures/graph/map-graph.js +15 -15
- package/dist/data-structures/graph/undirected-graph.d.ts +42 -42
- package/dist/data-structures/graph/undirected-graph.js +32 -32
- package/dist/data-structures/hash/hash-table.d.ts +4 -4
- package/dist/data-structures/hash/hash-table.js +8 -8
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
- package/dist/data-structures/linked-list/doubly-linked-list.js +54 -54
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +24 -24
- package/dist/data-structures/linked-list/singly-linked-list.js +52 -52
- package/dist/data-structures/queue/queue.d.ts +1 -1
- package/dist/data-structures/queue/queue.js +4 -4
- package/dist/interfaces/binary-tree.d.ts +2 -2
- package/dist/interfaces/graph.d.ts +3 -3
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +13 -13
- package/src/data-structures/binary-tree/binary-tree.ts +18 -18
- package/src/data-structures/binary-tree/bst.ts +16 -16
- package/src/data-structures/binary-tree/rb-tree.ts +6 -6
- package/src/data-structures/binary-tree/segment-tree.ts +15 -15
- package/src/data-structures/binary-tree/tree-multiset.ts +18 -18
- package/src/data-structures/graph/abstract-graph.ts +156 -154
- package/src/data-structures/graph/directed-graph.ts +99 -94
- package/src/data-structures/graph/map-graph.ts +22 -25
- package/src/data-structures/graph/undirected-graph.ts +62 -60
- package/src/data-structures/hash/hash-table.ts +9 -9
- package/src/data-structures/linked-list/doubly-linked-list.ts +61 -61
- package/src/data-structures/linked-list/singly-linked-list.ts +58 -58
- package/src/data-structures/queue/queue.ts +2 -2
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/interfaces/graph.ts +3 -3
|
@@ -15,11 +15,11 @@ class DirectedVertex extends abstract_graph_1.AbstractVertex {
|
|
|
15
15
|
* The constructor function initializes a vertex with an optional value.
|
|
16
16
|
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
17
17
|
* used to uniquely identify the vertex within a graph or data structure.
|
|
18
|
-
* @param {V} [
|
|
18
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
19
19
|
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
20
20
|
*/
|
|
21
|
-
constructor(key,
|
|
22
|
-
super(key,
|
|
21
|
+
constructor(key, value) {
|
|
22
|
+
super(key, value);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.DirectedVertex = DirectedVertex;
|
|
@@ -32,11 +32,11 @@ class DirectedEdge extends abstract_graph_1.AbstractEdge {
|
|
|
32
32
|
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
33
33
|
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
|
|
34
34
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
35
|
-
* @param {
|
|
35
|
+
* @param {E} [value] - The `value` parameter is an optional parameter of type `E`. It represents the value associated with
|
|
36
36
|
* the edge.
|
|
37
37
|
*/
|
|
38
|
-
constructor(src, dest, weight,
|
|
39
|
-
super(weight,
|
|
38
|
+
constructor(src, dest, weight, value) {
|
|
39
|
+
super(weight, value);
|
|
40
40
|
this._src = src;
|
|
41
41
|
this._dest = dest;
|
|
42
42
|
}
|
|
@@ -77,13 +77,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
77
77
|
* The function creates a new vertex with an optional value and returns it.
|
|
78
78
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
79
79
|
* could be a number or a string depending on how you want to identify your vertices.
|
|
80
|
-
* @param [
|
|
81
|
-
* it will be assigned to the '
|
|
80
|
+
* @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
81
|
+
* it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
|
|
82
82
|
* assigned the same value as the 'key' parameter
|
|
83
|
-
* @returns a new instance of a DirectedVertex object, casted as type
|
|
83
|
+
* @returns a new instance of a DirectedVertex object, casted as type VO.
|
|
84
84
|
*/
|
|
85
|
-
createVertex(key,
|
|
86
|
-
return new DirectedVertex(key,
|
|
85
|
+
createVertex(key, value) {
|
|
86
|
+
return new DirectedVertex(key, value !== null && value !== void 0 ? value : key);
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
|
@@ -95,18 +95,18 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
95
95
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
96
96
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
97
97
|
* weight is provided, it defaults to 1.
|
|
98
|
-
* @param [
|
|
98
|
+
* @param [value] - The 'value' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
99
99
|
* is used to store additional information or data associated with the edge.
|
|
100
|
-
* @returns a new instance of a DirectedEdge object, casted as type
|
|
100
|
+
* @returns a new instance of a DirectedEdge object, casted as type EO.
|
|
101
101
|
*/
|
|
102
|
-
createEdge(src, dest, weight,
|
|
103
|
-
return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1,
|
|
102
|
+
createEdge(src, dest, weight, value) {
|
|
103
|
+
return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1, value);
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
107
|
-
* @param {
|
|
108
|
-
* @param {
|
|
109
|
-
* destination vertex of the edge. It can be either a vertex object (`
|
|
107
|
+
* @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
108
|
+
* @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
109
|
+
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
|
|
110
110
|
* destination is not specified.
|
|
111
111
|
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
112
112
|
*/
|
|
@@ -126,9 +126,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
129
|
-
* @param {
|
|
130
|
-
* @param {
|
|
131
|
-
* @returns the removed edge (
|
|
129
|
+
* @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
|
|
130
|
+
* @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
131
|
+
* @returns the removed edge (EO) if it exists, or null if either the source or destination vertex does not exist.
|
|
132
132
|
*/
|
|
133
133
|
deleteEdgeSrcToDest(srcOrKey, destOrKey) {
|
|
134
134
|
const src = this._getVertex(srcOrKey);
|
|
@@ -149,9 +149,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
151
|
* The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
|
|
152
|
-
* @param {
|
|
152
|
+
* @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
153
153
|
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
154
|
-
* @returns The method `deleteEdge` returns the removed edge (`
|
|
154
|
+
* @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `null` if the edge does not exist.
|
|
155
155
|
*/
|
|
156
156
|
deleteEdge(edge) {
|
|
157
157
|
let removed = null;
|
|
@@ -171,11 +171,11 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
171
171
|
}
|
|
172
172
|
/**
|
|
173
173
|
* The function removes edges between two vertices and returns the removed edges.
|
|
174
|
-
* @param {VertexKey |
|
|
175
|
-
* unique identifier of a vertex in a graph, while `
|
|
176
|
-
* @param {VertexKey |
|
|
174
|
+
* @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
|
|
175
|
+
* unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
|
|
176
|
+
* @param {VertexKey | VO} v2 - The parameter `v2` represents either a `VertexKey` or a `VO` object. It is used to specify
|
|
177
177
|
* the second vertex in the edge that needs to be removed.
|
|
178
|
-
* @returns an array of removed edges (
|
|
178
|
+
* @returns an array of removed edges (EO[]).
|
|
179
179
|
*/
|
|
180
180
|
deleteEdgesBetween(v1, v2) {
|
|
181
181
|
const removed = [];
|
|
@@ -189,9 +189,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
191
191
|
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
192
|
-
* @param {
|
|
192
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
193
193
|
* (`VertexKey`).
|
|
194
|
-
* @returns The method `incomingEdgesOf` returns an array of edges (`
|
|
194
|
+
* @returns The method `incomingEdgesOf` returns an array of edges (`EO[]`).
|
|
195
195
|
*/
|
|
196
196
|
incomingEdgesOf(vertexOrKey) {
|
|
197
197
|
const target = this._getVertex(vertexOrKey);
|
|
@@ -202,9 +202,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
202
202
|
}
|
|
203
203
|
/**
|
|
204
204
|
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
205
|
-
* @param {
|
|
205
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
|
|
206
206
|
* (`VertexKey`).
|
|
207
|
-
* @returns The method `outgoingEdgesOf` returns an array of edges (`
|
|
207
|
+
* @returns The method `outgoingEdgesOf` returns an array of edges (`EO[]`).
|
|
208
208
|
*/
|
|
209
209
|
outgoingEdgesOf(vertexOrKey) {
|
|
210
210
|
const target = this._getVertex(vertexOrKey);
|
|
@@ -215,7 +215,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
217
|
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
|
|
218
|
-
* @param {VertexKey |
|
|
218
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
219
219
|
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
220
220
|
*/
|
|
221
221
|
degreeOf(vertexOrKey) {
|
|
@@ -223,7 +223,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
223
223
|
}
|
|
224
224
|
/**
|
|
225
225
|
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
|
|
226
|
-
* @param {VertexKey |
|
|
226
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
227
227
|
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
228
228
|
*/
|
|
229
229
|
inDegreeOf(vertexOrKey) {
|
|
@@ -231,7 +231,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
233
233
|
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
|
|
234
|
-
* @param {VertexKey |
|
|
234
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
235
235
|
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
236
236
|
*/
|
|
237
237
|
outDegreeOf(vertexOrKey) {
|
|
@@ -239,7 +239,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
241
241
|
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
|
|
242
|
-
* @param {VertexKey |
|
|
242
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
243
243
|
* @returns The function `edgesOf` returns an array of edges.
|
|
244
244
|
*/
|
|
245
245
|
edgesOf(vertexOrKey) {
|
|
@@ -247,25 +247,25 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
247
247
|
}
|
|
248
248
|
/**
|
|
249
249
|
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
|
|
250
|
-
* @param {
|
|
251
|
-
* @returns either a vertex object (
|
|
250
|
+
* @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
|
|
251
|
+
* @returns either a vertex object (VO) or null.
|
|
252
252
|
*/
|
|
253
253
|
getEdgeSrc(e) {
|
|
254
254
|
return this._getVertex(e.src);
|
|
255
255
|
}
|
|
256
256
|
/**
|
|
257
257
|
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
258
|
-
* @param {
|
|
259
|
-
* @returns either a vertex object of type
|
|
258
|
+
* @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
|
|
259
|
+
* @returns either a vertex object of type VO or null.
|
|
260
260
|
*/
|
|
261
261
|
getEdgeDest(e) {
|
|
262
262
|
return this._getVertex(e.dest);
|
|
263
263
|
}
|
|
264
264
|
/**
|
|
265
265
|
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
266
|
-
* @param {
|
|
267
|
-
* find the destinations. It can be either a `
|
|
268
|
-
* @returns an array of vertices (
|
|
266
|
+
* @param {VO | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
267
|
+
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `null`.
|
|
268
|
+
* @returns an array of vertices (VO[]).
|
|
269
269
|
*/
|
|
270
270
|
getDestinations(vertex) {
|
|
271
271
|
if (vertex === null) {
|
|
@@ -327,7 +327,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
329
329
|
* The `edgeSet` function returns an array of all the edges in the graph.
|
|
330
|
-
* @returns The `edgeSet()` method returns an array of edges (`
|
|
330
|
+
* @returns The `edgeSet()` method returns an array of edges (`EO[]`).
|
|
331
331
|
*/
|
|
332
332
|
edgeSet() {
|
|
333
333
|
let edges = [];
|
|
@@ -338,9 +338,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
338
338
|
}
|
|
339
339
|
/**
|
|
340
340
|
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
|
|
341
|
-
* @param {
|
|
341
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
342
342
|
* (`VertexKey`).
|
|
343
|
-
* @returns an array of vertices (
|
|
343
|
+
* @returns an array of vertices (VO[]).
|
|
344
344
|
*/
|
|
345
345
|
getNeighbors(vertexOrKey) {
|
|
346
346
|
const neighbors = [];
|
|
@@ -360,8 +360,8 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
360
360
|
/**
|
|
361
361
|
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
362
362
|
* otherwise it returns null.
|
|
363
|
-
* @param {
|
|
364
|
-
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[
|
|
363
|
+
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
|
|
364
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
|
|
365
365
|
* graph. If the edge does not exist, it returns `null`.
|
|
366
366
|
*/
|
|
367
367
|
getEndsOfEdge(edge) {
|
|
@@ -379,7 +379,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
379
379
|
}
|
|
380
380
|
/**
|
|
381
381
|
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
|
|
382
|
-
* @param {
|
|
382
|
+
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
383
383
|
* needs to be added to the graph.
|
|
384
384
|
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
385
385
|
* source or destination vertex does not exist in the graph.
|
|
@@ -10,10 +10,10 @@ export declare class MapVertex<V = any> extends DirectedVertex<V> {
|
|
|
10
10
|
* @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
|
|
11
11
|
* coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
|
|
12
12
|
* values ranging from -180 to 180.
|
|
13
|
-
* @param {V} [
|
|
13
|
+
* @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
|
|
14
14
|
* creating an instance of the class.
|
|
15
15
|
*/
|
|
16
|
-
constructor(key: VertexKey, lat: number, long: number
|
|
16
|
+
constructor(key: VertexKey, value: V, lat: number, long: number);
|
|
17
17
|
private _lat;
|
|
18
18
|
get lat(): number;
|
|
19
19
|
set lat(value: number);
|
|
@@ -21,7 +21,7 @@ export declare class MapVertex<V = any> extends DirectedVertex<V> {
|
|
|
21
21
|
get long(): number;
|
|
22
22
|
set long(value: number);
|
|
23
23
|
}
|
|
24
|
-
export declare class MapEdge<
|
|
24
|
+
export declare class MapEdge<E = any> extends DirectedEdge<E> {
|
|
25
25
|
/**
|
|
26
26
|
* The constructor function initializes a new instance of a class with the given source, destination, weight, and
|
|
27
27
|
* value.
|
|
@@ -29,12 +29,12 @@ export declare class MapEdge<V = any> extends DirectedEdge<V> {
|
|
|
29
29
|
* a graph.
|
|
30
30
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
31
31
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
32
|
-
* @param {
|
|
32
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
|
|
33
33
|
* information or data associated with the edge.
|
|
34
34
|
*/
|
|
35
|
-
constructor(src: VertexKey, dest: VertexKey, weight?: number,
|
|
35
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
|
|
36
36
|
}
|
|
37
|
-
export declare class MapGraph<V extends MapVertex<V
|
|
37
|
+
export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVertex<V>, EO extends MapEdge<E> = MapEdge<E>> extends DirectedGraph<V, E, VO, EO> {
|
|
38
38
|
/**
|
|
39
39
|
* The constructor function initializes the origin and bottomRight properties of a MapGraphCoordinate object.
|
|
40
40
|
* @param {MapGraphCoordinate} origin - The `origin` parameter is a `MapGraphCoordinate` object that represents the
|
|
@@ -55,14 +55,14 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
|
|
|
55
55
|
* The function creates a new vertex with the given key, value, latitude, and longitude.
|
|
56
56
|
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
|
|
57
57
|
* be a string or a number depending on how you define it in your code.
|
|
58
|
-
* @param [
|
|
59
|
-
* is of type `V
|
|
58
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
|
|
59
|
+
* is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
|
|
60
60
|
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
|
|
61
61
|
* position of the vertex on the Earth's surface in the north-south direction.
|
|
62
62
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
63
|
-
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `
|
|
63
|
+
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
64
64
|
*/
|
|
65
|
-
createVertex(key: VertexKey,
|
|
65
|
+
createVertex(key: VertexKey, value?: V, lat?: number, long?: number): VO;
|
|
66
66
|
/**
|
|
67
67
|
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
68
68
|
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
@@ -71,9 +71,9 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
|
|
|
71
71
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
72
72
|
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
73
73
|
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
74
|
-
* @param [
|
|
74
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
|
|
75
75
|
* depending on the specific implementation of the `MapEdge` class.
|
|
76
|
-
* @returns a new instance of the `MapEdge` class, cast as type `
|
|
76
|
+
* @returns a new instance of the `MapEdge` class, cast as type `EO`.
|
|
77
77
|
*/
|
|
78
|
-
createEdge(src: VertexKey, dest: VertexKey, weight?: number,
|
|
78
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
|
|
79
79
|
}
|
|
@@ -12,11 +12,11 @@ class MapVertex extends directed_graph_1.DirectedVertex {
|
|
|
12
12
|
* @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
|
|
13
13
|
* coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
|
|
14
14
|
* values ranging from -180 to 180.
|
|
15
|
-
* @param {V} [
|
|
15
|
+
* @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
|
|
16
16
|
* creating an instance of the class.
|
|
17
17
|
*/
|
|
18
|
-
constructor(key, lat, long
|
|
19
|
-
super(key,
|
|
18
|
+
constructor(key, value, lat, long) {
|
|
19
|
+
super(key, value);
|
|
20
20
|
this._lat = lat;
|
|
21
21
|
this._long = long;
|
|
22
22
|
}
|
|
@@ -42,11 +42,11 @@ class MapEdge extends directed_graph_1.DirectedEdge {
|
|
|
42
42
|
* a graph.
|
|
43
43
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
44
44
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
45
|
-
* @param {
|
|
45
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
|
|
46
46
|
* information or data associated with the edge.
|
|
47
47
|
*/
|
|
48
|
-
constructor(src, dest, weight,
|
|
49
|
-
super(src, dest, weight,
|
|
48
|
+
constructor(src, dest, weight, value) {
|
|
49
|
+
super(src, dest, weight, value);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
exports.MapEdge = MapEdge;
|
|
@@ -82,15 +82,15 @@ class MapGraph extends directed_graph_1.DirectedGraph {
|
|
|
82
82
|
* The function creates a new vertex with the given key, value, latitude, and longitude.
|
|
83
83
|
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
|
|
84
84
|
* be a string or a number depending on how you define it in your code.
|
|
85
|
-
* @param [
|
|
86
|
-
* is of type `V
|
|
85
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
|
|
86
|
+
* is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
|
|
87
87
|
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
|
|
88
88
|
* position of the vertex on the Earth's surface in the north-south direction.
|
|
89
89
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
90
|
-
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `
|
|
90
|
+
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
91
91
|
*/
|
|
92
|
-
createVertex(key, lat = this.origin[0], long = this.origin[1]
|
|
93
|
-
return new MapVertex(key, lat, long
|
|
92
|
+
createVertex(key, value, lat = this.origin[0], long = this.origin[1]) {
|
|
93
|
+
return new MapVertex(key, value, lat, long);
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
@@ -100,12 +100,12 @@ class MapGraph extends directed_graph_1.DirectedGraph {
|
|
|
100
100
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
101
101
|
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
102
102
|
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
103
|
-
* @param [
|
|
103
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
|
|
104
104
|
* depending on the specific implementation of the `MapEdge` class.
|
|
105
|
-
* @returns a new instance of the `MapEdge` class, cast as type `
|
|
105
|
+
* @returns a new instance of the `MapEdge` class, cast as type `EO`.
|
|
106
106
|
*/
|
|
107
|
-
createEdge(src, dest, weight,
|
|
108
|
-
return new MapEdge(src, dest, weight,
|
|
107
|
+
createEdge(src, dest, weight, value) {
|
|
108
|
+
return new MapEdge(src, dest, weight, value);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
exports.MapGraph = MapGraph;
|
|
@@ -6,12 +6,12 @@ export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
|
|
|
6
6
|
* The constructor function initializes a vertex with an optional value.
|
|
7
7
|
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
8
8
|
* used to uniquely identify the vertex within a graph or network.
|
|
9
|
-
* @param {V} [
|
|
9
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
10
10
|
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
11
11
|
*/
|
|
12
|
-
constructor(key: VertexKey,
|
|
12
|
+
constructor(key: VertexKey, value?: V);
|
|
13
13
|
}
|
|
14
|
-
export declare class UndirectedEdge<
|
|
14
|
+
export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
|
|
15
15
|
/**
|
|
16
16
|
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
17
17
|
* value.
|
|
@@ -19,109 +19,109 @@ export declare class UndirectedEdge<V = number> extends AbstractEdge<V> {
|
|
|
19
19
|
* @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
|
|
20
20
|
* graph edge.
|
|
21
21
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store a value associated
|
|
23
23
|
* with the edge.
|
|
24
24
|
*/
|
|
25
|
-
constructor(v1: VertexKey, v2: VertexKey, weight?: number,
|
|
25
|
+
constructor(v1: VertexKey, v2: VertexKey, weight?: number, value?: E);
|
|
26
26
|
private _vertices;
|
|
27
27
|
get vertices(): [VertexKey, VertexKey];
|
|
28
28
|
set vertices(v: [VertexKey, VertexKey]);
|
|
29
29
|
}
|
|
30
|
-
export declare class UndirectedGraph<V extends UndirectedVertex<
|
|
30
|
+
export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVertex<V> = UndirectedVertex<V>, EO extends UndirectedEdge<E> = UndirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
|
|
31
31
|
/**
|
|
32
32
|
* The constructor initializes a new Map object to store edges.
|
|
33
33
|
*/
|
|
34
34
|
constructor();
|
|
35
|
-
protected _edges: Map<
|
|
36
|
-
get edges(): Map<
|
|
35
|
+
protected _edges: Map<VO, EO[]>;
|
|
36
|
+
get edges(): Map<VO, EO[]>;
|
|
37
37
|
/**
|
|
38
38
|
* The function creates a new vertex with an optional value and returns it.
|
|
39
39
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
40
40
|
* vertex from another in the graph.
|
|
41
|
-
* @param [
|
|
41
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
42
42
|
* it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
|
|
43
43
|
* the vertex.
|
|
44
|
-
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `
|
|
44
|
+
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `VO`.
|
|
45
45
|
*/
|
|
46
|
-
createVertex(key: VertexKey,
|
|
46
|
+
createVertex(key: VertexKey, value?: VO['value']): VO;
|
|
47
47
|
/**
|
|
48
48
|
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
49
49
|
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
50
50
|
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
51
51
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
52
52
|
* no weight is provided, it defaults to 1.
|
|
53
|
-
* @param [
|
|
53
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
54
54
|
* is used to store additional information or data associated with the edge.
|
|
55
|
-
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `
|
|
55
|
+
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `EO`.
|
|
56
56
|
*/
|
|
57
|
-
createEdge(v1: VertexKey, v2: VertexKey, weight?: number,
|
|
57
|
+
createEdge(v1: VertexKey, v2: VertexKey, weight?: number, value?: EO['value']): EO;
|
|
58
58
|
/**
|
|
59
59
|
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
60
|
-
* @param {
|
|
60
|
+
* @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
61
61
|
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
62
|
-
* @param {
|
|
62
|
+
* @param {VO | VertexKey | null} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
63
63
|
* object), `null`, or `VertexKey` (vertex ID).
|
|
64
|
-
* @returns an edge (
|
|
64
|
+
* @returns an edge (EO) or null.
|
|
65
65
|
*/
|
|
66
|
-
getEdge(v1:
|
|
66
|
+
getEdge(v1: VO | VertexKey | null, v2: VO | VertexKey | null): EO | null;
|
|
67
67
|
/**
|
|
68
68
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
69
|
-
* @param {
|
|
70
|
-
* @param {
|
|
69
|
+
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
70
|
+
* @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
|
|
71
71
|
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
72
|
-
* @returns the removed edge (
|
|
72
|
+
* @returns the removed edge (EO) if it exists, or null if either of the vertices (VO) does not exist.
|
|
73
73
|
*/
|
|
74
|
-
deleteEdgeBetween(v1:
|
|
74
|
+
deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | null;
|
|
75
75
|
/**
|
|
76
76
|
* The deleteEdge function removes an edge between two vertices in a graph.
|
|
77
|
-
* @param {
|
|
78
|
-
* @returns The method is returning either the removed edge (of type
|
|
77
|
+
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
78
|
+
* @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
|
|
79
79
|
*/
|
|
80
|
-
deleteEdge(edge:
|
|
80
|
+
deleteEdge(edge: EO): EO | null;
|
|
81
81
|
/**
|
|
82
82
|
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
83
83
|
* vertex.
|
|
84
|
-
* @param {VertexKey |
|
|
84
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
85
85
|
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
86
86
|
* edges connected to that vertex.
|
|
87
87
|
*/
|
|
88
|
-
degreeOf(vertexOrKey: VertexKey |
|
|
88
|
+
degreeOf(vertexOrKey: VertexKey | VO): number;
|
|
89
89
|
/**
|
|
90
90
|
* The function returns the edges of a given vertex or vertex ID.
|
|
91
|
-
* @param {VertexKey |
|
|
92
|
-
* unique identifier for a vertex in a graph, while `
|
|
91
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
|
|
92
|
+
* unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
|
|
93
93
|
* @returns an array of edges.
|
|
94
94
|
*/
|
|
95
|
-
edgesOf(vertexOrKey: VertexKey |
|
|
95
|
+
edgesOf(vertexOrKey: VertexKey | VO): EO[];
|
|
96
96
|
/**
|
|
97
97
|
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
98
|
-
* @returns The method `edgeSet()` returns an array of type `
|
|
98
|
+
* @returns The method `edgeSet()` returns an array of type `EO[]`.
|
|
99
99
|
*/
|
|
100
|
-
edgeSet():
|
|
100
|
+
edgeSet(): EO[];
|
|
101
101
|
/**
|
|
102
102
|
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
103
|
-
* @param {
|
|
103
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
104
104
|
* (`VertexKey`).
|
|
105
|
-
* @returns an array of vertices (
|
|
105
|
+
* @returns an array of vertices (VO[]).
|
|
106
106
|
*/
|
|
107
|
-
getNeighbors(vertexOrKey:
|
|
107
|
+
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
108
108
|
/**
|
|
109
109
|
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
110
110
|
* it returns null.
|
|
111
|
-
* @param {
|
|
112
|
-
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[
|
|
111
|
+
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
112
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
|
|
113
113
|
* graph. If the edge does not exist, it returns `null`.
|
|
114
114
|
*/
|
|
115
|
-
getEndsOfEdge(edge:
|
|
115
|
+
getEndsOfEdge(edge: EO): [VO, VO] | null;
|
|
116
116
|
/**
|
|
117
117
|
* The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
|
|
118
|
-
* @param {
|
|
118
|
+
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
119
119
|
* @returns a boolean value.
|
|
120
120
|
*/
|
|
121
|
-
protected _addEdgeOnly(edge:
|
|
121
|
+
protected _addEdgeOnly(edge: EO): boolean;
|
|
122
122
|
/**
|
|
123
123
|
* The function sets the edges of a graph.
|
|
124
|
-
* @param v - A map where the keys are of type
|
|
124
|
+
* @param v - A map where the keys are of type VO and the values are arrays of type EO.
|
|
125
125
|
*/
|
|
126
|
-
protected _setEdges(v: Map<
|
|
126
|
+
protected _setEdges(v: Map<VO, EO[]>): void;
|
|
127
127
|
}
|