data-structure-typed 1.34.7 → 1.34.9
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/.eslintrc.js +1 -0
- package/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +0 -0
- package/README.md +8 -8
- package/dist/data-structures/binary-tree/aa-tree.js +2 -5
- package/dist/data-structures/binary-tree/aa-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +314 -457
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.js +64 -90
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.js +2 -5
- package/dist/data-structures/binary-tree/b-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +12 -31
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.js +157 -244
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/rb-tree.js +20 -44
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/segment-tree.js +80 -122
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.js +2 -5
- package/dist/data-structures/binary-tree/splay-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.js +168 -239
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
- package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -1
- package/dist/data-structures/graph/abstract-graph.js +351 -585
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.js +152 -282
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/map-graph.js +47 -88
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.js +91 -180
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.js +23 -45
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.js +20 -42
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.js +85 -247
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.js +87 -128
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/pair.js +2 -5
- package/dist/data-structures/hash/pair.js.map +1 -1
- package/dist/data-structures/hash/tree-map.js +2 -5
- package/dist/data-structures/hash/tree-map.js.map +1 -1
- package/dist/data-structures/hash/tree-set.js +2 -5
- package/dist/data-structures/hash/tree-set.js.map +1 -1
- package/dist/data-structures/heap/heap.js +56 -80
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/max-heap.js +8 -26
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.js +8 -26
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +149 -218
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +119 -218
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.js +50 -70
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/matrix.js +7 -8
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.js +57 -70
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.js +18 -37
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.js +63 -84
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js +13 -41
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +13 -41
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +93 -139
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.js +82 -128
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/queue.js +57 -157
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/stack.js +21 -22
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/tree.js +33 -46
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/trie.js +93 -200
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/utils/utils.js +22 -107
- package/dist/utils/utils.js.map +1 -1
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +124 -123
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +136 -216
- package/lib/data-structures/binary-tree/avl-tree.d.ts +19 -10
- package/lib/data-structures/binary-tree/avl-tree.js +35 -13
- package/lib/data-structures/binary-tree/binary-tree.d.ts +6 -6
- package/lib/data-structures/binary-tree/binary-tree.js +7 -7
- package/lib/data-structures/binary-tree/bst.d.ts +34 -34
- package/lib/data-structures/binary-tree/bst.js +86 -89
- package/lib/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/lib/data-structures/binary-tree/rb-tree.js +4 -4
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +40 -42
- package/lib/data-structures/binary-tree/tree-multiset.js +76 -86
- package/lib/data-structures/graph/abstract-graph.d.ts +62 -62
- package/lib/data-structures/graph/abstract-graph.js +86 -86
- package/lib/data-structures/graph/directed-graph.d.ts +51 -51
- package/lib/data-structures/graph/directed-graph.js +63 -63
- package/lib/data-structures/graph/map-graph.d.ts +13 -13
- package/lib/data-structures/graph/map-graph.js +12 -12
- package/lib/data-structures/graph/undirected-graph.d.ts +30 -30
- package/lib/data-structures/graph/undirected-graph.js +32 -32
- package/lib/data-structures/priority-queue/priority-queue.d.ts +3 -3
- package/lib/data-structures/priority-queue/priority-queue.js +3 -3
- package/lib/data-structures/tree/tree.d.ts +4 -4
- package/lib/data-structures/tree/tree.js +6 -6
- package/lib/interfaces/abstract-binary-tree.d.ts +37 -42
- package/lib/interfaces/abstract-graph.d.ts +13 -13
- package/lib/interfaces/avl-tree.d.ts +6 -4
- package/lib/interfaces/bst.d.ts +10 -9
- package/lib/interfaces/directed-graph.d.ts +5 -5
- package/lib/interfaces/rb-tree.d.ts +2 -2
- package/lib/interfaces/undirected-graph.d.ts +2 -2
- package/lib/types/data-structures/abstract-binary-tree.d.ts +3 -3
- package/lib/types/data-structures/abstract-binary-tree.js +0 -1
- package/lib/types/data-structures/abstract-graph.d.ts +2 -2
- package/lib/types/data-structures/bst.d.ts +2 -2
- package/lib/types/data-structures/tree-multiset.d.ts +1 -1
- package/lib/types/utils/validate-type.d.ts +8 -8
- package/package.json +6 -6
- package/scripts/rename_clear_files.sh +29 -0
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +241 -293
- package/src/data-structures/binary-tree/avl-tree.ts +43 -14
- package/src/data-structures/binary-tree/binary-tree.ts +8 -8
- package/src/data-structures/binary-tree/bst.ts +101 -96
- package/src/data-structures/binary-tree/rb-tree.ts +9 -9
- package/src/data-structures/binary-tree/tree-multiset.ts +82 -94
- package/src/data-structures/graph/abstract-graph.ts +114 -109
- package/src/data-structures/graph/directed-graph.ts +77 -77
- package/src/data-structures/graph/map-graph.ts +20 -15
- package/src/data-structures/graph/undirected-graph.ts +39 -39
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/tree/tree.ts +7 -7
- package/src/interfaces/abstract-binary-tree.ts +37 -50
- package/src/interfaces/abstract-graph.ts +13 -13
- package/src/interfaces/avl-tree.ts +6 -4
- package/src/interfaces/bst.ts +9 -9
- package/src/interfaces/directed-graph.ts +5 -5
- package/src/interfaces/rb-tree.ts +2 -2
- package/src/interfaces/undirected-graph.ts +2 -2
- package/src/types/data-structures/abstract-binary-tree.ts +3 -4
- package/src/types/data-structures/abstract-graph.ts +2 -2
- package/src/types/data-structures/bst.ts +2 -2
- package/src/types/data-structures/tree-multiset.ts +1 -1
- package/src/types/utils/validate-type.ts +10 -10
- package/test/integration/avl-tree.test.ts +24 -24
- package/test/integration/bst.test.ts +71 -71
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +28 -28
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +4 -12
- package/test/unit/data-structures/binary-tree/bst.test.ts +79 -79
- package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +80 -80
- package/test/unit/data-structures/graph/directed-graph.test.ts +8 -8
- package/test/unit/data-structures/graph/map-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/overall.test.ts +2 -2
- package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -5
- package/test/unit/data-structures/tree/tree.test.ts +2 -2
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
|
@@ -10,23 +10,23 @@ import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
|
|
|
10
10
|
export class DirectedVertex extends AbstractVertex {
|
|
11
11
|
/**
|
|
12
12
|
* The constructor function initializes a vertex with an optional value.
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
14
14
|
* used to uniquely identify the vertex within a graph or data structure.
|
|
15
15
|
* @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
16
16
|
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
17
17
|
*/
|
|
18
|
-
constructor(
|
|
19
|
-
super(
|
|
18
|
+
constructor(key, val) {
|
|
19
|
+
super(key, val);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
export class DirectedEdge extends AbstractEdge {
|
|
23
23
|
/**
|
|
24
24
|
* The constructor function initializes the source and destination vertices of an edge, along with an optional weight
|
|
25
25
|
* and value.
|
|
26
|
-
* @param {
|
|
26
|
+
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
27
27
|
* a graph.
|
|
28
|
-
* @param {
|
|
29
|
-
* `
|
|
28
|
+
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
29
|
+
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
|
|
30
30
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
31
31
|
* @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value associated with
|
|
32
32
|
* the edge.
|
|
@@ -70,15 +70,15 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
70
70
|
*/
|
|
71
71
|
/**
|
|
72
72
|
* The function creates a new vertex with an optional value and returns it.
|
|
73
|
-
* @param {
|
|
73
|
+
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
74
74
|
* could be a number or a string depending on how you want to identify your vertices.
|
|
75
75
|
* @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
76
76
|
* it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
|
|
77
|
-
* assigned the same value as the '
|
|
77
|
+
* assigned the same value as the 'key' parameter
|
|
78
78
|
* @returns a new instance of a DirectedVertex object, casted as type V.
|
|
79
79
|
*/
|
|
80
|
-
createVertex(
|
|
81
|
-
return new DirectedVertex(
|
|
80
|
+
createVertex(key, val) {
|
|
81
|
+
return new DirectedVertex(key, val !== null && val !== void 0 ? val : key);
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* 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.
|
|
@@ -86,8 +86,8 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
86
86
|
*/
|
|
87
87
|
/**
|
|
88
88
|
* The function creates a directed edge between two vertices with an optional weight and value.
|
|
89
|
-
* @param {
|
|
90
|
-
* @param {
|
|
89
|
+
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
90
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
91
91
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
92
92
|
* weight is provided, it defaults to 1.
|
|
93
93
|
* @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
@@ -99,21 +99,21 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
101
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
102
|
-
* @param {V | null |
|
|
103
|
-
* @param {V | null |
|
|
104
|
-
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`
|
|
102
|
+
* @param {V | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
103
|
+
* @param {V | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
104
|
+
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexKey`), or `null` if the
|
|
105
105
|
* destination is not specified.
|
|
106
106
|
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
107
107
|
*/
|
|
108
|
-
getEdge(
|
|
108
|
+
getEdge(srcOrKey, destOrKey) {
|
|
109
109
|
let edges = [];
|
|
110
|
-
if (
|
|
111
|
-
const src = this._getVertex(
|
|
112
|
-
const dest = this._getVertex(
|
|
110
|
+
if (srcOrKey !== null && destOrKey !== null) {
|
|
111
|
+
const src = this._getVertex(srcOrKey);
|
|
112
|
+
const dest = this._getVertex(destOrKey);
|
|
113
113
|
if (src && dest) {
|
|
114
114
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
115
115
|
if (srcOutEdges) {
|
|
116
|
-
edges = srcOutEdges.filter(edge => edge.dest === dest.
|
|
116
|
+
edges = srcOutEdges.filter(edge => edge.dest === dest.key);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -121,24 +121,24 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
123
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
124
|
-
* @param {V |
|
|
125
|
-
* @param {V |
|
|
124
|
+
* @param {V | VertexKey} srcOrKey - The source vertex or its ID.
|
|
125
|
+
* @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
126
126
|
* @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
|
|
127
127
|
*/
|
|
128
|
-
removeEdgeSrcToDest(
|
|
129
|
-
const src = this._getVertex(
|
|
130
|
-
const dest = this._getVertex(
|
|
128
|
+
removeEdgeSrcToDest(srcOrKey, destOrKey) {
|
|
129
|
+
const src = this._getVertex(srcOrKey);
|
|
130
|
+
const dest = this._getVertex(destOrKey);
|
|
131
131
|
let removed = null;
|
|
132
132
|
if (!src || !dest) {
|
|
133
133
|
return null;
|
|
134
134
|
}
|
|
135
135
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
136
136
|
if (srcOutEdges) {
|
|
137
|
-
arrayRemove(srcOutEdges, (edge) => edge.dest === dest.
|
|
137
|
+
arrayRemove(srcOutEdges, (edge) => edge.dest === dest.key);
|
|
138
138
|
}
|
|
139
139
|
const destInEdges = this._inEdgeMap.get(dest);
|
|
140
140
|
if (destInEdges) {
|
|
141
|
-
removed = arrayRemove(destInEdges, (edge) => edge.src === src.
|
|
141
|
+
removed = arrayRemove(destInEdges, (edge) => edge.src === src.key)[0] || null;
|
|
142
142
|
}
|
|
143
143
|
return removed;
|
|
144
144
|
}
|
|
@@ -155,20 +155,20 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
155
155
|
if (src && dest) {
|
|
156
156
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
157
157
|
if (srcOutEdges && srcOutEdges.length > 0) {
|
|
158
|
-
arrayRemove(srcOutEdges, (edge) => edge.src === src.
|
|
158
|
+
arrayRemove(srcOutEdges, (edge) => edge.src === src.key);
|
|
159
159
|
}
|
|
160
160
|
const destInEdges = this._inEdgeMap.get(dest);
|
|
161
161
|
if (destInEdges && destInEdges.length > 0) {
|
|
162
|
-
removed = arrayRemove(destInEdges, (edge) => edge.dest === dest.
|
|
162
|
+
removed = arrayRemove(destInEdges, (edge) => edge.dest === dest.key)[0];
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
return removed;
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
168
|
* The function removes edges between two vertices and returns the removed edges.
|
|
169
|
-
* @param {
|
|
169
|
+
* @param {VertexKey | V} v1 - The parameter `v1` can be either a `VertexKey` or a `V`. A `VertexKey` represents the
|
|
170
170
|
* unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
|
|
171
|
-
* @param {
|
|
171
|
+
* @param {VertexKey | V} v2 - The parameter `v2` represents either a `VertexKey` or a `V` object. It is used to specify
|
|
172
172
|
* the second vertex in the edge that needs to be removed.
|
|
173
173
|
* @returns an array of removed edges (E[]).
|
|
174
174
|
*/
|
|
@@ -184,12 +184,12 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
186
|
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
187
|
-
* @param {V |
|
|
188
|
-
* (`
|
|
187
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
188
|
+
* (`VertexKey`).
|
|
189
189
|
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
|
|
190
190
|
*/
|
|
191
|
-
incomingEdgesOf(
|
|
192
|
-
const target = this._getVertex(
|
|
191
|
+
incomingEdgesOf(vertexOrKey) {
|
|
192
|
+
const target = this._getVertex(vertexOrKey);
|
|
193
193
|
if (target) {
|
|
194
194
|
return this.inEdgeMap.get(target) || [];
|
|
195
195
|
}
|
|
@@ -197,12 +197,12 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
199
199
|
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
200
|
-
* @param {V |
|
|
201
|
-
* (`
|
|
200
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`V`) or a vertex ID
|
|
201
|
+
* (`VertexKey`).
|
|
202
202
|
* @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
|
|
203
203
|
*/
|
|
204
|
-
outgoingEdgesOf(
|
|
205
|
-
const target = this._getVertex(
|
|
204
|
+
outgoingEdgesOf(vertexOrKey) {
|
|
205
|
+
const target = this._getVertex(vertexOrKey);
|
|
206
206
|
if (target) {
|
|
207
207
|
return this._outEdgeMap.get(target) || [];
|
|
208
208
|
}
|
|
@@ -210,35 +210,35 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
210
210
|
}
|
|
211
211
|
/**
|
|
212
212
|
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
|
|
213
|
-
* @param {
|
|
213
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
214
214
|
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
215
215
|
*/
|
|
216
|
-
degreeOf(
|
|
217
|
-
return this.outDegreeOf(
|
|
216
|
+
degreeOf(vertexOrKey) {
|
|
217
|
+
return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
|
|
218
218
|
}
|
|
219
219
|
/**
|
|
220
220
|
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
|
|
221
|
-
* @param {
|
|
221
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
222
222
|
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
223
223
|
*/
|
|
224
|
-
inDegreeOf(
|
|
225
|
-
return this.incomingEdgesOf(
|
|
224
|
+
inDegreeOf(vertexOrKey) {
|
|
225
|
+
return this.incomingEdgesOf(vertexOrKey).length;
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
228
228
|
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
|
|
229
|
-
* @param {
|
|
229
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
230
230
|
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
231
231
|
*/
|
|
232
|
-
outDegreeOf(
|
|
233
|
-
return this.outgoingEdgesOf(
|
|
232
|
+
outDegreeOf(vertexOrKey) {
|
|
233
|
+
return this.outgoingEdgesOf(vertexOrKey).length;
|
|
234
234
|
}
|
|
235
235
|
/**
|
|
236
236
|
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
|
|
237
|
-
* @param {
|
|
237
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
238
238
|
* @returns The function `edgesOf` returns an array of edges.
|
|
239
239
|
*/
|
|
240
|
-
edgesOf(
|
|
241
|
-
return [...this.outgoingEdgesOf(
|
|
240
|
+
edgesOf(vertexOrKey) {
|
|
241
|
+
return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
|
|
242
242
|
}
|
|
243
243
|
/**
|
|
244
244
|
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
|
|
@@ -258,8 +258,8 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
258
258
|
}
|
|
259
259
|
/**
|
|
260
260
|
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
261
|
-
* @param {V |
|
|
262
|
-
* find the destinations. It can be either a `V` object, a `
|
|
261
|
+
* @param {V | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
262
|
+
* find the destinations. It can be either a `V` object, a `VertexKey` value, or `null`.
|
|
263
263
|
* @returns an array of vertices (V[]).
|
|
264
264
|
*/
|
|
265
265
|
getDestinations(vertex) {
|
|
@@ -279,13 +279,13 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
279
279
|
/**
|
|
280
280
|
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
|
|
281
281
|
* in the sorted order, or null if the graph contains a cycle.
|
|
282
|
-
* @param {'vertex' | '
|
|
283
|
-
* property to use for sorting the vertices. It can have two possible values: 'vertex' or '
|
|
284
|
-
* specified, the vertices themselves will be used for sorting. If '
|
|
282
|
+
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
283
|
+
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
|
|
284
|
+
* specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
|
|
285
285
|
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
|
|
286
286
|
*/
|
|
287
287
|
topologicalSort(propertyName) {
|
|
288
|
-
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : '
|
|
288
|
+
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
289
289
|
// When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
|
|
290
290
|
// When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
|
|
291
291
|
const statusMap = new Map();
|
|
@@ -316,8 +316,8 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
316
316
|
}
|
|
317
317
|
if (hasCycle)
|
|
318
318
|
return null;
|
|
319
|
-
if (propertyName === '
|
|
320
|
-
sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.
|
|
319
|
+
if (propertyName === 'key')
|
|
320
|
+
sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
|
|
321
321
|
return sorted.reverse();
|
|
322
322
|
}
|
|
323
323
|
/**
|
|
@@ -333,13 +333,13 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
333
333
|
}
|
|
334
334
|
/**
|
|
335
335
|
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
|
|
336
|
-
* @param {V |
|
|
337
|
-
* (`
|
|
336
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
337
|
+
* (`VertexKey`).
|
|
338
338
|
* @returns an array of vertices (V[]).
|
|
339
339
|
*/
|
|
340
|
-
getNeighbors(
|
|
340
|
+
getNeighbors(vertexOrKey) {
|
|
341
341
|
const neighbors = [];
|
|
342
|
-
const vertex = this._getVertex(
|
|
342
|
+
const vertex = this._getVertex(vertexOrKey);
|
|
343
343
|
if (vertex) {
|
|
344
344
|
const outEdges = this.outgoingEdgesOf(vertex);
|
|
345
345
|
for (const outEdge of outEdges) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { MapGraphCoordinate,
|
|
1
|
+
import { MapGraphCoordinate, VertexKey } from '../../types';
|
|
2
2
|
import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
|
|
3
3
|
export declare class MapVertex<V = any> extends DirectedVertex<V> {
|
|
4
4
|
/**
|
|
5
|
-
* The constructor function initializes an object with an
|
|
6
|
-
* @param {
|
|
5
|
+
* The constructor function initializes an object with an key, latitude, longitude, and an optional value.
|
|
6
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
|
|
7
7
|
* @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
|
|
8
8
|
* that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
|
|
9
9
|
* values representing points north of the equator and negative values representing points south of the equator.
|
|
@@ -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(
|
|
16
|
+
constructor(key: VertexKey, lat: number, long: number, val?: V);
|
|
17
17
|
private _lat;
|
|
18
18
|
get lat(): number;
|
|
19
19
|
set lat(value: number);
|
|
@@ -25,14 +25,14 @@ export declare class MapEdge<V = any> extends DirectedEdge<V> {
|
|
|
25
25
|
/**
|
|
26
26
|
* The constructor function initializes a new instance of a class with the given source, destination, weight, and
|
|
27
27
|
* value.
|
|
28
|
-
* @param {
|
|
28
|
+
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
29
29
|
* a graph.
|
|
30
|
-
* @param {
|
|
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
32
|
* @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store additional
|
|
33
33
|
* information or data associated with the edge.
|
|
34
34
|
*/
|
|
35
|
-
constructor(src:
|
|
35
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: V);
|
|
36
36
|
}
|
|
37
37
|
export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E extends MapEdge = MapEdge> extends DirectedGraph<V, E> {
|
|
38
38
|
/**
|
|
@@ -52,8 +52,8 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
|
|
|
52
52
|
get bottomRight(): MapGraphCoordinate | undefined;
|
|
53
53
|
set bottomRight(value: MapGraphCoordinate | undefined);
|
|
54
54
|
/**
|
|
55
|
-
* The function creates a new vertex with the given
|
|
56
|
-
* @param {
|
|
55
|
+
* The function creates a new vertex with the given key, value, latitude, and longitude.
|
|
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
59
|
* is of type `V['val']`, which means it should be of the same type as the `val` property of the vertex class `V`.
|
|
@@ -62,11 +62,11 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
|
|
|
62
62
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
63
63
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
|
|
64
64
|
*/
|
|
65
|
-
createVertex(
|
|
65
|
+
createVertex(key: VertexKey, val?: V['val'], lat?: number, long?: number): V;
|
|
66
66
|
/**
|
|
67
67
|
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
68
|
-
* @param {
|
|
69
|
-
* @param {
|
|
68
|
+
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
69
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
|
|
70
70
|
* created.
|
|
71
71
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
72
72
|
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
@@ -75,5 +75,5 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
|
|
|
75
75
|
* depending on the specific implementation of the `MapEdge` class.
|
|
76
76
|
* @returns a new instance of the `MapEdge` class, casted as type `E`.
|
|
77
77
|
*/
|
|
78
|
-
createEdge(src:
|
|
78
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E;
|
|
79
79
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
|
|
2
2
|
export class MapVertex extends DirectedVertex {
|
|
3
3
|
/**
|
|
4
|
-
* The constructor function initializes an object with an
|
|
5
|
-
* @param {
|
|
4
|
+
* The constructor function initializes an object with an key, latitude, longitude, and an optional value.
|
|
5
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
|
|
6
6
|
* @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
|
|
7
7
|
* that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
|
|
8
8
|
* values representing points north of the equator and negative values representing points south of the equator.
|
|
@@ -12,8 +12,8 @@ export class MapVertex extends DirectedVertex {
|
|
|
12
12
|
* @param {V} [val] - The "val" parameter is an optional value of type V. It is not required to be provided when
|
|
13
13
|
* creating an instance of the class.
|
|
14
14
|
*/
|
|
15
|
-
constructor(
|
|
16
|
-
super(
|
|
15
|
+
constructor(key, lat, long, val) {
|
|
16
|
+
super(key, val);
|
|
17
17
|
this._lat = lat;
|
|
18
18
|
this._long = long;
|
|
19
19
|
}
|
|
@@ -34,9 +34,9 @@ export class MapEdge extends DirectedEdge {
|
|
|
34
34
|
/**
|
|
35
35
|
* The constructor function initializes a new instance of a class with the given source, destination, weight, and
|
|
36
36
|
* value.
|
|
37
|
-
* @param {
|
|
37
|
+
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
38
38
|
* a graph.
|
|
39
|
-
* @param {
|
|
39
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
40
40
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
41
41
|
* @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store additional
|
|
42
42
|
* information or data associated with the edge.
|
|
@@ -74,8 +74,8 @@ export class MapGraph extends DirectedGraph {
|
|
|
74
74
|
this._bottomRight = value;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
* The function creates a new vertex with the given
|
|
78
|
-
* @param {
|
|
77
|
+
* The function creates a new vertex with the given key, value, latitude, and longitude.
|
|
78
|
+
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
|
|
79
79
|
* be a string or a number depending on how you define it in your code.
|
|
80
80
|
* @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It
|
|
81
81
|
* is of type `V['val']`, which means it should be of the same type as the `val` property of the vertex class `V`.
|
|
@@ -84,13 +84,13 @@ export class MapGraph extends DirectedGraph {
|
|
|
84
84
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
85
85
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
|
|
86
86
|
*/
|
|
87
|
-
createVertex(
|
|
88
|
-
return new MapVertex(
|
|
87
|
+
createVertex(key, val, lat = this.origin[0], long = this.origin[1]) {
|
|
88
|
+
return new MapVertex(key, lat, long, val);
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
92
|
-
* @param {
|
|
93
|
-
* @param {
|
|
92
|
+
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
93
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
|
|
94
94
|
* created.
|
|
95
95
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
96
96
|
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
|
|
2
|
-
import type {
|
|
2
|
+
import type { VertexKey } from '../../types';
|
|
3
3
|
import { IUNDirectedGraph } from '../../interfaces';
|
|
4
4
|
export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
|
|
5
5
|
/**
|
|
6
6
|
* The constructor function initializes a vertex with an optional value.
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
8
8
|
* used to uniquely identify the vertex within a graph or network.
|
|
9
9
|
* @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
10
10
|
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
11
11
|
*/
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(key: VertexKey, val?: V);
|
|
13
13
|
}
|
|
14
14
|
export declare class UndirectedEdge<V = number> extends AbstractEdge<V> {
|
|
15
15
|
/**
|
|
16
16
|
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
17
17
|
* value.
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {
|
|
18
|
+
* @param {VertexKey} v1 - The first vertex ID of the edge.
|
|
19
|
+
* @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
|
|
20
20
|
* graph edge.
|
|
21
21
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
22
22
|
* @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store a value associated
|
|
23
23
|
* with the edge.
|
|
24
24
|
*/
|
|
25
|
-
constructor(v1:
|
|
25
|
+
constructor(v1: VertexKey, v2: VertexKey, weight?: number, val?: V);
|
|
26
26
|
private _vertices;
|
|
27
|
-
get vertices(): [
|
|
28
|
-
set vertices(v: [
|
|
27
|
+
get vertices(): [VertexKey, VertexKey];
|
|
28
|
+
set vertices(v: [VertexKey, VertexKey]);
|
|
29
29
|
}
|
|
30
30
|
export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E> {
|
|
31
31
|
/**
|
|
@@ -36,42 +36,42 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
36
36
|
get edges(): Map<V, E[]>;
|
|
37
37
|
/**
|
|
38
38
|
* The function creates a new vertex with an optional value and returns it.
|
|
39
|
-
* @param {
|
|
39
|
+
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
40
40
|
* vertex from another in the graph.
|
|
41
41
|
* @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
42
|
-
* it will be used as the value of the vertex. If no value is provided, the `
|
|
42
|
+
* it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
|
|
43
43
|
* the vertex.
|
|
44
44
|
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
|
|
45
45
|
*/
|
|
46
|
-
createVertex(
|
|
46
|
+
createVertex(key: VertexKey, val?: V['val']): V;
|
|
47
47
|
/**
|
|
48
48
|
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
49
|
-
* @param {
|
|
50
|
-
* @param {
|
|
49
|
+
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
50
|
+
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
51
51
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
52
52
|
* no weight is provided, it defaults to 1.
|
|
53
53
|
* @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
54
54
|
* is used to store additional information or data associated with the edge.
|
|
55
55
|
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
|
|
56
56
|
*/
|
|
57
|
-
createEdge(v1:
|
|
57
|
+
createEdge(v1: VertexKey, v2: VertexKey, weight?: number, val?: E['val']): E;
|
|
58
58
|
/**
|
|
59
59
|
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
60
|
-
* @param {V | null |
|
|
61
|
-
* object), `null`, or `
|
|
62
|
-
* @param {V | null |
|
|
63
|
-
* object), `null`, or `
|
|
60
|
+
* @param {V | null | VertexKey} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
61
|
+
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
62
|
+
* @param {V | null | VertexKey} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
63
|
+
* object), `null`, or `VertexKey` (vertex ID).
|
|
64
64
|
* @returns an edge (E) or null.
|
|
65
65
|
*/
|
|
66
|
-
getEdge(v1: V | null |
|
|
66
|
+
getEdge(v1: V | null | VertexKey, v2: V | null | VertexKey): E | null;
|
|
67
67
|
/**
|
|
68
68
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
69
|
-
* @param {V |
|
|
70
|
-
* @param {V |
|
|
71
|
-
* (
|
|
69
|
+
* @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
|
|
70
|
+
* @param {V | VertexKey} v2 - V | VertexKey - This parameter can be either a vertex object (V) or a vertex ID
|
|
71
|
+
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
72
72
|
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
|
|
73
73
|
*/
|
|
74
|
-
removeEdgeBetween(v1: V |
|
|
74
|
+
removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
|
|
75
75
|
/**
|
|
76
76
|
* The removeEdge function removes an edge between two vertices in a graph.
|
|
77
77
|
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
@@ -81,18 +81,18 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
81
81
|
/**
|
|
82
82
|
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
83
83
|
* vertex.
|
|
84
|
-
* @param {
|
|
84
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
85
85
|
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
86
86
|
* edges connected to that vertex.
|
|
87
87
|
*/
|
|
88
|
-
degreeOf(
|
|
88
|
+
degreeOf(vertexOrKey: VertexKey | V): number;
|
|
89
89
|
/**
|
|
90
90
|
* The function returns the edges of a given vertex or vertex ID.
|
|
91
|
-
* @param {
|
|
91
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`. A `VertexKey` is a
|
|
92
92
|
* unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
|
|
93
93
|
* @returns an array of edges.
|
|
94
94
|
*/
|
|
95
|
-
edgesOf(
|
|
95
|
+
edgesOf(vertexOrKey: VertexKey | V): E[];
|
|
96
96
|
/**
|
|
97
97
|
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
98
98
|
* @returns The method `edgeSet()` returns an array of type `E[]`.
|
|
@@ -100,11 +100,11 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
100
100
|
edgeSet(): E[];
|
|
101
101
|
/**
|
|
102
102
|
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
103
|
-
* @param {V |
|
|
104
|
-
* (`
|
|
103
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
104
|
+
* (`VertexKey`).
|
|
105
105
|
* @returns an array of vertices (V[]).
|
|
106
106
|
*/
|
|
107
|
-
getNeighbors(
|
|
107
|
+
getNeighbors(vertexOrKey: V | VertexKey): V[];
|
|
108
108
|
/**
|
|
109
109
|
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
110
110
|
* it returns null.
|