data-structure-typed 1.18.8 → 1.19.1
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/README.md +169 -168
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +182 -148
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +288 -316
- package/dist/data-structures/binary-tree/avl-tree.d.ts +22 -14
- package/dist/data-structures/binary-tree/avl-tree.js +23 -17
- package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
- package/dist/data-structures/binary-tree/binary-tree.js +11 -26
- package/dist/data-structures/binary-tree/bst.d.ts +62 -74
- package/dist/data-structures/binary-tree/bst.js +72 -96
- package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -14
- package/dist/data-structures/binary-tree/rb-tree.js +5 -17
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +186 -17
- package/dist/data-structures/binary-tree/tree-multiset.js +712 -28
- package/dist/data-structures/graph/abstract-graph.d.ts +107 -49
- package/dist/data-structures/graph/abstract-graph.js +104 -55
- package/dist/data-structures/graph/directed-graph.d.ts +95 -94
- package/dist/data-structures/graph/directed-graph.js +95 -95
- package/dist/data-structures/graph/undirected-graph.d.ts +62 -61
- package/dist/data-structures/graph/undirected-graph.js +62 -61
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +10 -15
- package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
- package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
- package/dist/data-structures/interfaces/bst.d.ts +3 -4
- package/dist/data-structures/interfaces/rb-tree.d.ts +1 -2
- package/dist/data-structures/interfaces/tree-multiset.d.ts +3 -3
- package/dist/data-structures/types/abstract-binary-tree.d.ts +1 -1
- package/dist/data-structures/types/tree-multiset.d.ts +3 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/index.d.ts +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/utils.d.ts +0 -18
- package/dist/utils/types/validate-type.d.ts +19 -0
- package/dist/utils/types/validate-type.js +2 -0
- package/dist/utils/utils.d.ts +3 -8
- package/dist/utils/utils.js +1 -83
- package/dist/utils/validate-type.d.ts +45 -0
- package/dist/utils/validate-type.js +58 -0
- package/package.json +6 -2
- package/tsconfig.json +0 -17
|
@@ -65,10 +65,10 @@ var DirectedVertex = /** @class */ (function (_super) {
|
|
|
65
65
|
__extends(DirectedVertex, _super);
|
|
66
66
|
/**
|
|
67
67
|
* The constructor function initializes a vertex with an optional value.
|
|
68
|
-
* @param {VertexId} id - The `id` parameter is the identifier
|
|
69
|
-
*
|
|
70
|
-
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to
|
|
71
|
-
*
|
|
68
|
+
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
|
|
69
|
+
* used to uniquely identify the vertex within a graph or data structure.
|
|
70
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
|
|
71
|
+
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
72
72
|
*/
|
|
73
73
|
function DirectedVertex(id, val) {
|
|
74
74
|
return _super.call(this, id, val) || this;
|
|
@@ -83,11 +83,10 @@ var DirectedEdge = /** @class */ (function (_super) {
|
|
|
83
83
|
* and value.
|
|
84
84
|
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
85
85
|
* a graph.
|
|
86
|
-
* @param {VertexId} dest - The `dest` parameter
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
|
|
86
|
+
* @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
87
|
+
* `VertexId`, which is likely a unique identifier for a vertex in a graph.
|
|
88
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
89
|
+
* @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value associated with
|
|
91
90
|
* the edge.
|
|
92
91
|
*/
|
|
93
92
|
function DirectedEdge(src, dest, weight, val) {
|
|
@@ -119,9 +118,11 @@ var DirectedEdge = /** @class */ (function (_super) {
|
|
|
119
118
|
return DirectedEdge;
|
|
120
119
|
}(abstract_graph_1.AbstractEdge));
|
|
121
120
|
exports.DirectedEdge = DirectedEdge;
|
|
122
|
-
// Strongly connected, One direction connected, Weakly connected
|
|
123
121
|
var DirectedGraph = /** @class */ (function (_super) {
|
|
124
122
|
__extends(DirectedGraph, _super);
|
|
123
|
+
/**
|
|
124
|
+
* The constructor function initializes an instance of a class.
|
|
125
|
+
*/
|
|
125
126
|
function DirectedGraph() {
|
|
126
127
|
var _this = _super.call(this) || this;
|
|
127
128
|
_this._outEdgeMap = new Map();
|
|
@@ -145,8 +146,15 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
145
146
|
/**
|
|
146
147
|
* 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.
|
|
147
148
|
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* The function creates a new vertex with an optional value and returns it.
|
|
152
|
+
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is of type `VertexId`, which
|
|
153
|
+
* could be a number or a string depending on how you want to identify your vertices.
|
|
154
|
+
* @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
155
|
+
* it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
|
|
156
|
+
* assigned the same value as the 'id' parameter
|
|
157
|
+
* @returns a new instance of a DirectedVertex object, casted as type V.
|
|
150
158
|
*/
|
|
151
159
|
DirectedGraph.prototype.createVertex = function (id, val) {
|
|
152
160
|
return new DirectedVertex(id, val !== null && val !== void 0 ? val : id);
|
|
@@ -154,21 +162,27 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
154
162
|
/**
|
|
155
163
|
* 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.
|
|
156
164
|
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
*
|
|
160
|
-
* @param
|
|
165
|
+
*/
|
|
166
|
+
/**
|
|
167
|
+
* The function creates a directed edge between two vertices with an optional weight and value.
|
|
168
|
+
* @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
169
|
+
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
170
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
171
|
+
* weight is provided, it defaults to 1.
|
|
172
|
+
* @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
173
|
+
* is used to store additional information or data associated with the edge.
|
|
174
|
+
* @returns a new instance of a DirectedEdge object, casted as type E.
|
|
161
175
|
*/
|
|
162
176
|
DirectedGraph.prototype.createEdge = function (src, dest, weight, val) {
|
|
163
177
|
return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1, val);
|
|
164
178
|
};
|
|
165
179
|
/**
|
|
166
|
-
* The
|
|
167
|
-
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* @returns
|
|
180
|
+
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
181
|
+
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
182
|
+
* @param {V | null | VertexId} destOrId - The `destOrId` parameter in the `getEdge` function represents the
|
|
183
|
+
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexId`), or `null` if the
|
|
184
|
+
* destination is not specified.
|
|
185
|
+
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
172
186
|
*/
|
|
173
187
|
DirectedGraph.prototype.getEdge = function (srcOrId, destOrId) {
|
|
174
188
|
var edges = [];
|
|
@@ -185,14 +199,10 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
185
199
|
return edges[0] || null;
|
|
186
200
|
};
|
|
187
201
|
/**
|
|
188
|
-
* The
|
|
189
|
-
*
|
|
190
|
-
* @param {V | VertexId}
|
|
191
|
-
*
|
|
192
|
-
* @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex of the
|
|
193
|
-
* edge that you want to remove. It can be either a `V` object or a `VertexId` value.
|
|
194
|
-
* @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
|
|
195
|
-
* the edge does not exist.
|
|
202
|
+
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
203
|
+
* @param {V | VertexId} srcOrId - The source vertex or its ID.
|
|
204
|
+
* @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex or its ID.
|
|
205
|
+
* @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
|
|
196
206
|
*/
|
|
197
207
|
DirectedGraph.prototype.removeEdgeSrcToDest = function (srcOrId, destOrId) {
|
|
198
208
|
var src = this._getVertex(srcOrId);
|
|
@@ -212,12 +222,10 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
212
222
|
return removed;
|
|
213
223
|
};
|
|
214
224
|
/**
|
|
215
|
-
* The
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* @returns The function `removeEdge` returns a `E` object if an edge is successfully removed, or `null`
|
|
220
|
-
* if no edge is removed.
|
|
225
|
+
* The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
|
|
226
|
+
* @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
227
|
+
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
228
|
+
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
221
229
|
*/
|
|
222
230
|
DirectedGraph.prototype.removeEdge = function (edge) {
|
|
223
231
|
var removed = null;
|
|
@@ -236,12 +244,12 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
236
244
|
return removed;
|
|
237
245
|
};
|
|
238
246
|
/**
|
|
239
|
-
* The function removes
|
|
240
|
-
* @param {VertexId | V} v1 - The parameter `v1`
|
|
241
|
-
*
|
|
242
|
-
* @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V
|
|
243
|
-
* second vertex
|
|
244
|
-
* @returns
|
|
247
|
+
* The function removes edges between two vertices and returns the removed edges.
|
|
248
|
+
* @param {VertexId | V} v1 - The parameter `v1` can be either a `VertexId` or a `V`. A `VertexId` represents the
|
|
249
|
+
* unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
|
|
250
|
+
* @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V` object. It is used to specify
|
|
251
|
+
* the second vertex in the edge that needs to be removed.
|
|
252
|
+
* @returns an array of removed edges (E[]).
|
|
245
253
|
*/
|
|
246
254
|
DirectedGraph.prototype.removeEdgesBetween = function (v1, v2) {
|
|
247
255
|
var removed = [];
|
|
@@ -254,10 +262,10 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
254
262
|
return removed;
|
|
255
263
|
};
|
|
256
264
|
/**
|
|
257
|
-
* The function returns an array of incoming edges
|
|
258
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
|
|
259
|
-
*
|
|
260
|
-
* @returns The method `incomingEdgesOf` returns an array of `E`
|
|
265
|
+
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
266
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
267
|
+
* (`VertexId`).
|
|
268
|
+
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
|
|
261
269
|
*/
|
|
262
270
|
DirectedGraph.prototype.incomingEdgesOf = function (vertexOrId) {
|
|
263
271
|
var target = this._getVertex(vertexOrId);
|
|
@@ -267,10 +275,10 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
267
275
|
return [];
|
|
268
276
|
};
|
|
269
277
|
/**
|
|
270
|
-
* The function `outgoingEdgesOf` returns an array of outgoing
|
|
271
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can
|
|
272
|
-
*
|
|
273
|
-
* @returns The method `outgoingEdgesOf` returns an array of `E`
|
|
278
|
+
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
279
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
|
|
280
|
+
* (`VertexId`).
|
|
281
|
+
* @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
|
|
274
282
|
*/
|
|
275
283
|
DirectedGraph.prototype.outgoingEdgesOf = function (vertexOrId) {
|
|
276
284
|
var target = this._getVertex(vertexOrId);
|
|
@@ -280,64 +288,58 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
280
288
|
return [];
|
|
281
289
|
};
|
|
282
290
|
/**
|
|
283
|
-
* The function "degreeOf" returns the total degree of a vertex
|
|
284
|
-
*
|
|
285
|
-
* @
|
|
286
|
-
* `V`.
|
|
287
|
-
* @returns The sum of the out-degree and in-degree of the given vertex or vertex ID.
|
|
291
|
+
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
|
|
292
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
293
|
+
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
288
294
|
*/
|
|
289
295
|
DirectedGraph.prototype.degreeOf = function (vertexOrId) {
|
|
290
296
|
return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
|
|
291
297
|
};
|
|
292
298
|
/**
|
|
293
|
-
* The function "inDegreeOf" returns the number of incoming edges for a given vertex
|
|
294
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
|
|
295
|
-
* `V`.
|
|
299
|
+
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
|
|
300
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
296
301
|
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
297
302
|
*/
|
|
298
303
|
DirectedGraph.prototype.inDegreeOf = function (vertexOrId) {
|
|
299
304
|
return this.incomingEdgesOf(vertexOrId).length;
|
|
300
305
|
};
|
|
301
306
|
/**
|
|
302
|
-
* The function
|
|
303
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
|
|
304
|
-
* `V`.
|
|
307
|
+
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
|
|
308
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
305
309
|
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
306
310
|
*/
|
|
307
311
|
DirectedGraph.prototype.outDegreeOf = function (vertexOrId) {
|
|
308
312
|
return this.outgoingEdgesOf(vertexOrId).length;
|
|
309
313
|
};
|
|
310
314
|
/**
|
|
311
|
-
* The function "edgesOf" returns an array of both outgoing and incoming
|
|
312
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
|
|
313
|
-
* `
|
|
314
|
-
* @returns an array of directed edges.
|
|
315
|
+
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
|
|
316
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
317
|
+
* @returns The function `edgesOf` returns an array of edges.
|
|
315
318
|
*/
|
|
316
319
|
DirectedGraph.prototype.edgesOf = function (vertexOrId) {
|
|
317
320
|
return __spreadArray(__spreadArray([], __read(this.outgoingEdgesOf(vertexOrId)), false), __read(this.incomingEdgesOf(vertexOrId)), false);
|
|
318
321
|
};
|
|
319
322
|
/**
|
|
320
|
-
* The function "getEdgeSrc" returns the source vertex of
|
|
321
|
-
* @param e -
|
|
322
|
-
* @returns either a
|
|
323
|
+
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
|
|
324
|
+
* @param {E} e - The parameter "e" is of type E, which represents an edge in a graph.
|
|
325
|
+
* @returns either a vertex object (V) or null.
|
|
323
326
|
*/
|
|
324
327
|
DirectedGraph.prototype.getEdgeSrc = function (e) {
|
|
325
328
|
return this._getVertex(e.src);
|
|
326
329
|
};
|
|
327
330
|
/**
|
|
328
|
-
* The function "getEdgeDest" returns the destination vertex of
|
|
329
|
-
* @param e -
|
|
330
|
-
*
|
|
331
|
-
* @returns either a DirectedVertex object or null.
|
|
331
|
+
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
332
|
+
* @param {E} e - The parameter "e" is of type "E", which represents an edge in a graph.
|
|
333
|
+
* @returns either a vertex object of type V or null.
|
|
332
334
|
*/
|
|
333
335
|
DirectedGraph.prototype.getEdgeDest = function (e) {
|
|
334
336
|
return this._getVertex(e.dest);
|
|
335
337
|
};
|
|
336
338
|
/**
|
|
337
|
-
* The function `getDestinations` returns an array of
|
|
338
|
-
* from
|
|
339
|
-
*
|
|
340
|
-
* @returns an array of
|
|
339
|
+
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
340
|
+
* @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
341
|
+
* find the destinations. It can be either a `V` object, a `VertexId` value, or `null`.
|
|
342
|
+
* @returns an array of vertices (V[]).
|
|
341
343
|
*/
|
|
342
344
|
DirectedGraph.prototype.getDestinations = function (vertex) {
|
|
343
345
|
var e_1, _a;
|
|
@@ -370,7 +372,7 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
370
372
|
* @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
371
373
|
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
|
|
372
374
|
* specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
|
|
373
|
-
* @returns an array of vertices or vertex IDs in topological order
|
|
375
|
+
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
|
|
374
376
|
*/
|
|
375
377
|
DirectedGraph.prototype.topologicalSort = function (propertyName) {
|
|
376
378
|
var e_2, _a, e_3, _b;
|
|
@@ -442,8 +444,8 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
442
444
|
return sorted.reverse();
|
|
443
445
|
};
|
|
444
446
|
/**
|
|
445
|
-
* The `edgeSet` function returns an array of all
|
|
446
|
-
* @returns The `edgeSet()` method returns an array of `E`
|
|
447
|
+
* The `edgeSet` function returns an array of all the edges in the graph.
|
|
448
|
+
* @returns The `edgeSet()` method returns an array of edges (`E[]`).
|
|
447
449
|
*/
|
|
448
450
|
DirectedGraph.prototype.edgeSet = function () {
|
|
449
451
|
var edges = [];
|
|
@@ -453,10 +455,10 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
453
455
|
return edges;
|
|
454
456
|
};
|
|
455
457
|
/**
|
|
456
|
-
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in a
|
|
457
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
|
|
458
|
-
*
|
|
459
|
-
* @returns an array of
|
|
458
|
+
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
|
|
459
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
460
|
+
* (`VertexId`).
|
|
461
|
+
* @returns an array of vertices (V[]).
|
|
460
462
|
*/
|
|
461
463
|
DirectedGraph.prototype.getNeighbors = function (vertexOrId) {
|
|
462
464
|
var e_5, _a;
|
|
@@ -484,13 +486,12 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
484
486
|
}
|
|
485
487
|
return neighbors;
|
|
486
488
|
};
|
|
487
|
-
/**--- start find cycles --- */
|
|
488
489
|
/**
|
|
489
|
-
* The function "getEndsOfEdge" returns the source and destination vertices of
|
|
490
|
-
*
|
|
491
|
-
* @param edge -
|
|
492
|
-
* @returns an array containing
|
|
493
|
-
* not exist
|
|
490
|
+
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
491
|
+
* otherwise it returns null.
|
|
492
|
+
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph.
|
|
493
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
|
|
494
|
+
* graph. If the edge does not exist, it returns `null`.
|
|
494
495
|
*/
|
|
495
496
|
DirectedGraph.prototype.getEndsOfEdge = function (edge) {
|
|
496
497
|
if (!this.hasEdge(edge.src, edge.dest)) {
|
|
@@ -505,13 +506,12 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
505
506
|
return null;
|
|
506
507
|
}
|
|
507
508
|
};
|
|
508
|
-
/**--- end find cycles --- */
|
|
509
509
|
/**
|
|
510
|
-
* The `_addEdgeOnly`
|
|
511
|
-
* @param edge - The parameter `edge` is of type `E`, which represents
|
|
512
|
-
*
|
|
513
|
-
* @returns
|
|
514
|
-
*
|
|
510
|
+
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
|
|
511
|
+
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph. It is the edge that
|
|
512
|
+
* needs to be added to the graph.
|
|
513
|
+
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
514
|
+
* source or destination vertex does not exist in the graph.
|
|
515
515
|
*/
|
|
516
516
|
DirectedGraph.prototype._addEdgeOnly = function (edge) {
|
|
517
517
|
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
@@ -4,8 +4,8 @@ import { IUNDirectedGraph } from '../interfaces';
|
|
|
4
4
|
export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
|
|
5
5
|
/**
|
|
6
6
|
* The constructor function initializes a vertex with an optional value.
|
|
7
|
-
* @param {VertexId} id - The `id` parameter is the identifier
|
|
8
|
-
*
|
|
7
|
+
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
|
|
8
|
+
* used to uniquely identify the vertex within a graph or network.
|
|
9
9
|
* @param {T} [val] - The "val" parameter is an optional parameter of type T. 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
|
*/
|
|
@@ -13,14 +13,14 @@ export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
|
|
|
13
13
|
}
|
|
14
14
|
export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
|
|
15
15
|
/**
|
|
16
|
-
* The constructor function
|
|
16
|
+
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
17
17
|
* value.
|
|
18
|
-
* @param {VertexId} v1 - The
|
|
18
|
+
* @param {VertexId} v1 - The first vertex ID of the edge.
|
|
19
19
|
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, 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 {T} [val] - The "val" parameter is an optional parameter of type T. It
|
|
23
|
-
* the edge.
|
|
22
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store a value associated
|
|
23
|
+
* with the edge.
|
|
24
24
|
*/
|
|
25
25
|
constructor(v1: VertexId, v2: VertexId, weight?: number, val?: T);
|
|
26
26
|
private _vertices;
|
|
@@ -28,99 +28,100 @@ export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
|
|
|
28
28
|
set vertices(v: [VertexId, VertexId]);
|
|
29
29
|
}
|
|
30
30
|
export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E> {
|
|
31
|
+
/**
|
|
32
|
+
* The constructor initializes a new Map object to store edges.
|
|
33
|
+
*/
|
|
31
34
|
constructor();
|
|
32
35
|
protected _edges: Map<V, E[]>;
|
|
33
36
|
get edges(): Map<V, E[]>;
|
|
34
37
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @param val
|
|
38
|
+
* The function creates a new vertex with an optional value and returns it.
|
|
39
|
+
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
40
|
+
* vertex from another in the graph.
|
|
41
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
42
|
+
* it will be used as the value of the vertex. If no value is provided, the `id` parameter will be used as the value of
|
|
43
|
+
* the vertex.
|
|
44
|
+
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
|
|
39
45
|
*/
|
|
40
46
|
createVertex(id: VertexId, val?: V['val']): V;
|
|
41
47
|
/**
|
|
42
|
-
* The function
|
|
43
|
-
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
44
|
-
*
|
|
45
|
-
* @param {
|
|
46
|
-
*
|
|
47
|
-
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
48
|
-
* weight is provided, the default value is 1.
|
|
48
|
+
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
49
|
+
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
50
|
+
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
51
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
52
|
+
* no weight is provided, it defaults to 1.
|
|
49
53
|
* @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
50
54
|
* is used to store additional information or data associated with the edge.
|
|
51
|
-
* @returns
|
|
55
|
+
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
|
|
52
56
|
*/
|
|
53
57
|
createEdge(v1: VertexId, v2: VertexId, weight?: number, val?: E['val']): E;
|
|
54
58
|
/**
|
|
55
|
-
* The function `getEdge` returns the first
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @returns an instance of `E` or `null`.
|
|
59
|
+
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
60
|
+
* @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
61
|
+
* object), `null`, or `VertexId` (a string or number representing the ID of a vertex).
|
|
62
|
+
* @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
63
|
+
* object), `null`, or `VertexId` (vertex ID).
|
|
64
|
+
* @returns an edge (E) or null.
|
|
62
65
|
*/
|
|
63
66
|
getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
|
|
64
67
|
/**
|
|
65
|
-
* The function removes an edge between two vertices in
|
|
66
|
-
* @param {V | VertexId} v1 - The parameter `v1` represents either
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* removed.
|
|
71
|
-
* @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
|
|
72
|
-
* between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
|
|
73
|
-
* between them, the function returns `null`.
|
|
68
|
+
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
69
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
|
|
70
|
+
* @param {V | VertexId} v2 - V | VertexId - This parameter can be either a vertex object (V) or a vertex ID
|
|
71
|
+
* (VertexId). It represents the second vertex of the edge that needs to be removed.
|
|
72
|
+
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
|
|
74
73
|
*/
|
|
75
74
|
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
|
|
76
75
|
/**
|
|
77
|
-
* The removeEdge function removes an edge between two vertices in
|
|
78
|
-
* @param edge -
|
|
79
|
-
*
|
|
80
|
-
* @returns The method is returning an UndirectedEdge object or null.
|
|
76
|
+
* The removeEdge function removes an edge between two vertices in a graph.
|
|
77
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
78
|
+
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
|
|
81
79
|
*/
|
|
82
80
|
removeEdge(edge: E): E | null;
|
|
83
81
|
/**
|
|
84
|
-
* The function
|
|
85
|
-
*
|
|
86
|
-
* `V`.
|
|
87
|
-
* @returns the degree of
|
|
82
|
+
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
83
|
+
* vertex.
|
|
84
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
85
|
+
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
86
|
+
* edges connected to that vertex.
|
|
88
87
|
*/
|
|
89
88
|
degreeOf(vertexOrId: VertexId | V): number;
|
|
90
89
|
/**
|
|
91
|
-
* The function
|
|
92
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or
|
|
93
|
-
* `V
|
|
94
|
-
* @returns an array of
|
|
90
|
+
* The function returns the edges of a given vertex or vertex ID.
|
|
91
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
|
|
92
|
+
* unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
|
|
93
|
+
* @returns an array of edges.
|
|
95
94
|
*/
|
|
96
95
|
edgesOf(vertexOrId: VertexId | V): E[];
|
|
97
96
|
/**
|
|
98
|
-
* The function "edgeSet" returns an array of unique
|
|
99
|
-
* @returns The method `edgeSet()` returns an array of `E
|
|
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 `E[]`.
|
|
100
99
|
*/
|
|
101
100
|
edgeSet(): E[];
|
|
102
101
|
/**
|
|
103
|
-
* The function
|
|
104
|
-
* @param {V | VertexId} vertexOrId - The `vertexOrId`
|
|
105
|
-
* `
|
|
106
|
-
* @returns an array of
|
|
102
|
+
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
103
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
104
|
+
* (`VertexId`).
|
|
105
|
+
* @returns an array of vertices (V[]).
|
|
107
106
|
*/
|
|
108
107
|
getNeighbors(vertexOrId: V | VertexId): V[];
|
|
109
108
|
/**
|
|
110
|
-
* The function "getEndsOfEdge" returns the
|
|
111
|
-
*
|
|
112
|
-
* @param edge -
|
|
113
|
-
* array containing two vertices
|
|
114
|
-
*
|
|
115
|
-
* exists in the graph. If the edge does not exist, it returns `null`.
|
|
109
|
+
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
110
|
+
* it returns null.
|
|
111
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
112
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
|
|
113
|
+
* graph. If the edge does not exist, it returns `null`.
|
|
116
114
|
*/
|
|
117
115
|
getEndsOfEdge(edge: E): [V, V] | null;
|
|
118
116
|
/**
|
|
119
|
-
* The function adds an
|
|
120
|
-
* @param edge -
|
|
121
|
-
* array of two vertices connected by the edge.
|
|
117
|
+
* The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
|
|
118
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
122
119
|
* @returns a boolean value.
|
|
123
120
|
*/
|
|
124
121
|
protected _addEdgeOnly(edge: E): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* The function sets the edges of a graph.
|
|
124
|
+
* @param v - A map where the keys are of type V and the values are arrays of type E.
|
|
125
|
+
*/
|
|
125
126
|
protected _setEdges(v: Map<V, E[]>): void;
|
|
126
127
|
}
|