data-structure-typed 0.8.18 → 1.12.9
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/.dependency-cruiser.js +449 -0
- package/.idea/data-structure-typed.iml +2 -0
- package/.idea/modules.xml +1 -1
- package/README.md +298 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
- package/dist/data-structures/binary-tree/avl-tree.js +150 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
- package/dist/data-structures/binary-tree/binary-tree.js +747 -369
- package/dist/data-structures/binary-tree/bst.d.ts +20 -8
- package/dist/data-structures/binary-tree/bst.js +164 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
- package/dist/data-structures/binary-tree/segment-tree.js +95 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
- package/dist/data-structures/graph/abstract-graph.js +712 -323
- package/dist/data-structures/graph/directed-graph.d.ts +114 -12
- package/dist/data-structures/graph/directed-graph.js +372 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
- package/dist/data-structures/graph/undirected-graph.js +233 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
- package/dist/data-structures/hash/coordinate-map.js +70 -20
- package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
- package/dist/data-structures/hash/coordinate-set.js +58 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +26 -37
- package/dist/data-structures/heap/heap.js +56 -60
- package/dist/data-structures/heap/max-heap.d.ts +8 -2
- package/dist/data-structures/heap/max-heap.js +32 -9
- package/dist/data-structures/heap/min-heap.d.ts +9 -2
- package/dist/data-structures/heap/min-heap.js +33 -9
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
- package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
- package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
- package/dist/data-structures/matrix/matrix.d.ts +9 -0
- package/dist/data-structures/matrix/matrix.js +19 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
- package/dist/data-structures/matrix/matrix2d.js +158 -61
- package/dist/data-structures/matrix/navigator.d.ts +34 -16
- package/dist/data-structures/matrix/navigator.js +65 -18
- package/dist/data-structures/matrix/vector2d.d.ts +153 -29
- package/dist/data-structures/matrix/vector2d.js +249 -102
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
- package/dist/data-structures/priority-queue/priority-queue.js +285 -116
- package/dist/data-structures/queue/deque.d.ts +69 -0
- package/dist/data-structures/queue/deque.js +151 -56
- package/dist/data-structures/queue/queue.d.ts +34 -37
- package/dist/data-structures/queue/queue.js +59 -61
- package/dist/data-structures/stack/stack.d.ts +29 -35
- package/dist/data-structures/stack/stack.js +51 -56
- package/dist/data-structures/trie/trie.d.ts +36 -6
- package/dist/data-structures/trie/trie.js +256 -83
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/utils/trampoline.d.ts +14 -0
- package/dist/utils/trampoline.js +130 -0
- package/dist/utils/types/index.js +17 -0
- package/dist/{types → utils}/types/utils.d.ts +15 -1
- package/dist/{types → utils/types}/utils.js +21 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
- package/dist/utils/utils.js +651 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +85 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/classes/AVLTree.html +2046 -0
- package/docs/classes/AVLTreeNode.html +423 -0
- package/docs/classes/AaTree.html +117 -0
- package/docs/classes/AbstractEdge.html +198 -0
- package/docs/classes/AbstractGraph.html +891 -0
- package/docs/classes/AbstractVertex.html +164 -0
- package/docs/classes/ArrayDeque.html +384 -0
- package/docs/classes/BST.html +1893 -0
- package/docs/classes/BSTNode.html +425 -0
- package/docs/classes/BTree.html +117 -0
- package/docs/classes/BinaryIndexedTree.html +244 -0
- package/docs/classes/BinaryTree.html +1754 -0
- package/docs/classes/BinaryTreeNode.html +396 -0
- package/docs/classes/Character.html +165 -0
- package/docs/classes/CoordinateMap.html +394 -0
- package/docs/classes/CoordinateSet.html +355 -0
- package/docs/classes/Deque.html +617 -0
- package/docs/classes/DirectedEdge.html +247 -0
- package/docs/classes/DirectedGraph.html +1207 -0
- package/docs/classes/DirectedVertex.html +154 -0
- package/docs/classes/DoublyLinkedList.html +619 -0
- package/docs/classes/DoublyLinkedListNode.html +160 -0
- package/docs/classes/Heap.html +315 -0
- package/docs/classes/Matrix2D.html +447 -0
- package/docs/classes/MatrixNTI2D.html +181 -0
- package/docs/classes/MaxHeap.html +325 -0
- package/docs/classes/MaxPriorityQueue.html +668 -0
- package/docs/classes/MinHeap.html +326 -0
- package/docs/classes/MinPriorityQueue.html +668 -0
- package/docs/classes/Navigator.html +285 -0
- package/docs/classes/ObjectDeque.html +289 -0
- package/docs/classes/PriorityQueue.html +643 -0
- package/docs/classes/Queue.html +337 -0
- package/docs/classes/RBTree.html +117 -0
- package/docs/classes/SegmentTree.html +234 -0
- package/docs/classes/SegmentTreeNode.html +302 -0
- package/docs/classes/SinglyLinkedList.html +1035 -0
- package/docs/classes/SinglyLinkedListNode.html +304 -0
- package/docs/classes/SplayTree.html +117 -0
- package/docs/classes/Stack.html +313 -0
- package/docs/classes/TreeMultiSet.html +1897 -0
- package/docs/classes/Trie.html +317 -0
- package/docs/classes/TrieNode.html +221 -0
- package/docs/classes/TwoThreeTree.html +117 -0
- package/docs/classes/UndirectedEdge.html +220 -0
- package/docs/classes/UndirectedGraph.html +1006 -0
- package/docs/classes/UndirectedVertex.html +154 -0
- package/docs/classes/Vector2D.html +746 -0
- package/docs/enums/CP.html +126 -0
- package/docs/enums/FamilyPosition.html +126 -0
- package/docs/enums/LoopType.html +119 -0
- package/docs/index.html +288 -0
- package/docs/modules.html +146 -0
- package/jest.config.js +5 -0
- package/package.json +33 -47
- package/rename_clear_files.sh +29 -0
- package/src/assets/complexities-diff.jpg +0 -0
- package/src/assets/data-structure-complexities.jpg +0 -0
- package/src/data-structures/binary-tree/avl-tree.ts +58 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
- package/src/data-structures/binary-tree/binary-tree.ts +460 -145
- package/src/data-structures/binary-tree/bst.ts +31 -25
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/segment-tree.ts +25 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
- package/src/data-structures/diagrams/README.md +5 -0
- package/src/data-structures/graph/abstract-graph.ts +224 -108
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/src/data-structures/graph/directed-graph.ts +132 -26
- package/src/data-structures/graph/undirected-graph.ts +78 -11
- package/src/data-structures/hash/coordinate-map.ts +33 -1
- package/src/data-structures/hash/coordinate-set.ts +25 -0
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +27 -41
- package/src/data-structures/heap/max-heap.ts +8 -2
- package/src/data-structures/heap/min-heap.ts +9 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
- package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
- package/src/data-structures/matrix/matrix.ts +11 -0
- package/src/data-structures/matrix/matrix2d.ts +90 -10
- package/src/data-structures/matrix/navigator.ts +34 -14
- package/src/data-structures/matrix/vector2d.ts +187 -63
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
- package/src/data-structures/priority-queue/priority-queue.ts +200 -78
- package/src/data-structures/queue/deque.ts +71 -2
- package/src/data-structures/queue/queue.ts +37 -40
- package/src/data-structures/stack/stack.ts +32 -38
- package/src/data-structures/trie/trie.ts +83 -14
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +13 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +1 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/trampoline.ts +51 -0
- package/src/utils/types/index.ts +1 -0
- package/src/{types → utils/types}/utils.ts +27 -5
- package/src/{utils.ts → utils/utils.ts} +41 -131
- package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
- package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
- package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
- package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
- package/tsconfig.json +9 -6
- package/dist/data-structures/trampoline.d.ts +0 -25
- package/dist/data-structures/trampoline.js +0 -52
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/data-structures/trampoline.ts +0 -91
- package/src/types/index.ts +0 -1
- /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +0 -0
- /package/dist/{types → utils}/types/index.d.ts +0 -0
- /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
|
@@ -3,95 +3,90 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Stack = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @license MIT
|
|
6
|
-
* @copyright
|
|
7
|
-
*
|
|
6
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
8
7
|
* @class
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
var Stack = /** @class */ (function () {
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @param {
|
|
11
|
+
* The constructor initializes an array of elements, which can be provided as an optional parameter.
|
|
12
|
+
* @param {T[]} [elements] - The `elements` parameter is an optional parameter of type `T[]`, which represents an array
|
|
13
|
+
* of elements of type `T`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
|
|
14
|
+
* is provided and is an array, it is assigned to the `_elements
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
function Stack(elements) {
|
|
16
17
|
this._elements = Array.isArray(elements) ? elements : [];
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
* @returns {
|
|
20
|
+
* The function "fromArray" creates a new Stack object from an array of elements.
|
|
21
|
+
* @param {T[]} elements - The `elements` parameter is an array of elements of type `T`.
|
|
22
|
+
* @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
|
|
23
|
+
* array.
|
|
22
24
|
*/
|
|
23
|
-
|
|
25
|
+
Stack.fromArray = function (elements) {
|
|
26
|
+
return new Stack(elements);
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The function checks if an array is empty and returns a boolean value.
|
|
30
|
+
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
31
|
+
*/
|
|
32
|
+
Stack.prototype.isEmpty = function () {
|
|
24
33
|
return this._elements.length === 0;
|
|
25
|
-
}
|
|
34
|
+
};
|
|
26
35
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
29
|
-
* @returns {number}
|
|
36
|
+
* The size() function returns the number of elements in an array.
|
|
37
|
+
* @returns The size of the elements array.
|
|
30
38
|
*/
|
|
31
|
-
size() {
|
|
39
|
+
Stack.prototype.size = function () {
|
|
32
40
|
return this._elements.length;
|
|
33
|
-
}
|
|
41
|
+
};
|
|
34
42
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @
|
|
37
|
-
* @returns {object}
|
|
43
|
+
* The `peek` function returns the last element of an array, or null if the array is empty.
|
|
44
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
|
|
38
45
|
*/
|
|
39
|
-
peek() {
|
|
46
|
+
Stack.prototype.peek = function () {
|
|
40
47
|
if (this.isEmpty())
|
|
41
48
|
return null;
|
|
42
49
|
return this._elements[this._elements.length - 1];
|
|
43
|
-
}
|
|
50
|
+
};
|
|
44
51
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @
|
|
47
|
-
* @
|
|
52
|
+
* The push function adds an element to the stack and returns the updated stack.
|
|
53
|
+
* @param {T} element - The parameter "element" is of type T, which means it can be any data type.
|
|
54
|
+
* @returns The `push` method is returning the updated `Stack<T>` object.
|
|
48
55
|
*/
|
|
49
|
-
push(element) {
|
|
56
|
+
Stack.prototype.push = function (element) {
|
|
50
57
|
this._elements.push(element);
|
|
51
58
|
return this;
|
|
52
|
-
}
|
|
59
|
+
};
|
|
53
60
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
56
|
-
*
|
|
61
|
+
* The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
|
|
62
|
+
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
63
|
+
* array is empty, it returns `null`.
|
|
57
64
|
*/
|
|
58
|
-
pop() {
|
|
65
|
+
Stack.prototype.pop = function () {
|
|
59
66
|
if (this.isEmpty())
|
|
60
67
|
return null;
|
|
61
68
|
return this._elements.pop() || null;
|
|
62
|
-
}
|
|
69
|
+
};
|
|
63
70
|
/**
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
66
|
-
* @returns {array}
|
|
71
|
+
* The toArray function returns a copy of the elements in an array.
|
|
72
|
+
* @returns An array of type T.
|
|
67
73
|
*/
|
|
68
|
-
toArray() {
|
|
74
|
+
Stack.prototype.toArray = function () {
|
|
69
75
|
return this._elements.slice();
|
|
70
|
-
}
|
|
76
|
+
};
|
|
71
77
|
/**
|
|
72
|
-
*
|
|
73
|
-
* @public
|
|
78
|
+
* The clear function clears the elements array.
|
|
74
79
|
*/
|
|
75
|
-
clear() {
|
|
80
|
+
Stack.prototype.clear = function () {
|
|
76
81
|
this._elements = [];
|
|
77
|
-
}
|
|
82
|
+
};
|
|
78
83
|
/**
|
|
79
|
-
*
|
|
80
|
-
* @
|
|
81
|
-
* @return {Stack}
|
|
84
|
+
* The `clone()` function returns a new `Stack` object with the same elements as the original stack.
|
|
85
|
+
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
82
86
|
*/
|
|
83
|
-
clone() {
|
|
87
|
+
Stack.prototype.clone = function () {
|
|
84
88
|
return new Stack(this._elements.slice());
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
* @public
|
|
89
|
-
* @static
|
|
90
|
-
* @param {array} [elements]
|
|
91
|
-
* @return {Stack}
|
|
92
|
-
*/
|
|
93
|
-
static fromArray(elements) {
|
|
94
|
-
return new Stack(elements);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
89
|
+
};
|
|
90
|
+
return Stack;
|
|
91
|
+
}());
|
|
97
92
|
exports.Stack = Stack;
|
|
@@ -1,28 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
1
5
|
export declare class TrieNode {
|
|
6
|
+
protected _value: string;
|
|
7
|
+
constructor(v: string);
|
|
2
8
|
protected _children: Map<string, TrieNode>;
|
|
3
9
|
get children(): Map<string, TrieNode>;
|
|
4
10
|
set children(v: Map<string, TrieNode>);
|
|
5
11
|
protected _isEnd: boolean;
|
|
6
12
|
get isEnd(): boolean;
|
|
7
13
|
set isEnd(v: boolean);
|
|
14
|
+
get val(): string;
|
|
15
|
+
set val(v: string);
|
|
8
16
|
}
|
|
9
17
|
export declare class Trie {
|
|
18
|
+
constructor(words?: string[]);
|
|
10
19
|
protected _root: TrieNode;
|
|
11
20
|
get root(): TrieNode;
|
|
12
21
|
set root(v: TrieNode);
|
|
13
|
-
|
|
14
|
-
put(input: string): boolean;
|
|
22
|
+
put(word: string): boolean;
|
|
15
23
|
has(input: string): boolean;
|
|
16
24
|
remove(word: string): boolean;
|
|
17
25
|
/**
|
|
18
|
-
* Only can present as a prefix, not a word
|
|
19
|
-
* @param input
|
|
26
|
+
* The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
|
|
27
|
+
* @param {string} input - The input parameter is a string that represents the input value for the function.
|
|
28
|
+
* @returns a boolean value.
|
|
20
29
|
*/
|
|
21
30
|
isAbsPrefix(input: string): boolean;
|
|
22
31
|
/**
|
|
23
|
-
* Can present as a prefix or word
|
|
24
|
-
* @param input
|
|
32
|
+
* The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
|
|
33
|
+
* @param {string} input - The input parameter is a string that represents the prefix we want to check.
|
|
34
|
+
* @returns a boolean value.
|
|
25
35
|
*/
|
|
26
36
|
isPrefix(input: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
|
|
39
|
+
* @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
|
|
40
|
+
* in the Trie data structure.
|
|
41
|
+
* @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
|
|
42
|
+
*/
|
|
43
|
+
isCommonPrefix(input: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
|
|
46
|
+
* structure.
|
|
47
|
+
* @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
|
|
48
|
+
* Trie.
|
|
49
|
+
*/
|
|
50
|
+
getLongestCommonPrefix(): string;
|
|
51
|
+
/**
|
|
52
|
+
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
53
|
+
* @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
54
|
+
* trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
|
|
55
|
+
* @returns an array of strings.
|
|
56
|
+
*/
|
|
27
57
|
getAll(prefix?: string): string[];
|
|
28
58
|
}
|
|
@@ -1,63 +1,140 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.Trie = exports.TrieNode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
17
|
+
* @license MIT
|
|
18
|
+
*/
|
|
19
|
+
var TrieNode = /** @class */ (function () {
|
|
20
|
+
function TrieNode(v) {
|
|
21
|
+
this._value = v;
|
|
7
22
|
this._isEnd = false;
|
|
23
|
+
this._children = new Map();
|
|
8
24
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
Object.defineProperty(TrieNode.prototype, "children", {
|
|
26
|
+
get: function () {
|
|
27
|
+
return this._children;
|
|
28
|
+
},
|
|
29
|
+
set: function (v) {
|
|
30
|
+
this._children = v;
|
|
31
|
+
},
|
|
32
|
+
enumerable: false,
|
|
33
|
+
configurable: true
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(TrieNode.prototype, "isEnd", {
|
|
36
|
+
get: function () {
|
|
37
|
+
return this._isEnd;
|
|
38
|
+
},
|
|
39
|
+
set: function (v) {
|
|
40
|
+
this._isEnd = v;
|
|
41
|
+
},
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: true
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(TrieNode.prototype, "val", {
|
|
46
|
+
get: function () {
|
|
47
|
+
return this._value;
|
|
48
|
+
},
|
|
49
|
+
set: function (v) {
|
|
50
|
+
this._value = v;
|
|
51
|
+
},
|
|
52
|
+
enumerable: false,
|
|
53
|
+
configurable: true
|
|
54
|
+
});
|
|
55
|
+
return TrieNode;
|
|
56
|
+
}());
|
|
22
57
|
exports.TrieNode = TrieNode;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
58
|
+
var Trie = /** @class */ (function () {
|
|
59
|
+
function Trie(words) {
|
|
60
|
+
var e_1, _a;
|
|
61
|
+
this._root = new TrieNode('');
|
|
62
|
+
if (words) {
|
|
63
|
+
try {
|
|
64
|
+
for (var words_1 = __values(words), words_1_1 = words_1.next(); !words_1_1.done; words_1_1 = words_1.next()) {
|
|
65
|
+
var i = words_1_1.value;
|
|
66
|
+
this.put(i);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
70
|
+
finally {
|
|
71
|
+
try {
|
|
72
|
+
if (words_1_1 && !words_1_1.done && (_a = words_1.return)) _a.call(words_1);
|
|
73
|
+
}
|
|
74
|
+
finally { if (e_1) throw e_1.error; }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
32
77
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
78
|
+
Object.defineProperty(Trie.prototype, "root", {
|
|
79
|
+
get: function () {
|
|
80
|
+
return this._root;
|
|
81
|
+
},
|
|
82
|
+
set: function (v) {
|
|
83
|
+
this._root = v;
|
|
84
|
+
},
|
|
85
|
+
enumerable: false,
|
|
86
|
+
configurable: true
|
|
87
|
+
});
|
|
88
|
+
Trie.prototype.put = function (word) {
|
|
89
|
+
var e_2, _a;
|
|
90
|
+
var cur = this._root;
|
|
91
|
+
try {
|
|
92
|
+
for (var word_1 = __values(word), word_1_1 = word_1.next(); !word_1_1.done; word_1_1 = word_1.next()) {
|
|
93
|
+
var c = word_1_1.value;
|
|
94
|
+
var nodeC = cur.children.get(c);
|
|
95
|
+
if (!nodeC) {
|
|
96
|
+
nodeC = new TrieNode(c);
|
|
97
|
+
cur.children.set(c, nodeC);
|
|
98
|
+
}
|
|
99
|
+
cur = nodeC;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
103
|
+
finally {
|
|
104
|
+
try {
|
|
105
|
+
if (word_1_1 && !word_1_1.done && (_a = word_1.return)) _a.call(word_1);
|
|
106
|
+
}
|
|
107
|
+
finally { if (e_2) throw e_2.error; }
|
|
42
108
|
}
|
|
43
109
|
cur.isEnd = true;
|
|
44
110
|
return true;
|
|
45
|
-
}
|
|
46
|
-
has(input) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
111
|
+
};
|
|
112
|
+
Trie.prototype.has = function (input) {
|
|
113
|
+
var e_3, _a;
|
|
114
|
+
var cur = this._root;
|
|
115
|
+
try {
|
|
116
|
+
for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
|
|
117
|
+
var c = input_1_1.value;
|
|
118
|
+
var nodeC = cur.children.get(c);
|
|
119
|
+
if (!nodeC)
|
|
120
|
+
return false;
|
|
121
|
+
cur = nodeC;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
125
|
+
finally {
|
|
126
|
+
try {
|
|
127
|
+
if (input_1_1 && !input_1_1.done && (_a = input_1.return)) _a.call(input_1);
|
|
128
|
+
}
|
|
129
|
+
finally { if (e_3) throw e_3.error; }
|
|
53
130
|
}
|
|
54
131
|
return cur.isEnd;
|
|
55
|
-
}
|
|
56
|
-
remove(word) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
132
|
+
};
|
|
133
|
+
Trie.prototype.remove = function (word) {
|
|
134
|
+
var isDeleted = false;
|
|
135
|
+
var dfs = function (cur, i) {
|
|
136
|
+
var char = word[i];
|
|
137
|
+
var child = cur.children.get(char);
|
|
61
138
|
if (child) {
|
|
62
139
|
if (i === word.length - 1) {
|
|
63
140
|
if (child.isEnd) {
|
|
@@ -72,7 +149,7 @@ class Trie {
|
|
|
72
149
|
}
|
|
73
150
|
return false;
|
|
74
151
|
}
|
|
75
|
-
|
|
152
|
+
var res = dfs(child, i + 1);
|
|
76
153
|
if (res && !cur.isEnd && child.children.size === 0) {
|
|
77
154
|
cur.children.delete(char);
|
|
78
155
|
return true;
|
|
@@ -83,59 +160,155 @@ class Trie {
|
|
|
83
160
|
};
|
|
84
161
|
dfs(this.root, 0);
|
|
85
162
|
return isDeleted;
|
|
86
|
-
}
|
|
163
|
+
};
|
|
87
164
|
// --- start additional methods ---
|
|
88
165
|
/**
|
|
89
|
-
* Only can present as a prefix, not a word
|
|
90
|
-
* @param input
|
|
166
|
+
* The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
|
|
167
|
+
* @param {string} input - The input parameter is a string that represents the input value for the function.
|
|
168
|
+
* @returns a boolean value.
|
|
91
169
|
*/
|
|
92
|
-
isAbsPrefix(input) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
170
|
+
Trie.prototype.isAbsPrefix = function (input) {
|
|
171
|
+
var e_4, _a;
|
|
172
|
+
var cur = this._root;
|
|
173
|
+
try {
|
|
174
|
+
for (var input_2 = __values(input), input_2_1 = input_2.next(); !input_2_1.done; input_2_1 = input_2.next()) {
|
|
175
|
+
var c = input_2_1.value;
|
|
176
|
+
var nodeC = cur.children.get(c);
|
|
177
|
+
if (!nodeC)
|
|
178
|
+
return false;
|
|
179
|
+
cur = nodeC;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
183
|
+
finally {
|
|
184
|
+
try {
|
|
185
|
+
if (input_2_1 && !input_2_1.done && (_a = input_2.return)) _a.call(input_2);
|
|
186
|
+
}
|
|
187
|
+
finally { if (e_4) throw e_4.error; }
|
|
99
188
|
}
|
|
100
189
|
return !cur.isEnd;
|
|
101
|
-
}
|
|
190
|
+
};
|
|
102
191
|
/**
|
|
103
|
-
* Can present as a prefix or word
|
|
104
|
-
* @param input
|
|
192
|
+
* The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
|
|
193
|
+
* @param {string} input - The input parameter is a string that represents the prefix we want to check.
|
|
194
|
+
* @returns a boolean value.
|
|
105
195
|
*/
|
|
106
|
-
isPrefix(input) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
196
|
+
Trie.prototype.isPrefix = function (input) {
|
|
197
|
+
var e_5, _a;
|
|
198
|
+
var cur = this._root;
|
|
199
|
+
try {
|
|
200
|
+
for (var input_3 = __values(input), input_3_1 = input_3.next(); !input_3_1.done; input_3_1 = input_3.next()) {
|
|
201
|
+
var c = input_3_1.value;
|
|
202
|
+
var nodeC = cur.children.get(c);
|
|
203
|
+
if (!nodeC)
|
|
204
|
+
return false;
|
|
205
|
+
cur = nodeC;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
209
|
+
finally {
|
|
210
|
+
try {
|
|
211
|
+
if (input_3_1 && !input_3_1.done && (_a = input_3.return)) _a.call(input_3);
|
|
212
|
+
}
|
|
213
|
+
finally { if (e_5) throw e_5.error; }
|
|
113
214
|
}
|
|
114
215
|
return true;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
|
|
219
|
+
* @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
|
|
220
|
+
* in the Trie data structure.
|
|
221
|
+
* @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
|
|
222
|
+
*/
|
|
223
|
+
Trie.prototype.isCommonPrefix = function (input) {
|
|
224
|
+
var commonPre = '';
|
|
225
|
+
var dfs = function (cur) {
|
|
226
|
+
commonPre += cur.val;
|
|
227
|
+
if (commonPre === input)
|
|
228
|
+
return;
|
|
229
|
+
if (cur.isEnd)
|
|
230
|
+
return;
|
|
231
|
+
if (cur && cur.children && cur.children.size === 1)
|
|
232
|
+
dfs(Array.from(cur.children.values())[0]);
|
|
233
|
+
else
|
|
234
|
+
return;
|
|
235
|
+
};
|
|
236
|
+
dfs(this._root);
|
|
237
|
+
return commonPre === input;
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
|
|
241
|
+
* structure.
|
|
242
|
+
* @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
|
|
243
|
+
* Trie.
|
|
244
|
+
*/
|
|
245
|
+
Trie.prototype.getLongestCommonPrefix = function () {
|
|
246
|
+
var commonPre = '';
|
|
247
|
+
var dfs = function (cur) {
|
|
248
|
+
commonPre += cur.val;
|
|
249
|
+
if (cur.isEnd)
|
|
250
|
+
return;
|
|
251
|
+
if (cur && cur.children && cur.children.size === 1)
|
|
252
|
+
dfs(Array.from(cur.children.values())[0]);
|
|
253
|
+
else
|
|
254
|
+
return;
|
|
255
|
+
};
|
|
256
|
+
dfs(this._root);
|
|
257
|
+
return commonPre;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
261
|
+
* @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
262
|
+
* trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
|
|
263
|
+
* @returns an array of strings.
|
|
264
|
+
*/
|
|
265
|
+
Trie.prototype.getAll = function (prefix) {
|
|
266
|
+
var e_6, _a;
|
|
267
|
+
if (prefix === void 0) { prefix = ''; }
|
|
268
|
+
var words = [];
|
|
118
269
|
function dfs(node, word) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
270
|
+
var e_7, _a;
|
|
271
|
+
try {
|
|
272
|
+
for (var _b = __values(node.children.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
273
|
+
var char = _c.value;
|
|
274
|
+
var charNode = node.children.get(char);
|
|
275
|
+
if (charNode !== undefined) {
|
|
276
|
+
dfs(charNode, word.concat(char));
|
|
277
|
+
}
|
|
123
278
|
}
|
|
124
279
|
}
|
|
280
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
281
|
+
finally {
|
|
282
|
+
try {
|
|
283
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
284
|
+
}
|
|
285
|
+
finally { if (e_7) throw e_7.error; }
|
|
286
|
+
}
|
|
125
287
|
if (node.isEnd) {
|
|
126
288
|
words.push(word);
|
|
127
289
|
}
|
|
128
290
|
}
|
|
129
|
-
|
|
291
|
+
var startNode = this._root;
|
|
130
292
|
if (prefix) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
293
|
+
try {
|
|
294
|
+
for (var prefix_1 = __values(prefix), prefix_1_1 = prefix_1.next(); !prefix_1_1.done; prefix_1_1 = prefix_1.next()) {
|
|
295
|
+
var c = prefix_1_1.value;
|
|
296
|
+
var nodeC = startNode.children.get(c);
|
|
297
|
+
if (nodeC)
|
|
298
|
+
startNode = nodeC;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
302
|
+
finally {
|
|
303
|
+
try {
|
|
304
|
+
if (prefix_1_1 && !prefix_1_1.done && (_a = prefix_1.return)) _a.call(prefix_1);
|
|
305
|
+
}
|
|
306
|
+
finally { if (e_6) throw e_6.error; }
|
|
135
307
|
}
|
|
136
308
|
}
|
|
137
309
|
dfs(startNode, prefix);
|
|
138
310
|
return words;
|
|
139
|
-
}
|
|
140
|
-
|
|
311
|
+
};
|
|
312
|
+
return Trie;
|
|
313
|
+
}());
|
|
141
314
|
exports.Trie = Trie;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type VertexId = string | number;
|
|
2
|
+
export type DijkstraResult<V> = {
|
|
3
|
+
distMap: Map<V, number>;
|
|
4
|
+
preMap: Map<V, V | null>;
|
|
5
|
+
seen: Set<V>;
|
|
6
|
+
paths: V[][];
|
|
7
|
+
minDist: number;
|
|
8
|
+
minPath: V[];
|
|
9
|
+
} | null;
|
|
10
|
+
export interface IGraph<V, E> {
|
|
11
|
+
containsVertex(vertexOrId: V | VertexId): boolean;
|
|
12
|
+
getVertex(vertexOrId: VertexId | V): V | null;
|
|
13
|
+
getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
14
|
+
vertexSet(): Map<VertexId, V>;
|
|
15
|
+
addVertex(v: V): boolean;
|
|
16
|
+
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
17
|
+
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
|
18
|
+
degreeOf(vertexOrId: V | VertexId): number;
|
|
19
|
+
edgesOf(vertexOrId: V | VertexId): E[];
|
|
20
|
+
containsEdge(src: V | VertexId, dest: V | VertexId): boolean;
|
|
21
|
+
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
22
|
+
edgeSet(): E[];
|
|
23
|
+
addEdge(edge: E): boolean;
|
|
24
|
+
removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
25
|
+
removeEdge(edge: E): E | null;
|
|
26
|
+
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
|
|
27
|
+
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
28
|
+
getNeighbors(vertexOrId: V | VertexId): V[];
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BinaryTreeNode } from '../binary-tree';
|
|
2
|
+
export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
|
|
3
|
+
export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
|
|
4
|
+
export type DFSOrderPattern = 'in' | 'pre' | 'post';
|
|
5
|
+
export type BinaryTreeNodeId = number;
|
|
6
|
+
export type BinaryTreeDeleted<T> = {
|
|
7
|
+
deleted: BinaryTreeNode<T> | null | undefined;
|
|
8
|
+
needBalanced: BinaryTreeNode<T> | null;
|
|
9
|
+
};
|
|
10
|
+
export type ResultByProperty<T> = T | BinaryTreeNode<T> | number | BinaryTreeNodeId;
|
|
11
|
+
export type ResultsByProperty<T> = ResultByProperty<T>[];
|
|
12
|
+
export interface BinaryTreeNodeObj<T> {
|
|
13
|
+
id: BinaryTreeNodeId;
|
|
14
|
+
val: T;
|
|
15
|
+
count?: number;
|
|
16
|
+
}
|