graph-typed 1.39.5 → 1.40.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/binary-tree/avl-tree.d.ts +6 -6
- package/dist/data-structures/binary-tree/avl-tree.js +13 -14
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -11
- package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -27
- package/dist/data-structures/binary-tree/binary-tree.js +25 -46
- package/dist/data-structures/binary-tree/bst.d.ts +7 -7
- package/dist/data-structures/binary-tree/bst.js +16 -16
- package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -5
- package/dist/data-structures/binary-tree/rb-tree.js +5 -11
- package/dist/data-structures/binary-tree/segment-tree.d.ts +14 -30
- package/dist/data-structures/binary-tree/segment-tree.js +20 -68
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +7 -7
- package/dist/data-structures/binary-tree/tree-multiset.js +24 -24
- package/dist/data-structures/graph/abstract-graph.d.ts +16 -35
- package/dist/data-structures/graph/abstract-graph.js +18 -57
- package/dist/data-structures/graph/directed-graph.d.ts +16 -22
- package/dist/data-structures/graph/directed-graph.js +17 -35
- package/dist/data-structures/graph/map-graph.d.ts +13 -19
- package/dist/data-structures/graph/map-graph.js +15 -33
- package/dist/data-structures/graph/undirected-graph.d.ts +12 -19
- package/dist/data-structures/graph/undirected-graph.js +15 -28
- package/dist/data-structures/hash/coordinate-map.d.ts +0 -1
- package/dist/data-structures/hash/coordinate-map.js +0 -3
- package/dist/data-structures/hash/coordinate-set.d.ts +0 -1
- package/dist/data-structures/hash/coordinate-set.js +0 -3
- package/dist/data-structures/hash/hash-map.d.ts +8 -14
- package/dist/data-structures/hash/hash-map.js +4 -22
- package/dist/data-structures/hash/hash-table.d.ts +10 -13
- package/dist/data-structures/hash/hash-table.js +8 -17
- package/dist/data-structures/heap/heap.d.ts +12 -6
- package/dist/data-structures/heap/heap.js +40 -22
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +34 -42
- package/dist/data-structures/linked-list/doubly-linked-list.js +67 -91
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +26 -32
- package/dist/data-structures/linked-list/singly-linked-list.js +64 -82
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +29 -10
- package/dist/data-structures/linked-list/skip-linked-list.js +62 -17
- package/dist/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +1 -1
- package/dist/data-structures/matrix/navigator.d.ts +4 -4
- package/dist/data-structures/queue/deque.d.ts +8 -12
- package/dist/data-structures/queue/deque.js +31 -43
- package/dist/data-structures/queue/queue.d.ts +20 -5
- package/dist/data-structures/queue/queue.js +35 -18
- package/dist/data-structures/stack/stack.d.ts +2 -1
- package/dist/data-structures/stack/stack.js +10 -7
- package/dist/data-structures/tree/tree.d.ts +3 -9
- package/dist/data-structures/tree/tree.js +3 -21
- package/dist/data-structures/trie/trie.d.ts +6 -12
- package/dist/data-structures/trie/trie.js +6 -24
- package/dist/interfaces/binary-tree.d.ts +3 -3
- package/dist/interfaces/graph.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +15 -17
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -15
- package/src/data-structures/binary-tree/binary-tree.ts +35 -60
- package/src/data-structures/binary-tree/bst.ts +21 -22
- package/src/data-structures/binary-tree/rb-tree.ts +19 -27
- package/src/data-structures/binary-tree/segment-tree.ts +25 -92
- package/src/data-structures/binary-tree/tree-multiset.ts +26 -27
- package/src/data-structures/graph/abstract-graph.ts +42 -88
- package/src/data-structures/graph/directed-graph.ts +29 -55
- package/src/data-structures/graph/map-graph.ts +20 -45
- package/src/data-structures/graph/undirected-graph.ts +24 -41
- package/src/data-structures/hash/coordinate-map.ts +0 -4
- package/src/data-structures/hash/coordinate-set.ts +0 -4
- package/src/data-structures/hash/hash-map.ts +13 -37
- package/src/data-structures/hash/hash-table.ts +15 -27
- package/src/data-structures/hash/tree-map.ts +2 -1
- package/src/data-structures/hash/tree-set.ts +2 -1
- package/src/data-structures/heap/heap.ts +58 -30
- package/src/data-structures/heap/max-heap.ts +1 -1
- package/src/data-structures/heap/min-heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +81 -115
- package/src/data-structures/linked-list/singly-linked-list.ts +76 -101
- package/src/data-structures/linked-list/skip-linked-list.ts +73 -25
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/matrix2d.ts +1 -1
- package/src/data-structures/matrix/navigator.ts +4 -4
- package/src/data-structures/matrix/vector2d.ts +2 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/data-structures/queue/deque.ts +38 -53
- package/src/data-structures/queue/queue.ts +38 -20
- package/src/data-structures/stack/stack.ts +13 -9
- package/src/data-structures/tree/tree.ts +7 -33
- package/src/data-structures/trie/trie.ts +14 -40
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/interfaces/graph.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +2 -2
|
@@ -16,24 +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,
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
}
|
|
26
|
-
get key() {
|
|
27
|
-
return this._key;
|
|
28
|
-
}
|
|
29
|
-
set key(v) {
|
|
30
|
-
this._key = v;
|
|
31
|
-
}
|
|
32
|
-
get val() {
|
|
33
|
-
return this._val;
|
|
34
|
-
}
|
|
35
|
-
set val(value) {
|
|
36
|
-
this._val = value;
|
|
22
|
+
constructor(key, value) {
|
|
23
|
+
this.key = key;
|
|
24
|
+
this.value = value;
|
|
37
25
|
}
|
|
38
26
|
}
|
|
39
27
|
exports.AbstractVertex = AbstractVertex;
|
|
@@ -44,41 +32,17 @@ class AbstractEdge {
|
|
|
44
32
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
|
|
45
33
|
* a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
|
|
46
34
|
* will be assigned.
|
|
47
|
-
* @param {VO} [
|
|
35
|
+
* @param {VO} [value] - The `value` parameter is of type `VO`, which means it can be any type. It is an optional parameter,
|
|
48
36
|
* meaning it can be omitted when creating an instance of the class.
|
|
49
37
|
*/
|
|
50
|
-
constructor(weight,
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
38
|
+
constructor(weight, value) {
|
|
39
|
+
this.weight = weight !== undefined ? weight : 1;
|
|
40
|
+
this.value = value;
|
|
53
41
|
this._hashCode = (0, utils_1.uuidV4)();
|
|
54
42
|
}
|
|
55
|
-
get val() {
|
|
56
|
-
return this._val;
|
|
57
|
-
}
|
|
58
|
-
set val(value) {
|
|
59
|
-
this._val = value;
|
|
60
|
-
}
|
|
61
|
-
get weight() {
|
|
62
|
-
return this._weight;
|
|
63
|
-
}
|
|
64
|
-
set weight(v) {
|
|
65
|
-
this._weight = v;
|
|
66
|
-
}
|
|
67
43
|
get hashCode() {
|
|
68
44
|
return this._hashCode;
|
|
69
45
|
}
|
|
70
|
-
/**
|
|
71
|
-
* 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.
|
|
72
|
-
* 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.
|
|
73
|
-
*/
|
|
74
|
-
/**
|
|
75
|
-
* The function sets the value of the _hashCode property to the provided string.
|
|
76
|
-
* @param {string} v - The parameter "v" is of type string and represents the value that will be assigned to the
|
|
77
|
-
* "_hashCode" property.
|
|
78
|
-
*/
|
|
79
|
-
_setHashCode(v) {
|
|
80
|
-
this._hashCode = v;
|
|
81
|
-
}
|
|
82
46
|
}
|
|
83
47
|
exports.AbstractEdge = AbstractEdge;
|
|
84
48
|
class AbstractGraph {
|
|
@@ -107,12 +71,12 @@ class AbstractGraph {
|
|
|
107
71
|
hasVertex(vertexOrKey) {
|
|
108
72
|
return this._vertices.has(this._getVertexKey(vertexOrKey));
|
|
109
73
|
}
|
|
110
|
-
addVertex(keyOrVertex,
|
|
74
|
+
addVertex(keyOrVertex, value) {
|
|
111
75
|
if (keyOrVertex instanceof AbstractVertex) {
|
|
112
76
|
return this._addVertexOnly(keyOrVertex);
|
|
113
77
|
}
|
|
114
78
|
else {
|
|
115
|
-
const newVertex = this.createVertex(keyOrVertex,
|
|
79
|
+
const newVertex = this.createVertex(keyOrVertex, value);
|
|
116
80
|
return this._addVertexOnly(newVertex);
|
|
117
81
|
}
|
|
118
82
|
}
|
|
@@ -152,7 +116,7 @@ class AbstractGraph {
|
|
|
152
116
|
const edge = this.getEdge(v1, v2);
|
|
153
117
|
return !!edge;
|
|
154
118
|
}
|
|
155
|
-
addEdge(srcOrEdge, dest, weight,
|
|
119
|
+
addEdge(srcOrEdge, dest, weight, value) {
|
|
156
120
|
if (srcOrEdge instanceof AbstractEdge) {
|
|
157
121
|
return this._addEdgeOnly(srcOrEdge);
|
|
158
122
|
}
|
|
@@ -164,7 +128,7 @@ class AbstractGraph {
|
|
|
164
128
|
srcOrEdge = srcOrEdge.key;
|
|
165
129
|
if (dest instanceof AbstractVertex)
|
|
166
130
|
dest = dest.key;
|
|
167
|
-
const newEdge = this.createEdge(srcOrEdge, dest, weight,
|
|
131
|
+
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
168
132
|
return this._addEdgeOnly(newEdge);
|
|
169
133
|
}
|
|
170
134
|
else {
|
|
@@ -406,10 +370,10 @@ class AbstractGraph {
|
|
|
406
370
|
const getMinOfNoSeen = () => {
|
|
407
371
|
let min = Infinity;
|
|
408
372
|
let minV = null;
|
|
409
|
-
for (const [key,
|
|
373
|
+
for (const [key, value] of distMap) {
|
|
410
374
|
if (!seen.has(key)) {
|
|
411
|
-
if (
|
|
412
|
-
min =
|
|
375
|
+
if (value < min) {
|
|
376
|
+
min = value;
|
|
413
377
|
minV = key;
|
|
414
378
|
}
|
|
415
379
|
}
|
|
@@ -530,7 +494,7 @@ class AbstractGraph {
|
|
|
530
494
|
distMap.set(vertexOrKey, Infinity);
|
|
531
495
|
}
|
|
532
496
|
const heap = new priority_queue_1.PriorityQueue({ comparator: (a, b) => a.key - b.key });
|
|
533
|
-
heap.add({ key: 0,
|
|
497
|
+
heap.add({ key: 0, value: srcVertex });
|
|
534
498
|
distMap.set(srcVertex, 0);
|
|
535
499
|
preMap.set(srcVertex, null);
|
|
536
500
|
/**
|
|
@@ -558,7 +522,7 @@ class AbstractGraph {
|
|
|
558
522
|
while (heap.size > 0) {
|
|
559
523
|
const curHeapNode = heap.poll();
|
|
560
524
|
const dist = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.key;
|
|
561
|
-
const cur = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.
|
|
525
|
+
const cur = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.value;
|
|
562
526
|
if (dist !== undefined) {
|
|
563
527
|
if (cur) {
|
|
564
528
|
seen.add(cur);
|
|
@@ -579,7 +543,7 @@ class AbstractGraph {
|
|
|
579
543
|
const distSrcToNeighbor = distMap.get(neighbor);
|
|
580
544
|
if (distSrcToNeighbor) {
|
|
581
545
|
if (dist + weight < distSrcToNeighbor) {
|
|
582
|
-
heap.add({ key: dist + weight,
|
|
546
|
+
heap.add({ key: dist + weight, value: neighbor });
|
|
583
547
|
preMap.set(neighbor, cur);
|
|
584
548
|
distMap.set(neighbor, dist + weight);
|
|
585
549
|
}
|
|
@@ -916,8 +880,5 @@ class AbstractGraph {
|
|
|
916
880
|
_getVertexKey(vertexOrKey) {
|
|
917
881
|
return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
|
|
918
882
|
}
|
|
919
|
-
_setVertices(value) {
|
|
920
|
-
this._vertices = value;
|
|
921
|
-
}
|
|
922
883
|
}
|
|
923
884
|
exports.AbstractGraph = AbstractGraph;
|
|
@@ -6,12 +6,14 @@ 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
|
+
src: VertexKey;
|
|
16
|
+
dest: VertexKey;
|
|
15
17
|
/**
|
|
16
18
|
* The constructor function initializes the source and destination vertices of an edge, along with an optional weight
|
|
17
19
|
* and value.
|
|
@@ -20,25 +22,19 @@ export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
|
|
|
20
22
|
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
21
23
|
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
|
|
22
24
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
23
|
-
* @param {E} [
|
|
25
|
+
* @param {E} [value] - The `value` parameter is an optional parameter of type `E`. It represents the value associated with
|
|
24
26
|
* the edge.
|
|
25
27
|
*/
|
|
26
|
-
constructor(src: VertexKey, dest: VertexKey, weight?: number,
|
|
27
|
-
private _src;
|
|
28
|
-
get src(): VertexKey;
|
|
29
|
-
set src(v: VertexKey);
|
|
30
|
-
private _dest;
|
|
31
|
-
get dest(): VertexKey;
|
|
32
|
-
set dest(v: VertexKey);
|
|
28
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
|
|
33
29
|
}
|
|
34
30
|
export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V> = DirectedVertex<V>, EO extends DirectedEdge<E> = DirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
|
|
35
31
|
/**
|
|
36
32
|
* The constructor function initializes an instance of a class.
|
|
37
33
|
*/
|
|
38
34
|
constructor();
|
|
39
|
-
|
|
35
|
+
protected _outEdgeMap: Map<VO, EO[]>;
|
|
40
36
|
get outEdgeMap(): Map<VO, EO[]>;
|
|
41
|
-
|
|
37
|
+
protected _inEdgeMap: Map<VO, EO[]>;
|
|
42
38
|
get inEdgeMap(): Map<VO, EO[]>;
|
|
43
39
|
/**
|
|
44
40
|
* 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.
|
|
@@ -48,12 +44,12 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
48
44
|
* The function creates a new vertex with an optional value and returns it.
|
|
49
45
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
50
46
|
* 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 '
|
|
47
|
+
* @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
48
|
+
* it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
|
|
53
49
|
* assigned the same value as the 'key' parameter
|
|
54
50
|
* @returns a new instance of a DirectedVertex object, casted as type VO.
|
|
55
51
|
*/
|
|
56
|
-
createVertex(key: VertexKey,
|
|
52
|
+
createVertex(key: VertexKey, value?: V): VO;
|
|
57
53
|
/**
|
|
58
54
|
* 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
55
|
* 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 +60,20 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
64
60
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
65
61
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
66
62
|
* weight is provided, it defaults to 1.
|
|
67
|
-
* @param [
|
|
63
|
+
* @param [value] - The 'value' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
68
64
|
* is used to store additional information or data associated with the edge.
|
|
69
65
|
* @returns a new instance of a DirectedEdge object, casted as type EO.
|
|
70
66
|
*/
|
|
71
|
-
createEdge(src: VertexKey, dest: VertexKey, weight?: number,
|
|
67
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
|
|
72
68
|
/**
|
|
73
69
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
74
|
-
* @param {VO |
|
|
75
|
-
* @param {VO |
|
|
70
|
+
* @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
71
|
+
* @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
76
72
|
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
|
|
77
73
|
* destination is not specified.
|
|
78
74
|
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
79
75
|
*/
|
|
80
|
-
getEdge(srcOrKey: VO |
|
|
76
|
+
getEdge(srcOrKey: VO | VertexKey | null, destOrKey: VO | VertexKey | null): EO | null;
|
|
81
77
|
/**
|
|
82
78
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
83
79
|
* @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
|
|
@@ -195,6 +191,4 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
195
191
|
* source or destination vertex does not exist in the graph.
|
|
196
192
|
*/
|
|
197
193
|
protected _addEdgeOnly(edge: EO): boolean;
|
|
198
|
-
protected _setOutEdgeMap(value: Map<VO, EO[]>): void;
|
|
199
|
-
protected _setInEdgeMap(value: Map<VO, EO[]>): void;
|
|
200
194
|
}
|
|
@@ -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,25 +32,13 @@ 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,
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
42
|
-
}
|
|
43
|
-
get src() {
|
|
44
|
-
return this._src;
|
|
45
|
-
}
|
|
46
|
-
set src(v) {
|
|
47
|
-
this._src = v;
|
|
48
|
-
}
|
|
49
|
-
get dest() {
|
|
50
|
-
return this._dest;
|
|
51
|
-
}
|
|
52
|
-
set dest(v) {
|
|
53
|
-
this._dest = v;
|
|
38
|
+
constructor(src, dest, weight, value) {
|
|
39
|
+
super(weight, value);
|
|
40
|
+
this.src = src;
|
|
41
|
+
this.dest = dest;
|
|
54
42
|
}
|
|
55
43
|
}
|
|
56
44
|
exports.DirectedEdge = DirectedEdge;
|
|
@@ -77,13 +65,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
77
65
|
* The function creates a new vertex with an optional value and returns it.
|
|
78
66
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
79
67
|
* could be a number or a string depending on how you want to identify your vertices.
|
|
80
|
-
* @param [
|
|
81
|
-
* it will be assigned to the '
|
|
68
|
+
* @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
69
|
+
* it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
|
|
82
70
|
* assigned the same value as the 'key' parameter
|
|
83
71
|
* @returns a new instance of a DirectedVertex object, casted as type VO.
|
|
84
72
|
*/
|
|
85
|
-
createVertex(key,
|
|
86
|
-
return new DirectedVertex(key,
|
|
73
|
+
createVertex(key, value) {
|
|
74
|
+
return new DirectedVertex(key, value !== null && value !== void 0 ? value : key);
|
|
87
75
|
}
|
|
88
76
|
/**
|
|
89
77
|
* 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.
|
|
@@ -95,17 +83,17 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
95
83
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
96
84
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
97
85
|
* weight is provided, it defaults to 1.
|
|
98
|
-
* @param [
|
|
86
|
+
* @param [value] - The 'value' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
99
87
|
* is used to store additional information or data associated with the edge.
|
|
100
88
|
* @returns a new instance of a DirectedEdge object, casted as type EO.
|
|
101
89
|
*/
|
|
102
|
-
createEdge(src, dest, weight,
|
|
103
|
-
return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1,
|
|
90
|
+
createEdge(src, dest, weight, value) {
|
|
91
|
+
return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1, value);
|
|
104
92
|
}
|
|
105
93
|
/**
|
|
106
94
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
107
|
-
* @param {VO |
|
|
108
|
-
* @param {VO |
|
|
95
|
+
* @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
96
|
+
* @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
109
97
|
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
|
|
110
98
|
* destination is not specified.
|
|
111
99
|
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
@@ -412,11 +400,5 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
412
400
|
return false;
|
|
413
401
|
}
|
|
414
402
|
}
|
|
415
|
-
_setOutEdgeMap(value) {
|
|
416
|
-
this._outEdgeMap = value;
|
|
417
|
-
}
|
|
418
|
-
_setInEdgeMap(value) {
|
|
419
|
-
this._inEdgeMap = value;
|
|
420
|
-
}
|
|
421
403
|
}
|
|
422
404
|
exports.DirectedGraph = DirectedGraph;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
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
|
+
lat: number;
|
|
5
|
+
long: number;
|
|
4
6
|
/**
|
|
5
7
|
* The constructor function initializes an object with an key, latitude, longitude, and an optional value.
|
|
6
8
|
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
|
|
@@ -10,16 +12,10 @@ export declare class MapVertex<V = any> extends DirectedVertex<V> {
|
|
|
10
12
|
* @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
|
|
11
13
|
* coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
|
|
12
14
|
* values ranging from -180 to 180.
|
|
13
|
-
* @param {V} [
|
|
15
|
+
* @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
|
|
14
16
|
* creating an instance of the class.
|
|
15
17
|
*/
|
|
16
|
-
constructor(key: VertexKey,
|
|
17
|
-
private _lat;
|
|
18
|
-
get lat(): number;
|
|
19
|
-
set lat(value: number);
|
|
20
|
-
private _long;
|
|
21
|
-
get long(): number;
|
|
22
|
-
set long(value: number);
|
|
18
|
+
constructor(key: VertexKey, value: V, lat: number, long: number);
|
|
23
19
|
}
|
|
24
20
|
export declare class MapEdge<E = any> extends DirectedEdge<E> {
|
|
25
21
|
/**
|
|
@@ -29,10 +25,10 @@ export declare class MapEdge<E = any> extends DirectedEdge<E> {
|
|
|
29
25
|
* a graph.
|
|
30
26
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
31
27
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
32
|
-
* @param {E} [
|
|
28
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
|
|
33
29
|
* information or data associated with the edge.
|
|
34
30
|
*/
|
|
35
|
-
constructor(src: VertexKey, dest: VertexKey, weight?: number,
|
|
31
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
|
|
36
32
|
}
|
|
37
33
|
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
34
|
/**
|
|
@@ -45,24 +41,22 @@ export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVer
|
|
|
45
41
|
* it will default to `undefined`.
|
|
46
42
|
*/
|
|
47
43
|
constructor(origin: MapGraphCoordinate, bottomRight?: MapGraphCoordinate);
|
|
48
|
-
|
|
44
|
+
protected _origin: MapGraphCoordinate;
|
|
49
45
|
get origin(): MapGraphCoordinate;
|
|
50
|
-
|
|
51
|
-
private _bottomRight;
|
|
46
|
+
protected _bottomRight: MapGraphCoordinate | undefined;
|
|
52
47
|
get bottomRight(): MapGraphCoordinate | undefined;
|
|
53
|
-
set bottomRight(value: MapGraphCoordinate | undefined);
|
|
54
48
|
/**
|
|
55
49
|
* The function creates a new vertex with the given key, value, latitude, and longitude.
|
|
56
50
|
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
|
|
57
51
|
* 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 `
|
|
52
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
|
|
53
|
+
* is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
|
|
60
54
|
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
|
|
61
55
|
* position of the vertex on the Earth's surface in the north-south direction.
|
|
62
56
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
63
57
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
64
58
|
*/
|
|
65
|
-
createVertex(key: VertexKey,
|
|
59
|
+
createVertex(key: VertexKey, value?: V, lat?: number, long?: number): VO;
|
|
66
60
|
/**
|
|
67
61
|
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
68
62
|
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
@@ -71,9 +65,9 @@ export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVer
|
|
|
71
65
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
72
66
|
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
73
67
|
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
74
|
-
* @param [
|
|
68
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
|
|
75
69
|
* depending on the specific implementation of the `MapEdge` class.
|
|
76
70
|
* @returns a new instance of the `MapEdge` class, cast as type `EO`.
|
|
77
71
|
*/
|
|
78
|
-
createEdge(src: VertexKey, dest: VertexKey, weight?: number,
|
|
72
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
|
|
79
73
|
}
|
|
@@ -12,25 +12,13 @@ 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,
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
}
|
|
23
|
-
get lat() {
|
|
24
|
-
return this._lat;
|
|
25
|
-
}
|
|
26
|
-
set lat(value) {
|
|
27
|
-
this._lat = value;
|
|
28
|
-
}
|
|
29
|
-
get long() {
|
|
30
|
-
return this._long;
|
|
31
|
-
}
|
|
32
|
-
set long(value) {
|
|
33
|
-
this._long = value;
|
|
18
|
+
constructor(key, value, lat, long) {
|
|
19
|
+
super(key, value);
|
|
20
|
+
this.lat = lat;
|
|
21
|
+
this.long = long;
|
|
34
22
|
}
|
|
35
23
|
}
|
|
36
24
|
exports.MapVertex = MapVertex;
|
|
@@ -42,11 +30,11 @@ class MapEdge extends directed_graph_1.DirectedEdge {
|
|
|
42
30
|
* a graph.
|
|
43
31
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
44
32
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
45
|
-
* @param {E} [
|
|
33
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
|
|
46
34
|
* information or data associated with the edge.
|
|
47
35
|
*/
|
|
48
|
-
constructor(src, dest, weight,
|
|
49
|
-
super(src, dest, weight,
|
|
36
|
+
constructor(src, dest, weight, value) {
|
|
37
|
+
super(src, dest, weight, value);
|
|
50
38
|
}
|
|
51
39
|
}
|
|
52
40
|
exports.MapEdge = MapEdge;
|
|
@@ -69,28 +57,22 @@ class MapGraph extends directed_graph_1.DirectedGraph {
|
|
|
69
57
|
get origin() {
|
|
70
58
|
return this._origin;
|
|
71
59
|
}
|
|
72
|
-
set origin(value) {
|
|
73
|
-
this._origin = value;
|
|
74
|
-
}
|
|
75
60
|
get bottomRight() {
|
|
76
61
|
return this._bottomRight;
|
|
77
62
|
}
|
|
78
|
-
set bottomRight(value) {
|
|
79
|
-
this._bottomRight = value;
|
|
80
|
-
}
|
|
81
63
|
/**
|
|
82
64
|
* The function creates a new vertex with the given key, value, latitude, and longitude.
|
|
83
65
|
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
|
|
84
66
|
* be a string or a number depending on how you define it in your code.
|
|
85
|
-
* @param [
|
|
86
|
-
* is of type `V`, which means it should be of the same type as the `
|
|
67
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
|
|
68
|
+
* is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
|
|
87
69
|
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
|
|
88
70
|
* position of the vertex on the Earth's surface in the north-south direction.
|
|
89
71
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
90
72
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
91
73
|
*/
|
|
92
|
-
createVertex(key,
|
|
93
|
-
return new MapVertex(key,
|
|
74
|
+
createVertex(key, value, lat = this.origin[0], long = this.origin[1]) {
|
|
75
|
+
return new MapVertex(key, value, lat, long);
|
|
94
76
|
}
|
|
95
77
|
/**
|
|
96
78
|
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
@@ -100,12 +82,12 @@ class MapGraph extends directed_graph_1.DirectedGraph {
|
|
|
100
82
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
101
83
|
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
102
84
|
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
103
|
-
* @param [
|
|
85
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
|
|
104
86
|
* depending on the specific implementation of the `MapEdge` class.
|
|
105
87
|
* @returns a new instance of the `MapEdge` class, cast as type `EO`.
|
|
106
88
|
*/
|
|
107
|
-
createEdge(src, dest, weight,
|
|
108
|
-
return new MapEdge(src, dest, weight,
|
|
89
|
+
createEdge(src, dest, weight, value) {
|
|
90
|
+
return new MapEdge(src, dest, weight, value);
|
|
109
91
|
}
|
|
110
92
|
}
|
|
111
93
|
exports.MapGraph = MapGraph;
|
|
@@ -6,12 +6,13 @@ 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
|
+
vertices: [VertexKey, VertexKey];
|
|
15
16
|
/**
|
|
16
17
|
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
17
18
|
* value.
|
|
@@ -19,13 +20,10 @@ export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
|
|
|
19
20
|
* @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
|
|
20
21
|
* graph edge.
|
|
21
22
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
22
|
-
* @param {E} [
|
|
23
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store a value associated
|
|
23
24
|
* with the edge.
|
|
24
25
|
*/
|
|
25
|
-
constructor(v1: VertexKey, v2: VertexKey, weight?: number,
|
|
26
|
-
private _vertices;
|
|
27
|
-
get vertices(): [VertexKey, VertexKey];
|
|
28
|
-
set vertices(v: [VertexKey, VertexKey]);
|
|
26
|
+
constructor(v1: VertexKey, v2: VertexKey, weight?: number, value?: E);
|
|
29
27
|
}
|
|
30
28
|
export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVertex<V> = UndirectedVertex<V>, EO extends UndirectedEdge<E> = UndirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
|
|
31
29
|
/**
|
|
@@ -38,32 +36,32 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
38
36
|
* The function creates a new vertex with an optional value and returns it.
|
|
39
37
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
40
38
|
* vertex from another in the graph.
|
|
41
|
-
* @param [
|
|
39
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
42
40
|
* 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
41
|
* the vertex.
|
|
44
42
|
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `VO`.
|
|
45
43
|
*/
|
|
46
|
-
createVertex(key: VertexKey,
|
|
44
|
+
createVertex(key: VertexKey, value?: VO['value']): VO;
|
|
47
45
|
/**
|
|
48
46
|
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
49
47
|
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
50
48
|
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
51
49
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
52
50
|
* no weight is provided, it defaults to 1.
|
|
53
|
-
* @param [
|
|
51
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
54
52
|
* is used to store additional information or data associated with the edge.
|
|
55
53
|
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `EO`.
|
|
56
54
|
*/
|
|
57
|
-
createEdge(v1: VertexKey, v2: VertexKey, weight?: number,
|
|
55
|
+
createEdge(v1: VertexKey, v2: VertexKey, weight?: number, value?: EO['value']): EO;
|
|
58
56
|
/**
|
|
59
57
|
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
60
|
-
* @param {VO |
|
|
58
|
+
* @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
61
59
|
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
62
|
-
* @param {VO |
|
|
60
|
+
* @param {VO | VertexKey | null} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
63
61
|
* object), `null`, or `VertexKey` (vertex ID).
|
|
64
62
|
* @returns an edge (EO) or null.
|
|
65
63
|
*/
|
|
66
|
-
getEdge(v1: VO |
|
|
64
|
+
getEdge(v1: VO | VertexKey | null, v2: VO | VertexKey | null): EO | null;
|
|
67
65
|
/**
|
|
68
66
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
69
67
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
@@ -119,9 +117,4 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
119
117
|
* @returns a boolean value.
|
|
120
118
|
*/
|
|
121
119
|
protected _addEdgeOnly(edge: EO): boolean;
|
|
122
|
-
/**
|
|
123
|
-
* The function sets the edges of a graph.
|
|
124
|
-
* @param v - A map where the keys are of type VO and the values are arrays of type EO.
|
|
125
|
-
*/
|
|
126
|
-
protected _setEdges(v: Map<VO, EO[]>): void;
|
|
127
120
|
}
|