data-structure-typed 1.39.5 → 1.39.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/CHANGELOG.md +2 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +13 -13
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +7 -7
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +17 -17
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/bst.js +13 -13
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +4 -4
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +16 -16
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js +18 -18
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +24 -24
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +12 -12
- package/dist/cjs/data-structures/graph/directed-graph.js +15 -15
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +9 -9
- package/dist/cjs/data-structures/graph/map-graph.js +13 -13
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +11 -11
- package/dist/cjs/data-structures/graph/undirected-graph.js +14 -14
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-table.d.ts +4 -4
- package/dist/cjs/data-structures/hash/hash-table.js +8 -8
- package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +54 -54
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +24 -24
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +52 -52
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.js +1 -1
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/cjs/interfaces/graph.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +13 -13
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +7 -7
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +18 -18
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/bst.js +13 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +4 -4
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +7 -7
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +16 -16
- package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multiset.js +18 -18
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +26 -26
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +12 -12
- package/dist/mjs/data-structures/graph/directed-graph.js +15 -15
- package/dist/mjs/data-structures/graph/map-graph.d.ts +9 -9
- package/dist/mjs/data-structures/graph/map-graph.js +13 -13
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +11 -11
- package/dist/mjs/data-structures/graph/undirected-graph.js +14 -14
- package/dist/mjs/data-structures/hash/hash-table.d.ts +4 -4
- package/dist/mjs/data-structures/hash/hash-table.js +9 -9
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +55 -55
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +24 -24
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +53 -53
- package/dist/mjs/data-structures/queue/queue.js +1 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/interfaces/graph.d.ts +2 -2
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +5 -5
- package/src/data-structures/binary-tree/avl-tree.ts +13 -13
- package/src/data-structures/binary-tree/binary-tree.ts +18 -18
- package/src/data-structures/binary-tree/bst.ts +16 -16
- package/src/data-structures/binary-tree/rb-tree.ts +6 -6
- package/src/data-structures/binary-tree/segment-tree.ts +15 -15
- package/src/data-structures/binary-tree/tree-multiset.ts +18 -18
- package/src/data-structures/graph/abstract-graph.ts +34 -34
- package/src/data-structures/graph/directed-graph.ts +16 -16
- package/src/data-structures/graph/map-graph.ts +13 -13
- package/src/data-structures/graph/undirected-graph.ts +15 -15
- package/src/data-structures/hash/hash-table.ts +9 -9
- package/src/data-structures/linked-list/doubly-linked-list.ts +61 -61
- package/src/data-structures/linked-list/singly-linked-list.ts +58 -58
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/interfaces/graph.ts +2 -2
- package/test/integration/bst.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +8 -8
- package/test/unit/data-structures/binary-tree/bst.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +2 -2
- package/test/unit/data-structures/graph/abstract-graph.test.ts +99 -2
- package/test/unit/data-structures/graph/directed-graph.test.ts +22 -12
- package/test/unit/data-structures/graph/undirected-graph.test.ts +8 -0
- package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
- package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +15 -15
- package/test/utils/big-o.ts +7 -7
|
@@ -5,31 +5,31 @@ export declare abstract class AbstractVertex<V = any> {
|
|
|
5
5
|
* The function is a protected constructor that takes an key and an optional value as parameters.
|
|
6
6
|
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
7
7
|
* used to uniquely identify the vertex object.
|
|
8
|
-
* @param {V} [
|
|
8
|
+
* @param {V} [value] - The parameter "value" is an optional parameter of type V. It is used to assign a value to the
|
|
9
9
|
* vertex. If no value is provided, it will be set to undefined.
|
|
10
10
|
*/
|
|
11
|
-
protected constructor(key: VertexKey,
|
|
11
|
+
protected constructor(key: VertexKey, value?: V);
|
|
12
12
|
private _key;
|
|
13
13
|
get key(): VertexKey;
|
|
14
14
|
set key(v: VertexKey);
|
|
15
|
-
private
|
|
16
|
-
get
|
|
17
|
-
set
|
|
15
|
+
private _value;
|
|
16
|
+
get value(): V | undefined;
|
|
17
|
+
set value(value: V | undefined);
|
|
18
18
|
}
|
|
19
|
-
export declare abstract class AbstractEdge<
|
|
19
|
+
export declare abstract class AbstractEdge<E = any> {
|
|
20
20
|
/**
|
|
21
21
|
* The above function is a protected constructor that initializes the weight, value, and hash code properties of an
|
|
22
22
|
* object.
|
|
23
23
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
|
|
24
24
|
* a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
|
|
25
25
|
* will be assigned.
|
|
26
|
-
* @param {VO} [
|
|
26
|
+
* @param {VO} [value] - The `value` parameter is of type `VO`, which means it can be any type. It is an optional parameter,
|
|
27
27
|
* meaning it can be omitted when creating an instance of the class.
|
|
28
28
|
*/
|
|
29
|
-
protected constructor(weight?: number,
|
|
30
|
-
private
|
|
31
|
-
get
|
|
32
|
-
set
|
|
29
|
+
protected constructor(weight?: number, value?: E);
|
|
30
|
+
private _value;
|
|
31
|
+
get value(): E | undefined;
|
|
32
|
+
set value(value: E | undefined);
|
|
33
33
|
private _weight;
|
|
34
34
|
get weight(): number;
|
|
35
35
|
set weight(v: number);
|
|
@@ -53,18 +53,18 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
53
53
|
* 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.
|
|
54
54
|
* 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.
|
|
55
55
|
* @param key
|
|
56
|
-
* @param
|
|
56
|
+
* @param value
|
|
57
57
|
*/
|
|
58
|
-
abstract createVertex(key: VertexKey,
|
|
58
|
+
abstract createVertex(key: VertexKey, value?: V): VO;
|
|
59
59
|
/**
|
|
60
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
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
62
|
* @param srcOrV1
|
|
63
63
|
* @param destOrV2
|
|
64
64
|
* @param weight
|
|
65
|
-
* @param
|
|
65
|
+
* @param value
|
|
66
66
|
*/
|
|
67
|
-
abstract createEdge(srcOrV1: VertexKey
|
|
67
|
+
abstract createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
|
|
68
68
|
abstract deleteEdge(edge: EO): EO | null;
|
|
69
69
|
abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | null;
|
|
70
70
|
abstract degreeOf(vertexOrKey: VO | VertexKey): number;
|
|
@@ -88,7 +88,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
88
88
|
*/
|
|
89
89
|
hasVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
90
90
|
addVertex(vertex: VO): boolean;
|
|
91
|
-
addVertex(key: VertexKey,
|
|
91
|
+
addVertex(key: VertexKey, value?: V): boolean;
|
|
92
92
|
/**
|
|
93
93
|
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
94
94
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
@@ -114,7 +114,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
114
114
|
*/
|
|
115
115
|
hasEdge(v1: VertexKey | VO, v2: VertexKey | VO): boolean;
|
|
116
116
|
addEdge(edge: EO): boolean;
|
|
117
|
-
addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number,
|
|
117
|
+
addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number, value?: E): boolean;
|
|
118
118
|
/**
|
|
119
119
|
* The function sets the weight of an edge between two vertices in a graph.
|
|
120
120
|
* @param {VertexKey | VO} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `VO` object. It represents
|
|
@@ -16,12 +16,12 @@ class AbstractVertex {
|
|
|
16
16
|
* The function is a protected constructor that takes an key and an optional value as parameters.
|
|
17
17
|
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
18
18
|
* used to uniquely identify the vertex object.
|
|
19
|
-
* @param {V} [
|
|
19
|
+
* @param {V} [value] - The parameter "value" is an optional parameter of type V. It is used to assign a value to the
|
|
20
20
|
* vertex. If no value is provided, it will be set to undefined.
|
|
21
21
|
*/
|
|
22
|
-
constructor(key,
|
|
22
|
+
constructor(key, value) {
|
|
23
23
|
this._key = key;
|
|
24
|
-
this.
|
|
24
|
+
this._value = value;
|
|
25
25
|
}
|
|
26
26
|
_key;
|
|
27
27
|
get key() {
|
|
@@ -30,12 +30,12 @@ class AbstractVertex {
|
|
|
30
30
|
set key(v) {
|
|
31
31
|
this._key = v;
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
get
|
|
35
|
-
return this.
|
|
33
|
+
_value;
|
|
34
|
+
get value() {
|
|
35
|
+
return this._value;
|
|
36
36
|
}
|
|
37
|
-
set
|
|
38
|
-
this.
|
|
37
|
+
set value(value) {
|
|
38
|
+
this._value = value;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
exports.AbstractVertex = AbstractVertex;
|
|
@@ -46,20 +46,20 @@ class AbstractEdge {
|
|
|
46
46
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
|
|
47
47
|
* a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
|
|
48
48
|
* will be assigned.
|
|
49
|
-
* @param {VO} [
|
|
49
|
+
* @param {VO} [value] - The `value` parameter is of type `VO`, which means it can be any type. It is an optional parameter,
|
|
50
50
|
* meaning it can be omitted when creating an instance of the class.
|
|
51
51
|
*/
|
|
52
|
-
constructor(weight,
|
|
52
|
+
constructor(weight, value) {
|
|
53
53
|
this._weight = weight !== undefined ? weight : 1;
|
|
54
|
-
this.
|
|
54
|
+
this._value = value;
|
|
55
55
|
this._hashCode = (0, utils_1.uuidV4)();
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
get
|
|
59
|
-
return this.
|
|
57
|
+
_value;
|
|
58
|
+
get value() {
|
|
59
|
+
return this._value;
|
|
60
60
|
}
|
|
61
|
-
set
|
|
62
|
-
this.
|
|
61
|
+
set value(value) {
|
|
62
|
+
this._value = value;
|
|
63
63
|
}
|
|
64
64
|
_weight;
|
|
65
65
|
get weight() {
|
|
@@ -110,12 +110,12 @@ class AbstractGraph {
|
|
|
110
110
|
hasVertex(vertexOrKey) {
|
|
111
111
|
return this._vertices.has(this._getVertexKey(vertexOrKey));
|
|
112
112
|
}
|
|
113
|
-
addVertex(keyOrVertex,
|
|
113
|
+
addVertex(keyOrVertex, value) {
|
|
114
114
|
if (keyOrVertex instanceof AbstractVertex) {
|
|
115
115
|
return this._addVertexOnly(keyOrVertex);
|
|
116
116
|
}
|
|
117
117
|
else {
|
|
118
|
-
const newVertex = this.createVertex(keyOrVertex,
|
|
118
|
+
const newVertex = this.createVertex(keyOrVertex, value);
|
|
119
119
|
return this._addVertexOnly(newVertex);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
@@ -155,7 +155,7 @@ class AbstractGraph {
|
|
|
155
155
|
const edge = this.getEdge(v1, v2);
|
|
156
156
|
return !!edge;
|
|
157
157
|
}
|
|
158
|
-
addEdge(srcOrEdge, dest, weight,
|
|
158
|
+
addEdge(srcOrEdge, dest, weight, value) {
|
|
159
159
|
if (srcOrEdge instanceof AbstractEdge) {
|
|
160
160
|
return this._addEdgeOnly(srcOrEdge);
|
|
161
161
|
}
|
|
@@ -167,7 +167,7 @@ class AbstractGraph {
|
|
|
167
167
|
srcOrEdge = srcOrEdge.key;
|
|
168
168
|
if (dest instanceof AbstractVertex)
|
|
169
169
|
dest = dest.key;
|
|
170
|
-
const newEdge = this.createEdge(srcOrEdge, dest, weight,
|
|
170
|
+
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
171
171
|
return this._addEdgeOnly(newEdge);
|
|
172
172
|
}
|
|
173
173
|
else {
|
|
@@ -408,10 +408,10 @@ class AbstractGraph {
|
|
|
408
408
|
const getMinOfNoSeen = () => {
|
|
409
409
|
let min = Infinity;
|
|
410
410
|
let minV = null;
|
|
411
|
-
for (const [key,
|
|
411
|
+
for (const [key, value] of distMap) {
|
|
412
412
|
if (!seen.has(key)) {
|
|
413
|
-
if (
|
|
414
|
-
min =
|
|
413
|
+
if (value < min) {
|
|
414
|
+
min = value;
|
|
415
415
|
minV = key;
|
|
416
416
|
}
|
|
417
417
|
}
|
|
@@ -531,7 +531,7 @@ class AbstractGraph {
|
|
|
531
531
|
distMap.set(vertexOrKey, Infinity);
|
|
532
532
|
}
|
|
533
533
|
const heap = new priority_queue_1.PriorityQueue({ comparator: (a, b) => a.key - b.key });
|
|
534
|
-
heap.add({ key: 0,
|
|
534
|
+
heap.add({ key: 0, value: srcVertex });
|
|
535
535
|
distMap.set(srcVertex, 0);
|
|
536
536
|
preMap.set(srcVertex, null);
|
|
537
537
|
/**
|
|
@@ -559,7 +559,7 @@ class AbstractGraph {
|
|
|
559
559
|
while (heap.size > 0) {
|
|
560
560
|
const curHeapNode = heap.poll();
|
|
561
561
|
const dist = curHeapNode?.key;
|
|
562
|
-
const cur = curHeapNode?.
|
|
562
|
+
const cur = curHeapNode?.value;
|
|
563
563
|
if (dist !== undefined) {
|
|
564
564
|
if (cur) {
|
|
565
565
|
seen.add(cur);
|
|
@@ -580,7 +580,7 @@ class AbstractGraph {
|
|
|
580
580
|
const distSrcToNeighbor = distMap.get(neighbor);
|
|
581
581
|
if (distSrcToNeighbor) {
|
|
582
582
|
if (dist + weight < distSrcToNeighbor) {
|
|
583
|
-
heap.add({ key: dist + weight,
|
|
583
|
+
heap.add({ key: dist + weight, value: neighbor });
|
|
584
584
|
preMap.set(neighbor, cur);
|
|
585
585
|
distMap.set(neighbor, dist + weight);
|
|
586
586
|
}
|
|
@@ -6,10 +6,10 @@ export declare class DirectedVertex<V = any> extends AbstractVertex<V> {
|
|
|
6
6
|
* The constructor function initializes a vertex with an optional value.
|
|
7
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 data structure.
|
|
9
|
-
* @param {V} [
|
|
9
|
+
* @param {V} [value] - The "value" 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(key: VertexKey,
|
|
12
|
+
constructor(key: VertexKey, value?: V);
|
|
13
13
|
}
|
|
14
14
|
export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
|
|
15
15
|
/**
|
|
@@ -20,10 +20,10 @@ export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
|
|
|
20
20
|
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
21
21
|
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
|
|
22
22
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
23
|
-
* @param {E} [
|
|
23
|
+
* @param {E} [value] - The `value` parameter is an optional parameter of type `E`. It represents the value associated with
|
|
24
24
|
* the edge.
|
|
25
25
|
*/
|
|
26
|
-
constructor(src: VertexKey, dest: VertexKey, weight?: number,
|
|
26
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
|
|
27
27
|
private _src;
|
|
28
28
|
get src(): VertexKey;
|
|
29
29
|
set src(v: VertexKey);
|
|
@@ -48,12 +48,12 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
48
48
|
* The function creates a new vertex with an optional value and returns it.
|
|
49
49
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
50
50
|
* could be a number or a string depending on how you want to identify your vertices.
|
|
51
|
-
* @param [
|
|
52
|
-
* it will be assigned to the '
|
|
51
|
+
* @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
52
|
+
* it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
|
|
53
53
|
* assigned the same value as the 'key' parameter
|
|
54
54
|
* @returns a new instance of a DirectedVertex object, casted as type VO.
|
|
55
55
|
*/
|
|
56
|
-
createVertex(key: VertexKey,
|
|
56
|
+
createVertex(key: VertexKey, value?: V): VO;
|
|
57
57
|
/**
|
|
58
58
|
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
|
59
59
|
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
@@ -64,20 +64,20 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
64
64
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
65
65
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
66
66
|
* weight is provided, it defaults to 1.
|
|
67
|
-
* @param [
|
|
67
|
+
* @param [value] - The 'value' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
68
68
|
* is used to store additional information or data associated with the edge.
|
|
69
69
|
* @returns a new instance of a DirectedEdge object, casted as type EO.
|
|
70
70
|
*/
|
|
71
|
-
createEdge(src: VertexKey, dest: VertexKey, weight?: number,
|
|
71
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
|
|
72
72
|
/**
|
|
73
73
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
74
|
-
* @param {VO |
|
|
75
|
-
* @param {VO |
|
|
74
|
+
* @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
75
|
+
* @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
76
76
|
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
|
|
77
77
|
* destination is not specified.
|
|
78
78
|
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
79
79
|
*/
|
|
80
|
-
getEdge(srcOrKey: VO |
|
|
80
|
+
getEdge(srcOrKey: VO | VertexKey | null, destOrKey: VO | VertexKey | null): EO | null;
|
|
81
81
|
/**
|
|
82
82
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
83
83
|
* @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
|
|
@@ -15,11 +15,11 @@ class DirectedVertex extends abstract_graph_1.AbstractVertex {
|
|
|
15
15
|
* The constructor function initializes a vertex with an optional value.
|
|
16
16
|
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
17
17
|
* used to uniquely identify the vertex within a graph or data structure.
|
|
18
|
-
* @param {V} [
|
|
18
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
19
19
|
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
20
20
|
*/
|
|
21
|
-
constructor(key,
|
|
22
|
-
super(key,
|
|
21
|
+
constructor(key, value) {
|
|
22
|
+
super(key, value);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.DirectedVertex = DirectedVertex;
|
|
@@ -32,11 +32,11 @@ class DirectedEdge extends abstract_graph_1.AbstractEdge {
|
|
|
32
32
|
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
33
33
|
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
|
|
34
34
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
35
|
-
* @param {E} [
|
|
35
|
+
* @param {E} [value] - The `value` parameter is an optional parameter of type `E`. It represents the value associated with
|
|
36
36
|
* the edge.
|
|
37
37
|
*/
|
|
38
|
-
constructor(src, dest, weight,
|
|
39
|
-
super(weight,
|
|
38
|
+
constructor(src, dest, weight, value) {
|
|
39
|
+
super(weight, value);
|
|
40
40
|
this._src = src;
|
|
41
41
|
this._dest = dest;
|
|
42
42
|
}
|
|
@@ -79,13 +79,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
79
79
|
* The function creates a new vertex with an optional value and returns it.
|
|
80
80
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
81
81
|
* could be a number or a string depending on how you want to identify your vertices.
|
|
82
|
-
* @param [
|
|
83
|
-
* it will be assigned to the '
|
|
82
|
+
* @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
83
|
+
* it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
|
|
84
84
|
* assigned the same value as the 'key' parameter
|
|
85
85
|
* @returns a new instance of a DirectedVertex object, casted as type VO.
|
|
86
86
|
*/
|
|
87
|
-
createVertex(key,
|
|
88
|
-
return new DirectedVertex(key,
|
|
87
|
+
createVertex(key, value) {
|
|
88
|
+
return new DirectedVertex(key, value ?? key);
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* 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.
|
|
@@ -97,17 +97,17 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
97
97
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
98
98
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
99
99
|
* weight is provided, it defaults to 1.
|
|
100
|
-
* @param [
|
|
100
|
+
* @param [value] - The 'value' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
101
101
|
* is used to store additional information or data associated with the edge.
|
|
102
102
|
* @returns a new instance of a DirectedEdge object, casted as type EO.
|
|
103
103
|
*/
|
|
104
|
-
createEdge(src, dest, weight,
|
|
105
|
-
return new DirectedEdge(src, dest, weight ?? 1,
|
|
104
|
+
createEdge(src, dest, weight, value) {
|
|
105
|
+
return new DirectedEdge(src, dest, weight ?? 1, value);
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
109
|
-
* @param {VO |
|
|
110
|
-
* @param {VO |
|
|
109
|
+
* @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
110
|
+
* @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
111
111
|
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
|
|
112
112
|
* destination is not specified.
|
|
113
113
|
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
@@ -10,10 +10,10 @@ export declare class MapVertex<V = any> extends DirectedVertex<V> {
|
|
|
10
10
|
* @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
|
|
11
11
|
* coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
|
|
12
12
|
* values ranging from -180 to 180.
|
|
13
|
-
* @param {V} [
|
|
13
|
+
* @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
|
|
14
14
|
* creating an instance of the class.
|
|
15
15
|
*/
|
|
16
|
-
constructor(key: VertexKey,
|
|
16
|
+
constructor(key: VertexKey, value: V, lat: number, long: number);
|
|
17
17
|
private _lat;
|
|
18
18
|
get lat(): number;
|
|
19
19
|
set lat(value: number);
|
|
@@ -29,10 +29,10 @@ export declare class MapEdge<E = any> extends DirectedEdge<E> {
|
|
|
29
29
|
* a graph.
|
|
30
30
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
31
31
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
32
|
-
* @param {E} [
|
|
32
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
|
|
33
33
|
* information or data associated with the edge.
|
|
34
34
|
*/
|
|
35
|
-
constructor(src: VertexKey, dest: VertexKey, weight?: number,
|
|
35
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
|
|
36
36
|
}
|
|
37
37
|
export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVertex<V>, EO extends MapEdge<E> = MapEdge<E>> extends DirectedGraph<V, E, VO, EO> {
|
|
38
38
|
/**
|
|
@@ -55,14 +55,14 @@ export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVer
|
|
|
55
55
|
* The function creates a new vertex with the given key, value, latitude, and longitude.
|
|
56
56
|
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
|
|
57
57
|
* be a string or a number depending on how you define it in your code.
|
|
58
|
-
* @param [
|
|
59
|
-
* is of type `V`, which means it should be of the same type as the `
|
|
58
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
|
|
59
|
+
* is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
|
|
60
60
|
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
|
|
61
61
|
* position of the vertex on the Earth's surface in the north-south direction.
|
|
62
62
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
63
63
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
64
64
|
*/
|
|
65
|
-
createVertex(key: VertexKey,
|
|
65
|
+
createVertex(key: VertexKey, value?: V, lat?: number, long?: number): VO;
|
|
66
66
|
/**
|
|
67
67
|
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
68
68
|
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
@@ -71,9 +71,9 @@ export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVer
|
|
|
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.
|
|
73
73
|
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
74
|
-
* @param [
|
|
74
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
|
|
75
75
|
* depending on the specific implementation of the `MapEdge` class.
|
|
76
76
|
* @returns a new instance of the `MapEdge` class, cast as type `EO`.
|
|
77
77
|
*/
|
|
78
|
-
createEdge(src: VertexKey, dest: VertexKey, weight?: number,
|
|
78
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
|
|
79
79
|
}
|
|
@@ -12,11 +12,11 @@ class MapVertex extends directed_graph_1.DirectedVertex {
|
|
|
12
12
|
* @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
|
|
13
13
|
* coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
|
|
14
14
|
* values ranging from -180 to 180.
|
|
15
|
-
* @param {V} [
|
|
15
|
+
* @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
|
|
16
16
|
* creating an instance of the class.
|
|
17
17
|
*/
|
|
18
|
-
constructor(key,
|
|
19
|
-
super(key,
|
|
18
|
+
constructor(key, value, lat, long) {
|
|
19
|
+
super(key, value);
|
|
20
20
|
this._lat = lat;
|
|
21
21
|
this._long = long;
|
|
22
22
|
}
|
|
@@ -44,11 +44,11 @@ class MapEdge extends directed_graph_1.DirectedEdge {
|
|
|
44
44
|
* a graph.
|
|
45
45
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
46
46
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
47
|
-
* @param {E} [
|
|
47
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
|
|
48
48
|
* information or data associated with the edge.
|
|
49
49
|
*/
|
|
50
|
-
constructor(src, dest, weight,
|
|
51
|
-
super(src, dest, weight,
|
|
50
|
+
constructor(src, dest, weight, value) {
|
|
51
|
+
super(src, dest, weight, value);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
exports.MapEdge = MapEdge;
|
|
@@ -85,15 +85,15 @@ class MapGraph extends directed_graph_1.DirectedGraph {
|
|
|
85
85
|
* The function creates a new vertex with the given key, value, latitude, and longitude.
|
|
86
86
|
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
|
|
87
87
|
* be a string or a number depending on how you define it in your code.
|
|
88
|
-
* @param [
|
|
89
|
-
* is of type `V`, which means it should be of the same type as the `
|
|
88
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
|
|
89
|
+
* is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
|
|
90
90
|
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
|
|
91
91
|
* position of the vertex on the Earth's surface in the north-south direction.
|
|
92
92
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
93
93
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
94
94
|
*/
|
|
95
|
-
createVertex(key,
|
|
96
|
-
return new MapVertex(key,
|
|
95
|
+
createVertex(key, value, lat = this.origin[0], long = this.origin[1]) {
|
|
96
|
+
return new MapVertex(key, value, lat, long);
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
@@ -103,12 +103,12 @@ class MapGraph extends directed_graph_1.DirectedGraph {
|
|
|
103
103
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
104
104
|
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
105
105
|
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
106
|
-
* @param [
|
|
106
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
|
|
107
107
|
* depending on the specific implementation of the `MapEdge` class.
|
|
108
108
|
* @returns a new instance of the `MapEdge` class, cast as type `EO`.
|
|
109
109
|
*/
|
|
110
|
-
createEdge(src, dest, weight,
|
|
111
|
-
return new MapEdge(src, dest, weight,
|
|
110
|
+
createEdge(src, dest, weight, value) {
|
|
111
|
+
return new MapEdge(src, dest, weight, value);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
exports.MapGraph = MapGraph;
|
|
@@ -6,10 +6,10 @@ export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
|
|
|
6
6
|
* The constructor function initializes a vertex with an optional value.
|
|
7
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
|
-
* @param {V} [
|
|
9
|
+
* @param {V} [value] - The "value" 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(key: VertexKey,
|
|
12
|
+
constructor(key: VertexKey, value?: V);
|
|
13
13
|
}
|
|
14
14
|
export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
|
|
15
15
|
/**
|
|
@@ -19,10 +19,10 @@ export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
|
|
|
19
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
|
-
* @param {E} [
|
|
22
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store a value associated
|
|
23
23
|
* with the edge.
|
|
24
24
|
*/
|
|
25
|
-
constructor(v1: VertexKey, v2: VertexKey, weight?: number,
|
|
25
|
+
constructor(v1: VertexKey, v2: VertexKey, weight?: number, value?: E);
|
|
26
26
|
private _vertices;
|
|
27
27
|
get vertices(): [VertexKey, VertexKey];
|
|
28
28
|
set vertices(v: [VertexKey, VertexKey]);
|
|
@@ -38,32 +38,32 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
38
38
|
* The function creates a new vertex with an optional value and returns it.
|
|
39
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
|
-
* @param [
|
|
41
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
42
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 `VO`.
|
|
45
45
|
*/
|
|
46
|
-
createVertex(key: VertexKey,
|
|
46
|
+
createVertex(key: VertexKey, value?: VO['value']): VO;
|
|
47
47
|
/**
|
|
48
48
|
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
49
49
|
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
50
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
|
-
* @param [
|
|
53
|
+
* @param [value] - The `value` 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 `EO`.
|
|
56
56
|
*/
|
|
57
|
-
createEdge(v1: VertexKey, v2: VertexKey, weight?: number,
|
|
57
|
+
createEdge(v1: VertexKey, v2: VertexKey, weight?: number, value?: EO['value']): EO;
|
|
58
58
|
/**
|
|
59
59
|
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
60
|
-
* @param {VO |
|
|
60
|
+
* @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
61
61
|
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
62
|
-
* @param {VO |
|
|
62
|
+
* @param {VO | VertexKey | null} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
63
63
|
* object), `null`, or `VertexKey` (vertex ID).
|
|
64
64
|
* @returns an edge (EO) or null.
|
|
65
65
|
*/
|
|
66
|
-
getEdge(v1: VO |
|
|
66
|
+
getEdge(v1: VO | VertexKey | null, v2: VO | VertexKey | null): EO | null;
|
|
67
67
|
/**
|
|
68
68
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
69
69
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
@@ -15,11 +15,11 @@ class UndirectedVertex extends abstract_graph_1.AbstractVertex {
|
|
|
15
15
|
* The constructor function initializes a vertex with an optional value.
|
|
16
16
|
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
17
17
|
* used to uniquely identify the vertex within a graph or network.
|
|
18
|
-
* @param {V} [
|
|
18
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
19
19
|
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
20
20
|
*/
|
|
21
|
-
constructor(key,
|
|
22
|
-
super(key,
|
|
21
|
+
constructor(key, value) {
|
|
22
|
+
super(key, value);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.UndirectedVertex = UndirectedVertex;
|
|
@@ -31,11 +31,11 @@ class UndirectedEdge extends abstract_graph_1.AbstractEdge {
|
|
|
31
31
|
* @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
|
|
32
32
|
* graph edge.
|
|
33
33
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
34
|
-
* @param {E} [
|
|
34
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store a value associated
|
|
35
35
|
* with the edge.
|
|
36
36
|
*/
|
|
37
|
-
constructor(v1, v2, weight,
|
|
38
|
-
super(weight,
|
|
37
|
+
constructor(v1, v2, weight, value) {
|
|
38
|
+
super(weight, value);
|
|
39
39
|
this._vertices = [v1, v2];
|
|
40
40
|
}
|
|
41
41
|
_vertices;
|
|
@@ -63,13 +63,13 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
63
63
|
* The function creates a new vertex with an optional value and returns it.
|
|
64
64
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
65
65
|
* vertex from another in the graph.
|
|
66
|
-
* @param [
|
|
66
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
67
67
|
* 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
|
|
68
68
|
* the vertex.
|
|
69
69
|
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `VO`.
|
|
70
70
|
*/
|
|
71
|
-
createVertex(key,
|
|
72
|
-
return new UndirectedVertex(key,
|
|
71
|
+
createVertex(key, value) {
|
|
72
|
+
return new UndirectedVertex(key, value ?? key);
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
@@ -77,18 +77,18 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
77
77
|
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
78
78
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
79
79
|
* no weight is provided, it defaults to 1.
|
|
80
|
-
* @param [
|
|
80
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
81
81
|
* is used to store additional information or data associated with the edge.
|
|
82
82
|
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `EO`.
|
|
83
83
|
*/
|
|
84
|
-
createEdge(v1, v2, weight,
|
|
85
|
-
return new UndirectedEdge(v1, v2, weight ?? 1,
|
|
84
|
+
createEdge(v1, v2, weight, value) {
|
|
85
|
+
return new UndirectedEdge(v1, v2, weight ?? 1, value);
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
88
|
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
89
|
-
* @param {VO |
|
|
89
|
+
* @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
90
90
|
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
91
|
-
* @param {VO |
|
|
91
|
+
* @param {VO | VertexKey | null} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
92
92
|
* object), `null`, or `VertexKey` (vertex ID).
|
|
93
93
|
* @returns an edge (EO) or null.
|
|
94
94
|
*/
|