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
package/package.json
CHANGED
|
@@ -1,62 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.12.9",
|
|
4
|
+
"description": "Explore our comprehensive Javascript Data Structure / TypeScript Data Structure Library, meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures, such as Binary Tree, AVL Tree, Binary Search Tree (BST), Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Singly Linked List, Hash, CoordinateSet, CoordinateMap, Heap, Doubly Linked List, Priority Queue, Max Priority Queue, Min Priority Queue, Queue, ObjectDeque, ArrayDeque, Stack, and Trie. Each data structure is thoughtfully designed and implemented using TypeScript to provide efficient, reliable, and easy-to-use solutions for your programming needs. Whether you're optimizing algorithms, managing data, or enhancing performance, our TypeScript Data Structure Library is your go-to resource. Elevate your coding experience with these fundamental building blocks for software development.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"build": "rm -rf dist && npx tsc",
|
|
8
|
+
"test": "jest",
|
|
9
|
+
"build:docs": "typedoc --out docs ./src",
|
|
10
|
+
"deps:check": "dependency-cruiser src"
|
|
8
11
|
},
|
|
9
12
|
"repository": {
|
|
10
13
|
"type": "git",
|
|
11
14
|
"url": "git+https://github.com/zrwusa/data-structure-typed.git"
|
|
12
15
|
},
|
|
13
16
|
"keywords": [
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"Binary",
|
|
21
|
-
"Tree",
|
|
22
|
-
"AVL",
|
|
23
|
-
"Tree",
|
|
24
|
-
"Binary",
|
|
25
|
-
"Indexed",
|
|
26
|
-
"Tree",
|
|
27
|
-
"Binary",
|
|
28
|
-
"Search",
|
|
29
|
-
"Tree",
|
|
30
|
-
"Segment",
|
|
31
|
-
"Tree",
|
|
32
|
-
"Tree",
|
|
33
|
-
"Multiset",
|
|
34
|
-
"Graph",
|
|
35
|
-
"Directed",
|
|
17
|
+
"Binary Tree",
|
|
18
|
+
"Binary Search Tree (BST)",
|
|
19
|
+
"AVL Tree",
|
|
20
|
+
"Tree Multiset",
|
|
21
|
+
"Segment Tree",
|
|
22
|
+
"Binary Indexed Tree",
|
|
36
23
|
"Graph",
|
|
37
|
-
"
|
|
38
|
-
"Graph",
|
|
39
|
-
"Linked",
|
|
40
|
-
"List",
|
|
41
|
-
"
|
|
42
|
-
"Linked",
|
|
43
|
-
"List",
|
|
44
|
-
"Doubly",
|
|
45
|
-
"Linked",
|
|
46
|
-
"List",
|
|
47
|
-
"Matrix",
|
|
48
|
-
"Priority",
|
|
49
|
-
"Queue",
|
|
50
|
-
"Max",
|
|
51
|
-
"Priority",
|
|
24
|
+
"Directed Graph",
|
|
25
|
+
"Undirected Graph",
|
|
26
|
+
"Linked List",
|
|
27
|
+
"Singly Linked List",
|
|
28
|
+
"Doubly Linked List",
|
|
52
29
|
"Queue",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"Queue",
|
|
56
|
-
"Queue",
|
|
57
|
-
"Queue",
|
|
58
|
-
"Dequeue",
|
|
30
|
+
"Object Deque",
|
|
31
|
+
"Array Deque",
|
|
59
32
|
"Stack",
|
|
33
|
+
"Hash",
|
|
34
|
+
"Coordinate Set",
|
|
35
|
+
"Coordinate Map",
|
|
36
|
+
"Heap",
|
|
37
|
+
"Priority Queue",
|
|
38
|
+
"Max Priority Queue",
|
|
39
|
+
"Min Priority Queue",
|
|
60
40
|
"Trie"
|
|
61
41
|
],
|
|
62
42
|
"author": "Tyler Zeng",
|
|
@@ -67,7 +47,13 @@
|
|
|
67
47
|
"homepage": "https://github.com/zrwusa/data-structure-typed#readme",
|
|
68
48
|
"types": "dist/index.d.ts",
|
|
69
49
|
"devDependencies": {
|
|
70
|
-
"@types/
|
|
50
|
+
"@types/jest": "^29.5.3",
|
|
51
|
+
"@types/lodash": "^4.14.197",
|
|
52
|
+
"@types/node": "^20.4.9",
|
|
53
|
+
"dependency-cruiser": "^13.1.2",
|
|
54
|
+
"jest": "^29.6.2",
|
|
55
|
+
"ts-jest": "^29.1.1",
|
|
56
|
+
"typedoc": "^0.24.8",
|
|
71
57
|
"typescript": "^4.6.2"
|
|
72
58
|
},
|
|
73
59
|
"dependencies": {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# iterate the directory to rename and clear content of files
|
|
4
|
+
rename_and_clear_files() {
|
|
5
|
+
local directory="$1"
|
|
6
|
+
local extension="$2"
|
|
7
|
+
local new_prefix="$3"
|
|
8
|
+
|
|
9
|
+
for file in "$directory"/*; do
|
|
10
|
+
if [ -d "$file" ]; then
|
|
11
|
+
rename_and_clear_files "$file" "$extension" "$new_prefix"
|
|
12
|
+
elif [ -f "$file" ] && [[ "$file" == *"$extension" ]]; then
|
|
13
|
+
filename=$(basename "$file" "$extension")
|
|
14
|
+
new_name="$directory/${filename}${new_prefix}${extension}"
|
|
15
|
+
mv "$file" "$new_name"
|
|
16
|
+
echo "Renamed $file to $new_name"
|
|
17
|
+
> "$new_name" # clear content of file
|
|
18
|
+
fi
|
|
19
|
+
done
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
# check if directory, extension and prefix were provided
|
|
23
|
+
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
|
|
24
|
+
echo "Usage: $0 <directory> <extension> <new_prefix>"
|
|
25
|
+
exit 1
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
# evoke the recursive function to rename and clear files
|
|
29
|
+
rename_and_clear_files "$1" "$2" "$3"
|
|
Binary file
|
|
Binary file
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
1
5
|
import {BST, BSTNode} from './bst';
|
|
2
|
-
import {BinaryTreeNodeId} from '
|
|
3
|
-
|
|
4
|
-
export interface AVLTreeDeleted<T> {
|
|
5
|
-
deleted: AVLTreeNode<T> | null;
|
|
6
|
-
needBalanced: AVLTreeNode<T> | null;
|
|
7
|
-
}
|
|
6
|
+
import type {AVLTreeDeleted, BinaryTreeNodeId} from '../types';
|
|
8
7
|
|
|
9
8
|
export class AVLTreeNode<T> extends BSTNode<T> {
|
|
10
9
|
override clone(): AVLTreeNode<T> {
|
|
@@ -18,12 +17,34 @@ export class AVLTree<T> extends BST<T> {
|
|
|
18
17
|
return new AVLTreeNode<T>(id, val, count);
|
|
19
18
|
}
|
|
20
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The function overrides the put method of a Binary Search Tree to insert a node with a given id and value, and then
|
|
22
|
+
* balances the tree.
|
|
23
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to put or
|
|
24
|
+
* update in the AVL tree.
|
|
25
|
+
* @param {T | null} val - The `val` parameter represents the value that you want to assign to the node with the given
|
|
26
|
+
* `id`. It can be of type `T` (the generic type) or `null`.
|
|
27
|
+
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
|
|
28
|
+
* of times the value `val` should be inserted into the AVL tree. If the `count` parameter is not provided, it defaults
|
|
29
|
+
* to `1`, indicating that the value should be inserted once.
|
|
30
|
+
* @returns The method is returning either an AVLTreeNode<T> object or null.
|
|
31
|
+
*/
|
|
21
32
|
override put(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null {
|
|
22
33
|
const inserted = super.put(id, val, count);
|
|
23
34
|
if (inserted) this.balancePath(inserted);
|
|
24
35
|
return inserted;
|
|
25
36
|
}
|
|
26
37
|
|
|
38
|
+
/**
|
|
39
|
+
* The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
|
|
40
|
+
* then balances the tree if necessary.
|
|
41
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
|
|
42
|
+
* removed from the AVL tree.
|
|
43
|
+
* @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean parameter that
|
|
44
|
+
* determines whether the left sum of all nodes in the AVL tree should be updated after removing a node. If
|
|
45
|
+
* `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
|
|
46
|
+
* @returns The method is returning an array of `AVLTreeDeleted<T>` objects.
|
|
47
|
+
*/
|
|
27
48
|
override remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): AVLTreeDeleted<T>[] {
|
|
28
49
|
const deletedResults = super.remove(id, isUpdateAllLeftSum);
|
|
29
50
|
for (const {needBalanced} of deletedResults) {
|
|
@@ -34,6 +55,12 @@ export class AVLTree<T> extends BST<T> {
|
|
|
34
55
|
return deletedResults;
|
|
35
56
|
}
|
|
36
57
|
|
|
58
|
+
/**
|
|
59
|
+
* The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
|
|
60
|
+
* height of its right subtree.
|
|
61
|
+
* @param node - The parameter "node" is of type AVLTreeNode<T>, which represents a node in an AVL tree.
|
|
62
|
+
* @returns The balance factor of the given AVL tree node.
|
|
63
|
+
*/
|
|
37
64
|
balanceFactor(node: AVLTreeNode<T>): number {
|
|
38
65
|
if (!node.right) // node has no right subtree
|
|
39
66
|
return -node.height;
|
|
@@ -43,6 +70,10 @@ export class AVLTree<T> extends BST<T> {
|
|
|
43
70
|
return node.right.height - node.left.height;
|
|
44
71
|
}
|
|
45
72
|
|
|
73
|
+
/**
|
|
74
|
+
* The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.
|
|
75
|
+
* @param node - The parameter `node` is an AVLTreeNode object, which represents a node in an AVL tree.
|
|
76
|
+
*/
|
|
46
77
|
updateHeight(node: AVLTreeNode<T>): void {
|
|
47
78
|
if (!node.left && !node.right) // node is a leaf
|
|
48
79
|
node.height = 0;
|
|
@@ -56,6 +87,11 @@ export class AVLTree<T> extends BST<T> {
|
|
|
56
87
|
node.height = 1 + Math.max(node.right.height, node.left.height);
|
|
57
88
|
}
|
|
58
89
|
|
|
90
|
+
/**
|
|
91
|
+
* The `balancePath` function balances the AVL tree by performing appropriate rotations based on the balance factor of
|
|
92
|
+
* each node in the path from the given node to the root.
|
|
93
|
+
* @param node - The `node` parameter is an AVLTreeNode object, which represents a node in an AVL tree.
|
|
94
|
+
*/
|
|
59
95
|
balancePath(node: AVLTreeNode<T>): void {
|
|
60
96
|
const path = this.getPathToRoot(node);
|
|
61
97
|
for (let i = path.length - 1; i >= 0; i--) {
|
|
@@ -83,6 +119,10 @@ export class AVLTree<T> extends BST<T> {
|
|
|
83
119
|
}
|
|
84
120
|
}
|
|
85
121
|
|
|
122
|
+
/**
|
|
123
|
+
* The `balanceLL` function performs a left-left rotation on an AVL tree to balance it.
|
|
124
|
+
* @param A - The parameter A is an AVLTreeNode object.
|
|
125
|
+
*/
|
|
86
126
|
balanceLL(A: AVLTreeNode<T>): void {
|
|
87
127
|
const parentOfA = A.parent;
|
|
88
128
|
const B = A.left; // A is left-heavy and B is left-heavy
|
|
@@ -109,6 +149,10 @@ export class AVLTree<T> extends BST<T> {
|
|
|
109
149
|
if (B) this.updateHeight(B);
|
|
110
150
|
}
|
|
111
151
|
|
|
152
|
+
/**
|
|
153
|
+
* The `balanceLR` function performs a left-right rotation to balance an AVL tree.
|
|
154
|
+
* @param A - A is an AVLTreeNode object.
|
|
155
|
+
*/
|
|
112
156
|
balanceLR(A: AVLTreeNode<T>): void {
|
|
113
157
|
const parentOfA = A.parent;
|
|
114
158
|
const B = A.left; // A is left-heavy
|
|
@@ -153,6 +197,10 @@ export class AVLTree<T> extends BST<T> {
|
|
|
153
197
|
C && this.updateHeight(C);
|
|
154
198
|
}
|
|
155
199
|
|
|
200
|
+
/**
|
|
201
|
+
* The `balanceRR` function performs a right-right rotation on an AVL tree to balance it.
|
|
202
|
+
* @param A - The parameter A is an AVLTreeNode object.
|
|
203
|
+
*/
|
|
156
204
|
balanceRR(A: AVLTreeNode<T>): void {
|
|
157
205
|
const parentOfA = A.parent;
|
|
158
206
|
const B = A.right; // A is right-heavy and B is right-heavy
|
|
@@ -184,6 +232,10 @@ export class AVLTree<T> extends BST<T> {
|
|
|
184
232
|
B && this.updateHeight(B);
|
|
185
233
|
}
|
|
186
234
|
|
|
235
|
+
/**
|
|
236
|
+
* The `balanceRL` function performs a right-left rotation to balance an AVL tree.
|
|
237
|
+
* @param A - A is an AVLTreeNode object.
|
|
238
|
+
*/
|
|
187
239
|
balanceRL(A: AVLTreeNode<T>): void {
|
|
188
240
|
const parentOfA = A.parent;
|
|
189
241
|
const B = A.right; // A is right-heavy
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
1
5
|
export class BinaryIndexedTree {
|
|
2
6
|
private readonly _sumTree: number[];
|
|
3
7
|
|
|
@@ -5,6 +9,18 @@ export class BinaryIndexedTree {
|
|
|
5
9
|
this._sumTree = new Array<number>(n + 1).fill(0);
|
|
6
10
|
}
|
|
7
11
|
|
|
12
|
+
static lowBit(x: number) {
|
|
13
|
+
return x & (-x);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The update function updates the values in a binary indexed tree by adding a delta value to the specified index and
|
|
18
|
+
* its ancestors.
|
|
19
|
+
* @param {number} i - The parameter `i` represents the index of the element in the `_sumTree` array that needs to be
|
|
20
|
+
* updated.
|
|
21
|
+
* @param {number} delta - The "delta" parameter represents the change in value that needs to be added to the element
|
|
22
|
+
* at index "i" in the "_sumTree" array.
|
|
23
|
+
*/
|
|
8
24
|
update(i: number, delta: number) {
|
|
9
25
|
while (i < this._sumTree.length) {
|
|
10
26
|
this._sumTree[i] += delta;
|
|
@@ -12,6 +28,13 @@ export class BinaryIndexedTree {
|
|
|
12
28
|
}
|
|
13
29
|
}
|
|
14
30
|
|
|
31
|
+
/**
|
|
32
|
+
* The function calculates the prefix sum of an array using a binary indexed tree.
|
|
33
|
+
* @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
|
|
34
|
+
* array for which we want to calculate the prefix sum.
|
|
35
|
+
* @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
|
|
36
|
+
* `i`.
|
|
37
|
+
*/
|
|
15
38
|
getPrefixSum(i: number) {
|
|
16
39
|
let sum = 0;
|
|
17
40
|
while (i > 0) {
|
|
@@ -21,13 +44,17 @@ export class BinaryIndexedTree {
|
|
|
21
44
|
return sum;
|
|
22
45
|
}
|
|
23
46
|
|
|
47
|
+
/**
|
|
48
|
+
* The function `getRangeSum` calculates the sum of a range of numbers in an array.
|
|
49
|
+
* @param {number} start - The start parameter is the starting index of the range for which we want to calculate the
|
|
50
|
+
* sum.
|
|
51
|
+
* @param {number} end - The "end" parameter represents the ending index of the range for which we want to calculate
|
|
52
|
+
* the sum.
|
|
53
|
+
* @returns the sum of the elements in the range specified by the start and end indices.
|
|
54
|
+
*/
|
|
24
55
|
public getRangeSum(start: number, end: number): number {
|
|
25
56
|
if (!(0 <= start && start <= end && end <= this._sumTree.length))
|
|
26
57
|
throw 'Index out of bounds';
|
|
27
58
|
return this.getPrefixSum(end) - this.getPrefixSum(start);
|
|
28
59
|
}
|
|
29
|
-
|
|
30
|
-
static lowBit(x: number) {
|
|
31
|
-
return x & (-x);
|
|
32
|
-
}
|
|
33
60
|
}
|