data-structure-typed 1.35.1 → 1.40.0-rc
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/aa-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +527 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +323 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.d.ts +94 -0
- package/dist/data-structures/binary-tree/avl-tree.js +90 -3
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +46 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +36 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -0
- package/dist/data-structures/binary-tree/binary-tree.js +21 -0
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +133 -0
- package/dist/data-structures/binary-tree/bst.js +114 -0
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/index.d.ts +12 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
- package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
- package/dist/data-structures/binary-tree/segment-tree.js +45 -0
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +209 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +178 -0
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
- package/dist/data-structures/graph/abstract-graph.js +269 -4
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.d.ts +200 -0
- package/dist/data-structures/graph/directed-graph.js +167 -0
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/map-graph.d.ts +79 -0
- package/dist/data-structures/graph/map-graph.js +54 -0
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
- package/dist/data-structures/graph/undirected-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
- package/dist/data-structures/hash/coordinate-map.js +35 -0
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
- package/dist/data-structures/hash/coordinate-set.js +28 -0
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.d.ts +56 -0
- package/dist/data-structures/hash/hash-map.js +29 -1
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.d.ts +106 -0
- package/dist/data-structures/hash/hash-table.js +88 -6
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/index.d.ts +7 -0
- package/dist/data-structures/hash/pair.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/heap/heap.d.ts +83 -0
- package/dist/data-structures/heap/heap.js +62 -0
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/max-heap.d.ts +23 -0
- package/dist/data-structures/heap/max-heap.js +16 -0
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.d.ts +24 -0
- package/dist/data-structures/heap/min-heap.js +17 -0
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +202 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +135 -0
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +36 -0
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +15 -0
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
- package/dist/data-structures/matrix/matrix2d.js +91 -2
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +28 -0
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.d.ts +201 -0
- package/dist/data-structures/matrix/vector2d.js +188 -1
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +18 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +19 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.d.ts +180 -0
- package/dist/data-structures/priority-queue/priority-queue.js +141 -0
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.d.ts +165 -0
- package/dist/data-structures/queue/deque.js +124 -0
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/queue.d.ts +107 -0
- package/dist/data-structures/queue/queue.js +80 -0
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/stack.d.ts +63 -0
- package/dist/data-structures/stack/stack.js +50 -0
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/tree.d.ts +14 -0
- package/dist/data-structures/tree/tree.js +1 -0
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/trie.d.ts +61 -0
- package/dist/data-structures/trie/trie.js +36 -0
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/interfaces/abstract-binary-tree.d.ts +7 -0
- package/dist/interfaces/abstract-graph.d.ts +5 -0
- package/dist/interfaces/avl-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.d.ts +6 -0
- package/dist/interfaces/bst.d.ts +6 -0
- package/dist/interfaces/directed-graph.d.ts +3 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/index.d.ts +15 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/rb-tree.d.ts +6 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/tree-multiset.d.ts +6 -0
- package/dist/interfaces/undirected-graph.d.ts +3 -0
- package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
- package/dist/types/data-structures/abstract-binary-tree.js +6 -0
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/types/data-structures/abstract-graph.d.ts +11 -0
- package/dist/types/data-structures/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree.d.ts +4 -0
- package/dist/types/data-structures/bst.d.ts +13 -0
- package/dist/types/data-structures/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/hash.d.ts +1 -0
- package/dist/types/data-structures/heap.d.ts +3 -0
- package/dist/types/data-structures/index.d.ts +16 -0
- package/dist/types/data-structures/map-graph.d.ts +1 -0
- package/dist/types/data-structures/navigator.d.ts +14 -0
- package/dist/types/data-structures/priority-queue.d.ts +7 -0
- package/dist/types/data-structures/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/tree-multiset.d.ts +4 -0
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/utils.d.ts +19 -0
- package/package.json +10 -6
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
|
|
2
|
+
import type { VertexKey } from '../../types';
|
|
3
|
+
import { IDirectedGraph } from '../../interfaces';
|
|
4
|
+
export declare class DirectedVertex<V = any> extends AbstractVertex<V> {
|
|
5
|
+
/**
|
|
6
|
+
* The constructor function initializes a vertex with an optional value.
|
|
7
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
8
|
+
* used to uniquely identify the vertex within a graph or data structure.
|
|
9
|
+
* @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
10
|
+
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
11
|
+
*/
|
|
12
|
+
constructor(key: VertexKey, val?: V);
|
|
13
|
+
}
|
|
14
|
+
export declare class DirectedEdge<V = any> extends AbstractEdge<V> {
|
|
15
|
+
/**
|
|
16
|
+
* The constructor function initializes the source and destination vertices of an edge, along with an optional weight
|
|
17
|
+
* and value.
|
|
18
|
+
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
19
|
+
* a graph.
|
|
20
|
+
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
21
|
+
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
|
|
22
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
23
|
+
* @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value associated with
|
|
24
|
+
* the edge.
|
|
25
|
+
*/
|
|
26
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: V);
|
|
27
|
+
private _src;
|
|
28
|
+
get src(): VertexKey;
|
|
29
|
+
set src(v: VertexKey);
|
|
30
|
+
private _dest;
|
|
31
|
+
get dest(): VertexKey;
|
|
32
|
+
set dest(v: VertexKey);
|
|
33
|
+
}
|
|
34
|
+
export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVertex, E extends DirectedEdge<any> = DirectedEdge> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
|
|
35
|
+
/**
|
|
36
|
+
* The constructor function initializes an instance of a class.
|
|
37
|
+
*/
|
|
38
|
+
constructor();
|
|
39
|
+
private _outEdgeMap;
|
|
40
|
+
get outEdgeMap(): Map<V, E[]>;
|
|
41
|
+
private _inEdgeMap;
|
|
42
|
+
get inEdgeMap(): Map<V, E[]>;
|
|
43
|
+
/**
|
|
44
|
+
* 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.
|
|
45
|
+
* 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.
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* The function creates a new vertex with an optional value and returns it.
|
|
49
|
+
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
50
|
+
* could be a number or a string depending on how you want to identify your vertices.
|
|
51
|
+
* @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
52
|
+
* it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
|
|
53
|
+
* assigned the same value as the 'key' parameter
|
|
54
|
+
* @returns a new instance of a DirectedVertex object, casted as type V.
|
|
55
|
+
*/
|
|
56
|
+
createVertex(key: VertexKey, val?: V['val']): V;
|
|
57
|
+
/**
|
|
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
|
+
* 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.
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* The function creates a directed edge between two vertices with an optional weight and value.
|
|
63
|
+
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
64
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
65
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
66
|
+
* weight is provided, it defaults to 1.
|
|
67
|
+
* @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
68
|
+
* is used to store additional information or data associated with the edge.
|
|
69
|
+
* @returns a new instance of a DirectedEdge object, casted as type E.
|
|
70
|
+
*/
|
|
71
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E;
|
|
72
|
+
/**
|
|
73
|
+
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
74
|
+
* @param {V | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
75
|
+
* @param {V | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
76
|
+
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexKey`), or `null` if the
|
|
77
|
+
* destination is not specified.
|
|
78
|
+
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
79
|
+
*/
|
|
80
|
+
getEdge(srcOrKey: V | null | VertexKey, destOrKey: V | null | VertexKey): E | null;
|
|
81
|
+
/**
|
|
82
|
+
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
83
|
+
* @param {V | VertexKey} srcOrKey - The source vertex or its ID.
|
|
84
|
+
* @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
85
|
+
* @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
|
|
86
|
+
*/
|
|
87
|
+
removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
|
|
88
|
+
/**
|
|
89
|
+
* The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
|
|
90
|
+
* @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
91
|
+
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
92
|
+
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
93
|
+
*/
|
|
94
|
+
removeEdge(edge: E): E | null;
|
|
95
|
+
/**
|
|
96
|
+
* The function removes edges between two vertices and returns the removed edges.
|
|
97
|
+
* @param {VertexKey | V} v1 - The parameter `v1` can be either a `VertexKey` or a `V`. A `VertexKey` represents the
|
|
98
|
+
* unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
|
|
99
|
+
* @param {VertexKey | V} v2 - The parameter `v2` represents either a `VertexKey` or a `V` object. It is used to specify
|
|
100
|
+
* the second vertex in the edge that needs to be removed.
|
|
101
|
+
* @returns an array of removed edges (E[]).
|
|
102
|
+
*/
|
|
103
|
+
removeEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[];
|
|
104
|
+
/**
|
|
105
|
+
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
106
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
107
|
+
* (`VertexKey`).
|
|
108
|
+
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
|
|
109
|
+
*/
|
|
110
|
+
incomingEdgesOf(vertexOrKey: V | VertexKey): E[];
|
|
111
|
+
/**
|
|
112
|
+
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
113
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`V`) or a vertex ID
|
|
114
|
+
* (`VertexKey`).
|
|
115
|
+
* @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
|
|
116
|
+
*/
|
|
117
|
+
outgoingEdgesOf(vertexOrKey: V | VertexKey): E[];
|
|
118
|
+
/**
|
|
119
|
+
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
|
|
120
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
121
|
+
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
122
|
+
*/
|
|
123
|
+
degreeOf(vertexOrKey: VertexKey | V): number;
|
|
124
|
+
/**
|
|
125
|
+
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
|
|
126
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
127
|
+
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
128
|
+
*/
|
|
129
|
+
inDegreeOf(vertexOrKey: VertexKey | V): number;
|
|
130
|
+
/**
|
|
131
|
+
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
|
|
132
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
133
|
+
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
134
|
+
*/
|
|
135
|
+
outDegreeOf(vertexOrKey: VertexKey | V): number;
|
|
136
|
+
/**
|
|
137
|
+
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
|
|
138
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
139
|
+
* @returns The function `edgesOf` returns an array of edges.
|
|
140
|
+
*/
|
|
141
|
+
edgesOf(vertexOrKey: VertexKey | V): E[];
|
|
142
|
+
/**
|
|
143
|
+
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
|
|
144
|
+
* @param {E} e - The parameter "e" is of type E, which represents an edge in a graph.
|
|
145
|
+
* @returns either a vertex object (V) or null.
|
|
146
|
+
*/
|
|
147
|
+
getEdgeSrc(e: E): V | null;
|
|
148
|
+
/**
|
|
149
|
+
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
150
|
+
* @param {E} e - The parameter "e" is of type "E", which represents an edge in a graph.
|
|
151
|
+
* @returns either a vertex object of type V or null.
|
|
152
|
+
*/
|
|
153
|
+
getEdgeDest(e: E): V | null;
|
|
154
|
+
/**
|
|
155
|
+
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
156
|
+
* @param {V | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
157
|
+
* find the destinations. It can be either a `V` object, a `VertexKey` value, or `null`.
|
|
158
|
+
* @returns an array of vertices (V[]).
|
|
159
|
+
*/
|
|
160
|
+
getDestinations(vertex: V | VertexKey | null): V[];
|
|
161
|
+
/**
|
|
162
|
+
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
|
|
163
|
+
* in the sorted order, or null if the graph contains a cycle.
|
|
164
|
+
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
165
|
+
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
|
|
166
|
+
* specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
|
|
167
|
+
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
|
|
168
|
+
*/
|
|
169
|
+
topologicalSort(propertyName?: 'vertex' | 'key'): Array<V | VertexKey> | null;
|
|
170
|
+
/**
|
|
171
|
+
* The `edgeSet` function returns an array of all the edges in the graph.
|
|
172
|
+
* @returns The `edgeSet()` method returns an array of edges (`E[]`).
|
|
173
|
+
*/
|
|
174
|
+
edgeSet(): E[];
|
|
175
|
+
/**
|
|
176
|
+
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
|
|
177
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
178
|
+
* (`VertexKey`).
|
|
179
|
+
* @returns an array of vertices (V[]).
|
|
180
|
+
*/
|
|
181
|
+
getNeighbors(vertexOrKey: V | VertexKey): V[];
|
|
182
|
+
/**
|
|
183
|
+
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
184
|
+
* otherwise it returns null.
|
|
185
|
+
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph.
|
|
186
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
|
|
187
|
+
* graph. If the edge does not exist, it returns `null`.
|
|
188
|
+
*/
|
|
189
|
+
getEndsOfEdge(edge: E): [V, V] | null;
|
|
190
|
+
/**
|
|
191
|
+
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
|
|
192
|
+
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph. It is the edge that
|
|
193
|
+
* needs to be added to the graph.
|
|
194
|
+
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
195
|
+
* source or destination vertex does not exist in the graph.
|
|
196
|
+
*/
|
|
197
|
+
protected _addEdgeOnly(edge: E): boolean;
|
|
198
|
+
protected _setOutEdgeMap(value: Map<V, E[]>): void;
|
|
199
|
+
protected _setInEdgeMap(value: Map<V, E[]>): void;
|
|
200
|
+
}
|
|
@@ -1,15 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DirectedGraph = exports.DirectedEdge = exports.DirectedVertex = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
10
|
+
*/
|
|
4
11
|
const utils_1 = require("../../utils");
|
|
5
12
|
const abstract_graph_1 = require("./abstract-graph");
|
|
6
13
|
class DirectedVertex extends abstract_graph_1.AbstractVertex {
|
|
14
|
+
/**
|
|
15
|
+
* The constructor function initializes a vertex with an optional value.
|
|
16
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
17
|
+
* used to uniquely identify the vertex within a graph or data structure.
|
|
18
|
+
* @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
19
|
+
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
20
|
+
*/
|
|
7
21
|
constructor(key, val) {
|
|
8
22
|
super(key, val);
|
|
9
23
|
}
|
|
10
24
|
}
|
|
11
25
|
exports.DirectedVertex = DirectedVertex;
|
|
12
26
|
class DirectedEdge extends abstract_graph_1.AbstractEdge {
|
|
27
|
+
/**
|
|
28
|
+
* The constructor function initializes the source and destination vertices of an edge, along with an optional weight
|
|
29
|
+
* and value.
|
|
30
|
+
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
31
|
+
* a graph.
|
|
32
|
+
* @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
33
|
+
* `VertexKey`, which is likely a unique identifier for a vertex in a graph.
|
|
34
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
35
|
+
* @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value associated with
|
|
36
|
+
* the edge.
|
|
37
|
+
*/
|
|
13
38
|
constructor(src, dest, weight, val) {
|
|
14
39
|
super(weight, val);
|
|
15
40
|
this._src = src;
|
|
@@ -30,6 +55,9 @@ class DirectedEdge extends abstract_graph_1.AbstractEdge {
|
|
|
30
55
|
}
|
|
31
56
|
exports.DirectedEdge = DirectedEdge;
|
|
32
57
|
class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
58
|
+
/**
|
|
59
|
+
* The constructor function initializes an instance of a class.
|
|
60
|
+
*/
|
|
33
61
|
constructor() {
|
|
34
62
|
super();
|
|
35
63
|
this._outEdgeMap = new Map();
|
|
@@ -41,12 +69,47 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
41
69
|
get inEdgeMap() {
|
|
42
70
|
return this._inEdgeMap;
|
|
43
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* 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.
|
|
74
|
+
* 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.
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* The function creates a new vertex with an optional value and returns it.
|
|
78
|
+
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
79
|
+
* could be a number or a string depending on how you want to identify your vertices.
|
|
80
|
+
* @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
81
|
+
* it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
|
|
82
|
+
* assigned the same value as the 'key' parameter
|
|
83
|
+
* @returns a new instance of a DirectedVertex object, casted as type V.
|
|
84
|
+
*/
|
|
44
85
|
createVertex(key, val) {
|
|
45
86
|
return new DirectedVertex(key, val !== null && val !== void 0 ? val : key);
|
|
46
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* 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.
|
|
90
|
+
* 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.
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
* The function creates a directed edge between two vertices with an optional weight and value.
|
|
94
|
+
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
95
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
96
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
97
|
+
* weight is provided, it defaults to 1.
|
|
98
|
+
* @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
99
|
+
* is used to store additional information or data associated with the edge.
|
|
100
|
+
* @returns a new instance of a DirectedEdge object, casted as type E.
|
|
101
|
+
*/
|
|
47
102
|
createEdge(src, dest, weight, val) {
|
|
48
103
|
return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1, val);
|
|
49
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
107
|
+
* @param {V | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
108
|
+
* @param {V | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
109
|
+
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexKey`), or `null` if the
|
|
110
|
+
* destination is not specified.
|
|
111
|
+
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
112
|
+
*/
|
|
50
113
|
getEdge(srcOrKey, destOrKey) {
|
|
51
114
|
let edges = [];
|
|
52
115
|
if (srcOrKey !== null && destOrKey !== null) {
|
|
@@ -61,6 +124,12 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
61
124
|
}
|
|
62
125
|
return edges[0] || null;
|
|
63
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
129
|
+
* @param {V | VertexKey} srcOrKey - The source vertex or its ID.
|
|
130
|
+
* @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
131
|
+
* @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
|
|
132
|
+
*/
|
|
64
133
|
removeEdgeSrcToDest(srcOrKey, destOrKey) {
|
|
65
134
|
const src = this._getVertex(srcOrKey);
|
|
66
135
|
const dest = this._getVertex(destOrKey);
|
|
@@ -78,6 +147,12 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
78
147
|
}
|
|
79
148
|
return removed;
|
|
80
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
|
|
152
|
+
* @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
153
|
+
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
154
|
+
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
155
|
+
*/
|
|
81
156
|
removeEdge(edge) {
|
|
82
157
|
let removed = null;
|
|
83
158
|
const src = this._getVertex(edge.src);
|
|
@@ -94,6 +169,14 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
94
169
|
}
|
|
95
170
|
return removed;
|
|
96
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* The function removes edges between two vertices and returns the removed edges.
|
|
174
|
+
* @param {VertexKey | V} v1 - The parameter `v1` can be either a `VertexKey` or a `V`. A `VertexKey` represents the
|
|
175
|
+
* unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
|
|
176
|
+
* @param {VertexKey | V} v2 - The parameter `v2` represents either a `VertexKey` or a `V` object. It is used to specify
|
|
177
|
+
* the second vertex in the edge that needs to be removed.
|
|
178
|
+
* @returns an array of removed edges (E[]).
|
|
179
|
+
*/
|
|
97
180
|
removeEdgesBetween(v1, v2) {
|
|
98
181
|
const removed = [];
|
|
99
182
|
if (v1 && v2) {
|
|
@@ -104,6 +187,12 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
104
187
|
}
|
|
105
188
|
return removed;
|
|
106
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
192
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
193
|
+
* (`VertexKey`).
|
|
194
|
+
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
|
|
195
|
+
*/
|
|
107
196
|
incomingEdgesOf(vertexOrKey) {
|
|
108
197
|
const target = this._getVertex(vertexOrKey);
|
|
109
198
|
if (target) {
|
|
@@ -111,6 +200,12 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
111
200
|
}
|
|
112
201
|
return [];
|
|
113
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
205
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`V`) or a vertex ID
|
|
206
|
+
* (`VertexKey`).
|
|
207
|
+
* @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
|
|
208
|
+
*/
|
|
114
209
|
outgoingEdgesOf(vertexOrKey) {
|
|
115
210
|
const target = this._getVertex(vertexOrKey);
|
|
116
211
|
if (target) {
|
|
@@ -118,24 +213,60 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
118
213
|
}
|
|
119
214
|
return [];
|
|
120
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
|
|
218
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
219
|
+
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
220
|
+
*/
|
|
121
221
|
degreeOf(vertexOrKey) {
|
|
122
222
|
return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
|
|
123
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
|
|
226
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
227
|
+
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
228
|
+
*/
|
|
124
229
|
inDegreeOf(vertexOrKey) {
|
|
125
230
|
return this.incomingEdgesOf(vertexOrKey).length;
|
|
126
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
|
|
234
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
235
|
+
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
236
|
+
*/
|
|
127
237
|
outDegreeOf(vertexOrKey) {
|
|
128
238
|
return this.outgoingEdgesOf(vertexOrKey).length;
|
|
129
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
|
|
242
|
+
* @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
|
|
243
|
+
* @returns The function `edgesOf` returns an array of edges.
|
|
244
|
+
*/
|
|
130
245
|
edgesOf(vertexOrKey) {
|
|
131
246
|
return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
|
|
132
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
|
|
250
|
+
* @param {E} e - The parameter "e" is of type E, which represents an edge in a graph.
|
|
251
|
+
* @returns either a vertex object (V) or null.
|
|
252
|
+
*/
|
|
133
253
|
getEdgeSrc(e) {
|
|
134
254
|
return this._getVertex(e.src);
|
|
135
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
258
|
+
* @param {E} e - The parameter "e" is of type "E", which represents an edge in a graph.
|
|
259
|
+
* @returns either a vertex object of type V or null.
|
|
260
|
+
*/
|
|
136
261
|
getEdgeDest(e) {
|
|
137
262
|
return this._getVertex(e.dest);
|
|
138
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
266
|
+
* @param {V | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
267
|
+
* find the destinations. It can be either a `V` object, a `VertexKey` value, or `null`.
|
|
268
|
+
* @returns an array of vertices (V[]).
|
|
269
|
+
*/
|
|
139
270
|
getDestinations(vertex) {
|
|
140
271
|
if (vertex === null) {
|
|
141
272
|
return [];
|
|
@@ -150,8 +281,18 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
150
281
|
}
|
|
151
282
|
return destinations;
|
|
152
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
|
|
286
|
+
* in the sorted order, or null if the graph contains a cycle.
|
|
287
|
+
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
288
|
+
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
|
|
289
|
+
* specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
|
|
290
|
+
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
|
|
291
|
+
*/
|
|
153
292
|
topologicalSort(propertyName) {
|
|
154
293
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
294
|
+
// When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
|
|
295
|
+
// When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
|
|
155
296
|
const statusMap = new Map();
|
|
156
297
|
for (const entry of this.vertices) {
|
|
157
298
|
statusMap.set(entry[1], 0);
|
|
@@ -184,6 +325,10 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
184
325
|
sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
|
|
185
326
|
return sorted.reverse();
|
|
186
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* The `edgeSet` function returns an array of all the edges in the graph.
|
|
330
|
+
* @returns The `edgeSet()` method returns an array of edges (`E[]`).
|
|
331
|
+
*/
|
|
187
332
|
edgeSet() {
|
|
188
333
|
let edges = [];
|
|
189
334
|
this._outEdgeMap.forEach(outEdges => {
|
|
@@ -191,6 +336,12 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
191
336
|
});
|
|
192
337
|
return edges;
|
|
193
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
|
|
341
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
342
|
+
* (`VertexKey`).
|
|
343
|
+
* @returns an array of vertices (V[]).
|
|
344
|
+
*/
|
|
194
345
|
getNeighbors(vertexOrKey) {
|
|
195
346
|
const neighbors = [];
|
|
196
347
|
const vertex = this._getVertex(vertexOrKey);
|
|
@@ -198,6 +349,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
198
349
|
const outEdges = this.outgoingEdgesOf(vertex);
|
|
199
350
|
for (const outEdge of outEdges) {
|
|
200
351
|
const neighbor = this._getVertex(outEdge.dest);
|
|
352
|
+
// TODO after no-non-null-assertion not ensure the logic
|
|
201
353
|
if (neighbor) {
|
|
202
354
|
neighbors.push(neighbor);
|
|
203
355
|
}
|
|
@@ -205,6 +357,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
205
357
|
}
|
|
206
358
|
return neighbors;
|
|
207
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
362
|
+
* otherwise it returns null.
|
|
363
|
+
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph.
|
|
364
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
|
|
365
|
+
* graph. If the edge does not exist, it returns `null`.
|
|
366
|
+
*/
|
|
208
367
|
getEndsOfEdge(edge) {
|
|
209
368
|
if (!this.hasEdge(edge.src, edge.dest)) {
|
|
210
369
|
return null;
|
|
@@ -218,12 +377,20 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
218
377
|
return null;
|
|
219
378
|
}
|
|
220
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
|
|
382
|
+
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph. It is the edge that
|
|
383
|
+
* needs to be added to the graph.
|
|
384
|
+
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
385
|
+
* source or destination vertex does not exist in the graph.
|
|
386
|
+
*/
|
|
221
387
|
_addEdgeOnly(edge) {
|
|
222
388
|
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
223
389
|
return false;
|
|
224
390
|
}
|
|
225
391
|
const srcVertex = this._getVertex(edge.src);
|
|
226
392
|
const destVertex = this._getVertex(edge.dest);
|
|
393
|
+
// TODO after no-non-null-assertion not ensure the logic
|
|
227
394
|
if (srcVertex && destVertex) {
|
|
228
395
|
const srcOutEdges = this._outEdgeMap.get(srcVertex);
|
|
229
396
|
if (srcOutEdges) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directed-graph.js","sourceRoot":"","sources":["../../../src/data-structures/graph/directed-graph.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"directed-graph.js","sourceRoot":"","sources":["../../../src/data-structures/graph/directed-graph.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,uCAAwC;AACxC,qDAA6E;AAI7E,MAAa,cAAwB,SAAQ,+BAAiB;IAC5D;;;;;;OAMG;IACH,YAAY,GAAc,EAAE,GAAO;QACjC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,CAAC;CACF;AAXD,wCAWC;AAED,MAAa,YAAsB,SAAQ,6BAAe;IACxD;;;;;;;;;;OAUG;IACH,YAAY,GAAc,EAAE,IAAe,EAAE,MAAe,EAAE,GAAO;QACnE,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAID,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,GAAG,CAAC,CAAY;QAClB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAChB,CAAC;IAID,IAAI,IAAI;QACN,OAAO,I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C,CAAC;aACxB;iBAAM;gBACL,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;aACzC;YAED,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACpD,IAAI,WAAW,EAAE;gBACf,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACxB;iBAAM;gBACL,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;aACzC;YACD,OAAO,IAAI,CAAC;SACb;aAAM;YACL,OAAO,KAAK,CAAC;SACd;IACH,CAAC;IAES,cAAc,CAAC,KAAkB;QACzC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAES,aAAa,CAAC,KAAkB;QACxC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1B,CAAC;CACF;AArZD,sCAqZC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { MapGraphCoordinate, VertexKey } from '../../types';
|
|
2
|
+
import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
|
|
3
|
+
export declare class MapVertex<V = any> extends DirectedVertex<V> {
|
|
4
|
+
/**
|
|
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
|
+
* @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
|
|
8
|
+
* that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
|
|
9
|
+
* values representing points north of the equator and negative values representing points south of the equator.
|
|
10
|
+
* @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
|
|
11
|
+
* coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
|
|
12
|
+
* values ranging from -180 to 180.
|
|
13
|
+
* @param {V} [val] - The "val" parameter is an optional value of type V. It is not required to be provided when
|
|
14
|
+
* creating an instance of the class.
|
|
15
|
+
*/
|
|
16
|
+
constructor(key: VertexKey, lat: number, long: number, val?: V);
|
|
17
|
+
private _lat;
|
|
18
|
+
get lat(): number;
|
|
19
|
+
set lat(value: number);
|
|
20
|
+
private _long;
|
|
21
|
+
get long(): number;
|
|
22
|
+
set long(value: number);
|
|
23
|
+
}
|
|
24
|
+
export declare class MapEdge<V = any> extends DirectedEdge<V> {
|
|
25
|
+
/**
|
|
26
|
+
* The constructor function initializes a new instance of a class with the given source, destination, weight, and
|
|
27
|
+
* value.
|
|
28
|
+
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
29
|
+
* a graph.
|
|
30
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
31
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
32
|
+
* @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store additional
|
|
33
|
+
* information or data associated with the edge.
|
|
34
|
+
*/
|
|
35
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: V);
|
|
36
|
+
}
|
|
37
|
+
export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E extends MapEdge = MapEdge> extends DirectedGraph<V, E> {
|
|
38
|
+
/**
|
|
39
|
+
* The constructor function initializes the origin and bottomRight properties of a MapGraphCoordinate object.
|
|
40
|
+
* @param {MapGraphCoordinate} origin - The `origin` parameter is a `MapGraphCoordinate` object that represents the
|
|
41
|
+
* starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
|
|
42
|
+
* graph.
|
|
43
|
+
* @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
|
|
44
|
+
* `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
|
|
45
|
+
* it will default to `undefined`.
|
|
46
|
+
*/
|
|
47
|
+
constructor(origin: MapGraphCoordinate, bottomRight?: MapGraphCoordinate);
|
|
48
|
+
private _origin;
|
|
49
|
+
get origin(): MapGraphCoordinate;
|
|
50
|
+
set origin(value: MapGraphCoordinate);
|
|
51
|
+
private _bottomRight;
|
|
52
|
+
get bottomRight(): MapGraphCoordinate | undefined;
|
|
53
|
+
set bottomRight(value: MapGraphCoordinate | undefined);
|
|
54
|
+
/**
|
|
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
|
+
* be a string or a number depending on how you define it in your code.
|
|
58
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It
|
|
59
|
+
* is of type `V['val']`, which means it should be of the same type as the `val` property of the vertex class `V`.
|
|
60
|
+
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
|
|
61
|
+
* position of the vertex on the Earth's surface in the north-south direction.
|
|
62
|
+
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
63
|
+
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
|
|
64
|
+
*/
|
|
65
|
+
createVertex(key: VertexKey, val?: V['val'], lat?: number, long?: number): V;
|
|
66
|
+
/**
|
|
67
|
+
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
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
|
+
* created.
|
|
71
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
72
|
+
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
73
|
+
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
74
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type,
|
|
75
|
+
* depending on the specific implementation of the `MapEdge` class.
|
|
76
|
+
* @returns a new instance of the `MapEdge` class, casted as type `E`.
|
|
77
|
+
*/
|
|
78
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E;
|
|
79
|
+
}
|