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.
Files changed (287) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/.idea/modules.xml +1 -1
  4. package/README.md +298 -2
  5. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  6. package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
  7. package/dist/data-structures/binary-tree/avl-tree.js +150 -46
  8. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
  12. package/dist/data-structures/binary-tree/binary-tree.js +747 -369
  13. package/dist/data-structures/binary-tree/bst.d.ts +20 -8
  14. package/dist/data-structures/binary-tree/bst.js +164 -107
  15. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
  17. package/dist/data-structures/binary-tree/segment-tree.js +95 -61
  18. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  19. package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
  20. package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
  21. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  22. package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
  23. package/dist/data-structures/graph/abstract-graph.js +712 -323
  24. package/dist/data-structures/graph/directed-graph.d.ts +114 -12
  25. package/dist/data-structures/graph/directed-graph.js +372 -128
  26. package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
  27. package/dist/data-structures/graph/undirected-graph.js +233 -81
  28. package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
  29. package/dist/data-structures/hash/coordinate-map.js +70 -20
  30. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  31. package/dist/data-structures/hash/coordinate-set.js +58 -15
  32. package/dist/data-structures/hash/index.d.ts +5 -0
  33. package/dist/data-structures/hash/index.js +5 -0
  34. package/dist/data-structures/heap/heap.d.ts +26 -37
  35. package/dist/data-structures/heap/heap.js +56 -60
  36. package/dist/data-structures/heap/max-heap.d.ts +8 -2
  37. package/dist/data-structures/heap/max-heap.js +32 -9
  38. package/dist/data-structures/heap/min-heap.d.ts +9 -2
  39. package/dist/data-structures/heap/min-heap.js +33 -9
  40. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
  41. package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
  42. package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
  43. package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
  44. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  45. package/dist/data-structures/matrix/matrix.js +19 -7
  46. package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
  47. package/dist/data-structures/matrix/matrix2d.js +158 -61
  48. package/dist/data-structures/matrix/navigator.d.ts +34 -16
  49. package/dist/data-structures/matrix/navigator.js +65 -18
  50. package/dist/data-structures/matrix/vector2d.d.ts +153 -29
  51. package/dist/data-structures/matrix/vector2d.js +249 -102
  52. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
  53. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
  54. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
  55. package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
  56. package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
  57. package/dist/data-structures/priority-queue/priority-queue.js +285 -116
  58. package/dist/data-structures/queue/deque.d.ts +69 -0
  59. package/dist/data-structures/queue/deque.js +151 -56
  60. package/dist/data-structures/queue/queue.d.ts +34 -37
  61. package/dist/data-structures/queue/queue.js +59 -61
  62. package/dist/data-structures/stack/stack.d.ts +29 -35
  63. package/dist/data-structures/stack/stack.js +51 -56
  64. package/dist/data-structures/trie/trie.d.ts +36 -6
  65. package/dist/data-structures/trie/trie.js +256 -83
  66. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  67. package/dist/data-structures/types/abstract-graph.js +2 -0
  68. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  69. package/dist/data-structures/types/avl-tree.js +2 -0
  70. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  71. package/dist/data-structures/types/binary-tree.js +2 -0
  72. package/dist/data-structures/types/bst.d.ts +7 -0
  73. package/dist/data-structures/types/bst.js +2 -0
  74. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  75. package/dist/data-structures/types/directed-graph.js +2 -0
  76. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  77. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  78. package/dist/data-structures/types/heap.d.ts +7 -0
  79. package/dist/data-structures/types/heap.js +2 -0
  80. package/dist/data-structures/types/index.d.ts +13 -0
  81. package/dist/data-structures/types/index.js +29 -0
  82. package/dist/data-structures/types/navigator.d.ts +14 -0
  83. package/dist/data-structures/types/navigator.js +2 -0
  84. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  85. package/dist/data-structures/types/priority-queue.js +2 -0
  86. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  87. package/dist/data-structures/types/segment-tree.js +2 -0
  88. package/dist/data-structures/types/singly-linked-list.js +2 -0
  89. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  90. package/dist/data-structures/types/tree-multiset.js +2 -0
  91. package/dist/utils/trampoline.d.ts +14 -0
  92. package/dist/utils/trampoline.js +130 -0
  93. package/dist/utils/types/index.js +17 -0
  94. package/dist/{types → utils}/types/utils.d.ts +15 -1
  95. package/dist/{types → utils/types}/utils.js +21 -19
  96. package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
  97. package/dist/utils/utils.js +651 -0
  98. package/docs/.nojekyll +1 -0
  99. package/docs/assets/highlight.css +85 -0
  100. package/docs/assets/main.js +58 -0
  101. package/docs/assets/search.js +1 -0
  102. package/docs/assets/style.css +1367 -0
  103. package/docs/classes/AVLTree.html +2046 -0
  104. package/docs/classes/AVLTreeNode.html +423 -0
  105. package/docs/classes/AaTree.html +117 -0
  106. package/docs/classes/AbstractEdge.html +198 -0
  107. package/docs/classes/AbstractGraph.html +891 -0
  108. package/docs/classes/AbstractVertex.html +164 -0
  109. package/docs/classes/ArrayDeque.html +384 -0
  110. package/docs/classes/BST.html +1893 -0
  111. package/docs/classes/BSTNode.html +425 -0
  112. package/docs/classes/BTree.html +117 -0
  113. package/docs/classes/BinaryIndexedTree.html +244 -0
  114. package/docs/classes/BinaryTree.html +1754 -0
  115. package/docs/classes/BinaryTreeNode.html +396 -0
  116. package/docs/classes/Character.html +165 -0
  117. package/docs/classes/CoordinateMap.html +394 -0
  118. package/docs/classes/CoordinateSet.html +355 -0
  119. package/docs/classes/Deque.html +617 -0
  120. package/docs/classes/DirectedEdge.html +247 -0
  121. package/docs/classes/DirectedGraph.html +1207 -0
  122. package/docs/classes/DirectedVertex.html +154 -0
  123. package/docs/classes/DoublyLinkedList.html +619 -0
  124. package/docs/classes/DoublyLinkedListNode.html +160 -0
  125. package/docs/classes/Heap.html +315 -0
  126. package/docs/classes/Matrix2D.html +447 -0
  127. package/docs/classes/MatrixNTI2D.html +181 -0
  128. package/docs/classes/MaxHeap.html +325 -0
  129. package/docs/classes/MaxPriorityQueue.html +668 -0
  130. package/docs/classes/MinHeap.html +326 -0
  131. package/docs/classes/MinPriorityQueue.html +668 -0
  132. package/docs/classes/Navigator.html +285 -0
  133. package/docs/classes/ObjectDeque.html +289 -0
  134. package/docs/classes/PriorityQueue.html +643 -0
  135. package/docs/classes/Queue.html +337 -0
  136. package/docs/classes/RBTree.html +117 -0
  137. package/docs/classes/SegmentTree.html +234 -0
  138. package/docs/classes/SegmentTreeNode.html +302 -0
  139. package/docs/classes/SinglyLinkedList.html +1035 -0
  140. package/docs/classes/SinglyLinkedListNode.html +304 -0
  141. package/docs/classes/SplayTree.html +117 -0
  142. package/docs/classes/Stack.html +313 -0
  143. package/docs/classes/TreeMultiSet.html +1897 -0
  144. package/docs/classes/Trie.html +317 -0
  145. package/docs/classes/TrieNode.html +221 -0
  146. package/docs/classes/TwoThreeTree.html +117 -0
  147. package/docs/classes/UndirectedEdge.html +220 -0
  148. package/docs/classes/UndirectedGraph.html +1006 -0
  149. package/docs/classes/UndirectedVertex.html +154 -0
  150. package/docs/classes/Vector2D.html +746 -0
  151. package/docs/enums/CP.html +126 -0
  152. package/docs/enums/FamilyPosition.html +126 -0
  153. package/docs/enums/LoopType.html +119 -0
  154. package/docs/index.html +288 -0
  155. package/docs/modules.html +146 -0
  156. package/jest.config.js +5 -0
  157. package/package.json +33 -47
  158. package/rename_clear_files.sh +29 -0
  159. package/src/assets/complexities-diff.jpg +0 -0
  160. package/src/assets/data-structure-complexities.jpg +0 -0
  161. package/src/data-structures/binary-tree/avl-tree.ts +58 -6
  162. package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
  163. package/src/data-structures/binary-tree/binary-tree.ts +460 -145
  164. package/src/data-structures/binary-tree/bst.ts +31 -25
  165. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  166. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  167. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  168. package/src/data-structures/binary-tree/segment-tree.ts +25 -12
  169. package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
  170. package/src/data-structures/diagrams/README.md +5 -0
  171. package/src/data-structures/graph/abstract-graph.ts +224 -108
  172. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  173. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  174. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  175. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  176. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  177. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  178. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  179. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  180. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  181. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  182. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  183. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  184. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  185. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  186. package/src/data-structures/graph/directed-graph.ts +132 -26
  187. package/src/data-structures/graph/undirected-graph.ts +78 -11
  188. package/src/data-structures/hash/coordinate-map.ts +33 -1
  189. package/src/data-structures/hash/coordinate-set.ts +25 -0
  190. package/src/data-structures/hash/index.ts +5 -0
  191. package/src/data-structures/heap/heap.ts +27 -41
  192. package/src/data-structures/heap/max-heap.ts +8 -2
  193. package/src/data-structures/heap/min-heap.ts +9 -2
  194. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
  195. package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
  196. package/src/data-structures/matrix/matrix.ts +11 -0
  197. package/src/data-structures/matrix/matrix2d.ts +90 -10
  198. package/src/data-structures/matrix/navigator.ts +34 -14
  199. package/src/data-structures/matrix/vector2d.ts +187 -63
  200. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
  201. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
  202. package/src/data-structures/priority-queue/priority-queue.ts +200 -78
  203. package/src/data-structures/queue/deque.ts +71 -2
  204. package/src/data-structures/queue/queue.ts +37 -40
  205. package/src/data-structures/stack/stack.ts +32 -38
  206. package/src/data-structures/trie/trie.ts +83 -14
  207. package/src/data-structures/types/abstract-graph.ts +51 -0
  208. package/src/data-structures/types/avl-tree.ts +6 -0
  209. package/src/data-structures/types/binary-tree.ts +15 -0
  210. package/src/data-structures/types/bst.ts +5 -0
  211. package/src/data-structures/types/directed-graph.ts +18 -0
  212. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  213. package/src/data-structures/types/heap.ts +8 -0
  214. package/src/data-structures/types/index.ts +13 -0
  215. package/src/data-structures/types/navigator.ts +13 -0
  216. package/src/data-structures/types/priority-queue.ts +9 -0
  217. package/src/data-structures/types/segment-tree.ts +1 -0
  218. package/src/data-structures/types/singly-linked-list.ts +1 -0
  219. package/src/data-structures/types/tree-multiset.ts +3 -0
  220. package/src/utils/index.ts +1 -0
  221. package/src/utils/trampoline.ts +51 -0
  222. package/src/utils/types/index.ts +1 -0
  223. package/src/{types → utils/types}/utils.ts +27 -5
  224. package/src/{utils.ts → utils/utils.ts} +41 -131
  225. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  226. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  227. package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
  228. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  229. package/tsconfig.json +9 -6
  230. package/dist/data-structures/trampoline.d.ts +0 -25
  231. package/dist/data-structures/trampoline.js +0 -52
  232. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  233. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  234. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  235. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  236. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  237. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  238. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  239. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  240. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  241. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  242. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  243. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  244. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  245. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  246. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  247. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  248. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  249. package/dist/types/data-structures/hash/index.d.ts +0 -1
  250. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  251. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  252. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  253. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  254. package/dist/types/data-structures/heap/index.d.ts +0 -3
  255. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  256. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  257. package/dist/types/data-structures/index.d.ts +0 -9
  258. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  259. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  260. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  261. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  262. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  263. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  264. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  265. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  266. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  267. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  268. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  269. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  270. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  271. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  272. package/dist/types/data-structures/queue/index.d.ts +0 -1
  273. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  274. package/dist/types/data-structures/stack/index.d.ts +0 -1
  275. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  276. package/dist/types/data-structures/trampoline.d.ts +0 -25
  277. package/dist/types/data-structures/trie/index.d.ts +0 -1
  278. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  279. package/dist/types/utils.d.ts +0 -46
  280. package/dist/utils.js +0 -569
  281. package/src/data-structures/trampoline.ts +0 -91
  282. package/src/types/index.ts +0 -1
  283. /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
  284. /package/dist/{types → utils}/index.d.ts +0 -0
  285. /package/dist/{types → utils}/index.js +0 -0
  286. /package/dist/{types → utils}/types/index.d.ts +0 -0
  287. /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-ts
