data-structure-typed 1.18.7 → 1.18.8
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/README.md +154 -366
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +29 -32
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +179 -136
- package/dist/data-structures/binary-tree/avl-tree.d.ts +4 -4
- package/dist/data-structures/binary-tree/avl-tree.js +2 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/binary-tree.js +4 -4
- package/dist/data-structures/binary-tree/bst.d.ts +13 -25
- package/dist/data-structures/binary-tree/bst.js +20 -74
- package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -6
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/data-structures/binary-tree/tree-multiset.js +7 -14
- package/dist/data-structures/graph/abstract-graph.d.ts +11 -9
- package/dist/data-structures/graph/abstract-graph.js +39 -22
- package/dist/data-structures/graph/directed-graph.d.ts +17 -15
- package/dist/data-structures/graph/directed-graph.js +47 -42
- package/dist/data-structures/graph/undirected-graph.d.ts +7 -7
- package/dist/data-structures/graph/undirected-graph.js +48 -48
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +2 -3
- package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
- package/dist/data-structures/interfaces/avl-tree.d.ts +1 -1
- package/dist/data-structures/interfaces/bst.d.ts +2 -2
- package/dist/data-structures/interfaces/rb-tree.d.ts +2 -2
- package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
- package/dist/data-structures/tree/tree.d.ts +1 -4
- package/dist/data-structures/tree/tree.js +1 -12
- package/dist/data-structures/types/abstract-binary-tree.d.ts +9 -5
- package/dist/data-structures/types/abstract-binary-tree.js +9 -5
- package/dist/data-structures/types/avl-tree.d.ts +1 -1
- package/dist/data-structures/types/binary-tree.d.ts +1 -1
- package/dist/data-structures/types/bst.d.ts +1 -1
- package/dist/data-structures/types/bst.js +1 -1
- package/dist/data-structures/types/directed-graph.js +1 -1
- package/dist/data-structures/types/helpers.d.ts +1 -8
- package/dist/data-structures/types/rb-tree.d.ts +2 -0
- package/dist/data-structures/types/rb-tree.js +1 -1
- package/dist/data-structures/types/tree-multiset.d.ts +4 -4
- package/dist/utils/types/utils.d.ts +18 -0
- package/dist/utils/utils.d.ts +6 -1
- package/dist/utils/utils.js +21 -1
- package/package.json +2 -2
- package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
- package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
- package/backup/recursive-type/src/assets/logo.png +0 -0
- package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
- package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
- package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
- package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
- package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
- package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
- package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
- package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
- package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
- package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
- package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
- package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
- package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
- package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
- package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
- package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
- package/backup/recursive-type/src/data-structures/index.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
- package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
- package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
- package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
- package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
- package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
- package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
- package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
- package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
- package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
- package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
- package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
- package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
- package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
- package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
- package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
- package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
- package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
- package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
- package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
- package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
- package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
- package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
- package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
- package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
- package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/index.ts +0 -1
- package/backup/recursive-type/src/utils/index.ts +0 -2
- package/backup/recursive-type/src/utils/types/index.ts +0 -1
- package/backup/recursive-type/src/utils/types/utils.ts +0 -6
- package/backup/recursive-type/src/utils/utils.ts +0 -78
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -92
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/classes/AVLTree.html +0 -2451
- package/docs/classes/AVLTreeNode.html +0 -499
- package/docs/classes/AaTree.html +0 -172
- package/docs/classes/AbstractBinaryTree.html +0 -2118
- package/docs/classes/AbstractBinaryTreeNode.html +0 -524
- package/docs/classes/AbstractEdge.html +0 -295
- package/docs/classes/AbstractGraph.html +0 -1043
- package/docs/classes/AbstractVertex.html +0 -258
- package/docs/classes/ArrayDeque.html +0 -439
- package/docs/classes/BST.html +0 -2297
- package/docs/classes/BSTNode.html +0 -503
- package/docs/classes/BTree.html +0 -172
- package/docs/classes/BinaryIndexedTree.html +0 -341
- package/docs/classes/BinaryTree.html +0 -2133
- package/docs/classes/BinaryTreeNode.html +0 -501
- package/docs/classes/Character.html +0 -220
- package/docs/classes/CoordinateMap.html +0 -483
- package/docs/classes/CoordinateSet.html +0 -444
- package/docs/classes/Deque.html +0 -975
- package/docs/classes/DirectedEdge.html +0 -366
- package/docs/classes/DirectedGraph.html +0 -1443
- package/docs/classes/DirectedVertex.html +0 -254
- package/docs/classes/DoublyLinkedList.html +0 -968
- package/docs/classes/DoublyLinkedListNode.html +0 -297
- package/docs/classes/HashTable.html +0 -172
- package/docs/classes/Heap.html +0 -423
- package/docs/classes/HeapItem.html +0 -255
- package/docs/classes/Matrix2D.html +0 -502
- package/docs/classes/MatrixNTI2D.html +0 -240
- package/docs/classes/MaxHeap.html +0 -436
- package/docs/classes/MaxPriorityQueue.html +0 -836
- package/docs/classes/MinHeap.html +0 -437
- package/docs/classes/MinPriorityQueue.html +0 -838
- package/docs/classes/Navigator.html +0 -313
- package/docs/classes/ObjectDeque.html +0 -455
- package/docs/classes/Pair.html +0 -172
- package/docs/classes/PriorityQueue.html +0 -760
- package/docs/classes/Queue.html +0 -392
- package/docs/classes/RBTree.html +0 -2388
- package/docs/classes/RBTreeNode.html +0 -516
- package/docs/classes/SegmentTree.html +0 -434
- package/docs/classes/SegmentTreeNode.html +0 -357
- package/docs/classes/SinglyLinkedList.html +0 -788
- package/docs/classes/SinglyLinkedListNode.html +0 -270
- package/docs/classes/SkipLinkedList.html +0 -172
- package/docs/classes/SplayTree.html +0 -172
- package/docs/classes/Stack.html +0 -368
- package/docs/classes/TreeMap.html +0 -172
- package/docs/classes/TreeMultiSet.html +0 -2297
- package/docs/classes/TreeMultiSetNode.html +0 -499
- package/docs/classes/TreeNode.html +0 -343
- package/docs/classes/TreeSet.html +0 -172
- package/docs/classes/Trie.html +0 -372
- package/docs/classes/TrieNode.html +0 -280
- package/docs/classes/TwoThreeTree.html +0 -172
- package/docs/classes/UndirectedEdge.html +0 -337
- package/docs/classes/UndirectedGraph.html +0 -1210
- package/docs/classes/UndirectedVertex.html +0 -254
- package/docs/classes/Vector2D.html +0 -805
- package/docs/enums/CP.html +0 -181
- package/docs/enums/FamilyPosition.html +0 -181
- package/docs/enums/LoopType.html +0 -182
- package/docs/enums/RBColor.html +0 -174
- package/docs/enums/TopologicalProperty.html +0 -181
- package/docs/index.html +0 -645
- package/docs/interfaces/IAVLTree.html +0 -1378
- package/docs/interfaces/IAVLTreeNode.html +0 -405
- package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
- package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
- package/docs/interfaces/IAbstractGraph.html +0 -433
- package/docs/interfaces/IBST.html +0 -1271
- package/docs/interfaces/IBSTNode.html +0 -408
- package/docs/interfaces/IDirectedGraph.html +0 -572
- package/docs/interfaces/IUNDirectedGraph.html +0 -465
- package/docs/modules.html +0 -262
- package/docs/types/AVLTreeOptions.html +0 -150
- package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
- package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
- package/docs/types/AbstractBinaryTreeOptions.html +0 -156
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
- package/docs/types/BSTComparator.html +0 -162
- package/docs/types/BSTOptions.html +0 -152
- package/docs/types/BinaryTreeDeletedResult.html +0 -159
- package/docs/types/BinaryTreeNodeId.html +0 -147
- package/docs/types/BinaryTreeNodePropertyName.html +0 -147
- package/docs/types/BinaryTreeOptions.html +0 -150
- package/docs/types/DFSOrderPattern.html +0 -147
- package/docs/types/DijkstraResult.html +0 -167
- package/docs/types/Direction.html +0 -147
- package/docs/types/EdgeId.html +0 -147
- package/docs/types/HeapOptions.html +0 -168
- package/docs/types/IdObject.html +0 -157
- package/docs/types/KeyValObject.html +0 -152
- package/docs/types/NavigatorParams.html +0 -181
- package/docs/types/NodeOrPropertyName.html +0 -147
- package/docs/types/PriorityQueueComparator.html +0 -167
- package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
- package/docs/types/PriorityQueueOptions.html +0 -161
- package/docs/types/RBTreeOptions.html +0 -150
- package/docs/types/RecursiveAVLTreeNode.html +0 -152
- package/docs/types/RecursiveBSTNode.html +0 -152
- package/docs/types/RecursiveBinaryTreeNode.html +0 -152
- package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
- package/docs/types/SegmentTreeNodeVal.html +0 -147
- package/docs/types/TopologicalStatus.html +0 -147
- package/docs/types/TreeMultiSetOptions.html +0 -152
- package/docs/types/Turning.html +0 -147
- package/docs/types/VertexId.html +0 -147
- package/notes/bst.test.ts +0 -181
- package/notes/note.md +0 -34
|
@@ -184,41 +184,6 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
184
184
|
}
|
|
185
185
|
return edges[0] || null;
|
|
186
186
|
};
|
|
187
|
-
/**
|
|
188
|
-
* The `addEdge` function adds a directed edge to a graph if the source and destination vertices exist.
|
|
189
|
-
* @param edge - The parameter `edge` is of type `E`, which represents a directed edge in a graph. It
|
|
190
|
-
* contains two properties:
|
|
191
|
-
* @returns The method `addEdge` returns a boolean value. It returns `true` if the edge was successfully added to the
|
|
192
|
-
* graph, and `false` if either the source or destination vertex of the edge is not present in the graph.
|
|
193
|
-
*/
|
|
194
|
-
DirectedGraph.prototype.addEdge = function (edge) {
|
|
195
|
-
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
var srcVertex = this._getVertex(edge.src);
|
|
199
|
-
var destVertex = this._getVertex(edge.dest);
|
|
200
|
-
// TODO after no-non-null-assertion not ensure the logic
|
|
201
|
-
if (srcVertex && destVertex) {
|
|
202
|
-
var srcOutEdges = this._outEdgeMap.get(srcVertex);
|
|
203
|
-
if (srcOutEdges) {
|
|
204
|
-
srcOutEdges.push(edge);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
this._outEdgeMap.set(srcVertex, [edge]);
|
|
208
|
-
}
|
|
209
|
-
var destInEdges = this._inEdgeMap.get(destVertex);
|
|
210
|
-
if (destInEdges) {
|
|
211
|
-
destInEdges.push(edge);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
this._inEdgeMap.set(destVertex, [edge]);
|
|
215
|
-
}
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
187
|
/**
|
|
223
188
|
* The `removeEdgeBetween` function removes an edge between two vertices in a directed graph and returns the removed
|
|
224
189
|
* edge, or null if the edge was not found.
|
|
@@ -400,14 +365,17 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
400
365
|
return destinations;
|
|
401
366
|
};
|
|
402
367
|
/**
|
|
403
|
-
* The `topologicalSort` function performs a topological sort on a
|
|
404
|
-
*
|
|
405
|
-
* @
|
|
406
|
-
*
|
|
368
|
+
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
|
|
369
|
+
* in the sorted order, or null if the graph contains a cycle.
|
|
370
|
+
* @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
371
|
+
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
|
|
372
|
+
* specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
|
|
373
|
+
* @returns an array of vertices or vertex IDs in topological order, or null if there is a cycle in the graph.
|
|
407
374
|
*/
|
|
408
|
-
DirectedGraph.prototype.topologicalSort = function () {
|
|
375
|
+
DirectedGraph.prototype.topologicalSort = function (propertyName) {
|
|
409
376
|
var e_2, _a, e_3, _b;
|
|
410
377
|
var _this = this;
|
|
378
|
+
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
411
379
|
// When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
|
|
412
380
|
// When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
|
|
413
381
|
var statusMap = new Map();
|
|
@@ -469,6 +437,8 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
469
437
|
}
|
|
470
438
|
if (hasCycle)
|
|
471
439
|
return null;
|
|
440
|
+
if (propertyName === 'id')
|
|
441
|
+
sorted = sorted.map(function (vertex) { return vertex instanceof DirectedVertex ? vertex.id : vertex; });
|
|
472
442
|
return sorted.reverse();
|
|
473
443
|
};
|
|
474
444
|
/**
|
|
@@ -482,7 +452,6 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
482
452
|
});
|
|
483
453
|
return edges;
|
|
484
454
|
};
|
|
485
|
-
/**--- start find cycles --- */
|
|
486
455
|
/**
|
|
487
456
|
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in a directed graph.
|
|
488
457
|
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
|
|
@@ -515,7 +484,7 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
515
484
|
}
|
|
516
485
|
return neighbors;
|
|
517
486
|
};
|
|
518
|
-
/**---
|
|
487
|
+
/**--- start find cycles --- */
|
|
519
488
|
/**
|
|
520
489
|
* The function "getEndsOfEdge" returns the source and destination vertices of a directed edge if it exists in the
|
|
521
490
|
* graph, otherwise it returns null.
|
|
@@ -536,6 +505,42 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
536
505
|
return null;
|
|
537
506
|
}
|
|
538
507
|
};
|
|
508
|
+
/**--- end find cycles --- */
|
|
509
|
+
/**
|
|
510
|
+
* The `_addEdgeOnly` function adds a directed edge to a graph if the source and destination vertices exist.
|
|
511
|
+
* @param edge - The parameter `edge` is of type `E`, which represents a directed edge in a graph. It
|
|
512
|
+
* contains two properties:
|
|
513
|
+
* @returns The method `_addEdgeOnly` returns a boolean value. It returns `true` if the edge was successfully added to the
|
|
514
|
+
* graph, and `false` if either the source or destination vertex of the edge is not present in the graph.
|
|
515
|
+
*/
|
|
516
|
+
DirectedGraph.prototype._addEdgeOnly = function (edge) {
|
|
517
|
+
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
var srcVertex = this._getVertex(edge.src);
|
|
521
|
+
var destVertex = this._getVertex(edge.dest);
|
|
522
|
+
// TODO after no-non-null-assertion not ensure the logic
|
|
523
|
+
if (srcVertex && destVertex) {
|
|
524
|
+
var srcOutEdges = this._outEdgeMap.get(srcVertex);
|
|
525
|
+
if (srcOutEdges) {
|
|
526
|
+
srcOutEdges.push(edge);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
this._outEdgeMap.set(srcVertex, [edge]);
|
|
530
|
+
}
|
|
531
|
+
var destInEdges = this._inEdgeMap.get(destVertex);
|
|
532
|
+
if (destInEdges) {
|
|
533
|
+
destInEdges.push(edge);
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
this._inEdgeMap.set(destVertex, [edge]);
|
|
537
|
+
}
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
};
|
|
539
544
|
DirectedGraph.prototype._setOutEdgeMap = function (value) {
|
|
540
545
|
this._outEdgeMap = value;
|
|
541
546
|
};
|
|
@@ -61,13 +61,6 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
61
61
|
* @returns an instance of `E` or `null`.
|
|
62
62
|
*/
|
|
63
63
|
getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
|
|
64
|
-
/**
|
|
65
|
-
* The function adds an undirected edge to a graph by updating the adjacency list.
|
|
66
|
-
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
67
|
-
* array of two vertices connected by the edge.
|
|
68
|
-
* @returns a boolean value.
|
|
69
|
-
*/
|
|
70
|
-
addEdge(edge: E): boolean;
|
|
71
64
|
/**
|
|
72
65
|
* The function removes an edge between two vertices in an undirected graph.
|
|
73
66
|
* @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
|
|
@@ -122,5 +115,12 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
122
115
|
* exists in the graph. If the edge does not exist, it returns `null`.
|
|
123
116
|
*/
|
|
124
117
|
getEndsOfEdge(edge: E): [V, V] | null;
|
|
118
|
+
/**
|
|
119
|
+
* The function adds an undirected edge to a graph by updating the adjacency list.
|
|
120
|
+
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
121
|
+
* array of two vertices connected by the edge.
|
|
122
|
+
* @returns a boolean value.
|
|
123
|
+
*/
|
|
124
|
+
protected _addEdgeOnly(edge: E): boolean;
|
|
125
125
|
protected _setEdges(v: Map<V, E[]>): void;
|
|
126
126
|
}
|
|
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
-
var __values = (this && this.__values) || function(o) {
|
|
18
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
-
if (m) return m.call(o);
|
|
20
|
-
if (o && typeof o.length === "number") return {
|
|
21
|
-
next: function () {
|
|
22
|
-
if (o && i >= o.length) o = void 0;
|
|
23
|
-
return { value: o && o[i++], done: !o };
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
-
};
|
|
28
17
|
var __read = (this && this.__read) || function (o, n) {
|
|
29
18
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30
19
|
if (!m) return o;
|
|
@@ -50,6 +39,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
50
39
|
}
|
|
51
40
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
52
41
|
};
|
|
42
|
+
var __values = (this && this.__values) || function(o) {
|
|
43
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
44
|
+
if (m) return m.call(o);
|
|
45
|
+
if (o && typeof o.length === "number") return {
|
|
46
|
+
next: function () {
|
|
47
|
+
if (o && i >= o.length) o = void 0;
|
|
48
|
+
return { value: o && o[i++], done: !o };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
52
|
+
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
exports.UndirectedGraph = exports.UndirectedEdge = exports.UndirectedVertex = void 0;
|
|
55
55
|
/**
|
|
@@ -165,40 +165,6 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
165
165
|
}
|
|
166
166
|
return edges ? edges[0] || null : null;
|
|
167
167
|
};
|
|
168
|
-
/**
|
|
169
|
-
* The function adds an undirected edge to a graph by updating the adjacency list.
|
|
170
|
-
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
171
|
-
* array of two vertices connected by the edge.
|
|
172
|
-
* @returns a boolean value.
|
|
173
|
-
*/
|
|
174
|
-
UndirectedGraph.prototype.addEdge = function (edge) {
|
|
175
|
-
var e_1, _a;
|
|
176
|
-
try {
|
|
177
|
-
for (var _b = __values(edge.vertices), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
178
|
-
var end = _c.value;
|
|
179
|
-
var endVertex = this._getVertex(end);
|
|
180
|
-
if (endVertex === null)
|
|
181
|
-
return false;
|
|
182
|
-
if (endVertex) {
|
|
183
|
-
var edges = this._edges.get(endVertex);
|
|
184
|
-
if (edges) {
|
|
185
|
-
edges.push(edge);
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
this._edges.set(endVertex, [edge]);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
194
|
-
finally {
|
|
195
|
-
try {
|
|
196
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
197
|
-
}
|
|
198
|
-
finally { if (e_1) throw e_1.error; }
|
|
199
|
-
}
|
|
200
|
-
return true;
|
|
201
|
-
};
|
|
202
168
|
/**
|
|
203
169
|
* The function removes an edge between two vertices in an undirected graph.
|
|
204
170
|
* @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
|
|
@@ -287,7 +253,7 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
287
253
|
* @returns an array of UndirectedVertex objects.
|
|
288
254
|
*/
|
|
289
255
|
UndirectedGraph.prototype.getNeighbors = function (vertexOrId) {
|
|
290
|
-
var
|
|
256
|
+
var e_1, _a;
|
|
291
257
|
var neighbors = [];
|
|
292
258
|
var vertex = this._getVertex(vertexOrId);
|
|
293
259
|
if (vertex) {
|
|
@@ -301,12 +267,12 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
301
267
|
}
|
|
302
268
|
}
|
|
303
269
|
}
|
|
304
|
-
catch (
|
|
270
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
305
271
|
finally {
|
|
306
272
|
try {
|
|
307
273
|
if (neighborEdges_1_1 && !neighborEdges_1_1.done && (_a = neighborEdges_1.return)) _a.call(neighborEdges_1);
|
|
308
274
|
}
|
|
309
|
-
finally { if (
|
|
275
|
+
finally { if (e_1) throw e_1.error; }
|
|
310
276
|
}
|
|
311
277
|
}
|
|
312
278
|
return neighbors;
|
|
@@ -332,6 +298,40 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
332
298
|
return null;
|
|
333
299
|
}
|
|
334
300
|
};
|
|
301
|
+
/**
|
|
302
|
+
* The function adds an undirected edge to a graph by updating the adjacency list.
|
|
303
|
+
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
304
|
+
* array of two vertices connected by the edge.
|
|
305
|
+
* @returns a boolean value.
|
|
306
|
+
*/
|
|
307
|
+
UndirectedGraph.prototype._addEdgeOnly = function (edge) {
|
|
308
|
+
var e_2, _a;
|
|
309
|
+
try {
|
|
310
|
+
for (var _b = __values(edge.vertices), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
311
|
+
var end = _c.value;
|
|
312
|
+
var endVertex = this._getVertex(end);
|
|
313
|
+
if (endVertex === null)
|
|
314
|
+
return false;
|
|
315
|
+
if (endVertex) {
|
|
316
|
+
var edges = this._edges.get(endVertex);
|
|
317
|
+
if (edges) {
|
|
318
|
+
edges.push(edge);
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
this._edges.set(endVertex, [edge]);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
327
|
+
finally {
|
|
328
|
+
try {
|
|
329
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
330
|
+
}
|
|
331
|
+
finally { if (e_2) throw e_2.error; }
|
|
332
|
+
}
|
|
333
|
+
return true;
|
|
334
|
+
};
|
|
335
335
|
UndirectedGraph.prototype._setEdges = function (v) {
|
|
336
336
|
this._edges = v;
|
|
337
337
|
};
|
|
@@ -13,7 +13,6 @@ export interface IAbstractBinaryTreeNode<T, FAMILY extends IAbstractBinaryTreeNo
|
|
|
13
13
|
get parent(): FAMILY | null | undefined;
|
|
14
14
|
set parent(v: FAMILY | null | undefined);
|
|
15
15
|
get familyPosition(): FamilyPosition;
|
|
16
|
-
set familyPosition(v: FamilyPosition);
|
|
17
16
|
get count(): number;
|
|
18
17
|
set count(v: number);
|
|
19
18
|
get height(): number;
|
|
@@ -22,7 +21,7 @@ export interface IAbstractBinaryTreeNode<T, FAMILY extends IAbstractBinaryTreeNo
|
|
|
22
21
|
clone(): FAMILY | null;
|
|
23
22
|
}
|
|
24
23
|
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
|
|
25
|
-
createNode(id: BinaryTreeNodeId, val
|
|
24
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null;
|
|
26
25
|
get loopType(): LoopType;
|
|
27
26
|
get visitedId(): BinaryTreeNodeId[];
|
|
28
27
|
get visitedVal(): Array<N['val']>;
|
|
@@ -31,7 +30,7 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
|
|
|
31
30
|
get visitedLeftSum(): number[];
|
|
32
31
|
get autoIncrementId(): boolean;
|
|
33
32
|
get maxId(): number;
|
|
34
|
-
get
|
|
33
|
+
get isMergeDuplicatedVal(): boolean;
|
|
35
34
|
get root(): N | null;
|
|
36
35
|
get size(): number;
|
|
37
36
|
get count(): number;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { VertexId } from '../types';
|
|
2
2
|
export interface IAbstractGraph<V, E> {
|
|
3
3
|
hasVertex(vertexOrId: V | VertexId): boolean;
|
|
4
|
-
|
|
5
|
-
addVertex(newVertex: V): boolean;
|
|
4
|
+
addVertex(id: VertexId, val?: V): boolean;
|
|
6
5
|
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
7
6
|
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
|
8
7
|
degreeOf(vertexOrId: V | VertexId): number;
|
|
@@ -10,8 +9,7 @@ export interface IAbstractGraph<V, E> {
|
|
|
10
9
|
hasEdge(src: V | VertexId, dest: V | VertexId): boolean;
|
|
11
10
|
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
12
11
|
edgeSet(): E[];
|
|
13
|
-
|
|
14
|
-
addEdge(edge: E): boolean;
|
|
12
|
+
addEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E): boolean;
|
|
15
13
|
removeEdge(edge: E): E | null;
|
|
16
14
|
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
|
|
17
15
|
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
@@ -4,7 +4,7 @@ import { BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
|
|
|
4
4
|
export interface IAVLTreeNode<T, FAMILY extends IAVLTreeNode<T, FAMILY>> extends IBSTNode<T, FAMILY> {
|
|
5
5
|
}
|
|
6
6
|
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
|
|
7
|
-
add(id: BinaryTreeNodeId, val
|
|
7
|
+
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null;
|
|
8
8
|
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): BinaryTreeDeletedResult<N>[];
|
|
9
9
|
balanceFactor(node: N): number;
|
|
10
10
|
updateHeight(node: N): void;
|
|
@@ -5,8 +5,8 @@ export interface IBSTNode<T, FAMILY extends IBSTNode<T, FAMILY>> extends IBinary
|
|
|
5
5
|
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
6
6
|
}
|
|
7
7
|
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
|
|
8
|
-
createNode(id: BinaryTreeNodeId, val?: N['val']
|
|
9
|
-
add(id: BinaryTreeNodeId, val
|
|
8
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
9
|
+
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null;
|
|
10
10
|
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
11
11
|
lastKey(): BinaryTreeNodeId;
|
|
12
12
|
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
@@ -2,8 +2,8 @@ import { RBTreeNode } from '../binary-tree';
|
|
|
2
2
|
import { IBST, IBSTNode } from './bst';
|
|
3
3
|
import { BinaryTreeNodeId } from '../types';
|
|
4
4
|
export interface IRBTreeNode<T, FAMILY extends IRBTreeNode<T, FAMILY>> extends IBSTNode<T, FAMILY> {
|
|
5
|
-
createNode(id: BinaryTreeNodeId, val?: T
|
|
5
|
+
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
6
6
|
}
|
|
7
7
|
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
|
|
8
|
-
createNode(id: BinaryTreeNodeId, val?: N
|
|
8
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
9
9
|
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { TreeMultiSetNode } from '../binary-tree';
|
|
2
|
+
import { IBSTNode } from './bst';
|
|
3
|
+
import { IAVLTree } from './avl-tree';
|
|
4
|
+
export interface ITreeMultiSetNode<T, FAMILY extends ITreeMultiSetNode<T, FAMILY>> extends IBSTNode<T, FAMILY> {
|
|
5
|
+
}
|
|
6
|
+
export interface ITreeMultiSet<N extends TreeMultiSetNode<N['val'], N>> extends IAVLTree<N> {
|
|
7
|
+
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
export declare class TreeNode<T = number> {
|
|
2
|
-
constructor(id: string,
|
|
2
|
+
constructor(id: string, value?: T, children?: TreeNode<T>[]);
|
|
3
3
|
private _id;
|
|
4
4
|
get id(): string;
|
|
5
5
|
set id(value: string);
|
|
6
|
-
private _name?;
|
|
7
|
-
get name(): string | undefined;
|
|
8
|
-
set name(value: string | undefined);
|
|
9
6
|
private _value?;
|
|
10
7
|
get value(): T | undefined;
|
|
11
8
|
set value(value: T | undefined);
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TreeNode = void 0;
|
|
4
4
|
var TreeNode = /** @class */ (function () {
|
|
5
|
-
function TreeNode(id,
|
|
5
|
+
function TreeNode(id, value, children) {
|
|
6
6
|
this._id = id;
|
|
7
|
-
this._name = name || '';
|
|
8
7
|
this._value = value || undefined;
|
|
9
8
|
this._children = children || [];
|
|
10
9
|
}
|
|
@@ -18,16 +17,6 @@ var TreeNode = /** @class */ (function () {
|
|
|
18
17
|
enumerable: false,
|
|
19
18
|
configurable: true
|
|
20
19
|
});
|
|
21
|
-
Object.defineProperty(TreeNode.prototype, "name", {
|
|
22
|
-
get: function () {
|
|
23
|
-
return this._name;
|
|
24
|
-
},
|
|
25
|
-
set: function (value) {
|
|
26
|
-
this._name = value;
|
|
27
|
-
},
|
|
28
|
-
enumerable: false,
|
|
29
|
-
configurable: true
|
|
30
|
-
});
|
|
31
20
|
Object.defineProperty(TreeNode.prototype, "value", {
|
|
32
21
|
get: function () {
|
|
33
22
|
return this._value;
|
|
@@ -10,9 +10,13 @@ export declare enum LoopType {
|
|
|
10
10
|
RECURSIVE = "RECURSIVE"
|
|
11
11
|
}
|
|
12
12
|
export declare enum FamilyPosition {
|
|
13
|
-
ROOT =
|
|
14
|
-
LEFT =
|
|
15
|
-
RIGHT =
|
|
13
|
+
ROOT = "ROOT",
|
|
14
|
+
LEFT = "LEFT",
|
|
15
|
+
RIGHT = "RIGHT",
|
|
16
|
+
ROOT_LEFT = "ROOT_LEFT",
|
|
17
|
+
ROOT_RIGHT = "ROOT_RIGHT",
|
|
18
|
+
ISOLATED = "ISOLATED",
|
|
19
|
+
MAL_NODE = "MAL_NODE"
|
|
16
20
|
}
|
|
17
21
|
export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
|
|
18
22
|
export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
|
|
@@ -24,9 +28,9 @@ export type BinaryTreeDeletedResult<N> = {
|
|
|
24
28
|
};
|
|
25
29
|
export type AbstractBinaryTreeNodeProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeId;
|
|
26
30
|
export type AbstractBinaryTreeNodeProperties<N extends AbstractBinaryTreeNode<N['val'], N>> = AbstractBinaryTreeNodeProperty<N>[];
|
|
27
|
-
export type
|
|
31
|
+
export type AbstractBinaryTreeNodeNested<T> = AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
28
32
|
export type AbstractBinaryTreeOptions = {
|
|
29
33
|
loopType?: LoopType;
|
|
30
34
|
autoIncrementId?: boolean;
|
|
31
|
-
|
|
35
|
+
isMergeDuplicatedVal?: boolean;
|
|
32
36
|
};
|
|
@@ -11,11 +11,15 @@ var LoopType;
|
|
|
11
11
|
(function (LoopType) {
|
|
12
12
|
LoopType["ITERATIVE"] = "ITERATIVE";
|
|
13
13
|
LoopType["RECURSIVE"] = "RECURSIVE";
|
|
14
|
-
})(LoopType
|
|
14
|
+
})(LoopType = exports.LoopType || (exports.LoopType = {}));
|
|
15
15
|
/* This enumeration defines the position of a node within a family tree composed of three associated nodes, where 'root' represents the root node of the family tree, 'left' represents the left child node, and 'right' represents the right child node. */
|
|
16
16
|
var FamilyPosition;
|
|
17
17
|
(function (FamilyPosition) {
|
|
18
|
-
FamilyPosition[
|
|
19
|
-
FamilyPosition[
|
|
20
|
-
FamilyPosition[
|
|
21
|
-
|
|
18
|
+
FamilyPosition["ROOT"] = "ROOT";
|
|
19
|
+
FamilyPosition["LEFT"] = "LEFT";
|
|
20
|
+
FamilyPosition["RIGHT"] = "RIGHT";
|
|
21
|
+
FamilyPosition["ROOT_LEFT"] = "ROOT_LEFT";
|
|
22
|
+
FamilyPosition["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
23
|
+
FamilyPosition["ISOLATED"] = "ISOLATED";
|
|
24
|
+
FamilyPosition["MAL_NODE"] = "MAL_NODE";
|
|
25
|
+
})(FamilyPosition = exports.FamilyPosition || (exports.FamilyPosition = {}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { AVLTreeNode } from '../binary-tree';
|
|
2
2
|
import { BSTOptions } from './bst';
|
|
3
|
-
export type
|
|
3
|
+
export type AVLTreeNodeNested<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
4
|
export type AVLTreeOptions = BSTOptions & {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BinaryTreeNode } from '../binary-tree';
|
|
2
2
|
import { AbstractBinaryTreeOptions } from './abstract-binary-tree';
|
|
3
|
-
export type
|
|
3
|
+
export type BinaryTreeNodeNested<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
4
|
export type BinaryTreeOptions = AbstractBinaryTreeOptions & {};
|
|
@@ -2,7 +2,7 @@ import { BSTNode } from '../binary-tree';
|
|
|
2
2
|
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
3
|
import { BinaryTreeNodeId } from './abstract-binary-tree';
|
|
4
4
|
export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number;
|
|
5
|
-
export type
|
|
5
|
+
export type BSTNodeNested<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
6
|
export type BSTOptions = BinaryTreeOptions & {
|
|
7
7
|
comparator?: BSTComparator;
|
|
8
8
|
};
|
|
@@ -6,4 +6,4 @@ var TopologicalProperty;
|
|
|
6
6
|
TopologicalProperty["VAL"] = "VAL";
|
|
7
7
|
TopologicalProperty["NODE"] = "NODE";
|
|
8
8
|
TopologicalProperty["ID"] = "ID";
|
|
9
|
-
})(TopologicalProperty
|
|
9
|
+
})(TopologicalProperty = exports.TopologicalProperty || (exports.TopologicalProperty = {}));
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { BinaryTreeOptions } from './binary-tree';
|
|
2
|
+
import { RBTreeNode } from '../binary-tree';
|
|
2
3
|
export declare enum RBColor {
|
|
3
4
|
RED = "RED",
|
|
4
5
|
BLACK = "BLACK"
|
|
5
6
|
}
|
|
7
|
+
export type RBTreeNodeNested<T> = RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
8
|
export type RBTreeOptions = BinaryTreeOptions & {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BSTOptions } from './bst';
|
|
2
1
|
import { TreeMultiSetNode } from '../binary-tree';
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
|
|
2
|
+
import { AVLTreeOptions } from './avl-tree';
|
|
3
|
+
export type TreeMultiSetNodeNested<T> = TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
+
export type TreeMultiSetOptions = Omit<AVLTreeOptions, 'isMergeDuplicatedVal'> & {
|
|
5
|
+
isMergeDuplicatedVal: true;
|
|
6
6
|
};
|
|
@@ -5,3 +5,21 @@ export type Thunk = () => ReturnType<ToThunkFn> & {
|
|
|
5
5
|
export type TrlFn = (...args: any[]) => any;
|
|
6
6
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
7
7
|
export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
8
|
+
export type KeyValueObject = {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
};
|
|
11
|
+
export type KeyValueObjectWithId = {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
id: string | number | symbol;
|
|
14
|
+
};
|
|
15
|
+
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
16
|
+
export type ObjectWithoutId = Omit<KeyValueObject, 'id'>;
|
|
17
|
+
export type ObjectWithNonNumberId = {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
id: string | boolean | symbol | null | object | undefined;
|
|
20
|
+
};
|
|
21
|
+
export type ObjectWithNumberId = {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
id: number;
|
|
24
|
+
};
|
|
25
|
+
export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | Function | never;
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: nu
|
|
|
7
7
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
8
8
|
* @license MIT License
|
|
9
9
|
*/
|
|
10
|
-
import type { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
|
|
10
|
+
import type { NonNumberNonObjectButDefined, ObjectWithNonNumberId, ObjectWithNumberId, ObjectWithoutId, Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
|
|
11
11
|
export declare const THUNK_SYMBOL: unique symbol;
|
|
12
12
|
export declare const isThunk: (fnOrValue: any) => boolean;
|
|
13
13
|
export declare const toThunk: (fn: ToThunkFn) => Thunk;
|
|
@@ -17,3 +17,8 @@ export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>
|
|
|
17
17
|
export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
|
|
18
18
|
cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
|
|
19
19
|
};
|
|
20
|
+
export declare function isNonNumberNonObjectButDefined(val: any): val is NonNumberNonObjectButDefined;
|
|
21
|
+
export declare function isObjectWithoutId(val: any): val is ObjectWithoutId;
|
|
22
|
+
export declare function isObjectWithNonNumberId(val: any): val is ObjectWithNonNumberId;
|
|
23
|
+
export declare function isObjectWithNumberId(val: any): val is ObjectWithNumberId;
|
|
24
|
+
export declare function isNumber(val: any): val is number;
|