doubly-linked-list-typed 1.52.4 → 1.52.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/base/iterable-element-base.d.ts +1 -37
- package/dist/data-structures/base/iterable-element-base.js +1 -37
- package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/data-structures/binary-tree/binary-tree.js +300 -332
- package/dist/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/data-structures/binary-tree/bst.js +12 -44
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/data-structures/graph/abstract-graph.js +0 -75
- package/dist/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/data-structures/graph/directed-graph.js +0 -98
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/data-structures/graph/undirected-graph.js +0 -50
- package/dist/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/data-structures/hash/hash-map.js +27 -111
- package/dist/data-structures/heap/heap.d.ts +0 -32
- package/dist/data-structures/heap/heap.js +0 -32
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/data-structures/queue/deque.d.ts +1 -98
- package/dist/data-structures/queue/deque.js +3 -99
- package/dist/data-structures/queue/queue.d.ts +1 -54
- package/dist/data-structures/queue/queue.js +0 -53
- package/dist/data-structures/stack/stack.d.ts +1 -34
- package/dist/data-structures/stack/stack.js +1 -34
- package/dist/data-structures/tree/tree.js +2 -1
- package/dist/data-structures/trie/trie.d.ts +0 -64
- package/dist/data-structures/trie/trie.js +0 -64
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/types/utils/utils.d.ts +13 -12
- package/dist/utils/number.d.ts +13 -0
- package/dist/utils/number.js +13 -0
- package/dist/utils/utils.d.ts +125 -3
- package/dist/utils/utils.js +177 -21
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +330 -359
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +29 -133
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +1 -68
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
|
@@ -45,10 +45,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
45
45
|
protected _inEdgeMap: Map<VO, EO[]>;
|
|
46
46
|
get inEdgeMap(): Map<VO, EO[]>;
|
|
47
47
|
set inEdgeMap(v: Map<VO, EO[]>);
|
|
48
|
-
/**
|
|
49
|
-
* 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.
|
|
50
|
-
* 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
|
-
*/
|
|
52
48
|
/**
|
|
53
49
|
* The function creates a new vertex with an optional value and returns it.
|
|
54
50
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
@@ -59,10 +55,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
59
55
|
* @returns a new instance of a DirectedVertex object, casted as type VO.
|
|
60
56
|
*/
|
|
61
57
|
createVertex(key: VertexKey, value?: V): VO;
|
|
62
|
-
/**
|
|
63
|
-
* 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.
|
|
64
|
-
* 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.
|
|
65
|
-
*/
|
|
66
58
|
/**
|
|
67
59
|
* The function creates a directed edge between two vertexMap with an optional weight and value.
|
|
68
60
|
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
@@ -74,10 +66,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
74
66
|
* @returns a new instance of a DirectedEdge object, casted as type EO.
|
|
75
67
|
*/
|
|
76
68
|
createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
|
|
77
|
-
/**
|
|
78
|
-
* Time Complexity: O(|V|) where |V| is the number of vertexMap
|
|
79
|
-
* Space Complexity: O(1)
|
|
80
|
-
*/
|
|
81
69
|
/**
|
|
82
70
|
* Time Complexity: O(|V|) where |V| is the number of vertexMap
|
|
83
71
|
* Space Complexity: O(1)
|
|
@@ -90,10 +78,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
90
78
|
* @returns the first edge found between the source and destination vertexMap, or undefined if no such edge is found.
|
|
91
79
|
*/
|
|
92
80
|
getEdge(srcOrKey: VO | VertexKey | undefined, destOrKey: VO | VertexKey | undefined): EO | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
95
|
-
* Space Complexity: O(1)
|
|
96
|
-
*/
|
|
97
81
|
/**
|
|
98
82
|
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
99
83
|
* Space Complexity: O(1)
|
|
@@ -104,10 +88,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
104
88
|
* @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
|
|
105
89
|
*/
|
|
106
90
|
deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
|
|
107
|
-
/**
|
|
108
|
-
* Time Complexity: O(E) where E is the number of edgeMap
|
|
109
|
-
* Space Complexity: O(1)
|
|
110
|
-
*/
|
|
111
91
|
/**
|
|
112
92
|
* Time Complexity: O(E) where E is the number of edgeMap
|
|
113
93
|
* Space Complexity: O(1)
|
|
@@ -122,10 +102,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
122
102
|
* @returns the removed edge (EO) or undefined if no edge was removed.
|
|
123
103
|
*/
|
|
124
104
|
deleteEdge(edgeOrSrcVertexKey: EO | VertexKey, destVertexKey?: VertexKey): EO | undefined;
|
|
125
|
-
/**
|
|
126
|
-
* Time Complexity: O(1) - Constant time for Map operations.
|
|
127
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
128
|
-
*/
|
|
129
105
|
/**
|
|
130
106
|
* Time Complexity: O(1) - Constant time for Map operations.
|
|
131
107
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -136,10 +112,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
136
112
|
* @returns The method is returning a boolean value.
|
|
137
113
|
*/
|
|
138
114
|
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
139
|
-
/**
|
|
140
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
141
|
-
* Space Complexity: O(1)
|
|
142
|
-
*/
|
|
143
115
|
/**
|
|
144
116
|
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
145
117
|
* Space Complexity: O(1)
|
|
@@ -152,10 +124,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
152
124
|
* @returns an array of removed edgeMap (EO[]).
|
|
153
125
|
*/
|
|
154
126
|
deleteEdgesBetween(v1: VertexKey | VO, v2: VertexKey | VO): EO[];
|
|
155
|
-
/**
|
|
156
|
-
* Time Complexity: O(1)
|
|
157
|
-
* Space Complexity: O(1)
|
|
158
|
-
*/
|
|
159
127
|
/**
|
|
160
128
|
* Time Complexity: O(1)
|
|
161
129
|
* Space Complexity: O(1)
|
|
@@ -166,10 +134,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
166
134
|
* @returns The method `incomingEdgesOf` returns an array of edgeMap (`EO[]`).
|
|
167
135
|
*/
|
|
168
136
|
incomingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
169
|
-
/**
|
|
170
|
-
* Time Complexity: O(1)
|
|
171
|
-
* Space Complexity: O(1)
|
|
172
|
-
*/
|
|
173
137
|
/**
|
|
174
138
|
* Time Complexity: O(1)
|
|
175
139
|
* Space Complexity: O(1)
|
|
@@ -180,10 +144,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
180
144
|
* @returns The method `outgoingEdgesOf` returns an array of edgeMap (`EO[]`).
|
|
181
145
|
*/
|
|
182
146
|
outgoingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
183
|
-
/**
|
|
184
|
-
* Time Complexity: O(1)
|
|
185
|
-
* Space Complexity: O(1)
|
|
186
|
-
*/
|
|
187
147
|
/**
|
|
188
148
|
* Time Complexity: O(1)
|
|
189
149
|
* Space Complexity: O(1)
|
|
@@ -193,10 +153,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
193
153
|
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
194
154
|
*/
|
|
195
155
|
degreeOf(vertexOrKey: VertexKey | VO): number;
|
|
196
|
-
/**
|
|
197
|
-
* Time Complexity: O(1)
|
|
198
|
-
* Space Complexity: O(1)
|
|
199
|
-
*/
|
|
200
156
|
/**
|
|
201
157
|
* Time Complexity: O(1)
|
|
202
158
|
* Space Complexity: O(1)
|
|
@@ -206,10 +162,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
206
162
|
* @returns The number of incoming edgeMap of the specified vertex or vertex ID.
|
|
207
163
|
*/
|
|
208
164
|
inDegreeOf(vertexOrKey: VertexKey | VO): number;
|
|
209
|
-
/**
|
|
210
|
-
* Time Complexity: O(1)
|
|
211
|
-
* Space Complexity: O(1)
|
|
212
|
-
*/
|
|
213
165
|
/**
|
|
214
166
|
* Time Complexity: O(1)
|
|
215
167
|
* Space Complexity: O(1)
|
|
@@ -219,10 +171,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
219
171
|
* @returns The number of outgoing edgeMap from the specified vertex or vertex ID.
|
|
220
172
|
*/
|
|
221
173
|
outDegreeOf(vertexOrKey: VertexKey | VO): number;
|
|
222
|
-
/**
|
|
223
|
-
* Time Complexity: O(1)
|
|
224
|
-
* Space Complexity: O(1)
|
|
225
|
-
*/
|
|
226
174
|
/**
|
|
227
175
|
* Time Complexity: O(1)
|
|
228
176
|
* Space Complexity: O(1)
|
|
@@ -232,10 +180,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
232
180
|
* @returns The function `edgesOf` returns an array of edgeMap.
|
|
233
181
|
*/
|
|
234
182
|
edgesOf(vertexOrKey: VertexKey | VO): EO[];
|
|
235
|
-
/**
|
|
236
|
-
* Time Complexity: O(1)
|
|
237
|
-
* Space Complexity: O(1)
|
|
238
|
-
*/
|
|
239
183
|
/**
|
|
240
184
|
* Time Complexity: O(1)
|
|
241
185
|
* Space Complexity: O(1)
|
|
@@ -245,10 +189,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
245
189
|
* @returns either a vertex object (VO) or undefined.
|
|
246
190
|
*/
|
|
247
191
|
getEdgeSrc(e: EO): VO | undefined;
|
|
248
|
-
/**
|
|
249
|
-
* Time Complexity: O(1)
|
|
250
|
-
* Space Complexity: O(1)
|
|
251
|
-
*/
|
|
252
192
|
/**
|
|
253
193
|
* Time Complexity: O(1)
|
|
254
194
|
* Space Complexity: O(1)
|
|
@@ -258,10 +198,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
258
198
|
* @returns either a vertex object of type VO or undefined.
|
|
259
199
|
*/
|
|
260
200
|
getEdgeDest(e: EO): VO | undefined;
|
|
261
|
-
/**
|
|
262
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
263
|
-
* Space Complexity: O(1)
|
|
264
|
-
*/
|
|
265
201
|
/**
|
|
266
202
|
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
267
203
|
* Space Complexity: O(1)
|
|
@@ -272,10 +208,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
272
208
|
* @returns an array of vertexMap (VO[]).
|
|
273
209
|
*/
|
|
274
210
|
getDestinations(vertex: VO | VertexKey | undefined): VO[];
|
|
275
|
-
/**
|
|
276
|
-
* Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
|
|
277
|
-
* Space Complexity: O(|V|)
|
|
278
|
-
*/
|
|
279
211
|
/**
|
|
280
212
|
* Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
|
|
281
213
|
* Space Complexity: O(|V|)
|
|
@@ -288,10 +220,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
288
220
|
* @returns an array of vertexMap or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
|
|
289
221
|
*/
|
|
290
222
|
topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | undefined;
|
|
291
|
-
/**
|
|
292
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
293
|
-
* Space Complexity: O(|E|)
|
|
294
|
-
*/
|
|
295
223
|
/**
|
|
296
224
|
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
297
225
|
* Space Complexity: O(|E|)
|
|
@@ -300,10 +228,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
300
228
|
* @returns The `edgeSet()` method returns an array of edgeMap (`EO[]`).
|
|
301
229
|
*/
|
|
302
230
|
edgeSet(): EO[];
|
|
303
|
-
/**
|
|
304
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
305
|
-
* Space Complexity: O(1)
|
|
306
|
-
*/
|
|
307
231
|
/**
|
|
308
232
|
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
309
233
|
* Space Complexity: O(1)
|
|
@@ -314,10 +238,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
314
238
|
* @returns an array of vertexMap (VO[]).
|
|
315
239
|
*/
|
|
316
240
|
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
317
|
-
/**
|
|
318
|
-
* Time Complexity: O(1)
|
|
319
|
-
* Space Complexity: O(1)
|
|
320
|
-
*/
|
|
321
241
|
/**
|
|
322
242
|
* Time Complexity: O(1)
|
|
323
243
|
* Space Complexity: O(1)
|
|
@@ -335,10 +255,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
335
255
|
* @return A boolean value
|
|
336
256
|
*/
|
|
337
257
|
isEmpty(): boolean;
|
|
338
|
-
/**
|
|
339
|
-
* Time Complexity: O(1)
|
|
340
|
-
* Space Complexity: O(1)
|
|
341
|
-
*/
|
|
342
258
|
/**
|
|
343
259
|
* Time Complexity: O(1)
|
|
344
260
|
* Space Complexity: O(1)
|
|
@@ -352,12 +268,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
352
268
|
* @return A new instance of the directedgraph class
|
|
353
269
|
*/
|
|
354
270
|
clone(): DirectedGraph<V, E, VO, EO>;
|
|
355
|
-
/**
|
|
356
|
-
* Time Complexity: O(V + E)
|
|
357
|
-
* Space Complexity: O(V)
|
|
358
|
-
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
359
|
-
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
360
|
-
*/
|
|
361
271
|
/**
|
|
362
272
|
* Time Complexity: O(V + E)
|
|
363
273
|
* Space Complexity: O(V)
|
|
@@ -374,10 +284,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
374
284
|
lowMap: Map<VO, number>;
|
|
375
285
|
SCCs: Map<number, VO[]>;
|
|
376
286
|
};
|
|
377
|
-
/**
|
|
378
|
-
* Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
|
|
379
|
-
* Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
|
|
380
|
-
*/
|
|
381
287
|
/**
|
|
382
288
|
* Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
|
|
383
289
|
* Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
|
|
@@ -400,10 +306,6 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
400
306
|
* @returns a map where the keys are numbers and the values are arrays of VO objects.
|
|
401
307
|
*/
|
|
402
308
|
getSCCs(): Map<number, VO[]>;
|
|
403
|
-
/**
|
|
404
|
-
* Time Complexity: O(1)
|
|
405
|
-
* Space Complexity: O(1)
|
|
406
|
-
*/
|
|
407
309
|
/**
|
|
408
310
|
* Time Complexity: O(1)
|
|
409
311
|
* Space Complexity: O(1)
|
|
@@ -56,10 +56,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
56
56
|
set inEdgeMap(v) {
|
|
57
57
|
this._inEdgeMap = v;
|
|
58
58
|
}
|
|
59
|
-
/**
|
|
60
|
-
* 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.
|
|
61
|
-
* 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.
|
|
62
|
-
*/
|
|
63
59
|
/**
|
|
64
60
|
* The function creates a new vertex with an optional value and returns it.
|
|
65
61
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
@@ -72,10 +68,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
72
68
|
createVertex(key, value) {
|
|
73
69
|
return new DirectedVertex(key, value);
|
|
74
70
|
}
|
|
75
|
-
/**
|
|
76
|
-
* 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.
|
|
77
|
-
* 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.
|
|
78
|
-
*/
|
|
79
71
|
/**
|
|
80
72
|
* The function creates a directed edge between two vertexMap with an optional weight and value.
|
|
81
73
|
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
@@ -89,10 +81,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
89
81
|
createEdge(src, dest, weight, value) {
|
|
90
82
|
return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1, value);
|
|
91
83
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Time Complexity: O(|V|) where |V| is the number of vertexMap
|
|
94
|
-
* Space Complexity: O(1)
|
|
95
|
-
*/
|
|
96
84
|
/**
|
|
97
85
|
* Time Complexity: O(|V|) where |V| is the number of vertexMap
|
|
98
86
|
* Space Complexity: O(1)
|
|
@@ -118,10 +106,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
118
106
|
}
|
|
119
107
|
return edgeMap[0] || undefined;
|
|
120
108
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
123
|
-
* Space Complexity: O(1)
|
|
124
|
-
*/
|
|
125
109
|
/**
|
|
126
110
|
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
127
111
|
* Space Complexity: O(1)
|
|
@@ -148,10 +132,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
148
132
|
}
|
|
149
133
|
return removed;
|
|
150
134
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Time Complexity: O(E) where E is the number of edgeMap
|
|
153
|
-
* Space Complexity: O(1)
|
|
154
|
-
*/
|
|
155
135
|
/**
|
|
156
136
|
* Time Complexity: O(E) where E is the number of edgeMap
|
|
157
137
|
* Space Complexity: O(1)
|
|
@@ -193,10 +173,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
193
173
|
}
|
|
194
174
|
return removed;
|
|
195
175
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Time Complexity: O(1) - Constant time for Map operations.
|
|
198
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
199
|
-
*/
|
|
200
176
|
/**
|
|
201
177
|
* Time Complexity: O(1) - Constant time for Map operations.
|
|
202
178
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -228,10 +204,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
228
204
|
}
|
|
229
205
|
return this._vertexMap.delete(vertexKey);
|
|
230
206
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
233
|
-
* Space Complexity: O(1)
|
|
234
|
-
*/
|
|
235
207
|
/**
|
|
236
208
|
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
237
209
|
* Space Complexity: O(1)
|
|
@@ -253,10 +225,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
253
225
|
}
|
|
254
226
|
return removed;
|
|
255
227
|
}
|
|
256
|
-
/**
|
|
257
|
-
* Time Complexity: O(1)
|
|
258
|
-
* Space Complexity: O(1)
|
|
259
|
-
*/
|
|
260
228
|
/**
|
|
261
229
|
* Time Complexity: O(1)
|
|
262
230
|
* Space Complexity: O(1)
|
|
@@ -273,10 +241,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
273
241
|
}
|
|
274
242
|
return [];
|
|
275
243
|
}
|
|
276
|
-
/**
|
|
277
|
-
* Time Complexity: O(1)
|
|
278
|
-
* Space Complexity: O(1)
|
|
279
|
-
*/
|
|
280
244
|
/**
|
|
281
245
|
* Time Complexity: O(1)
|
|
282
246
|
* Space Complexity: O(1)
|
|
@@ -293,10 +257,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
293
257
|
}
|
|
294
258
|
return [];
|
|
295
259
|
}
|
|
296
|
-
/**
|
|
297
|
-
* Time Complexity: O(1)
|
|
298
|
-
* Space Complexity: O(1)
|
|
299
|
-
*/
|
|
300
260
|
/**
|
|
301
261
|
* Time Complexity: O(1)
|
|
302
262
|
* Space Complexity: O(1)
|
|
@@ -308,10 +268,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
308
268
|
degreeOf(vertexOrKey) {
|
|
309
269
|
return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
|
|
310
270
|
}
|
|
311
|
-
/**
|
|
312
|
-
* Time Complexity: O(1)
|
|
313
|
-
* Space Complexity: O(1)
|
|
314
|
-
*/
|
|
315
271
|
/**
|
|
316
272
|
* Time Complexity: O(1)
|
|
317
273
|
* Space Complexity: O(1)
|
|
@@ -323,10 +279,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
323
279
|
inDegreeOf(vertexOrKey) {
|
|
324
280
|
return this.incomingEdgesOf(vertexOrKey).length;
|
|
325
281
|
}
|
|
326
|
-
/**
|
|
327
|
-
* Time Complexity: O(1)
|
|
328
|
-
* Space Complexity: O(1)
|
|
329
|
-
*/
|
|
330
282
|
/**
|
|
331
283
|
* Time Complexity: O(1)
|
|
332
284
|
* Space Complexity: O(1)
|
|
@@ -338,10 +290,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
338
290
|
outDegreeOf(vertexOrKey) {
|
|
339
291
|
return this.outgoingEdgesOf(vertexOrKey).length;
|
|
340
292
|
}
|
|
341
|
-
/**
|
|
342
|
-
* Time Complexity: O(1)
|
|
343
|
-
* Space Complexity: O(1)
|
|
344
|
-
*/
|
|
345
293
|
/**
|
|
346
294
|
* Time Complexity: O(1)
|
|
347
295
|
* Space Complexity: O(1)
|
|
@@ -353,10 +301,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
353
301
|
edgesOf(vertexOrKey) {
|
|
354
302
|
return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
|
|
355
303
|
}
|
|
356
|
-
/**
|
|
357
|
-
* Time Complexity: O(1)
|
|
358
|
-
* Space Complexity: O(1)
|
|
359
|
-
*/
|
|
360
304
|
/**
|
|
361
305
|
* Time Complexity: O(1)
|
|
362
306
|
* Space Complexity: O(1)
|
|
@@ -368,10 +312,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
368
312
|
getEdgeSrc(e) {
|
|
369
313
|
return this._getVertex(e.src);
|
|
370
314
|
}
|
|
371
|
-
/**
|
|
372
|
-
* Time Complexity: O(1)
|
|
373
|
-
* Space Complexity: O(1)
|
|
374
|
-
*/
|
|
375
315
|
/**
|
|
376
316
|
* Time Complexity: O(1)
|
|
377
317
|
* Space Complexity: O(1)
|
|
@@ -383,10 +323,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
383
323
|
getEdgeDest(e) {
|
|
384
324
|
return this._getVertex(e.dest);
|
|
385
325
|
}
|
|
386
|
-
/**
|
|
387
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
388
|
-
* Space Complexity: O(1)
|
|
389
|
-
*/
|
|
390
326
|
/**
|
|
391
327
|
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
392
328
|
* Space Complexity: O(1)
|
|
@@ -410,10 +346,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
410
346
|
}
|
|
411
347
|
return destinations;
|
|
412
348
|
}
|
|
413
|
-
/**
|
|
414
|
-
* Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
|
|
415
|
-
* Space Complexity: O(|V|)
|
|
416
|
-
*/
|
|
417
349
|
/**
|
|
418
350
|
* Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
|
|
419
351
|
* Space Complexity: O(|V|)
|
|
@@ -461,10 +393,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
461
393
|
sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
|
|
462
394
|
return sorted.reverse();
|
|
463
395
|
}
|
|
464
|
-
/**
|
|
465
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
466
|
-
* Space Complexity: O(|E|)
|
|
467
|
-
*/
|
|
468
396
|
/**
|
|
469
397
|
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
470
398
|
* Space Complexity: O(|E|)
|
|
@@ -479,10 +407,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
479
407
|
});
|
|
480
408
|
return edgeMap;
|
|
481
409
|
}
|
|
482
|
-
/**
|
|
483
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
484
|
-
* Space Complexity: O(1)
|
|
485
|
-
*/
|
|
486
410
|
/**
|
|
487
411
|
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
488
412
|
* Space Complexity: O(1)
|
|
@@ -507,10 +431,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
507
431
|
}
|
|
508
432
|
return neighbors;
|
|
509
433
|
}
|
|
510
|
-
/**
|
|
511
|
-
* Time Complexity: O(1)
|
|
512
|
-
* Space Complexity: O(1)
|
|
513
|
-
*/
|
|
514
434
|
/**
|
|
515
435
|
* Time Complexity: O(1)
|
|
516
436
|
* Space Complexity: O(1)
|
|
@@ -542,10 +462,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
542
462
|
isEmpty() {
|
|
543
463
|
return this.vertexMap.size === 0 && this.inEdgeMap.size === 0 && this.outEdgeMap.size === 0;
|
|
544
464
|
}
|
|
545
|
-
/**
|
|
546
|
-
* Time Complexity: O(1)
|
|
547
|
-
* Space Complexity: O(1)
|
|
548
|
-
*/
|
|
549
465
|
/**
|
|
550
466
|
* Time Complexity: O(1)
|
|
551
467
|
* Space Complexity: O(1)
|
|
@@ -569,12 +485,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
569
485
|
cloned.outEdgeMap = new Map(this.outEdgeMap);
|
|
570
486
|
return cloned;
|
|
571
487
|
}
|
|
572
|
-
/**
|
|
573
|
-
* Time Complexity: O(V + E)
|
|
574
|
-
* Space Complexity: O(V)
|
|
575
|
-
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
576
|
-
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
577
|
-
*/
|
|
578
488
|
/**
|
|
579
489
|
* Time Complexity: O(V + E)
|
|
580
490
|
* Space Complexity: O(V)
|
|
@@ -627,10 +537,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
627
537
|
}
|
|
628
538
|
return { dfnMap, lowMap, SCCs };
|
|
629
539
|
}
|
|
630
|
-
/**
|
|
631
|
-
* Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
|
|
632
|
-
* Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
|
|
633
|
-
*/
|
|
634
540
|
/**
|
|
635
541
|
* Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
|
|
636
542
|
* Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
|
|
@@ -659,10 +565,6 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
659
565
|
getSCCs() {
|
|
660
566
|
return this.tarjan().SCCs;
|
|
661
567
|
}
|
|
662
|
-
/**
|
|
663
|
-
* Time Complexity: O(1)
|
|
664
|
-
* Space Complexity: O(1)
|
|
665
|
-
*/
|
|
666
568
|
/**
|
|
667
569
|
* Time Complexity: O(1)
|
|
668
570
|
* Space Complexity: O(1)
|
|
@@ -61,10 +61,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
61
61
|
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `EO`.
|
|
62
62
|
*/
|
|
63
63
|
createEdge(v1: VertexKey, v2: VertexKey, weight?: number, value?: EO['value']): EO;
|
|
64
|
-
/**
|
|
65
|
-
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
66
|
-
* Space Complexity: O(1)
|
|
67
|
-
*/
|
|
68
64
|
/**
|
|
69
65
|
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
70
66
|
* Space Complexity: O(1)
|
|
@@ -77,10 +73,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
77
73
|
* @returns an edge (EO) or undefined.
|
|
78
74
|
*/
|
|
79
75
|
getEdge(v1: VO | VertexKey | undefined, v2: VO | VertexKey | undefined): EO | undefined;
|
|
80
|
-
/**
|
|
81
|
-
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
82
|
-
* Space Complexity: O(1)
|
|
83
|
-
*/
|
|
84
76
|
/**
|
|
85
77
|
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
86
78
|
* Space Complexity: O(1)
|
|
@@ -92,10 +84,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
92
84
|
* @returns the removed edge (EO) if it exists, or undefined if either of the endpoints (VO) does not exist.
|
|
93
85
|
*/
|
|
94
86
|
deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | undefined;
|
|
95
|
-
/**
|
|
96
|
-
* Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
|
|
97
|
-
* Space Complexity: O(1)
|
|
98
|
-
*/
|
|
99
87
|
/**
|
|
100
88
|
* Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
|
|
101
89
|
* Space Complexity: O(1)
|
|
@@ -110,10 +98,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
110
98
|
* @returns The `deleteEdge` function returns either the deleted edge object (EO) or `undefined`.
|
|
111
99
|
*/
|
|
112
100
|
deleteEdge(edgeOrOneSideVertexKey: EO | VertexKey, otherSideVertexKey?: VertexKey): EO | undefined;
|
|
113
|
-
/**
|
|
114
|
-
* Time Complexity: O(1) - Constant time for Map operations.
|
|
115
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
116
|
-
*/
|
|
117
101
|
/**
|
|
118
102
|
* Time Complexity: O(1) - Constant time for Map operations.
|
|
119
103
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -124,10 +108,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
124
108
|
* @returns The method is returning a boolean value.
|
|
125
109
|
*/
|
|
126
110
|
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
127
|
-
/**
|
|
128
|
-
* Time Complexity: O(1)
|
|
129
|
-
* Space Complexity: O(1)
|
|
130
|
-
*/
|
|
131
111
|
/**
|
|
132
112
|
* Time Complexity: O(1)
|
|
133
113
|
* Space Complexity: O(1)
|
|
@@ -139,10 +119,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
139
119
|
* edgeMap connected to that vertex.
|
|
140
120
|
*/
|
|
141
121
|
degreeOf(vertexOrKey: VertexKey | VO): number;
|
|
142
|
-
/**
|
|
143
|
-
* Time Complexity: O(1)
|
|
144
|
-
* Space Complexity: O(1)
|
|
145
|
-
*/
|
|
146
122
|
/**
|
|
147
123
|
* Time Complexity: O(1)
|
|
148
124
|
* Space Complexity: O(1)
|
|
@@ -153,10 +129,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
153
129
|
* @returns an array of edgeMap.
|
|
154
130
|
*/
|
|
155
131
|
edgesOf(vertexOrKey: VertexKey | VO): EO[];
|
|
156
|
-
/**
|
|
157
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
158
|
-
* Space Complexity: O(|E|)
|
|
159
|
-
*/
|
|
160
132
|
/**
|
|
161
133
|
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
162
134
|
* Space Complexity: O(|E|)
|
|
@@ -165,10 +137,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
165
137
|
* @returns The method `edgeSet()` returns an array of type `EO[]`.
|
|
166
138
|
*/
|
|
167
139
|
edgeSet(): EO[];
|
|
168
|
-
/**
|
|
169
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
170
|
-
* Space Complexity: O(|E|)
|
|
171
|
-
*/
|
|
172
140
|
/**
|
|
173
141
|
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
174
142
|
* Space Complexity: O(|E|)
|
|
@@ -179,10 +147,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
179
147
|
* @returns an array of vertexMap (VO[]).
|
|
180
148
|
*/
|
|
181
149
|
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
182
|
-
/**
|
|
183
|
-
* Time Complexity: O(1)
|
|
184
|
-
* Space Complexity: O(1)
|
|
185
|
-
*/
|
|
186
150
|
/**
|
|
187
151
|
* Time Complexity: O(1)
|
|
188
152
|
* Space Complexity: O(1)
|
|
@@ -199,10 +163,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
199
163
|
* @return True if the graph is empty and false otherwise
|
|
200
164
|
*/
|
|
201
165
|
isEmpty(): boolean;
|
|
202
|
-
/**
|
|
203
|
-
* Time Complexity: O(1)
|
|
204
|
-
* Space Complexity: O(1)
|
|
205
|
-
*/
|
|
206
166
|
/**
|
|
207
167
|
* Time Complexity: O(1)
|
|
208
168
|
* Space Complexity: O(1)
|
|
@@ -220,10 +180,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
220
180
|
* @return A new instance of the undirectedgraph class
|
|
221
181
|
*/
|
|
222
182
|
clone(): UndirectedGraph<V, E, VO, EO>;
|
|
223
|
-
/**
|
|
224
|
-
* Time Complexity: O(1)
|
|
225
|
-
* Space Complexity: O(1)
|
|
226
|
-
*/
|
|
227
183
|
/**
|
|
228
184
|
* Time Complexity: O(V + E)
|
|
229
185
|
* Space Complexity: O(V)
|
|
@@ -240,12 +196,6 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
240
196
|
bridges: EO[];
|
|
241
197
|
cutVertices: VO[];
|
|
242
198
|
};
|
|
243
|
-
/**
|
|
244
|
-
* Time Complexity: O(V + E)
|
|
245
|
-
* Space Complexity: O(V)
|
|
246
|
-
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
247
|
-
* 1. Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time
|
|
248
|
-
*/
|
|
249
199
|
/**
|
|
250
200
|
* The function "getBridges" returns an array of bridges in a graph using the Tarjan's algorithm.
|
|
251
201
|
* @returns The function `getBridges()` is returning the bridges found using the Tarjan's algorithm.
|