directed-graph-typed 2.0.5 → 2.1.0
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 +186 -83
- package/dist/data-structures/base/iterable-element-base.js +149 -107
- package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/data-structures/base/linear-base.d.ts +250 -192
- package/dist/data-structures/base/linear-base.js +137 -274
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/data-structures/binary-tree/avl-tree.js +208 -195
- package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/data-structures/binary-tree/binary-tree.js +598 -869
- package/dist/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/data-structures/binary-tree/bst.js +505 -481
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
- package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/data-structures/binary-tree/tree-counter.js +172 -203
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/data-structures/graph/abstract-graph.js +267 -237
- package/dist/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/data-structures/graph/directed-graph.js +146 -233
- package/dist/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/data-structures/graph/map-graph.js +56 -59
- package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/data-structures/graph/undirected-graph.js +129 -149
- package/dist/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/data-structures/hash/hash-map.js +270 -457
- package/dist/data-structures/heap/heap.d.ts +214 -289
- package/dist/data-structures/heap/heap.js +340 -349
- package/dist/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/data-structures/heap/max-heap.js +11 -66
- package/dist/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/data-structures/heap/min-heap.js +11 -66
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/data-structures/queue/deque.d.ts +227 -254
- package/dist/data-structures/queue/deque.js +309 -348
- package/dist/data-structures/queue/queue.d.ts +180 -201
- package/dist/data-structures/queue/queue.js +265 -248
- package/dist/data-structures/stack/stack.d.ts +124 -102
- package/dist/data-structures/stack/stack.js +181 -125
- package/dist/data-structures/trie/trie.d.ts +164 -165
- package/dist/data-structures/trie/trie.js +189 -172
- package/dist/interfaces/binary-tree.d.ts +56 -6
- package/dist/interfaces/graph.d.ts +16 -0
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +2 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +238 -115
- package/src/data-structures/base/iterable-entry-base.ts +96 -120
- package/src/data-structures/base/linear-base.ts +271 -277
- package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
- package/src/data-structures/binary-tree/avl-tree.ts +239 -206
- package/src/data-structures/binary-tree/binary-tree.ts +664 -893
- package/src/data-structures/binary-tree/bst.ts +568 -570
- package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
- package/src/data-structures/binary-tree/tree-counter.ts +199 -218
- package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
- package/src/data-structures/graph/abstract-graph.ts +339 -264
- package/src/data-structures/graph/directed-graph.ts +146 -236
- package/src/data-structures/graph/map-graph.ts +63 -60
- package/src/data-structures/graph/undirected-graph.ts +129 -152
- package/src/data-structures/hash/hash-map.ts +274 -496
- package/src/data-structures/heap/heap.ts +389 -402
- package/src/data-structures/heap/max-heap.ts +12 -76
- package/src/data-structures/heap/min-heap.ts +13 -76
- package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
- package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
- package/src/data-structures/priority-queue/priority-queue.ts +3 -92
- package/src/data-structures/queue/deque.ts +381 -357
- package/src/data-structures/queue/queue.ts +310 -264
- package/src/data-structures/stack/stack.ts +217 -131
- package/src/data-structures/trie/trie.ts +240 -175
- package/src/interfaces/binary-tree.ts +240 -6
- package/src/interfaces/graph.ts +37 -0
- package/src/types/data-structures/base/base.ts +5 -5
- package/src/types/data-structures/graph/abstract-graph.ts +5 -0
- package/src/types/utils/utils.ts +2 -0
- package/src/utils/utils.ts +9 -14
|
@@ -5,43 +5,33 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { VertexKey } from '../../types';
|
|
8
|
+
import type { GraphOptions, VertexKey } from '../../types';
|
|
9
9
|
import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
|
|
10
10
|
import { IGraph } from '../../interfaces';
|
|
11
11
|
export declare class DirectedVertex<V = any> extends AbstractVertex<V> {
|
|
12
|
-
/**
|
|
13
|
-
* The constructor function initializes a vertex with an optional value.
|
|
14
|
-
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
15
|
-
* used to uniquely identify the vertex within a graph or data structure.
|
|
16
|
-
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
17
|
-
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
18
|
-
*/
|
|
19
12
|
constructor(key: VertexKey, value?: V);
|
|
20
13
|
}
|
|
21
14
|
export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
|
|
22
15
|
src: VertexKey;
|
|
23
16
|
dest: VertexKey;
|
|
24
|
-
/**
|
|
25
|
-
* The constructor function initializes the source and destination vertexMap of an edge, along with an optional weight
|
|
26
|
-
* and value.
|
|
27
|
-
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
28
|
-
* a graph.
|
|
29
|
-
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
30
|
-
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
|
|
31
|
-
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
32
|
-
* @param {E} [value] - The `value` parameter is an optional parameter of type `E`. It represents the value associated with
|
|
33
|
-
* the edge.
|
|
34
|
-
*/
|
|
35
17
|
constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
|
|
36
18
|
}
|
|
37
19
|
/**
|
|
38
|
-
*
|
|
20
|
+
* Directed graph implementation.
|
|
21
|
+
* @template V - Vertex value type.
|
|
22
|
+
* @template E - Edge value type.
|
|
23
|
+
* @template VO - Concrete vertex class (extends AbstractVertex<V>).
|
|
24
|
+
* @template EO - Concrete edge class (extends AbstractEdge<E>).
|
|
25
|
+
* @remarks Time O(1), Space O(1)
|
|
26
|
+
* @example examples will be generated by unit test
|
|
39
27
|
*/
|
|
40
28
|
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> {
|
|
41
29
|
/**
|
|
42
|
-
*
|
|
30
|
+
* Construct a directed graph with runtime defaults.
|
|
31
|
+
* @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
|
|
32
|
+
* @remarks Time O(1), Space O(1)
|
|
43
33
|
*/
|
|
44
|
-
constructor();
|
|
34
|
+
constructor(options?: Partial<GraphOptions<V>>);
|
|
45
35
|
protected _outEdgeMap: Map<VO, EO[]>;
|
|
46
36
|
get outEdgeMap(): Map<VO, EO[]>;
|
|
47
37
|
set outEdgeMap(v: Map<VO, EO[]>);
|
|
@@ -49,238 +39,140 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
49
39
|
get inEdgeMap(): Map<VO, EO[]>;
|
|
50
40
|
set inEdgeMap(v: Map<VO, EO[]>);
|
|
51
41
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
42
|
+
* Construct a directed graph from keys with value initializer `v => v`.
|
|
43
|
+
* @template K - Vertex key type.
|
|
44
|
+
* @param keys - Iterable of vertex keys.
|
|
45
|
+
* @returns DirectedGraph with all keys added.
|
|
46
|
+
* @remarks Time O(V), Space O(V)
|
|
47
|
+
*/
|
|
48
|
+
static fromKeys<K extends VertexKey>(keys: Iterable<K>): DirectedGraph<K, any, DirectedVertex<K>, DirectedEdge<any>>;
|
|
49
|
+
/**
|
|
50
|
+
* Construct a directed graph from `[key, value]` entries.
|
|
51
|
+
* @template V - Vertex value type.
|
|
52
|
+
* @param entries - Iterable of `[key, value]` pairs.
|
|
53
|
+
* @returns DirectedGraph with all vertices added.
|
|
54
|
+
* @remarks Time O(V), Space O(V)
|
|
59
55
|
*/
|
|
60
|
-
|
|
56
|
+
static fromEntries<V>(entries: Iterable<[VertexKey, V]>): DirectedGraph<V, any, DirectedVertex<V>, DirectedEdge<any>>;
|
|
61
57
|
/**
|
|
62
|
-
*
|
|
63
|
-
* @param
|
|
64
|
-
* @param
|
|
65
|
-
* @
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
* Create a directed vertex instance. Does not insert into the graph.
|
|
59
|
+
* @param key - Vertex identifier.
|
|
60
|
+
* @param value - Optional payload.
|
|
61
|
+
* @returns Concrete vertex instance.
|
|
62
|
+
* @remarks Time O(1), Space O(1)
|
|
63
|
+
*/
|
|
64
|
+
createVertex(key: VertexKey, value?: VO['value']): VO;
|
|
65
|
+
/**
|
|
66
|
+
* Create a directed edge instance. Does not insert into the graph.
|
|
67
|
+
* @param src - Source vertex key.
|
|
68
|
+
* @param dest - Destination vertex key.
|
|
69
|
+
* @param weight - Edge weight; defaults to `defaultEdgeWeight`.
|
|
70
|
+
* @param value - Edge payload.
|
|
71
|
+
* @returns Concrete edge instance.
|
|
72
|
+
* @remarks Time O(1), Space O(1)
|
|
70
73
|
*/
|
|
71
74
|
createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
|
|
72
75
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @
|
|
78
|
-
* @param {VO | VertexKey | undefined} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
79
|
-
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `undefined` if the
|
|
80
|
-
* destination is not specified.
|
|
81
|
-
* @returns the first edge found between the source and destination vertexMap, or undefined if no such edge is found.
|
|
76
|
+
* Get the unique edge from `src` to `dest`, if present.
|
|
77
|
+
* @param srcOrKey - Source vertex or key.
|
|
78
|
+
* @param destOrKey - Destination vertex or key.
|
|
79
|
+
* @returns Edge instance or `undefined`.
|
|
80
|
+
* @remarks Time O(1) avg, Space O(1)
|
|
82
81
|
*/
|
|
83
82
|
getEdge(srcOrKey: VO | VertexKey | undefined, destOrKey: VO | VertexKey | undefined): EO | undefined;
|
|
84
83
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @
|
|
90
|
-
* @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
91
|
-
* @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
|
|
84
|
+
* Delete edge `src -> dest` if present.
|
|
85
|
+
* @param srcOrKey - Source vertex or key.
|
|
86
|
+
* @param destOrKey - Destination vertex or key.
|
|
87
|
+
* @returns Removed edge or `undefined`.
|
|
88
|
+
* @remarks Time O(1) avg, Space O(1)
|
|
92
89
|
*/
|
|
93
90
|
deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
|
|
94
91
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @
|
|
100
|
-
* a `VertexKey` (key of a vertex).
|
|
101
|
-
* @param {VertexKey} [destVertexKey] - The `destVertexKey` parameter is an optional parameter that
|
|
102
|
-
* represents the key of the destination vertex of the edge. It is used to specify the destination
|
|
103
|
-
* vertex when the `edge` parameter is a vertex key. If `destVertexKey` is not provided, the function
|
|
104
|
-
* assumes that the `edge`
|
|
105
|
-
* @returns the removed edge (EO) or undefined if no edge was removed.
|
|
92
|
+
* Delete an edge by instance or by `(srcKey, destKey)`.
|
|
93
|
+
* @param edgeOrSrcVertexKey - Edge instance or source vertex/key.
|
|
94
|
+
* @param destVertexKey - Optional destination vertex/key when deleting by pair.
|
|
95
|
+
* @returns Removed edge or `undefined`.
|
|
96
|
+
* @remarks Time O(1) avg, Space O(1)
|
|
106
97
|
*/
|
|
107
98
|
deleteEdge(edgeOrSrcVertexKey: EO | VertexKey, destVertexKey?: VertexKey): EO | undefined;
|
|
108
|
-
/**
|
|
109
|
-
* Time Complexity: O(1) - Constant time for Map operations.
|
|
110
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
111
|
-
*
|
|
112
|
-
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
113
|
-
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
114
|
-
* (`VertexKey`).
|
|
115
|
-
* @returns The method is returning a boolean value.
|
|
116
|
-
*/
|
|
117
99
|
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
118
|
-
/**
|
|
119
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
120
|
-
* Space Complexity: O(1)
|
|
121
|
-
*
|
|
122
|
-
* The function removes edgeMap between two vertexMap and returns the removed edgeMap.
|
|
123
|
-
* @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
|
|
124
|
-
* unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
|
|
125
|
-
* @param {VertexKey | VO} v2 - The parameter `v2` represents either a `VertexKey` or a `VO` object. It is used to specify
|
|
126
|
-
* the second vertex in the edge that needs to be removed.
|
|
127
|
-
* @returns an array of removed edgeMap (EO[]).
|
|
128
|
-
*/
|
|
129
100
|
deleteEdgesBetween(v1: VertexKey | VO, v2: VertexKey | VO): EO[];
|
|
130
101
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
136
|
-
* (`VertexKey`).
|
|
137
|
-
* @returns The method `incomingEdgesOf` returns an array of edgeMap (`EO[]`).
|
|
102
|
+
* Incoming edges of a vertex.
|
|
103
|
+
* @param vertexOrKey - Vertex or key.
|
|
104
|
+
* @returns Array of incoming edges.
|
|
105
|
+
* @remarks Time O(deg_in), Space O(deg_in)
|
|
138
106
|
*/
|
|
139
107
|
incomingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
140
108
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
|
|
146
|
-
* (`VertexKey`).
|
|
147
|
-
* @returns The method `outgoingEdgesOf` returns an array of edgeMap (`EO[]`).
|
|
109
|
+
* Outgoing edges of a vertex.
|
|
110
|
+
* @param vertexOrKey - Vertex or key.
|
|
111
|
+
* @returns Array of outgoing edges.
|
|
112
|
+
* @remarks Time O(deg_out), Space O(deg_out)
|
|
148
113
|
*/
|
|
149
114
|
outgoingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
150
115
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
156
|
-
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
116
|
+
* Degree (in + out) of a vertex.
|
|
117
|
+
* @param vertexOrKey - Vertex or key.
|
|
118
|
+
* @returns Non-negative integer.
|
|
119
|
+
* @remarks Time O(1) avg, Space O(1)
|
|
157
120
|
*/
|
|
158
121
|
degreeOf(vertexOrKey: VertexKey | VO): number;
|
|
159
|
-
/**
|
|
160
|
-
* Time Complexity: O(1)
|
|
161
|
-
* Space Complexity: O(1)
|
|
162
|
-
*
|
|
163
|
-
* The function "inDegreeOf" returns the number of incoming edgeMap for a given vertex.
|
|
164
|
-
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
165
|
-
* @returns The number of incoming edgeMap of the specified vertex or vertex ID.
|
|
166
|
-
*/
|
|
167
122
|
inDegreeOf(vertexOrKey: VertexKey | VO): number;
|
|
168
|
-
/**
|
|
169
|
-
* Time Complexity: O(1)
|
|
170
|
-
* Space Complexity: O(1)
|
|
171
|
-
*
|
|
172
|
-
* The function `outDegreeOf` returns the number of outgoing edgeMap from a given vertex.
|
|
173
|
-
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
174
|
-
* @returns The number of outgoing edgeMap from the specified vertex or vertex ID.
|
|
175
|
-
*/
|
|
176
123
|
outDegreeOf(vertexOrKey: VertexKey | VO): number;
|
|
177
124
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
183
|
-
* @returns The function `edgesOf` returns an array of edgeMap.
|
|
125
|
+
* All incident edges of a vertex.
|
|
126
|
+
* @param vertexOrKey - Vertex or key.
|
|
127
|
+
* @returns Array of incident edges.
|
|
128
|
+
* @remarks Time O(deg_in + deg_out), Space O(deg_in + deg_out)
|
|
184
129
|
*/
|
|
185
130
|
edgesOf(vertexOrKey: VertexKey | VO): EO[];
|
|
186
|
-
/**
|
|
187
|
-
* Time Complexity: O(1)
|
|
188
|
-
* Space Complexity: O(1)
|
|
189
|
-
*
|
|
190
|
-
* The function "getEdgeSrc" returns the source vertex of an edge, or undefined if the edge does not exist.
|
|
191
|
-
* @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
|
|
192
|
-
* @returns either a vertex object (VO) or undefined.
|
|
193
|
-
*/
|
|
194
131
|
getEdgeSrc(e: EO): VO | undefined;
|
|
195
|
-
/**
|
|
196
|
-
* Time Complexity: O(1)
|
|
197
|
-
* Space Complexity: O(1)
|
|
198
|
-
*
|
|
199
|
-
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
200
|
-
* @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
|
|
201
|
-
* @returns either a vertex object of type VO or undefined.
|
|
202
|
-
*/
|
|
203
132
|
getEdgeDest(e: EO): VO | undefined;
|
|
204
133
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* @param {VO | VertexKey | undefined} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
210
|
-
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `undefined`.
|
|
211
|
-
* @returns an array of vertexMap (VO[]).
|
|
134
|
+
* Direct children reachable by one outgoing edge.
|
|
135
|
+
* @param vertex - Vertex or key.
|
|
136
|
+
* @returns Array of neighbor vertices.
|
|
137
|
+
* @remarks Time O(deg_out), Space O(deg_out)
|
|
212
138
|
*/
|
|
213
139
|
getDestinations(vertex: VO | VertexKey | undefined): VO[];
|
|
214
140
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* in the sorted order, or undefined if the graph contains a cycle.
|
|
220
|
-
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
221
|
-
* property to use for sorting the vertexMap. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
|
|
222
|
-
* specified, the vertexMap themselves will be used for sorting. If 'key' is specified, the ids of
|
|
223
|
-
* @returns an array of vertexMap or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
|
|
141
|
+
* Topological sort if DAG; returns `undefined` if a cycle exists.
|
|
142
|
+
* @param propertyName - `'key'` to map to keys; `'vertex'` to keep instances.
|
|
143
|
+
* @returns Array of keys/vertices, or `undefined` when cycle is found.
|
|
144
|
+
* @remarks Time O(V + E), Space O(V)
|
|
224
145
|
*/
|
|
225
146
|
topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | undefined;
|
|
226
|
-
/**
|
|
227
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
228
|
-
* Space Complexity: O(|E|)
|
|
229
|
-
*
|
|
230
|
-
* The `edgeSet` function returns an array of all the edgeMap in the graph.
|
|
231
|
-
* @returns The `edgeSet()` method returns an array of edgeMap (`EO[]`).
|
|
232
|
-
*/
|
|
233
147
|
edgeSet(): EO[];
|
|
234
|
-
/**
|
|
235
|
-
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
236
|
-
* Space Complexity: O(1)
|
|
237
|
-
*
|
|
238
|
-
* The function `getNeighbors` returns an array of neighboring vertexMap of a given vertex or vertex ID in a graph.
|
|
239
|
-
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
240
|
-
* (`VertexKey`).
|
|
241
|
-
* @returns an array of vertexMap (VO[]).
|
|
242
|
-
*/
|
|
243
148
|
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
244
149
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
* otherwise it returns undefined.
|
|
250
|
-
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
|
|
251
|
-
* @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
|
|
252
|
-
* graph. If the edge does not exist, it returns `undefined`.
|
|
150
|
+
* Resolve an edge's `[src, dest]` endpoints to vertex instances.
|
|
151
|
+
* @param edge - Edge instance.
|
|
152
|
+
* @returns `[src, dest]` or `undefined` if either endpoint is missing.
|
|
153
|
+
* @remarks Time O(1), Space O(1)
|
|
253
154
|
*/
|
|
254
155
|
getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
255
156
|
/**
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* @return A boolean value
|
|
157
|
+
* Whether the graph has no vertices and no edges.
|
|
158
|
+
* @remarks Time O(1), Space O(1)
|
|
259
159
|
*/
|
|
260
160
|
isEmpty(): boolean;
|
|
261
161
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* The clear function resets the vertex map, in-edge map, and out-edge map.
|
|
162
|
+
* Remove all vertices and edges.
|
|
163
|
+
* @remarks Time O(V + E), Space O(1)
|
|
266
164
|
*/
|
|
267
165
|
clear(): void;
|
|
268
166
|
/**
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
* @
|
|
167
|
+
* Deep clone as the same concrete class.
|
|
168
|
+
* @returns A new graph of the same concrete class (`this` type).
|
|
169
|
+
* @remarks Time O(V + E), Space O(V + E)
|
|
272
170
|
*/
|
|
273
|
-
clone():
|
|
171
|
+
clone(): this;
|
|
274
172
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
279
|
-
*
|
|
280
|
-
* The function `tarjan` implements the Tarjan's algorithm to find strongly connected components in a
|
|
281
|
-
* graph.
|
|
282
|
-
* @returns The function `tarjan()` returns an object with three properties: `dfnMap`, `lowMap`, and
|
|
283
|
-
* `SCCs`.
|
|
173
|
+
* Tarjan's algorithm for strongly connected components.
|
|
174
|
+
* @returns `{ dfnMap, lowMap, SCCs }`.
|
|
175
|
+
* @remarks Time O(V + E), Space O(V + E)
|
|
284
176
|
*/
|
|
285
177
|
tarjan(): {
|
|
286
178
|
dfnMap: Map<VO, number>;
|
|
@@ -288,36 +180,28 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
288
180
|
SCCs: Map<number, VO[]>;
|
|
289
181
|
};
|
|
290
182
|
/**
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* The function returns a map that associates each vertex object with its corresponding depth-first
|
|
295
|
-
* number.
|
|
296
|
-
* @returns A Map object with keys of type VO and values of type number.
|
|
183
|
+
* DFN index map computed by `tarjan()`.
|
|
184
|
+
* @returns Map from vertex to DFN index.
|
|
185
|
+
* @remarks Time O(V), Space O(V)
|
|
297
186
|
*/
|
|
298
187
|
getDFNMap(): Map<VO, number>;
|
|
299
188
|
/**
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* @
|
|
303
|
-
* type `number`.
|
|
189
|
+
* LOW link map computed by `tarjan()`.
|
|
190
|
+
* @returns Map from vertex to LOW value.
|
|
191
|
+
* @remarks Time O(V), Space O(V)
|
|
304
192
|
*/
|
|
305
193
|
getLowMap(): Map<VO, number>;
|
|
306
194
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* @
|
|
195
|
+
* Strongly connected components computed by `tarjan()`.
|
|
196
|
+
* @returns Map from SCC id to vertices.
|
|
197
|
+
* @remarks Time O(#SCC + V), Space O(V)
|
|
310
198
|
*/
|
|
311
199
|
getSCCs(): Map<number, VO[]>;
|
|
312
200
|
/**
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
318
|
-
* needs to be added to the graph.
|
|
319
|
-
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
320
|
-
* source or destination vertex does not exist in the graph.
|
|
201
|
+
* Internal hook to attach a directed edge into adjacency maps.
|
|
202
|
+
* @param edge - Edge instance.
|
|
203
|
+
* @returns `true` if inserted; otherwise `false`.
|
|
204
|
+
* @remarks Time O(1) avg, Space O(1)
|
|
321
205
|
*/
|
|
322
206
|
protected _addEdge(edge: EO): boolean;
|
|
323
207
|
}
|