data-structure-typed 1.39.3 → 1.39.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +4 -2
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +5 -13
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +17 -25
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.js +6 -6
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +88 -88
- package/dist/cjs/data-structures/graph/abstract-graph.js +41 -41
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +63 -63
- package/dist/cjs/data-structures/graph/directed-graph.js +36 -36
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +10 -10
- package/dist/cjs/data-structures/graph/map-graph.js +7 -7
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +38 -38
- package/dist/cjs/data-structures/graph/undirected-graph.js +21 -21
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/data-structures/queue/queue.js +3 -3
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/interfaces/graph.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +4 -2
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +5 -13
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +17 -25
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.js +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/tree-multiset.js +2 -2
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +88 -88
- package/dist/mjs/data-structures/graph/abstract-graph.js +41 -41
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +63 -63
- package/dist/mjs/data-structures/graph/directed-graph.js +36 -36
- package/dist/mjs/data-structures/graph/map-graph.d.ts +10 -10
- package/dist/mjs/data-structures/graph/map-graph.js +7 -7
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +38 -38
- package/dist/mjs/data-structures/graph/undirected-graph.js +21 -21
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/queue/queue.js +3 -3
- package/dist/mjs/interfaces/graph.d.ts +3 -3
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +5 -5
- package/src/data-structures/binary-tree/avl-tree.ts +3 -2
- package/src/data-structures/binary-tree/binary-tree.ts +19 -28
- package/src/data-structures/binary-tree/bst.ts +6 -6
- package/src/data-structures/binary-tree/tree-multiset.ts +2 -2
- package/src/data-structures/graph/abstract-graph.ts +135 -133
- package/src/data-structures/graph/directed-graph.ts +92 -87
- package/src/data-structures/graph/map-graph.ts +17 -20
- package/src/data-structures/graph/undirected-graph.ts +56 -54
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/graph.ts +3 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +0 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +20 -15
- package/test/unit/data-structures/graph/map-graph.test.ts +23 -23
- package/test/unit/data-structures/graph/undirected-graph.test.ts +2 -2
- package/test/unit/data-structures/queue/queue.test.ts +8 -8
|
@@ -11,7 +11,7 @@ export declare class DirectedVertex<V = any> extends AbstractVertex<V> {
|
|
|
11
11
|
*/
|
|
12
12
|
constructor(key: VertexKey, val?: V);
|
|
13
13
|
}
|
|
14
|
-
export declare class DirectedEdge<
|
|
14
|
+
export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
|
|
15
15
|
/**
|
|
16
16
|
* The constructor function initializes the source and destination vertices of an edge, along with an optional weight
|
|
17
17
|
* and value.
|
|
@@ -20,10 +20,10 @@ export declare class DirectedEdge<V = any> extends AbstractEdge<V> {
|
|
|
20
20
|
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
21
21
|
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
|
|
22
22
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
23
|
-
* @param {
|
|
23
|
+
* @param {E} [val] - The `val` parameter is an optional parameter of type `E`. It represents the value associated with
|
|
24
24
|
* the edge.
|
|
25
25
|
*/
|
|
26
|
-
constructor(src: VertexKey, dest: VertexKey, weight?: number, val?:
|
|
26
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: E);
|
|
27
27
|
private _src;
|
|
28
28
|
get src(): VertexKey;
|
|
29
29
|
set src(v: VertexKey);
|
|
@@ -31,15 +31,15 @@ export declare class DirectedEdge<V = any> extends AbstractEdge<V> {
|
|
|
31
31
|
get dest(): VertexKey;
|
|
32
32
|
set dest(v: VertexKey);
|
|
33
33
|
}
|
|
34
|
-
export declare class DirectedGraph<V extends DirectedVertex<
|
|
34
|
+
export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V> = DirectedVertex<V>, EO extends DirectedEdge<E> = DirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
|
|
35
35
|
/**
|
|
36
36
|
* The constructor function initializes an instance of a class.
|
|
37
37
|
*/
|
|
38
38
|
constructor();
|
|
39
39
|
private _outEdgeMap;
|
|
40
|
-
get outEdgeMap(): Map<
|
|
40
|
+
get outEdgeMap(): Map<VO, EO[]>;
|
|
41
41
|
private _inEdgeMap;
|
|
42
|
-
get inEdgeMap(): Map<
|
|
42
|
+
get inEdgeMap(): Map<VO, EO[]>;
|
|
43
43
|
/**
|
|
44
44
|
* 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.
|
|
45
45
|
* 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.
|
|
@@ -51,9 +51,9 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
|
|
|
51
51
|
* @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
52
52
|
* it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
|
|
53
53
|
* assigned the same value as the 'key' parameter
|
|
54
|
-
* @returns a new instance of a DirectedVertex object, casted as type
|
|
54
|
+
* @returns a new instance of a DirectedVertex object, casted as type VO.
|
|
55
55
|
*/
|
|
56
|
-
createVertex(key: VertexKey, val?: V
|
|
56
|
+
createVertex(key: VertexKey, val?: V): VO;
|
|
57
57
|
/**
|
|
58
58
|
* 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.
|
|
59
59
|
* 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.
|
|
@@ -66,98 +66,98 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
|
|
|
66
66
|
* weight is provided, it defaults to 1.
|
|
67
67
|
* @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
68
68
|
* is used to store additional information or data associated with the edge.
|
|
69
|
-
* @returns a new instance of a DirectedEdge object, casted as type
|
|
69
|
+
* @returns a new instance of a DirectedEdge object, casted as type EO.
|
|
70
70
|
*/
|
|
71
|
-
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E
|
|
71
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E): EO;
|
|
72
72
|
/**
|
|
73
73
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
74
|
-
* @param {
|
|
75
|
-
* @param {
|
|
76
|
-
* destination vertex of the edge. It can be either a vertex object (`
|
|
74
|
+
* @param {VO | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
75
|
+
* @param {VO | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
76
|
+
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
|
|
77
77
|
* destination is not specified.
|
|
78
78
|
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
79
79
|
*/
|
|
80
|
-
getEdge(srcOrKey:
|
|
80
|
+
getEdge(srcOrKey: VO | null | VertexKey, destOrKey: VO | null | VertexKey): EO | null;
|
|
81
81
|
/**
|
|
82
82
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
83
|
-
* @param {
|
|
84
|
-
* @param {
|
|
85
|
-
* @returns the removed edge (
|
|
83
|
+
* @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
|
|
84
|
+
* @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
85
|
+
* @returns the removed edge (EO) if it exists, or null if either the source or destination vertex does not exist.
|
|
86
86
|
*/
|
|
87
|
-
deleteEdgeSrcToDest(srcOrKey:
|
|
87
|
+
deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | null;
|
|
88
88
|
/**
|
|
89
89
|
* The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
|
|
90
|
-
* @param {
|
|
90
|
+
* @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
91
91
|
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
92
|
-
* @returns The method `deleteEdge` returns the removed edge (`
|
|
92
|
+
* @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `null` if the edge does not exist.
|
|
93
93
|
*/
|
|
94
|
-
deleteEdge(edge:
|
|
94
|
+
deleteEdge(edge: EO): EO | null;
|
|
95
95
|
/**
|
|
96
96
|
* The function removes edges between two vertices and returns the removed edges.
|
|
97
|
-
* @param {VertexKey |
|
|
98
|
-
* unique identifier of a vertex in a graph, while `
|
|
99
|
-
* @param {VertexKey |
|
|
97
|
+
* @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
|
|
98
|
+
* unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
|
|
99
|
+
* @param {VertexKey | VO} v2 - The parameter `v2` represents either a `VertexKey` or a `VO` object. It is used to specify
|
|
100
100
|
* the second vertex in the edge that needs to be removed.
|
|
101
|
-
* @returns an array of removed edges (
|
|
101
|
+
* @returns an array of removed edges (EO[]).
|
|
102
102
|
*/
|
|
103
|
-
deleteEdgesBetween(v1: VertexKey |
|
|
103
|
+
deleteEdgesBetween(v1: VertexKey | VO, v2: VertexKey | VO): EO[];
|
|
104
104
|
/**
|
|
105
105
|
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
106
|
-
* @param {
|
|
106
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
107
107
|
* (`VertexKey`).
|
|
108
|
-
* @returns The method `incomingEdgesOf` returns an array of edges (`
|
|
108
|
+
* @returns The method `incomingEdgesOf` returns an array of edges (`EO[]`).
|
|
109
109
|
*/
|
|
110
|
-
incomingEdgesOf(vertexOrKey:
|
|
110
|
+
incomingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
111
111
|
/**
|
|
112
112
|
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
113
|
-
* @param {
|
|
113
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
|
|
114
114
|
* (`VertexKey`).
|
|
115
|
-
* @returns The method `outgoingEdgesOf` returns an array of edges (`
|
|
115
|
+
* @returns The method `outgoingEdgesOf` returns an array of edges (`EO[]`).
|
|
116
116
|
*/
|
|
117
|
-
outgoingEdgesOf(vertexOrKey:
|
|
117
|
+
outgoingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
118
118
|
/**
|
|
119
119
|
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
|
|
120
|
-
* @param {VertexKey |
|
|
120
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
121
121
|
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
122
122
|
*/
|
|
123
|
-
degreeOf(vertexOrKey: VertexKey |
|
|
123
|
+
degreeOf(vertexOrKey: VertexKey | VO): number;
|
|
124
124
|
/**
|
|
125
125
|
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
|
|
126
|
-
* @param {VertexKey |
|
|
126
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
127
127
|
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
128
128
|
*/
|
|
129
|
-
inDegreeOf(vertexOrKey: VertexKey |
|
|
129
|
+
inDegreeOf(vertexOrKey: VertexKey | VO): number;
|
|
130
130
|
/**
|
|
131
131
|
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
|
|
132
|
-
* @param {VertexKey |
|
|
132
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
133
133
|
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
134
134
|
*/
|
|
135
|
-
outDegreeOf(vertexOrKey: VertexKey |
|
|
135
|
+
outDegreeOf(vertexOrKey: VertexKey | VO): number;
|
|
136
136
|
/**
|
|
137
137
|
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
|
|
138
|
-
* @param {VertexKey |
|
|
138
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
139
139
|
* @returns The function `edgesOf` returns an array of edges.
|
|
140
140
|
*/
|
|
141
|
-
edgesOf(vertexOrKey: VertexKey |
|
|
141
|
+
edgesOf(vertexOrKey: VertexKey | VO): EO[];
|
|
142
142
|
/**
|
|
143
143
|
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
|
|
144
|
-
* @param {
|
|
145
|
-
* @returns either a vertex object (
|
|
144
|
+
* @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
|
|
145
|
+
* @returns either a vertex object (VO) or null.
|
|
146
146
|
*/
|
|
147
|
-
getEdgeSrc(e:
|
|
147
|
+
getEdgeSrc(e: EO): VO | null;
|
|
148
148
|
/**
|
|
149
149
|
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
150
|
-
* @param {
|
|
151
|
-
* @returns either a vertex object of type
|
|
150
|
+
* @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
|
|
151
|
+
* @returns either a vertex object of type VO or null.
|
|
152
152
|
*/
|
|
153
|
-
getEdgeDest(e:
|
|
153
|
+
getEdgeDest(e: EO): VO | null;
|
|
154
154
|
/**
|
|
155
155
|
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
156
|
-
* @param {
|
|
157
|
-
* find the destinations. It can be either a `
|
|
158
|
-
* @returns an array of vertices (
|
|
156
|
+
* @param {VO | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
157
|
+
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `null`.
|
|
158
|
+
* @returns an array of vertices (VO[]).
|
|
159
159
|
*/
|
|
160
|
-
getDestinations(vertex:
|
|
160
|
+
getDestinations(vertex: VO | VertexKey | null): VO[];
|
|
161
161
|
/**
|
|
162
162
|
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
|
|
163
163
|
* in the sorted order, or null if the graph contains a cycle.
|
|
@@ -166,35 +166,35 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
|
|
|
166
166
|
* specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
|
|
167
167
|
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
|
|
168
168
|
*/
|
|
169
|
-
topologicalSort(propertyName?: 'vertex' | 'key'): Array<
|
|
169
|
+
topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | null;
|
|
170
170
|
/**
|
|
171
171
|
* The `edgeSet` function returns an array of all the edges in the graph.
|
|
172
|
-
* @returns The `edgeSet()` method returns an array of edges (`
|
|
172
|
+
* @returns The `edgeSet()` method returns an array of edges (`EO[]`).
|
|
173
173
|
*/
|
|
174
|
-
edgeSet():
|
|
174
|
+
edgeSet(): EO[];
|
|
175
175
|
/**
|
|
176
176
|
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
|
|
177
|
-
* @param {
|
|
177
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
178
178
|
* (`VertexKey`).
|
|
179
|
-
* @returns an array of vertices (
|
|
179
|
+
* @returns an array of vertices (VO[]).
|
|
180
180
|
*/
|
|
181
|
-
getNeighbors(vertexOrKey:
|
|
181
|
+
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
182
182
|
/**
|
|
183
183
|
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
184
184
|
* otherwise it returns null.
|
|
185
|
-
* @param {
|
|
186
|
-
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[
|
|
185
|
+
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
|
|
186
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
|
|
187
187
|
* graph. If the edge does not exist, it returns `null`.
|
|
188
188
|
*/
|
|
189
|
-
getEndsOfEdge(edge:
|
|
189
|
+
getEndsOfEdge(edge: EO): [VO, VO] | null;
|
|
190
190
|
/**
|
|
191
191
|
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
|
|
192
|
-
* @param {
|
|
192
|
+
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
193
193
|
* needs to be added to the graph.
|
|
194
194
|
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
195
195
|
* source or destination vertex does not exist in the graph.
|
|
196
196
|
*/
|
|
197
|
-
protected _addEdgeOnly(edge:
|
|
198
|
-
protected _setOutEdgeMap(value: Map<
|
|
199
|
-
protected _setInEdgeMap(value: Map<
|
|
197
|
+
protected _addEdgeOnly(edge: EO): boolean;
|
|
198
|
+
protected _setOutEdgeMap(value: Map<VO, EO[]>): void;
|
|
199
|
+
protected _setInEdgeMap(value: Map<VO, EO[]>): void;
|
|
200
200
|
}
|
|
@@ -32,7 +32,7 @@ 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} [val] - The `val` parameter is an optional parameter of type `E`. It represents the value associated with
|
|
36
36
|
* the edge.
|
|
37
37
|
*/
|
|
38
38
|
constructor(src, dest, weight, val) {
|
|
@@ -82,7 +82,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
82
82
|
* @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
83
83
|
* it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
|
|
84
84
|
* assigned the same value as the 'key' parameter
|
|
85
|
-
* @returns a new instance of a DirectedVertex object, casted as type
|
|
85
|
+
* @returns a new instance of a DirectedVertex object, casted as type VO.
|
|
86
86
|
*/
|
|
87
87
|
createVertex(key, val) {
|
|
88
88
|
return new DirectedVertex(key, val ?? key);
|
|
@@ -99,16 +99,16 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
99
99
|
* weight is provided, it defaults to 1.
|
|
100
100
|
* @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
101
101
|
* is used to store additional information or data associated with the edge.
|
|
102
|
-
* @returns a new instance of a DirectedEdge object, casted as type
|
|
102
|
+
* @returns a new instance of a DirectedEdge object, casted as type EO.
|
|
103
103
|
*/
|
|
104
104
|
createEdge(src, dest, weight, val) {
|
|
105
105
|
return new DirectedEdge(src, dest, weight ?? 1, val);
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
109
|
-
* @param {
|
|
110
|
-
* @param {
|
|
111
|
-
* destination vertex of the edge. It can be either a vertex object (`
|
|
109
|
+
* @param {VO | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
110
|
+
* @param {VO | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
111
|
+
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
|
|
112
112
|
* destination is not specified.
|
|
113
113
|
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
114
114
|
*/
|
|
@@ -128,9 +128,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
130
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
131
|
-
* @param {
|
|
132
|
-
* @param {
|
|
133
|
-
* @returns the removed edge (
|
|
131
|
+
* @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
|
|
132
|
+
* @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
133
|
+
* @returns the removed edge (EO) if it exists, or null if either the source or destination vertex does not exist.
|
|
134
134
|
*/
|
|
135
135
|
deleteEdgeSrcToDest(srcOrKey, destOrKey) {
|
|
136
136
|
const src = this._getVertex(srcOrKey);
|
|
@@ -151,9 +151,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
153
153
|
* The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
|
|
154
|
-
* @param {
|
|
154
|
+
* @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
155
155
|
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
156
|
-
* @returns The method `deleteEdge` returns the removed edge (`
|
|
156
|
+
* @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `null` if the edge does not exist.
|
|
157
157
|
*/
|
|
158
158
|
deleteEdge(edge) {
|
|
159
159
|
let removed = null;
|
|
@@ -173,11 +173,11 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
175
|
* The function removes edges between two vertices and returns the removed edges.
|
|
176
|
-
* @param {VertexKey |
|
|
177
|
-
* unique identifier of a vertex in a graph, while `
|
|
178
|
-
* @param {VertexKey |
|
|
176
|
+
* @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
|
|
177
|
+
* unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
|
|
178
|
+
* @param {VertexKey | VO} v2 - The parameter `v2` represents either a `VertexKey` or a `VO` object. It is used to specify
|
|
179
179
|
* the second vertex in the edge that needs to be removed.
|
|
180
|
-
* @returns an array of removed edges (
|
|
180
|
+
* @returns an array of removed edges (EO[]).
|
|
181
181
|
*/
|
|
182
182
|
deleteEdgesBetween(v1, v2) {
|
|
183
183
|
const removed = [];
|
|
@@ -191,9 +191,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
194
|
-
* @param {
|
|
194
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
195
195
|
* (`VertexKey`).
|
|
196
|
-
* @returns The method `incomingEdgesOf` returns an array of edges (`
|
|
196
|
+
* @returns The method `incomingEdgesOf` returns an array of edges (`EO[]`).
|
|
197
197
|
*/
|
|
198
198
|
incomingEdgesOf(vertexOrKey) {
|
|
199
199
|
const target = this._getVertex(vertexOrKey);
|
|
@@ -204,9 +204,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
206
206
|
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
207
|
-
* @param {
|
|
207
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
|
|
208
208
|
* (`VertexKey`).
|
|
209
|
-
* @returns The method `outgoingEdgesOf` returns an array of edges (`
|
|
209
|
+
* @returns The method `outgoingEdgesOf` returns an array of edges (`EO[]`).
|
|
210
210
|
*/
|
|
211
211
|
outgoingEdgesOf(vertexOrKey) {
|
|
212
212
|
const target = this._getVertex(vertexOrKey);
|
|
@@ -217,7 +217,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
219
|
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
|
|
220
|
-
* @param {VertexKey |
|
|
220
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
221
221
|
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
222
222
|
*/
|
|
223
223
|
degreeOf(vertexOrKey) {
|
|
@@ -225,7 +225,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
225
225
|
}
|
|
226
226
|
/**
|
|
227
227
|
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
|
|
228
|
-
* @param {VertexKey |
|
|
228
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
229
229
|
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
230
230
|
*/
|
|
231
231
|
inDegreeOf(vertexOrKey) {
|
|
@@ -233,7 +233,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
235
235
|
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
|
|
236
|
-
* @param {VertexKey |
|
|
236
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
237
237
|
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
238
238
|
*/
|
|
239
239
|
outDegreeOf(vertexOrKey) {
|
|
@@ -241,7 +241,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
241
241
|
}
|
|
242
242
|
/**
|
|
243
243
|
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
|
|
244
|
-
* @param {VertexKey |
|
|
244
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
245
245
|
* @returns The function `edgesOf` returns an array of edges.
|
|
246
246
|
*/
|
|
247
247
|
edgesOf(vertexOrKey) {
|
|
@@ -249,25 +249,25 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
249
249
|
}
|
|
250
250
|
/**
|
|
251
251
|
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
|
|
252
|
-
* @param {
|
|
253
|
-
* @returns either a vertex object (
|
|
252
|
+
* @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
|
|
253
|
+
* @returns either a vertex object (VO) or null.
|
|
254
254
|
*/
|
|
255
255
|
getEdgeSrc(e) {
|
|
256
256
|
return this._getVertex(e.src);
|
|
257
257
|
}
|
|
258
258
|
/**
|
|
259
259
|
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
260
|
-
* @param {
|
|
261
|
-
* @returns either a vertex object of type
|
|
260
|
+
* @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
|
|
261
|
+
* @returns either a vertex object of type VO or null.
|
|
262
262
|
*/
|
|
263
263
|
getEdgeDest(e) {
|
|
264
264
|
return this._getVertex(e.dest);
|
|
265
265
|
}
|
|
266
266
|
/**
|
|
267
267
|
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
268
|
-
* @param {
|
|
269
|
-
* find the destinations. It can be either a `
|
|
270
|
-
* @returns an array of vertices (
|
|
268
|
+
* @param {VO | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
269
|
+
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `null`.
|
|
270
|
+
* @returns an array of vertices (VO[]).
|
|
271
271
|
*/
|
|
272
272
|
getDestinations(vertex) {
|
|
273
273
|
if (vertex === null) {
|
|
@@ -329,7 +329,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
329
329
|
}
|
|
330
330
|
/**
|
|
331
331
|
* The `edgeSet` function returns an array of all the edges in the graph.
|
|
332
|
-
* @returns The `edgeSet()` method returns an array of edges (`
|
|
332
|
+
* @returns The `edgeSet()` method returns an array of edges (`EO[]`).
|
|
333
333
|
*/
|
|
334
334
|
edgeSet() {
|
|
335
335
|
let edges = [];
|
|
@@ -340,9 +340,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
340
340
|
}
|
|
341
341
|
/**
|
|
342
342
|
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
|
|
343
|
-
* @param {
|
|
343
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
344
344
|
* (`VertexKey`).
|
|
345
|
-
* @returns an array of vertices (
|
|
345
|
+
* @returns an array of vertices (VO[]).
|
|
346
346
|
*/
|
|
347
347
|
getNeighbors(vertexOrKey) {
|
|
348
348
|
const neighbors = [];
|
|
@@ -362,8 +362,8 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
362
362
|
/**
|
|
363
363
|
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
364
364
|
* otherwise it returns null.
|
|
365
|
-
* @param {
|
|
366
|
-
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[
|
|
365
|
+
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
|
|
366
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
|
|
367
367
|
* graph. If the edge does not exist, it returns `null`.
|
|
368
368
|
*/
|
|
369
369
|
getEndsOfEdge(edge) {
|
|
@@ -381,7 +381,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
381
381
|
}
|
|
382
382
|
/**
|
|
383
383
|
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
|
|
384
|
-
* @param {
|
|
384
|
+
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
385
385
|
* needs to be added to the graph.
|
|
386
386
|
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
387
387
|
* source or destination vertex does not exist in the graph.
|
|
@@ -13,7 +13,7 @@ export declare class MapVertex<V = any> extends DirectedVertex<V> {
|
|
|
13
13
|
* @param {V} [val] - The "val" 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, val: 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} [val] - The "val" 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, val?:
|
|
35
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: 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
|
|
@@ -56,13 +56,13 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
|
|
|
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
58
|
* @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It
|
|
59
|
-
* is of type `V
|
|
59
|
+
* is of type `V`, which means it should be of the same type as the `val` 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, val?: 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.
|
|
@@ -73,7 +73,7 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
|
|
|
73
73
|
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
74
74
|
* @param [val] - The `val` 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, val?: E
|
|
78
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E): EO;
|
|
79
79
|
}
|
|
@@ -15,7 +15,7 @@ class MapVertex extends directed_graph_1.DirectedVertex {
|
|
|
15
15
|
* @param {V} [val] - The "val" 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
|
|
18
|
+
constructor(key, val, lat, long) {
|
|
19
19
|
super(key, val);
|
|
20
20
|
this._lat = lat;
|
|
21
21
|
this._long = long;
|
|
@@ -44,7 +44,7 @@ class MapEdge extends directed_graph_1.DirectedEdge {
|
|
|
44
44
|
* a graph.
|
|
45
45
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
46
46
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
47
|
-
* @param {
|
|
47
|
+
* @param {E} [val] - The "val" parameter is an optional parameter of type E. It is used to store additional
|
|
48
48
|
* information or data associated with the edge.
|
|
49
49
|
*/
|
|
50
50
|
constructor(src, dest, weight, val) {
|
|
@@ -86,14 +86,14 @@ class MapGraph extends directed_graph_1.DirectedGraph {
|
|
|
86
86
|
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
|
|
87
87
|
* be a string or a number depending on how you define it in your code.
|
|
88
88
|
* @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It
|
|
89
|
-
* is of type `V
|
|
89
|
+
* is of type `V`, which means it should be of the same type as the `val` property of the vertex class `VO`.
|
|
90
90
|
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
|
|
91
91
|
* position of the vertex on the Earth's surface in the north-south direction.
|
|
92
92
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
93
|
-
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `
|
|
93
|
+
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
94
94
|
*/
|
|
95
|
-
createVertex(key, lat = this.origin[0], long = this.origin[1]
|
|
96
|
-
return new MapVertex(key, lat, long
|
|
95
|
+
createVertex(key, val, lat = this.origin[0], long = this.origin[1]) {
|
|
96
|
+
return new MapVertex(key, val, lat, long);
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
@@ -105,7 +105,7 @@ class MapGraph extends directed_graph_1.DirectedGraph {
|
|
|
105
105
|
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
106
106
|
* @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type,
|
|
107
107
|
* depending on the specific implementation of the `MapEdge` class.
|
|
108
|
-
* @returns a new instance of the `MapEdge` class, cast as type `
|
|
108
|
+
* @returns a new instance of the `MapEdge` class, cast as type `EO`.
|
|
109
109
|
*/
|
|
110
110
|
createEdge(src, dest, weight, val) {
|
|
111
111
|
return new MapEdge(src, dest, weight, val);
|