data-structure-typed 1.18.5 → 1.18.7
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/abstract-binary-tree.d.ts +357 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +1480 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +8 -6
- package/dist/data-structures/binary-tree/avl-tree.js +7 -5
- package/dist/data-structures/binary-tree/binary-tree.d.ts +19 -337
- package/dist/data-structures/binary-tree/binary-tree.js +40 -1441
- package/dist/data-structures/binary-tree/bst.d.ts +31 -17
- package/dist/data-structures/binary-tree/bst.js +57 -40
- package/dist/data-structures/binary-tree/index.d.ts +1 -0
- package/dist/data-structures/binary-tree/index.js +1 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +30 -1
- package/dist/data-structures/binary-tree/rb-tree.js +29 -20
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +21 -25
- package/dist/data-structures/binary-tree/tree-multiset.js +40 -31
- package/dist/data-structures/graph/abstract-graph.d.ts +20 -21
- package/dist/data-structures/graph/abstract-graph.js +24 -19
- package/dist/data-structures/graph/directed-graph.d.ts +12 -13
- package/dist/data-structures/graph/directed-graph.js +21 -25
- package/dist/data-structures/graph/undirected-graph.d.ts +15 -19
- package/dist/data-structures/graph/undirected-graph.js +16 -29
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +101 -0
- package/dist/data-structures/interfaces/abstract-binary-tree.js +2 -0
- package/dist/data-structures/interfaces/abstract-graph.d.ts +1 -4
- package/dist/data-structures/interfaces/avl-tree.d.ts +16 -1
- package/dist/data-structures/interfaces/binary-tree.d.ts +4 -25
- package/dist/data-structures/interfaces/bst.d.ts +18 -1
- package/dist/data-structures/interfaces/directed-graph.d.ts +4 -1
- package/dist/data-structures/interfaces/index.d.ts +1 -1
- package/dist/data-structures/interfaces/index.js +1 -1
- package/dist/data-structures/interfaces/rb-tree.d.ts +9 -0
- package/dist/data-structures/interfaces/rb-tree.js +2 -0
- package/dist/data-structures/interfaces/undirected-graph.d.ts +4 -1
- package/dist/data-structures/types/abstract-binary-tree.d.ts +32 -0
- package/dist/data-structures/types/abstract-binary-tree.js +21 -0
- package/dist/data-structures/types/avl-tree.d.ts +2 -4
- package/dist/data-structures/types/binary-tree.d.ts +2 -10
- package/dist/data-structures/types/bst.d.ts +10 -5
- package/dist/data-structures/types/bst.js +7 -0
- package/dist/data-structures/types/helpers.d.ts +8 -0
- package/dist/data-structures/types/helpers.js +2 -0
- package/dist/data-structures/types/index.d.ts +3 -0
- package/dist/data-structures/types/index.js +3 -0
- package/dist/data-structures/types/rb-tree.d.ts +6 -0
- package/dist/data-structures/types/rb-tree.js +8 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -3
- package/dist/utils/utils.js +62 -0
- package/docs/assets/search.js +1 -1
- package/docs/classes/AVLTree.html +316 -204
- package/docs/classes/AVLTreeNode.html +141 -81
- package/docs/classes/AaTree.html +27 -10
- package/docs/classes/AbstractBinaryTree.html +2118 -0
- package/docs/classes/AbstractBinaryTreeNode.html +524 -0
- package/docs/classes/AbstractEdge.html +37 -20
- package/docs/classes/AbstractGraph.html +152 -144
- package/docs/classes/AbstractVertex.html +34 -17
- package/docs/classes/ArrayDeque.html +40 -23
- package/docs/classes/BST.html +294 -187
- package/docs/classes/BSTNode.html +144 -82
- package/docs/classes/BTree.html +27 -10
- package/docs/classes/BinaryIndexedTree.html +35 -18
- package/docs/classes/BinaryTree.html +597 -500
- package/docs/classes/BinaryTreeNode.html +189 -168
- package/docs/classes/Character.html +30 -13
- package/docs/classes/CoordinateMap.html +35 -18
- package/docs/classes/CoordinateSet.html +34 -17
- package/docs/classes/Deque.html +60 -43
- package/docs/classes/DirectedEdge.html +41 -24
- package/docs/classes/DirectedGraph.html +208 -247
- package/docs/classes/DirectedVertex.html +32 -15
- package/docs/classes/DoublyLinkedList.html +63 -46
- package/docs/classes/DoublyLinkedListNode.html +37 -20
- package/docs/classes/HashTable.html +27 -10
- package/docs/classes/Heap.html +41 -24
- package/docs/classes/HeapItem.html +34 -17
- package/docs/classes/Matrix2D.html +42 -25
- package/docs/classes/MatrixNTI2D.html +30 -13
- package/docs/classes/MaxHeap.html +41 -24
- package/docs/classes/MaxPriorityQueue.html +60 -43
- package/docs/classes/MinHeap.html +41 -24
- package/docs/classes/MinPriorityQueue.html +60 -43
- package/docs/classes/Navigator.html +36 -19
- package/docs/classes/ObjectDeque.html +51 -34
- package/docs/classes/Pair.html +27 -10
- package/docs/classes/PriorityQueue.html +58 -41
- package/docs/classes/Queue.html +40 -23
- package/docs/classes/RBTree.html +2388 -0
- package/docs/classes/RBTreeNode.html +516 -0
- package/docs/classes/SegmentTree.html +43 -26
- package/docs/classes/SegmentTreeNode.html +46 -29
- package/docs/classes/SinglyLinkedList.html +60 -43
- package/docs/classes/SinglyLinkedListNode.html +34 -17
- package/docs/classes/SkipLinkedList.html +27 -10
- package/docs/classes/SplayTree.html +27 -10
- package/docs/classes/Stack.html +38 -21
- package/docs/classes/TreeMap.html +27 -10
- package/docs/classes/TreeMultiSet.html +332 -224
- package/docs/classes/TreeMultiSetNode.html +499 -0
- package/docs/classes/TreeNode.html +42 -25
- package/docs/classes/TreeSet.html +27 -10
- package/docs/classes/Trie.html +39 -22
- package/docs/classes/TrieNode.html +37 -20
- package/docs/classes/TwoThreeTree.html +27 -10
- package/docs/classes/UndirectedEdge.html +38 -21
- package/docs/classes/UndirectedGraph.html +179 -227
- package/docs/classes/UndirectedVertex.html +32 -15
- package/docs/classes/Vector2D.html +54 -37
- package/docs/enums/CP.html +33 -16
- package/docs/enums/FamilyPosition.html +45 -28
- package/docs/enums/LoopType.html +39 -22
- package/docs/{interfaces/IBinaryTree.html → enums/RBColor.html} +51 -54
- package/docs/enums/TopologicalProperty.html +30 -13
- package/docs/index.html +26 -9
- package/docs/interfaces/IAVLTree.html +1378 -0
- package/docs/interfaces/IAVLTreeNode.html +405 -0
- package/docs/interfaces/IAbstractBinaryTree.html +1124 -0
- package/docs/interfaces/{IBinaryTreeNode.html → IAbstractBinaryTreeNode.html} +76 -75
- package/docs/interfaces/{IGraph.html → IAbstractGraph.html} +67 -94
- package/docs/interfaces/IBST.html +1271 -0
- package/docs/interfaces/IBSTNode.html +408 -0
- package/docs/interfaces/IDirectedGraph.html +344 -20
- package/docs/interfaces/IUNDirectedGraph.html +337 -12
- package/docs/modules.html +52 -18
- package/docs/types/{AVLTreeDeleted.html → AVLTreeOptions.html} +32 -24
- package/docs/types/{ResultsByProperty.html → AbstractBinaryTreeNodeProperties.html} +32 -15
- package/docs/types/AbstractBinaryTreeNodeProperty.html +152 -0
- package/docs/types/AbstractBinaryTreeOptions.html +156 -0
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +152 -0
- package/docs/types/BSTComparator.html +27 -10
- package/docs/types/{TreeMultiSetDeletedResult.html → BSTOptions.html} +32 -22
- package/docs/types/BinaryTreeDeletedResult.html +159 -0
- package/docs/types/BinaryTreeNodeId.html +27 -10
- package/docs/types/BinaryTreeNodePropertyName.html +27 -10
- package/docs/types/{BinaryTreeDeleted.html → BinaryTreeOptions.html} +32 -24
- package/docs/types/DFSOrderPattern.html +27 -10
- package/docs/types/DijkstraResult.html +27 -10
- package/docs/types/Direction.html +27 -10
- package/docs/types/EdgeId.html +27 -10
- package/docs/types/HeapOptions.html +27 -10
- package/docs/types/IdObject.html +157 -0
- package/docs/types/{ResultByProperty.html → KeyValObject.html} +36 -19
- package/docs/types/NavigatorParams.html +27 -10
- package/docs/types/NodeOrPropertyName.html +27 -10
- package/docs/types/PriorityQueueComparator.html +27 -10
- package/docs/types/PriorityQueueDFSOrderPattern.html +27 -10
- package/docs/types/PriorityQueueOptions.html +27 -10
- package/docs/types/{BSTDeletedResult.html → RBTreeOptions.html} +32 -24
- package/docs/types/RecursiveAVLTreeNode.html +27 -10
- package/docs/types/RecursiveBSTNode.html +27 -10
- package/docs/types/RecursiveBinaryTreeNode.html +27 -10
- package/docs/types/RecursiveTreeMultiSetNode.html +152 -0
- package/docs/types/SegmentTreeNodeVal.html +27 -10
- package/docs/types/TopologicalStatus.html +27 -10
- package/docs/types/TreeMultiSetOptions.html +152 -0
- package/docs/types/Turning.html +27 -10
- package/docs/types/VertexId.html +27 -10
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DijkstraResult, VertexId } from '../types';
|
|
2
|
-
import {
|
|
2
|
+
import { IAbstractGraph } from '../interfaces';
|
|
3
3
|
export declare abstract class AbstractVertex<T = number> {
|
|
4
4
|
protected constructor(id: VertexId, val?: T);
|
|
5
5
|
private _id;
|
|
@@ -21,7 +21,7 @@ export declare abstract class AbstractEdge<T = number> {
|
|
|
21
21
|
get hashCode(): string;
|
|
22
22
|
protected _setHashCode(v: string): void;
|
|
23
23
|
}
|
|
24
|
-
export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E extends AbstractEdge<any>> implements
|
|
24
|
+
export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E extends AbstractEdge<any>> implements IAbstractGraph<V, E> {
|
|
25
25
|
private _vertices;
|
|
26
26
|
get vertices(): Map<VertexId, V>;
|
|
27
27
|
/**
|
|
@@ -30,7 +30,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
30
30
|
* @param id
|
|
31
31
|
* @param val
|
|
32
32
|
*/
|
|
33
|
-
abstract
|
|
33
|
+
abstract createVertex(id: VertexId, val?: V): V;
|
|
34
34
|
/**
|
|
35
35
|
* 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.
|
|
36
36
|
* 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.
|
|
@@ -39,12 +39,9 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
39
39
|
* @param weight
|
|
40
40
|
* @param val
|
|
41
41
|
*/
|
|
42
|
-
abstract
|
|
43
|
-
abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
42
|
+
abstract createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
|
|
44
43
|
abstract removeEdge(edge: E): E | null;
|
|
45
|
-
_getVertex(vertexOrId: VertexId | V): V | null;
|
|
46
44
|
getVertex(vertexId: VertexId): V | null;
|
|
47
|
-
_getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
48
45
|
/**
|
|
49
46
|
* The function checks if a vertex exists in a graph.
|
|
50
47
|
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
|
|
@@ -179,11 +176,6 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
179
176
|
* @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
|
|
180
177
|
*/
|
|
181
178
|
dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
182
|
-
/**
|
|
183
|
-
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
|
|
184
|
-
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
|
|
185
|
-
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
186
|
-
*/
|
|
187
179
|
/**
|
|
188
180
|
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
189
181
|
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
@@ -214,10 +206,9 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
214
206
|
minPath: V[];
|
|
215
207
|
};
|
|
216
208
|
/**
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* The
|
|
220
|
-
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
209
|
+
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
|
|
210
|
+
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
|
|
211
|
+
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
221
212
|
*/
|
|
222
213
|
/**
|
|
223
214
|
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
@@ -234,11 +225,6 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
234
225
|
costs: number[][];
|
|
235
226
|
predecessor: (V | null)[][];
|
|
236
227
|
};
|
|
237
|
-
/**
|
|
238
|
-
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
239
|
-
* all pairs
|
|
240
|
-
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
241
|
-
*/
|
|
242
228
|
/**
|
|
243
229
|
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
|
|
244
230
|
* Tarjan can find cycles in directed or undirected graph
|
|
@@ -268,6 +254,19 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
268
254
|
SCCs: Map<number, V[]>;
|
|
269
255
|
cycles: Map<number, V[]>;
|
|
270
256
|
};
|
|
257
|
+
/**
|
|
258
|
+
* BellmanFord time:O(VE) space:O(V)
|
|
259
|
+
* one to rest pairs
|
|
260
|
+
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
261
|
+
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
262
|
+
*/
|
|
263
|
+
protected _getVertex(vertexOrId: VertexId | V): V | null;
|
|
264
|
+
/**
|
|
265
|
+
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
266
|
+
* all pairs
|
|
267
|
+
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
268
|
+
*/
|
|
269
|
+
protected _getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
271
270
|
/**--- start find cycles --- */
|
|
272
271
|
protected _setVertices(value: Map<VertexId, V>): void;
|
|
273
272
|
}
|
|
@@ -115,7 +115,7 @@ var AbstractEdge = /** @class */ (function () {
|
|
|
115
115
|
// * @param weight
|
|
116
116
|
// * @param val
|
|
117
117
|
// */
|
|
118
|
-
// abstract
|
|
118
|
+
// abstract createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
|
|
119
119
|
AbstractEdge.prototype._setHashCode = function (v) {
|
|
120
120
|
this._hashCode = v;
|
|
121
121
|
};
|
|
@@ -137,16 +137,9 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
137
137
|
enumerable: false,
|
|
138
138
|
configurable: true
|
|
139
139
|
});
|
|
140
|
-
AbstractGraph.prototype._getVertex = function (vertexOrId) {
|
|
141
|
-
var vertexId = this._getVertexId(vertexOrId);
|
|
142
|
-
return this._vertices.get(vertexId) || null;
|
|
143
|
-
};
|
|
144
140
|
AbstractGraph.prototype.getVertex = function (vertexId) {
|
|
145
141
|
return this._vertices.get(vertexId) || null;
|
|
146
142
|
};
|
|
147
|
-
AbstractGraph.prototype._getVertexId = function (vertexOrId) {
|
|
148
|
-
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
|
|
149
|
-
};
|
|
150
143
|
/**
|
|
151
144
|
* The function checks if a vertex exists in a graph.
|
|
152
145
|
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
|
|
@@ -157,7 +150,7 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
157
150
|
return this._vertices.has(this._getVertexId(vertexOrId));
|
|
158
151
|
};
|
|
159
152
|
AbstractGraph.prototype.createAddVertex = function (id, val) {
|
|
160
|
-
var newVertex = this.
|
|
153
|
+
var newVertex = this.createVertex(id, val);
|
|
161
154
|
return this.addVertex(newVertex);
|
|
162
155
|
};
|
|
163
156
|
AbstractGraph.prototype.addVertex = function (newVertex) {
|
|
@@ -221,7 +214,7 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
221
214
|
src = src.id;
|
|
222
215
|
if (dest instanceof AbstractVertex)
|
|
223
216
|
dest = dest.id;
|
|
224
|
-
var newEdge = this.
|
|
217
|
+
var newEdge = this.createEdge(src, dest, weight, val);
|
|
225
218
|
return this.addEdge(newEdge);
|
|
226
219
|
};
|
|
227
220
|
/**
|
|
@@ -892,10 +885,9 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
892
885
|
return { hasNegativeCycle: hasNegativeCycle, distMap: distMap, preMap: preMap, paths: paths, min: min, minPath: minPath };
|
|
893
886
|
};
|
|
894
887
|
/**
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
* The
|
|
898
|
-
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
888
|
+
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
|
|
889
|
+
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
|
|
890
|
+
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
899
891
|
*/
|
|
900
892
|
/**
|
|
901
893
|
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
@@ -939,11 +931,6 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
939
931
|
}
|
|
940
932
|
return { costs: costs, predecessor: predecessor };
|
|
941
933
|
};
|
|
942
|
-
/**
|
|
943
|
-
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
944
|
-
* all pairs
|
|
945
|
-
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
946
|
-
*/
|
|
947
934
|
/**
|
|
948
935
|
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
|
|
949
936
|
* Tarjan can find cycles in directed or undirected graph
|
|
@@ -1071,6 +1058,24 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
1071
1058
|
}
|
|
1072
1059
|
return { dfnMap: dfnMap, lowMap: lowMap, bridges: bridges, articulationPoints: articulationPoints, SCCs: SCCs, cycles: cycles };
|
|
1073
1060
|
};
|
|
1061
|
+
/**
|
|
1062
|
+
* BellmanFord time:O(VE) space:O(V)
|
|
1063
|
+
* one to rest pairs
|
|
1064
|
+
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
1065
|
+
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
1066
|
+
*/
|
|
1067
|
+
AbstractGraph.prototype._getVertex = function (vertexOrId) {
|
|
1068
|
+
var vertexId = this._getVertexId(vertexOrId);
|
|
1069
|
+
return this._vertices.get(vertexId) || null;
|
|
1070
|
+
};
|
|
1071
|
+
/**
|
|
1072
|
+
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
1073
|
+
* all pairs
|
|
1074
|
+
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
1075
|
+
*/
|
|
1076
|
+
AbstractGraph.prototype._getVertexId = function (vertexOrId) {
|
|
1077
|
+
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
|
|
1078
|
+
};
|
|
1074
1079
|
/**--- start find cycles --- */
|
|
1075
1080
|
AbstractGraph.prototype._setVertices = function (value) {
|
|
1076
1081
|
this._vertices = value;
|
|
@@ -32,10 +32,8 @@ export declare class DirectedEdge<T = number> extends AbstractEdge<T> {
|
|
|
32
32
|
get dest(): VertexId;
|
|
33
33
|
set dest(v: VertexId);
|
|
34
34
|
}
|
|
35
|
-
export declare class DirectedGraph<V extends DirectedVertex<any
|
|
36
|
-
|
|
37
|
-
private readonly _edgeConstructor;
|
|
38
|
-
constructor(vertexConstructor: new (id: VertexId, val?: V['val']) => V, edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E);
|
|
35
|
+
export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVertex, E extends DirectedEdge<any> = DirectedEdge> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
|
|
36
|
+
constructor();
|
|
39
37
|
private _outEdgeMap;
|
|
40
38
|
get outEdgeMap(): Map<V, E[]>;
|
|
41
39
|
private _inEdgeMap;
|
|
@@ -46,7 +44,7 @@ export declare class DirectedGraph<V extends DirectedVertex<any>, E extends Dire
|
|
|
46
44
|
* @param id
|
|
47
45
|
* @param val
|
|
48
46
|
*/
|
|
49
|
-
|
|
47
|
+
createVertex(id: VertexId, val?: V['val']): V;
|
|
50
48
|
/**
|
|
51
49
|
* 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.
|
|
52
50
|
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
@@ -55,7 +53,7 @@ export declare class DirectedGraph<V extends DirectedVertex<any>, E extends Dire
|
|
|
55
53
|
* @param weight
|
|
56
54
|
* @param val
|
|
57
55
|
*/
|
|
58
|
-
|
|
56
|
+
createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
|
|
59
57
|
/**
|
|
60
58
|
* The function `getEdge` returns the directed edge between two vertices, given their source and destination.
|
|
61
59
|
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a
|
|
@@ -83,7 +81,7 @@ export declare class DirectedGraph<V extends DirectedVertex<any>, E extends Dire
|
|
|
83
81
|
* @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
|
|
84
82
|
* the edge does not exist.
|
|
85
83
|
*/
|
|
86
|
-
|
|
84
|
+
removeEdgeSrcToDest(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
87
85
|
/**
|
|
88
86
|
* The `removeEdge` function removes a directed edge from a graph and returns the removed edge, or null if the edge was
|
|
89
87
|
* not found.
|
|
@@ -94,13 +92,14 @@ export declare class DirectedGraph<V extends DirectedVertex<any>, E extends Dire
|
|
|
94
92
|
*/
|
|
95
93
|
removeEdge(edge: E): E | null;
|
|
96
94
|
/**
|
|
97
|
-
* The function
|
|
98
|
-
* @param {VertexId | V}
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
95
|
+
* The function removes all edges between two vertices and returns the removed edges.
|
|
96
|
+
* @param {VertexId | V} v1 - The parameter `v1` represents either a `VertexId` or a `V` object. It is used to identify
|
|
97
|
+
* the first vertex in the graph.
|
|
98
|
+
* @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V`. It is used to identify the
|
|
99
|
+
* second vertex involved in the edges that need to be removed.
|
|
100
|
+
* @returns The function `removeEdgesBetween` returns an array of removed edges (`E[]`).
|
|
102
101
|
*/
|
|
103
|
-
|
|
102
|
+
removeEdgesBetween(v1: VertexId | V, v2: VertexId | V): E[];
|
|
104
103
|
/**
|
|
105
104
|
* The function returns an array of incoming edges of a given vertex or vertex ID.
|
|
106
105
|
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
|
|
@@ -122,12 +122,10 @@ exports.DirectedEdge = DirectedEdge;
|
|
|
122
122
|
// Strongly connected, One direction connected, Weakly connected
|
|
123
123
|
var DirectedGraph = /** @class */ (function (_super) {
|
|
124
124
|
__extends(DirectedGraph, _super);
|
|
125
|
-
function DirectedGraph(
|
|
125
|
+
function DirectedGraph() {
|
|
126
126
|
var _this = _super.call(this) || this;
|
|
127
127
|
_this._outEdgeMap = new Map();
|
|
128
128
|
_this._inEdgeMap = new Map();
|
|
129
|
-
_this._vertexConstructor = vertexConstructor;
|
|
130
|
-
_this._edgeConstructor = edgeConstructor;
|
|
131
129
|
return _this;
|
|
132
130
|
}
|
|
133
131
|
Object.defineProperty(DirectedGraph.prototype, "outEdgeMap", {
|
|
@@ -150,8 +148,8 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
150
148
|
* @param id
|
|
151
149
|
* @param val
|
|
152
150
|
*/
|
|
153
|
-
DirectedGraph.prototype.
|
|
154
|
-
return new
|
|
151
|
+
DirectedGraph.prototype.createVertex = function (id, val) {
|
|
152
|
+
return new DirectedVertex(id, val !== null && val !== void 0 ? val : id);
|
|
155
153
|
};
|
|
156
154
|
/**
|
|
157
155
|
* 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.
|
|
@@ -161,10 +159,8 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
161
159
|
* @param weight
|
|
162
160
|
* @param val
|
|
163
161
|
*/
|
|
164
|
-
DirectedGraph.prototype.
|
|
165
|
-
|
|
166
|
-
weight = 1;
|
|
167
|
-
return new this._edgeConstructor(src, dest, weight, val);
|
|
162
|
+
DirectedGraph.prototype.createEdge = function (src, dest, weight, val) {
|
|
163
|
+
return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1, val);
|
|
168
164
|
};
|
|
169
165
|
/**
|
|
170
166
|
* The function `getEdge` returns the directed edge between two vertices, given their source and destination.
|
|
@@ -233,7 +229,7 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
233
229
|
* @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
|
|
234
230
|
* the edge does not exist.
|
|
235
231
|
*/
|
|
236
|
-
DirectedGraph.prototype.
|
|
232
|
+
DirectedGraph.prototype.removeEdgeSrcToDest = function (srcOrId, destOrId) {
|
|
237
233
|
var src = this._getVertex(srcOrId);
|
|
238
234
|
var dest = this._getVertex(destOrId);
|
|
239
235
|
var removed = null;
|
|
@@ -242,14 +238,6 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
242
238
|
}
|
|
243
239
|
var srcOutEdges = this._outEdgeMap.get(src);
|
|
244
240
|
if (srcOutEdges) {
|
|
245
|
-
/**
|
|
246
|
-
* The removeEdge function removes an edge from a graph and returns the removed edge, or null if the edge was not
|
|
247
|
-
* found.
|
|
248
|
-
* @param {E} edge - The `edge` parameter represents the edge that you want to remove from the graph. It should be an
|
|
249
|
-
* object that has `src` and `dest` properties, which represent the source and destination vertices of the edge,
|
|
250
|
-
* respectively.
|
|
251
|
-
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
252
|
-
*/
|
|
253
241
|
(0, utils_1.arrayRemove)(srcOutEdges, function (edge) { return edge.dest === dest.id; });
|
|
254
242
|
}
|
|
255
243
|
var destInEdges = this._inEdgeMap.get(dest);
|
|
@@ -283,14 +271,22 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
283
271
|
return removed;
|
|
284
272
|
};
|
|
285
273
|
/**
|
|
286
|
-
* The function
|
|
287
|
-
* @param {VertexId | V}
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
274
|
+
* The function removes all edges between two vertices and returns the removed edges.
|
|
275
|
+
* @param {VertexId | V} v1 - The parameter `v1` represents either a `VertexId` or a `V` object. It is used to identify
|
|
276
|
+
* the first vertex in the graph.
|
|
277
|
+
* @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V`. It is used to identify the
|
|
278
|
+
* second vertex involved in the edges that need to be removed.
|
|
279
|
+
* @returns The function `removeEdgesBetween` returns an array of removed edges (`E[]`).
|
|
291
280
|
*/
|
|
292
|
-
DirectedGraph.prototype.
|
|
293
|
-
|
|
281
|
+
DirectedGraph.prototype.removeEdgesBetween = function (v1, v2) {
|
|
282
|
+
var removed = [];
|
|
283
|
+
if (v1 && v2) {
|
|
284
|
+
var v1ToV2 = this.removeEdgeSrcToDest(v1, v2);
|
|
285
|
+
var v2ToV1 = this.removeEdgeSrcToDest(v2, v1);
|
|
286
|
+
v1ToV2 && removed.push(v1ToV2);
|
|
287
|
+
v2ToV1 && removed.push(v2ToV1);
|
|
288
|
+
}
|
|
289
|
+
return removed;
|
|
294
290
|
};
|
|
295
291
|
/**
|
|
296
292
|
* The function returns an array of incoming edges of a given vertex or vertex ID.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
|
|
2
2
|
import type { VertexId } from '../types';
|
|
3
|
+
import { IUNDirectedGraph } from '../interfaces';
|
|
3
4
|
export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
|
|
4
5
|
/**
|
|
5
6
|
* The constructor function initializes a vertex with an optional value.
|
|
@@ -26,10 +27,8 @@ export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
|
|
|
26
27
|
get vertices(): [VertexId, VertexId];
|
|
27
28
|
set vertices(v: [VertexId, VertexId]);
|
|
28
29
|
}
|
|
29
|
-
export declare class UndirectedGraph<V extends UndirectedVertex<any
|
|
30
|
-
|
|
31
|
-
private readonly _edgeConstructor;
|
|
32
|
-
constructor(vertexConstructor: new (id: VertexId, val?: V['val']) => V, edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E);
|
|
30
|
+
export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E> {
|
|
31
|
+
constructor();
|
|
33
32
|
protected _edges: Map<V, E[]>;
|
|
34
33
|
get edges(): Map<V, E[]>;
|
|
35
34
|
/**
|
|
@@ -38,16 +37,20 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any>, E extends
|
|
|
38
37
|
* @param id
|
|
39
38
|
* @param val
|
|
40
39
|
*/
|
|
41
|
-
|
|
40
|
+
createVertex(id: VertexId, val?: V['val']): V;
|
|
42
41
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @param
|
|
47
|
-
*
|
|
48
|
-
* @param
|
|
42
|
+
* The function createEdge creates an undirected edge between two vertices with an optional weight and value.
|
|
43
|
+
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge. It is of type `VertexId`, which
|
|
44
|
+
* could be a unique identifier or label for the vertex.
|
|
45
|
+
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge. It is of type `VertexId`, which
|
|
46
|
+
* is typically a unique identifier for a vertex in a graph.
|
|
47
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
48
|
+
* weight is provided, the default value is 1.
|
|
49
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
50
|
+
* is used to store additional information or data associated with the edge.
|
|
51
|
+
* @returns an instance of the UndirectedEdge class, casted as type E.
|
|
49
52
|
*/
|
|
50
|
-
|
|
53
|
+
createEdge(v1: VertexId, v2: VertexId, weight?: number, val?: E['val']): E;
|
|
51
54
|
/**
|
|
52
55
|
* The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
|
|
53
56
|
* exists.
|
|
@@ -103,13 +106,6 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any>, E extends
|
|
|
103
106
|
* @returns The method `edgeSet()` returns an array of `E` objects.
|
|
104
107
|
*/
|
|
105
108
|
edgeSet(): E[];
|
|
106
|
-
/**
|
|
107
|
-
* The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
|
|
108
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either an
|
|
109
|
-
* `V` object or a `VertexId`.
|
|
110
|
-
* @returns The function `getEdgesOf` returns an array of `E` objects.
|
|
111
|
-
*/
|
|
112
|
-
getEdgesOf(vertexOrId: V | VertexId): E[];
|
|
113
109
|
/**
|
|
114
110
|
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
|
|
115
111
|
* @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
|
|
@@ -108,10 +108,8 @@ var UndirectedEdge = /** @class */ (function (_super) {
|
|
|
108
108
|
exports.UndirectedEdge = UndirectedEdge;
|
|
109
109
|
var UndirectedGraph = /** @class */ (function (_super) {
|
|
110
110
|
__extends(UndirectedGraph, _super);
|
|
111
|
-
function UndirectedGraph(
|
|
111
|
+
function UndirectedGraph() {
|
|
112
112
|
var _this = _super.call(this) || this;
|
|
113
|
-
_this._vertexConstructor = vertexConstructor;
|
|
114
|
-
_this._edgeConstructor = edgeConstructor;
|
|
115
113
|
_this._edges = new Map();
|
|
116
114
|
return _this;
|
|
117
115
|
}
|
|
@@ -128,21 +126,23 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
128
126
|
* @param id
|
|
129
127
|
* @param val
|
|
130
128
|
*/
|
|
131
|
-
UndirectedGraph.prototype.
|
|
132
|
-
return new
|
|
129
|
+
UndirectedGraph.prototype.createVertex = function (id, val) {
|
|
130
|
+
return new UndirectedVertex(id, val !== null && val !== void 0 ? val : id);
|
|
133
131
|
};
|
|
134
132
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* @param
|
|
139
|
-
*
|
|
140
|
-
* @param
|
|
133
|
+
* The function createEdge creates an undirected edge between two vertices with an optional weight and value.
|
|
134
|
+
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge. It is of type `VertexId`, which
|
|
135
|
+
* could be a unique identifier or label for the vertex.
|
|
136
|
+
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge. It is of type `VertexId`, which
|
|
137
|
+
* is typically a unique identifier for a vertex in a graph.
|
|
138
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
139
|
+
* weight is provided, the default value is 1.
|
|
140
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
141
|
+
* is used to store additional information or data associated with the edge.
|
|
142
|
+
* @returns an instance of the UndirectedEdge class, casted as type E.
|
|
141
143
|
*/
|
|
142
|
-
UndirectedGraph.prototype.
|
|
143
|
-
|
|
144
|
-
weight = 1;
|
|
145
|
-
return new this._edgeConstructor(src, dest, weight, val);
|
|
144
|
+
UndirectedGraph.prototype.createEdge = function (v1, v2, weight, val) {
|
|
145
|
+
return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, val);
|
|
146
146
|
};
|
|
147
147
|
/**
|
|
148
148
|
* The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
|
|
@@ -280,19 +280,6 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
280
280
|
});
|
|
281
281
|
return __spreadArray([], __read(edgeSet), false);
|
|
282
282
|
};
|
|
283
|
-
/**
|
|
284
|
-
* The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
|
|
285
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either an
|
|
286
|
-
* `V` object or a `VertexId`.
|
|
287
|
-
* @returns The function `getEdgesOf` returns an array of `E` objects.
|
|
288
|
-
*/
|
|
289
|
-
UndirectedGraph.prototype.getEdgesOf = function (vertexOrId) {
|
|
290
|
-
var vertex = this._getVertex(vertexOrId);
|
|
291
|
-
if (!vertex) {
|
|
292
|
-
return [];
|
|
293
|
-
}
|
|
294
|
-
return this._edges.get(vertex) || [];
|
|
295
|
-
};
|
|
296
283
|
/**
|
|
297
284
|
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
|
|
298
285
|
* @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
|
|
@@ -304,7 +291,7 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
304
291
|
var neighbors = [];
|
|
305
292
|
var vertex = this._getVertex(vertexOrId);
|
|
306
293
|
if (vertex) {
|
|
307
|
-
var neighborEdges = this.
|
|
294
|
+
var neighborEdges = this.edgesOf(vertex);
|
|
308
295
|
try {
|
|
309
296
|
for (var neighborEdges_1 = __values(neighborEdges), neighborEdges_1_1 = neighborEdges_1.next(); !neighborEdges_1_1.done; neighborEdges_1_1 = neighborEdges_1.next()) {
|
|
310
297
|
var edge = neighborEdges_1_1.value;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { AbstractBinaryTreeNodeProperties, AbstractBinaryTreeNodeProperty, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName } from '../types';
|
|
2
|
+
import { AbstractBinaryTreeNode } from '../binary-tree';
|
|
3
|
+
export interface IAbstractBinaryTreeNode<T, FAMILY extends IAbstractBinaryTreeNode<T, FAMILY>> {
|
|
4
|
+
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
5
|
+
get id(): BinaryTreeNodeId;
|
|
6
|
+
set id(v: BinaryTreeNodeId);
|
|
7
|
+
get val(): T | undefined;
|
|
8
|
+
set val(v: T | undefined);
|
|
9
|
+
get left(): FAMILY | null | undefined;
|
|
10
|
+
set left(v: FAMILY | null | undefined);
|
|
11
|
+
get right(): FAMILY | null | undefined;
|
|
12
|
+
set right(v: FAMILY | null | undefined);
|
|
13
|
+
get parent(): FAMILY | null | undefined;
|
|
14
|
+
set parent(v: FAMILY | null | undefined);
|
|
15
|
+
get familyPosition(): FamilyPosition;
|
|
16
|
+
set familyPosition(v: FamilyPosition);
|
|
17
|
+
get count(): number;
|
|
18
|
+
set count(v: number);
|
|
19
|
+
get height(): number;
|
|
20
|
+
set height(v: number);
|
|
21
|
+
swapLocation(swapNode: FAMILY): FAMILY;
|
|
22
|
+
clone(): FAMILY | null;
|
|
23
|
+
}
|
|
24
|
+
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
|
|
25
|
+
createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
|
|
26
|
+
get loopType(): LoopType;
|
|
27
|
+
get visitedId(): BinaryTreeNodeId[];
|
|
28
|
+
get visitedVal(): Array<N['val']>;
|
|
29
|
+
get visitedNode(): N[];
|
|
30
|
+
get visitedCount(): number[];
|
|
31
|
+
get visitedLeftSum(): number[];
|
|
32
|
+
get autoIncrementId(): boolean;
|
|
33
|
+
get maxId(): number;
|
|
34
|
+
get isDuplicatedVal(): boolean;
|
|
35
|
+
get root(): N | null;
|
|
36
|
+
get size(): number;
|
|
37
|
+
get count(): number;
|
|
38
|
+
clear(): void;
|
|
39
|
+
isEmpty(): boolean;
|
|
40
|
+
add(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null | undefined;
|
|
41
|
+
addTo(newNode: N | null, parent: N): N | null | undefined;
|
|
42
|
+
addMany(data: N[] | Array<N['val']>): (N | null | undefined)[];
|
|
43
|
+
fill(data: N[] | Array<N['val']>): boolean;
|
|
44
|
+
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
45
|
+
getDepth(node: N): number;
|
|
46
|
+
getHeight(beginRoot?: N | null): number;
|
|
47
|
+
getMinHeight(beginRoot?: N | null): number;
|
|
48
|
+
isBalanced(beginRoot?: N | null): boolean;
|
|
49
|
+
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
50
|
+
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
51
|
+
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
52
|
+
getPathToRoot(node: N): N[];
|
|
53
|
+
getLeftMost(): N | null;
|
|
54
|
+
getLeftMost(node: N): N;
|
|
55
|
+
getLeftMost(node?: N | null): N | null;
|
|
56
|
+
getRightMost(): N | null;
|
|
57
|
+
getRightMost(node: N): N;
|
|
58
|
+
getRightMost(node?: N | null): N | null;
|
|
59
|
+
isBSTByRooted(node: N | null): boolean;
|
|
60
|
+
isBST(node?: N | null): boolean;
|
|
61
|
+
getSubTreeSizeAndCount(subTreeRoot: N | null | undefined): [number, number];
|
|
62
|
+
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
|
|
63
|
+
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
64
|
+
BFS(): BinaryTreeNodeId[];
|
|
65
|
+
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
|
|
66
|
+
BFS(nodeOrPropertyName: 'val'): N['val'][];
|
|
67
|
+
BFS(nodeOrPropertyName: 'node'): N[];
|
|
68
|
+
BFS(nodeOrPropertyName: 'count'): number[];
|
|
69
|
+
BFS(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
70
|
+
DFS(): BinaryTreeNodeId[];
|
|
71
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
72
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
73
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
74
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
75
|
+
DFS(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
76
|
+
DFSIterative(): BinaryTreeNodeId[];
|
|
77
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
78
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
79
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
80
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
81
|
+
DFSIterative(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
82
|
+
levelIterative(node: N | null): BinaryTreeNodeId[];
|
|
83
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
84
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
|
|
85
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
|
|
86
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
|
|
87
|
+
levelIterative(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
88
|
+
listLevels(node: N | null): BinaryTreeNodeId[][];
|
|
89
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
|
|
90
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
|
|
91
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
|
|
92
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
|
|
93
|
+
listLevels(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperty<N>[][];
|
|
94
|
+
getPredecessor(node: N): N;
|
|
95
|
+
morris(): BinaryTreeNodeId[];
|
|
96
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
97
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
98
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
99
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
100
|
+
morris(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
101
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { VertexId } from '../types';
|
|
2
|
-
export interface
|
|
2
|
+
export interface IAbstractGraph<V, E> {
|
|
3
3
|
hasVertex(vertexOrId: V | VertexId): boolean;
|
|
4
|
-
_getVertex(vertexOrId: VertexId | V): V | null;
|
|
5
|
-
_getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
6
4
|
createAddVertex(id: VertexId, val?: V): boolean;
|
|
7
5
|
addVertex(newVertex: V): boolean;
|
|
8
6
|
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
@@ -14,7 +12,6 @@ export interface IGraph<V, E> {
|
|
|
14
12
|
edgeSet(): E[];
|
|
15
13
|
createAddEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E): boolean;
|
|
16
14
|
addEdge(edge: E): boolean;
|
|
17
|
-
removeEdgeBetween(src: V | VertexId, dest: V | VertexId): E | null;
|
|
18
15
|
removeEdge(edge: E): E | null;
|
|
19
16
|
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
|
|
20
17
|
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { AVLTreeNode } from '../binary-tree';
|
|
2
|
+
import { IBST, IBSTNode } from './bst';
|
|
3
|
+
import { BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
|
|
4
|
+
export interface IAVLTreeNode<T, FAMILY extends IAVLTreeNode<T, FAMILY>> extends IBSTNode<T, FAMILY> {
|
|
5
|
+
}
|
|
6
|
+
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
|
|
7
|
+
add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
|
|
8
|
+
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): BinaryTreeDeletedResult<N>[];
|
|
9
|
+
balanceFactor(node: N): number;
|
|
10
|
+
updateHeight(node: N): void;
|
|
11
|
+
balancePath(node: N): void;
|
|
12
|
+
balanceLL(A: N): void;
|
|
13
|
+
balanceLR(A: N): void;
|
|
14
|
+
balanceRR(A: N): void;
|
|
15
|
+
balanceRL(A: N): void;
|
|
16
|
+
}
|