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/README.md
CHANGED
|
@@ -1,2 +1,298 @@
|
|
|
1
|
-
# data-structure-
|
|
2
|
-
|
|
1
|
+
# data-structure-typed
|
|
2
|
+
|
|
3
|
+
Javascript Data Structure, TypeScript Data Structure Library
|
|
4
|
+
|
|
5
|
+
## install
|
|
6
|
+
|
|
7
|
+
### yarn
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
yarn add data-structure-typed
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### npm
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install data-structure-typed
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## api docs
|
|
20
|
+
|
|
21
|
+
[//]: # ([api docs](https://data-structure-typed-docs.vercel.app/))
|
|
22
|
+
|
|
23
|
+
<nav class="tsd-navigation"><a href="https://data-structure-typed-docs.vercel.app/modules.html" class="current"><span>data-<wbr/>structure-<wbr/>typed</span></a>
|
|
24
|
+
<ul class="tsd-small-nested-navigation">
|
|
25
|
+
|
|
26
|
+
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/enums/CP.html"><span>CP</span></a></li>)
|
|
27
|
+
|
|
28
|
+
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/enums/FamilyPosition.html"><span>Family<wbr/>Position</span></a></li>)
|
|
29
|
+
|
|
30
|
+
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/enums/LoopType.html"><span>Loop<wbr/>Type</span></a></li>)
|
|
31
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTree.html"><span>AVLTree</span></a></li>
|
|
32
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTreeNode.html"><span>AVLTree<wbr/>Node</span></a></li>
|
|
33
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AaTree.html"><span>Aa<wbr/>Tree</span></a></li>
|
|
34
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractEdge.html"><span>Abstract<wbr/>Edge</span></a></li>
|
|
35
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractGraph.html"><span>Abstract<wbr/>Graph</span></a></li>
|
|
36
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractVertex.html"><span>Abstract<wbr/>Vertex</span></a></li>
|
|
37
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/ArrayDeque.html"><span>Array<wbr/>Deque</span></a></li>
|
|
38
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BST.html"><span>BST</span></a></li>
|
|
39
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BSTNode.html"><span>BSTNode</span></a></li>
|
|
40
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BTree.html"><span>BTree</span></a></li>
|
|
41
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryIndexedTree.html"><span>Binary<wbr/>Indexed<wbr/>Tree</span></a></li>
|
|
42
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html"><span>Binary<wbr/>Tree</span></a></li>
|
|
43
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTreeNode.html"><span>Binary<wbr/>Tree<wbr/>Node</span></a></li>
|
|
44
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Character.html"><span>Character</span></a></li>
|
|
45
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateMap.html"><span>Coordinate<wbr/>Map</span></a></li>
|
|
46
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateSet.html"><span>Coordinate<wbr/>Set</span></a></li>
|
|
47
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Deque.html"><span>Deque</span></a></li>
|
|
48
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedEdge.html"><span>Directed<wbr/>Edge</span></a></li>
|
|
49
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedGraph.html"><span>Directed<wbr/>Graph</span></a></li>
|
|
50
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedVertex.html"><span>Directed<wbr/>Vertex</span></a></li>
|
|
51
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedList.html"><span>Doubly<wbr/>Linked<wbr/>List</span></a></li>
|
|
52
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedListNode.html"><span>Doubly<wbr/>Linked<wbr/>List<wbr/>Node</span></a></li>
|
|
53
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Heap.html"><span>Heap</span></a></li>
|
|
54
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Matrix2D.html"><span>Matrix2D</span></a></li>
|
|
55
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/MatrixNTI2D.html"><span>MatrixNTI2D</span></a></li>
|
|
56
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/MaxHeap.html"><span>Max<wbr/>Heap</span></a></li>
|
|
57
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/MaxPriorityQueue.html"><span>Max<wbr/>Priority<wbr/>Queue</span></a></li>
|
|
58
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/MinHeap.html"><span>Min<wbr/>Heap</span></a></li>
|
|
59
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/MinPriorityQueue.html"><span>Min<wbr/>Priority<wbr/>Queue</span></a></li>
|
|
60
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Navigator.html"><span>Navigator</span></a></li>
|
|
61
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/ObjectDeque.html"><span>Object<wbr/>Deque</span></a></li>
|
|
62
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/PriorityQueue.html"><span>Priority<wbr/>Queue</span></a></li>
|
|
63
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Queue.html"><span>Queue</span></a></li>
|
|
64
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/RBTree.html"><span>RBTree</span></a></li>
|
|
65
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTree.html"><span>Segment<wbr/>Tree</span></a></li>
|
|
66
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTreeNode.html"><span>Segment<wbr/>Tree<wbr/>Node</span></a></li>
|
|
67
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>Singly<wbr/>Linked<wbr/>List</span></a></li>
|
|
68
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedListNode.html"><span>Singly<wbr/>Linked<wbr/>List<wbr/>Node</span></a></li>
|
|
69
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SplayTree.html"><span>Splay<wbr/>Tree</span></a></li>
|
|
70
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Stack.html"><span>Stack</span></a></li>
|
|
71
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiSet.html"><span>Tree<wbr/>Multi<wbr/>Set</span></a></li>
|
|
72
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Trie.html"><span>Trie</span></a></li>
|
|
73
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/TrieNode.html"><span>Trie<wbr/>Node</span></a></li>
|
|
74
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/TwoThreeTree.html"><span>Two<wbr/>Three<wbr/>Tree</span></a></li>
|
|
75
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedEdge.html"><span>Undirected<wbr/>Edge</span></a></li>
|
|
76
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedGraph.html"><span>Undirected<wbr/>Graph</span></a></li>
|
|
77
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedVertex.html"><span>Undirected<wbr/>Vertex</span></a></li>
|
|
78
|
+
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Vector2D.html"><span>Vector2D</span></a></li></ul></nav>
|
|
79
|
+
|
|
80
|
+
## data structures
|
|
81
|
+
|
|
82
|
+
Meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures:
|
|
83
|
+
Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack, Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
|
|
84
|
+
<table>
|
|
85
|
+
<thead>
|
|
86
|
+
<tr>
|
|
87
|
+
<th>Data Structure</th>
|
|
88
|
+
<th>Derived</th>
|
|
89
|
+
<th>Basic Features</th>
|
|
90
|
+
<th>Additional Features</th>
|
|
91
|
+
</tr>
|
|
92
|
+
</thead>
|
|
93
|
+
|
|
94
|
+
<tbody>
|
|
95
|
+
<tr>
|
|
96
|
+
<td>Binary Tree</td>
|
|
97
|
+
<td>AVL Tree, Binary Search Tree, Tree Multiset</td>
|
|
98
|
+
<td>put, has, get, remove, size, insertTo, insertMany, fill, getDepth, getHeight, getMinHeight, getPathToRoot, isBalanced </td>
|
|
99
|
+
<td>getLeftMost, isBST, getSubTreeSizeAndCount, subTreeSum, subTreeAdd, BFS, DFS, DFSIterative, levelIterative, listLevels, getPredecessor, morris, </td>
|
|
100
|
+
</tr>
|
|
101
|
+
|
|
102
|
+
<tr>
|
|
103
|
+
<td>AVL Tree</td>
|
|
104
|
+
<td></td>
|
|
105
|
+
<td>All the features inherited from Binary Tree, balanceFactor, updateHeight, balancePath, balanceLL, balanceLR, balanceRR, balanceRL</td>
|
|
106
|
+
<td></td>
|
|
107
|
+
</tr>
|
|
108
|
+
|
|
109
|
+
<tr>
|
|
110
|
+
<td>Binary Search Tree (BST)</td>
|
|
111
|
+
<td></td>
|
|
112
|
+
<td>All the features inherited from Binary Tree, lastKey</td>
|
|
113
|
+
<td>All the features inherited from Binary Tree, lesserSum, allGreaterNodesAdd, balance, isAVLBalanced</td>
|
|
114
|
+
</tr>
|
|
115
|
+
|
|
116
|
+
<tr>
|
|
117
|
+
<td>Tree Multiset</td>
|
|
118
|
+
<td></td>
|
|
119
|
+
<td>All the features inherited from Binary Tree</td>
|
|
120
|
+
<td>All the features inherited from Binary Tree</td>
|
|
121
|
+
</tr>
|
|
122
|
+
|
|
123
|
+
<tr>
|
|
124
|
+
<td>Segment Tree</td>
|
|
125
|
+
<td></td>
|
|
126
|
+
<td>build, updateNode, querySumByRange</td>
|
|
127
|
+
<td></td>
|
|
128
|
+
</tr>
|
|
129
|
+
|
|
130
|
+
<tr>
|
|
131
|
+
<td>Binary Indexed Tree</td>
|
|
132
|
+
<td></td>
|
|
133
|
+
<td>update, getPrefixSum, getRangeSum, BinaryIndexedTree.lowBit</td>
|
|
134
|
+
<td></td>
|
|
135
|
+
</tr>
|
|
136
|
+
<tr>
|
|
137
|
+
<td>Graph</td>
|
|
138
|
+
<td>Directed Graph, Undirected Graph</td>
|
|
139
|
+
<td>getVertex, getVertexId, containsVertex, vertexSet, addVertex, removeVertex, removeAllVertices, containsEdge, setEdgeWeight, getAllPathsBetween, getPathSumWeight, getMinCostBetween, getMinPathBetween, </td>
|
|
140
|
+
<td>dijkstra, dijkstraWithoutHeap, bellmanFord, floyd, tarjan</td>
|
|
141
|
+
</tr>
|
|
142
|
+
<tr>
|
|
143
|
+
<td>Directed Graph</td>
|
|
144
|
+
<td></td>
|
|
145
|
+
<td>All the features inherited from Graph, getEdge, addEdge, removeEdgeBetween, removeEdge, removeAllEdges, incomingEdgesOf, outgoingEdgesOf, degreeOf, inDegreeOf, outDegreeOf, edgesOf, getEdgeSrc, getEdgeDest, getDestinations, edgeSet, getNeighbors, getEndsOfEdge</td>
|
|
146
|
+
<td>All the features inherited from Graph, topologicalSort</td>
|
|
147
|
+
</tr>
|
|
148
|
+
<tr>
|
|
149
|
+
<td>Undirected Graph</td>
|
|
150
|
+
<td></td>
|
|
151
|
+
<td>All the features inherited from Graph, getEdge, addEdge, removeEdgeBetween, removeEdge, degreeOf, edgesOf, edgeSet, getEdgesOf, getNeighbors, getEndsOfEdge</td>
|
|
152
|
+
<td>All the features inherited from Graph</td>
|
|
153
|
+
</tr>
|
|
154
|
+
<tr>
|
|
155
|
+
<td>Singly Linked List</td>
|
|
156
|
+
<td></td>
|
|
157
|
+
<td>length, head, tail, size, get, getNode, findNodeIndex, findNode, find, findIndex, append, push, prepend, insertAt, removeNode, removeAt, insertBefore, sort, insertAfter, shift, pop, merge, clear, slice, reverse, forEach, map, filter, reduce, toArray, toString</td>
|
|
158
|
+
<td></td>
|
|
159
|
+
|
|
160
|
+
</tr>
|
|
161
|
+
<tr>
|
|
162
|
+
<td>Hash</td>
|
|
163
|
+
<td>CoordinateSet, CoordinateMap</td>
|
|
164
|
+
<td></td>
|
|
165
|
+
<td></td>
|
|
166
|
+
</tr>
|
|
167
|
+
<tr>
|
|
168
|
+
<td>CoordinateSet</td>
|
|
169
|
+
<td></td>
|
|
170
|
+
<td>has, set, get, delete</td>
|
|
171
|
+
<td></td>
|
|
172
|
+
</tr>
|
|
173
|
+
<tr>
|
|
174
|
+
<td>CoordinateMap</td>
|
|
175
|
+
<td></td>
|
|
176
|
+
<td>has, add, delete</td>
|
|
177
|
+
<td></td>
|
|
178
|
+
</tr>
|
|
179
|
+
<tr>
|
|
180
|
+
<td>Heap</td>
|
|
181
|
+
<td></td>
|
|
182
|
+
<td></td>
|
|
183
|
+
</tr>
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
<tr>
|
|
187
|
+
<td>Doubly Linked List</td>
|
|
188
|
+
<td></td>
|
|
189
|
+
<td>size, offerFirst, offerLast, peekFirst, peekLast, pollFirst, pollLast, get, isEmpty, insert, remove, </td>
|
|
190
|
+
<td></td>
|
|
191
|
+
</tr>
|
|
192
|
+
|
|
193
|
+
[//]: # ( <tr>)
|
|
194
|
+
|
|
195
|
+
[//]: # ( <td>Matrix</td>)
|
|
196
|
+
|
|
197
|
+
[//]: # ( <td></td>)
|
|
198
|
+
|
|
199
|
+
[//]: # ( <td></td>)
|
|
200
|
+
|
|
201
|
+
[//]: # ( <td></td>)
|
|
202
|
+
|
|
203
|
+
[//]: # ( </tr>)
|
|
204
|
+
|
|
205
|
+
<tr>
|
|
206
|
+
<td>Priority Queue</td>
|
|
207
|
+
<td>Max Priority Queue, Min Priority Queue</td>
|
|
208
|
+
<td>offer, peek, poll, leaf, isEmpty, clear, toArray, clone</td>
|
|
209
|
+
<td>isValid, sort, DFS</td>
|
|
210
|
+
</tr>
|
|
211
|
+
<tr>
|
|
212
|
+
<td>Max Priority Queue</td>
|
|
213
|
+
<td></td>
|
|
214
|
+
<td>All the features inherited from Priority Queue</td>
|
|
215
|
+
<td>All the features inherited from Priority Queue</td>
|
|
216
|
+
</tr>
|
|
217
|
+
<tr>
|
|
218
|
+
<td>Min Priority Queue</td>
|
|
219
|
+
<td></td>
|
|
220
|
+
<td>All the features inherited from Priority Queue</td>
|
|
221
|
+
<td>All the features inherited from Priority Queue</td>
|
|
222
|
+
</tr>
|
|
223
|
+
<tr>
|
|
224
|
+
<td>Queue</td>
|
|
225
|
+
<td>Queue, Dequeue</td>
|
|
226
|
+
<td>offer, poll, peek, peekLast, size, isEmpty, toArray, clear, clone, Queue.fromArray</td>
|
|
227
|
+
<td></td>
|
|
228
|
+
</tr>
|
|
229
|
+
<tr>
|
|
230
|
+
<td>ObjectDeque</td>
|
|
231
|
+
<td></td>
|
|
232
|
+
<td>size, offerFirst, offerLast, pollFirst, peekFirst, pollLast, peekLast, get, isEmpty</td>
|
|
233
|
+
<td></td>
|
|
234
|
+
</tr>
|
|
235
|
+
<tr>
|
|
236
|
+
<td>ArrayDeque</td>
|
|
237
|
+
<td></td>
|
|
238
|
+
<td>offerLast, pollLast, pollFirst, offerFirst, peekFirst, peekLast, get, set, insert, remove, isEmpty</td>
|
|
239
|
+
<td></td>
|
|
240
|
+
</tr>
|
|
241
|
+
<tr>
|
|
242
|
+
<td>Stack</td>
|
|
243
|
+
<td></td>
|
|
244
|
+
<td>isEmpty, size, peek, push, pop, toArray, clear, clone, Stack.fromArray</td>
|
|
245
|
+
<td></td>
|
|
246
|
+
</tr>
|
|
247
|
+
<tr>
|
|
248
|
+
<td>Trie</td>
|
|
249
|
+
<td></td>
|
|
250
|
+
<td>put, has, remove, isAbsPrefix, isPrefix, getAll</td>
|
|
251
|
+
<td></td>
|
|
252
|
+
</tr>
|
|
253
|
+
</tbody>
|
|
254
|
+
|
|
255
|
+
</table>
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+

|
|
261
|
+
|
|
262
|
+

|
|
263
|
+
|
|
264
|
+

|
|
265
|
+
|
|
266
|
+

|
|
267
|
+
|
|
268
|
+
|
|
269
|
+

|
|
270
|
+
|
|
271
|
+

|
|
272
|
+
|
|
273
|
+

|
|
274
|
+
|
|
275
|
+

|
|
276
|
+
|
|
277
|
+

|
|
278
|
+
|
|
279
|
+

|
|
280
|
+
|
|
281
|
+

|
|
282
|
+
|
|
283
|
+

|
|
284
|
+
|
|
285
|
+

|
|
286
|
+
|
|
287
|
+

|
|
288
|
+
|
|
289
|
+
[//]: # ()
|
|
290
|
+
|
|
291
|
+
[//]: # ()
|
|
292
|
+
|
|
293
|
+
[//]: # ()
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
@@ -1,21 +1,74 @@
|
|
|
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
|
-
export interface AVLTreeDeleted<T> {
|
|
4
|
-
deleted: AVLTreeNode<T> | null;
|
|
5
|
-
needBalanced: AVLTreeNode<T> | null;
|
|
6
|
-
}
|
|
6
|
+
import type { AVLTreeDeleted, BinaryTreeNodeId } from '../types';
|
|
7
7
|
export declare class AVLTreeNode<T> extends BSTNode<T> {
|
|
8
8
|
clone(): AVLTreeNode<T>;
|
|
9
9
|
}
|
|
10
10
|
export declare class AVLTree<T> extends BST<T> {
|
|
11
11
|
createNode(id: BinaryTreeNodeId, val: T, count?: number): AVLTreeNode<T>;
|
|
12
|
+
/**
|
|
13
|
+
* The function overrides the put method of a Binary Search Tree to insert a node with a given id and value, and then
|
|
14
|
+
* balances the tree.
|
|
15
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to put or
|
|
16
|
+
* update in the AVL tree.
|
|
17
|
+
* @param {T | null} val - The `val` parameter represents the value that you want to assign to the node with the given
|
|
18
|
+
* `id`. It can be of type `T` (the generic type) or `null`.
|
|
19
|
+
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
|
|
20
|
+
* of times the value `val` should be inserted into the AVL tree. If the `count` parameter is not provided, it defaults
|
|
21
|
+
* to `1`, indicating that the value should be inserted once.
|
|
22
|
+
* @returns The method is returning either an AVLTreeNode<T> object or null.
|
|
23
|
+
*/
|
|
12
24
|
put(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null;
|
|
25
|
+
/**
|
|
26
|
+
* The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
|
|
27
|
+
* then balances the tree if necessary.
|
|
28
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
|
|
29
|
+
* removed from the AVL tree.
|
|
30
|
+
* @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean parameter that
|
|
31
|
+
* determines whether the left sum of all nodes in the AVL tree should be updated after removing a node. If
|
|
32
|
+
* `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
|
|
33
|
+
* @returns The method is returning an array of `AVLTreeDeleted<T>` objects.
|
|
34
|
+
*/
|
|
13
35
|
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): AVLTreeDeleted<T>[];
|
|
36
|
+
/**
|
|
37
|
+
* The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
|
|
38
|
+
* height of its right subtree.
|
|
39
|
+
* @param node - The parameter "node" is of type AVLTreeNode<T>, which represents a node in an AVL tree.
|
|
40
|
+
* @returns The balance factor of the given AVL tree node.
|
|
41
|
+
*/
|
|
14
42
|
balanceFactor(node: AVLTreeNode<T>): number;
|
|
43
|
+
/**
|
|
44
|
+
* The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.
|
|
45
|
+
* @param node - The parameter `node` is an AVLTreeNode object, which represents a node in an AVL tree.
|
|
46
|
+
*/
|
|
15
47
|
updateHeight(node: AVLTreeNode<T>): void;
|
|
48
|
+
/**
|
|
49
|
+
* The `balancePath` function balances the AVL tree by performing appropriate rotations based on the balance factor of
|
|
50
|
+
* each node in the path from the given node to the root.
|
|
51
|
+
* @param node - The `node` parameter is an AVLTreeNode object, which represents a node in an AVL tree.
|
|
52
|
+
*/
|
|
16
53
|
balancePath(node: AVLTreeNode<T>): void;
|
|
54
|
+
/**
|
|
55
|
+
* The `balanceLL` function performs a left-left rotation on an AVL tree to balance it.
|
|
56
|
+
* @param A - The parameter A is an AVLTreeNode object.
|
|
57
|
+
*/
|
|
17
58
|
balanceLL(A: AVLTreeNode<T>): void;
|
|
59
|
+
/**
|
|
60
|
+
* The `balanceLR` function performs a left-right rotation to balance an AVL tree.
|
|
61
|
+
* @param A - A is an AVLTreeNode object.
|
|
62
|
+
*/
|
|
18
63
|
balanceLR(A: AVLTreeNode<T>): void;
|
|
64
|
+
/**
|
|
65
|
+
* The `balanceRR` function performs a right-right rotation on an AVL tree to balance it.
|
|
66
|
+
* @param A - The parameter A is an AVLTreeNode object.
|
|
67
|
+
*/
|
|
19
68
|
balanceRR(A: AVLTreeNode<T>): void;
|
|
69
|
+
/**
|
|
70
|
+
* The `balanceRL` function performs a right-left rotation to balance an AVL tree.
|
|
71
|
+
* @param A - A is an AVLTreeNode object.
|
|
72
|
+
*/
|
|
20
73
|
balanceRL(A: AVLTreeNode<T>): void;
|
|
21
74
|
}
|
|
@@ -1,57 +1,144 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
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
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
29
|
exports.AVLTree = exports.AVLTreeNode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
32
|
+
* @license MIT
|
|
33
|
+
*/
|
|
34
|
+
var bst_1 = require("./bst");
|
|
35
|
+
var AVLTreeNode = /** @class */ (function (_super) {
|
|
36
|
+
__extends(AVLTreeNode, _super);
|
|
37
|
+
function AVLTreeNode() {
|
|
38
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
8
39
|
}
|
|
9
|
-
|
|
40
|
+
AVLTreeNode.prototype.clone = function () {
|
|
41
|
+
return new AVLTreeNode(this.id, this.val, this.count);
|
|
42
|
+
};
|
|
43
|
+
return AVLTreeNode;
|
|
44
|
+
}(bst_1.BSTNode));
|
|
10
45
|
exports.AVLTreeNode = AVLTreeNode;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
46
|
+
var AVLTree = /** @class */ (function (_super) {
|
|
47
|
+
__extends(AVLTree, _super);
|
|
48
|
+
function AVLTree() {
|
|
49
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
14
50
|
}
|
|
15
|
-
|
|
16
|
-
|
|
51
|
+
AVLTree.prototype.createNode = function (id, val, count) {
|
|
52
|
+
return new AVLTreeNode(id, val, count);
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The function overrides the put method of a Binary Search Tree to insert a node with a given id and value, and then
|
|
56
|
+
* balances the tree.
|
|
57
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to put or
|
|
58
|
+
* update in the AVL tree.
|
|
59
|
+
* @param {T | null} val - The `val` parameter represents the value that you want to assign to the node with the given
|
|
60
|
+
* `id`. It can be of type `T` (the generic type) or `null`.
|
|
61
|
+
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
|
|
62
|
+
* of times the value `val` should be inserted into the AVL tree. If the `count` parameter is not provided, it defaults
|
|
63
|
+
* to `1`, indicating that the value should be inserted once.
|
|
64
|
+
* @returns The method is returning either an AVLTreeNode<T> object or null.
|
|
65
|
+
*/
|
|
66
|
+
AVLTree.prototype.put = function (id, val, count) {
|
|
67
|
+
var inserted = _super.prototype.put.call(this, id, val, count);
|
|
17
68
|
if (inserted)
|
|
18
69
|
this.balancePath(inserted);
|
|
19
70
|
return inserted;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
|
|
74
|
+
* then balances the tree if necessary.
|
|
75
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
|
|
76
|
+
* removed from the AVL tree.
|
|
77
|
+
* @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean parameter that
|
|
78
|
+
* determines whether the left sum of all nodes in the AVL tree should be updated after removing a node. If
|
|
79
|
+
* `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
|
|
80
|
+
* @returns The method is returning an array of `AVLTreeDeleted<T>` objects.
|
|
81
|
+
*/
|
|
82
|
+
AVLTree.prototype.remove = function (id, isUpdateAllLeftSum) {
|
|
83
|
+
var e_1, _a;
|
|
84
|
+
var deletedResults = _super.prototype.remove.call(this, id, isUpdateAllLeftSum);
|
|
85
|
+
try {
|
|
86
|
+
for (var deletedResults_1 = __values(deletedResults), deletedResults_1_1 = deletedResults_1.next(); !deletedResults_1_1.done; deletedResults_1_1 = deletedResults_1.next()) {
|
|
87
|
+
var needBalanced = deletedResults_1_1.value.needBalanced;
|
|
88
|
+
if (needBalanced) {
|
|
89
|
+
this.balancePath(needBalanced);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
94
|
+
finally {
|
|
95
|
+
try {
|
|
96
|
+
if (deletedResults_1_1 && !deletedResults_1_1.done && (_a = deletedResults_1.return)) _a.call(deletedResults_1);
|
|
26
97
|
}
|
|
98
|
+
finally { if (e_1) throw e_1.error; }
|
|
27
99
|
}
|
|
28
100
|
return deletedResults;
|
|
29
|
-
}
|
|
30
|
-
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
|
|
104
|
+
* height of its right subtree.
|
|
105
|
+
* @param node - The parameter "node" is of type AVLTreeNode<T>, which represents a node in an AVL tree.
|
|
106
|
+
* @returns The balance factor of the given AVL tree node.
|
|
107
|
+
*/
|
|
108
|
+
AVLTree.prototype.balanceFactor = function (node) {
|
|
31
109
|
if (!node.right) // node has no right subtree
|
|
32
110
|
return -node.height;
|
|
33
111
|
else if (!node.left) // node has no left subtree
|
|
34
112
|
return +node.height;
|
|
35
113
|
else
|
|
36
114
|
return node.right.height - node.left.height;
|
|
37
|
-
}
|
|
38
|
-
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.
|
|
118
|
+
* @param node - The parameter `node` is an AVLTreeNode object, which represents a node in an AVL tree.
|
|
119
|
+
*/
|
|
120
|
+
AVLTree.prototype.updateHeight = function (node) {
|
|
39
121
|
if (!node.left && !node.right) // node is a leaf
|
|
40
122
|
node.height = 0;
|
|
41
123
|
else if (!node.left) {
|
|
42
124
|
// node has no left subtree
|
|
43
|
-
|
|
125
|
+
var rightHeight = node.right ? node.right.height : 0;
|
|
44
126
|
node.height = 1 + rightHeight;
|
|
45
127
|
}
|
|
46
128
|
else if (!node.right) // node has no right subtree
|
|
47
129
|
node.height = 1 + node.left.height;
|
|
48
130
|
else
|
|
49
131
|
node.height = 1 + Math.max(node.right.height, node.left.height);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* The `balancePath` function balances the AVL tree by performing appropriate rotations based on the balance factor of
|
|
135
|
+
* each node in the path from the given node to the root.
|
|
136
|
+
* @param node - The `node` parameter is an AVLTreeNode object, which represents a node in an AVL tree.
|
|
137
|
+
*/
|
|
138
|
+
AVLTree.prototype.balancePath = function (node) {
|
|
139
|
+
var path = this.getPathToRoot(node);
|
|
140
|
+
for (var i = path.length - 1; i >= 0; i--) {
|
|
141
|
+
var A = path[i];
|
|
55
142
|
this.updateHeight(A);
|
|
56
143
|
switch (this.balanceFactor(A)) {
|
|
57
144
|
case -2:
|
|
@@ -75,10 +162,14 @@ class AVLTree extends bst_1.BST {
|
|
|
75
162
|
}
|
|
76
163
|
}
|
|
77
164
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* The `balanceLL` function performs a left-left rotation on an AVL tree to balance it.
|
|
168
|
+
* @param A - The parameter A is an AVLTreeNode object.
|
|
169
|
+
*/
|
|
170
|
+
AVLTree.prototype.balanceLL = function (A) {
|
|
171
|
+
var parentOfA = A.parent;
|
|
172
|
+
var B = A.left; // A is left-heavy and B is left-heavy
|
|
82
173
|
A.parent = B;
|
|
83
174
|
if (B && B.right) {
|
|
84
175
|
B.right.parent = A;
|
|
@@ -105,11 +196,15 @@ class AVLTree extends bst_1.BST {
|
|
|
105
196
|
this.updateHeight(A);
|
|
106
197
|
if (B)
|
|
107
198
|
this.updateHeight(B);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* The `balanceLR` function performs a left-right rotation to balance an AVL tree.
|
|
202
|
+
* @param A - A is an AVLTreeNode object.
|
|
203
|
+
*/
|
|
204
|
+
AVLTree.prototype.balanceLR = function (A) {
|
|
205
|
+
var parentOfA = A.parent;
|
|
206
|
+
var B = A.left; // A is left-heavy
|
|
207
|
+
var C = null;
|
|
113
208
|
if (B) {
|
|
114
209
|
C = B.right; // B is right-heavy
|
|
115
210
|
}
|
|
@@ -150,10 +245,14 @@ class AVLTree extends bst_1.BST {
|
|
|
150
245
|
this.updateHeight(A); // Adjust heights
|
|
151
246
|
B && this.updateHeight(B);
|
|
152
247
|
C && this.updateHeight(C);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* The `balanceRR` function performs a right-right rotation on an AVL tree to balance it.
|
|
251
|
+
* @param A - The parameter A is an AVLTreeNode object.
|
|
252
|
+
*/
|
|
253
|
+
AVLTree.prototype.balanceRR = function (A) {
|
|
254
|
+
var parentOfA = A.parent;
|
|
255
|
+
var B = A.right; // A is right-heavy and B is right-heavy
|
|
157
256
|
A.parent = B;
|
|
158
257
|
if (B) {
|
|
159
258
|
if (B.left) {
|
|
@@ -181,11 +280,15 @@ class AVLTree extends bst_1.BST {
|
|
|
181
280
|
}
|
|
182
281
|
this.updateHeight(A);
|
|
183
282
|
B && this.updateHeight(B);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* The `balanceRL` function performs a right-left rotation to balance an AVL tree.
|
|
286
|
+
* @param A - A is an AVLTreeNode object.
|
|
287
|
+
*/
|
|
288
|
+
AVLTree.prototype.balanceRL = function (A) {
|
|
289
|
+
var parentOfA = A.parent;
|
|
290
|
+
var B = A.right; // A is right-heavy
|
|
291
|
+
var C = null;
|
|
189
292
|
if (B) {
|
|
190
293
|
C = B.left; // B is left-heavy
|
|
191
294
|
}
|
|
@@ -226,6 +329,7 @@ class AVLTree extends bst_1.BST {
|
|
|
226
329
|
this.updateHeight(A); // Adjust heights
|
|
227
330
|
B && this.updateHeight(B);
|
|
228
331
|
C && this.updateHeight(C);
|
|
229
|
-
}
|
|
230
|
-
|
|
332
|
+
};
|
|
333
|
+
return AVLTree;
|
|
334
|
+
}(bst_1.BST));
|
|
231
335
|
exports.AVLTree = AVLTree;
|