2
- Hash (CoordinateSet, CoordinateMap) Heap (MaxHeap, MinHeap) Binary Tree (AVL Tree, Binary Indexed Tree, Binary Search Tree, Segment Tree, Tree Multiset) Graph (Directed Graph, Undirected Graph) Linked List (Singly Linked List, Doubly Linked List) Matrix Priority Queue (Max Priority Queue, Min Priority Queue) Queue (Queue, Dequeue) Stack Trie
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
+ ![complexities](src/assets/complexities-diff.jpg)
261
+
262
+ ![complexities of data structures](src/assets/data-structure-complexities.jpg)
263
+
264
+ ![](src/data-structures/binary-tree/diagrams/bst-rotation.gif)
265
+
266
+ ![](src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif)
267
+
268
+
269
+ ![](src/data-structures/graph/diagrams/tarjan.webp)
270
+
271
+ ![](src/data-structures/graph/diagrams/adjacency-list.jpg)
272
+
273
+ ![](src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg)
274
+
275
+ ![](src/data-structures/graph/diagrams/adjacency-matrix.jpg)
276
+
277
+ ![](src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg)
278
+
279
+ ![](src/data-structures/graph/diagrams/dfs-can-do.jpg)
280
+
281
+ ![](src/data-structures/graph/diagrams/edge-list.jpg)
282
+
283
+ ![](src/data-structures/graph/diagrams/edge-list-pros-cons.jpg)
284
+
285
+ ![](src/data-structures/graph/diagrams/max-flow.jpg)
286
+
287
+ ![](src/data-structures/graph/diagrams/mst.jpg)
288
+
289
+ [//]: # (![]&#40;src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png&#41;)
290
+
291
+ [//]: # (![]&#40;src/data-structures/graph/diagrams/tarjan-complicate-simple.png&#41;)
292
+
293
+ [//]: # (![]&#40;src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png&#41;)
294
+
295
+
296
+
297
+
298
+
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AaTree = void 0;
4
- class AaTree {
5
- }
4
+ var AaTree = /** @class */ (function () {
5
+ function AaTree() {
6
+ }
7
+ return AaTree;
8
+ }());
6
9
  exports.AaTree = AaTree;
@@ -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 './binary-tree';
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
- const bst_1 = require("./bst");
5
- class AVLTreeNode extends bst_1.BSTNode {
6
- clone() {
7
- return new AVLTreeNode(this.id, this.val, this.count);
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
- class AVLTree extends bst_1.BST {
12
- createNode(id, val, count) {
13
- return new AVLTreeNode(id, val, count);
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
- put(id, val, count) {
16
- const inserted = super.put(id, val, count);
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
- remove(id, isUpdateAllLeftSum) {
22
- const deletedResults = super.remove(id, isUpdateAllLeftSum);
23
- for (const { needBalanced } of deletedResults) {
24
- if (needBalanced) {
25
- this.balancePath(needBalanced);
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
- balanceFactor(node) {
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
- updateHeight(node) {
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
- const rightHeight = node.right ? node.right.height : 0;
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
- balancePath(node) {
52
- const path = this.getPathToRoot(node);
53
- for (let i = path.length - 1; i >= 0; i--) {
54
- const A = path[i];
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
- balanceLL(A) {
80
- const parentOfA = A.parent;
81
- const B = A.left; // A is left-heavy and B is left-heavy
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
- balanceLR(A) {
110
- const parentOfA = A.parent;
111
- const B = A.left; // A is left-heavy
112
- let C = null;
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
- balanceRR(A) {
155
- const parentOfA = A.parent;
156
- const B = A.right; // A is right-heavy and B is right-heavy
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
- balanceRL(A) {
186
- const parentOfA = A.parent;
187
- const B = A.right; // A is right-heavy
188
- let C = null;
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;