data-structure-typed 1.18.6 → 1.18.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/README.md +154 -366
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +72 -51
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +226 -158
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +7 -6
  5. package/dist/data-structures/binary-tree/avl-tree.js +5 -3
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +16 -6
  7. package/dist/data-structures/binary-tree/binary-tree.js +16 -7
  8. package/dist/data-structures/binary-tree/bst.d.ts +37 -28
  9. package/dist/data-structures/binary-tree/bst.js +44 -76
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +30 -1
  11. package/dist/data-structures/binary-tree/rb-tree.js +27 -14
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +18 -7
  13. package/dist/data-structures/binary-tree/tree-multiset.js +20 -15
  14. package/dist/data-structures/graph/abstract-graph.d.ts +28 -27
  15. package/dist/data-structures/graph/abstract-graph.js +58 -36
  16. package/dist/data-structures/graph/directed-graph.d.ts +27 -24
  17. package/dist/data-structures/graph/directed-graph.js +65 -60
  18. package/dist/data-structures/graph/undirected-graph.d.ts +12 -18
  19. package/dist/data-structures/graph/undirected-graph.js +52 -65
  20. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +100 -0
  21. package/dist/data-structures/interfaces/abstract-binary-tree.js +2 -0
  22. package/dist/data-structures/interfaces/abstract-graph.d.ts +3 -8
  23. package/dist/data-structures/interfaces/avl-tree.d.ts +16 -1
  24. package/dist/data-structures/interfaces/binary-tree.d.ts +4 -24
  25. package/dist/data-structures/interfaces/bst.d.ts +18 -1
  26. package/dist/data-structures/interfaces/directed-graph.d.ts +4 -1
  27. package/dist/data-structures/interfaces/index.d.ts +1 -1
  28. package/dist/data-structures/interfaces/index.js +1 -1
  29. package/dist/data-structures/interfaces/rb-tree.d.ts +9 -0
  30. package/dist/data-structures/interfaces/rb-tree.js +2 -0
  31. package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
  32. package/dist/data-structures/interfaces/undirected-graph.d.ts +4 -1
  33. package/dist/data-structures/tree/tree.d.ts +1 -4
  34. package/dist/data-structures/tree/tree.js +1 -12
  35. package/dist/data-structures/types/abstract-binary-tree.d.ts +11 -7
  36. package/dist/data-structures/types/abstract-binary-tree.js +9 -5
  37. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  38. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  39. package/dist/data-structures/types/bst.d.ts +1 -1
  40. package/dist/data-structures/types/bst.js +1 -1
  41. package/dist/data-structures/types/directed-graph.js +1 -1
  42. package/dist/data-structures/types/helpers.d.ts +1 -8
  43. package/dist/data-structures/types/rb-tree.d.ts +2 -0
  44. package/dist/data-structures/types/rb-tree.js +1 -1
  45. package/dist/data-structures/types/tree-multiset.d.ts +4 -4
  46. package/dist/utils/types/utils.d.ts +18 -0
  47. package/dist/utils/utils.d.ts +6 -1
  48. package/dist/utils/utils.js +83 -1
  49. package/package.json +2 -2
  50. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  51. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  52. package/backup/recursive-type/src/assets/logo.png +0 -0
  53. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  54. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
  55. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
  56. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
  57. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
  58. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
  59. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
  60. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  61. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  62. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  63. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
  64. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
  65. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
  66. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
  67. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
  68. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  69. package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
  70. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
  71. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  72. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  73. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  74. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  75. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  76. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  77. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  78. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  79. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  80. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  81. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  82. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  83. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  84. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  85. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
  86. package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
  87. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
  88. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
  89. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
  90. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
  91. package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
  92. package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
  93. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
  94. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
  95. package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
  96. package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
  97. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
  98. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
  99. package/backup/recursive-type/src/data-structures/index.ts +0 -15
  100. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
  101. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
  102. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
  103. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
  104. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
  105. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
  106. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
  107. package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
  108. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
  109. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
  110. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
  111. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
  112. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
  113. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
  114. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  115. package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
  116. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
  117. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
  118. package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
  119. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
  120. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
  121. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
  122. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
  123. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
  124. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
  125. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
  126. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
  127. package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
  128. package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
  129. package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
  130. package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
  131. package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
  132. package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
  133. package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
  134. package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
  135. package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
  136. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
  137. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
  138. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
  139. package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
  140. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
  141. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
  142. package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
  143. package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
  144. package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
  145. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
  146. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
  147. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
  148. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
  149. package/backup/recursive-type/src/index.ts +0 -1
  150. package/backup/recursive-type/src/utils/index.ts +0 -2
  151. package/backup/recursive-type/src/utils/types/index.ts +0 -1
  152. package/backup/recursive-type/src/utils/types/utils.ts +0 -6
  153. package/backup/recursive-type/src/utils/utils.ts +0 -78
  154. package/docs/.nojekyll +0 -1
  155. package/docs/assets/highlight.css +0 -92
  156. package/docs/assets/main.js +0 -58
  157. package/docs/assets/search.js +0 -1
  158. package/docs/assets/style.css +0 -1367
  159. package/docs/classes/AVLTree.html +0 -2339
  160. package/docs/classes/AVLTreeNode.html +0 -450
  161. package/docs/classes/AaTree.html +0 -166
  162. package/docs/classes/AbstractBinaryTree.html +0 -2023
  163. package/docs/classes/AbstractBinaryTreeNode.html +0 -491
  164. package/docs/classes/AbstractEdge.html +0 -289
  165. package/docs/classes/AbstractGraph.html +0 -1046
  166. package/docs/classes/AbstractVertex.html +0 -252
  167. package/docs/classes/ArrayDeque.html +0 -433
  168. package/docs/classes/BST.html +0 -2196
  169. package/docs/classes/BSTNode.html +0 -453
  170. package/docs/classes/BTree.html +0 -166
  171. package/docs/classes/BinaryIndexedTree.html +0 -335
  172. package/docs/classes/BinaryTree.html +0 -2037
  173. package/docs/classes/BinaryTreeNode.html +0 -452
  174. package/docs/classes/Character.html +0 -214
  175. package/docs/classes/CoordinateMap.html +0 -477
  176. package/docs/classes/CoordinateSet.html +0 -438
  177. package/docs/classes/Deque.html +0 -969
  178. package/docs/classes/DirectedEdge.html +0 -360
  179. package/docs/classes/DirectedGraph.html +0 -1408
  180. package/docs/classes/DirectedVertex.html +0 -248
  181. package/docs/classes/DoublyLinkedList.html +0 -962
  182. package/docs/classes/DoublyLinkedListNode.html +0 -291
  183. package/docs/classes/HashTable.html +0 -166
  184. package/docs/classes/Heap.html +0 -417
  185. package/docs/classes/HeapItem.html +0 -249
  186. package/docs/classes/Matrix2D.html +0 -496
  187. package/docs/classes/MatrixNTI2D.html +0 -234
  188. package/docs/classes/MaxHeap.html +0 -430
  189. package/docs/classes/MaxPriorityQueue.html +0 -830
  190. package/docs/classes/MinHeap.html +0 -431
  191. package/docs/classes/MinPriorityQueue.html +0 -832
  192. package/docs/classes/Navigator.html +0 -307
  193. package/docs/classes/ObjectDeque.html +0 -449
  194. package/docs/classes/Pair.html +0 -166
  195. package/docs/classes/PriorityQueue.html +0 -754
  196. package/docs/classes/Queue.html +0 -386
  197. package/docs/classes/SegmentTree.html +0 -428
  198. package/docs/classes/SegmentTreeNode.html +0 -351
  199. package/docs/classes/SinglyLinkedList.html +0 -782
  200. package/docs/classes/SinglyLinkedListNode.html +0 -264
  201. package/docs/classes/SkipLinkedList.html +0 -166
  202. package/docs/classes/SplayTree.html +0 -166
  203. package/docs/classes/Stack.html +0 -362
  204. package/docs/classes/TreeMap.html +0 -166
  205. package/docs/classes/TreeMultiSet.html +0 -2196
  206. package/docs/classes/TreeMultiSetNode.html +0 -450
  207. package/docs/classes/TreeNode.html +0 -337
  208. package/docs/classes/TreeSet.html +0 -166
  209. package/docs/classes/Trie.html +0 -366
  210. package/docs/classes/TrieNode.html +0 -274
  211. package/docs/classes/TwoThreeTree.html +0 -166
  212. package/docs/classes/UndirectedEdge.html +0 -331
  213. package/docs/classes/UndirectedGraph.html +0 -1196
  214. package/docs/classes/UndirectedVertex.html +0 -248
  215. package/docs/classes/Vector2D.html +0 -799
  216. package/docs/enums/CP.html +0 -175
  217. package/docs/enums/FamilyPosition.html +0 -175
  218. package/docs/enums/LoopType.html +0 -176
  219. package/docs/enums/RBColor.html +0 -168
  220. package/docs/enums/TopologicalProperty.html +0 -175
  221. package/docs/index.html +0 -639
  222. package/docs/interfaces/IBinaryTree.html +0 -189
  223. package/docs/interfaces/IBinaryTreeNode.html +0 -396
  224. package/docs/interfaces/IDirectedGraph.html +0 -259
  225. package/docs/interfaces/IGraph.html +0 -471
  226. package/docs/interfaces/IUNDirectedGraph.html +0 -151
  227. package/docs/modules.html +0 -250
  228. package/docs/types/AVLTreeOptions.html +0 -144
  229. package/docs/types/AbstractBinaryTreeOptions.html +0 -150
  230. package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -146
  231. package/docs/types/AbstractResultByProperty.html +0 -146
  232. package/docs/types/AbstractResultsByProperty.html +0 -146
  233. package/docs/types/BSTComparator.html +0 -156
  234. package/docs/types/BSTOptions.html +0 -146
  235. package/docs/types/BinaryTreeDeletedResult.html +0 -153
  236. package/docs/types/BinaryTreeNodeId.html +0 -141
  237. package/docs/types/BinaryTreeNodePropertyName.html +0 -141
  238. package/docs/types/BinaryTreeOptions.html +0 -144
  239. package/docs/types/DFSOrderPattern.html +0 -141
  240. package/docs/types/DijkstraResult.html +0 -161
  241. package/docs/types/Direction.html +0 -141
  242. package/docs/types/EdgeId.html +0 -141
  243. package/docs/types/HeapOptions.html +0 -162
  244. package/docs/types/IdObject.html +0 -151
  245. package/docs/types/KeyValObject.html +0 -146
  246. package/docs/types/NavigatorParams.html +0 -175
  247. package/docs/types/NodeOrPropertyName.html +0 -141
  248. package/docs/types/PriorityQueueComparator.html +0 -161
  249. package/docs/types/PriorityQueueDFSOrderPattern.html +0 -141
  250. package/docs/types/PriorityQueueOptions.html +0 -155
  251. package/docs/types/RBTreeOptions.html +0 -144
  252. package/docs/types/RecursiveAVLTreeNode.html +0 -146
  253. package/docs/types/RecursiveBSTNode.html +0 -146
  254. package/docs/types/RecursiveBinaryTreeNode.html +0 -146
  255. package/docs/types/RecursiveTreeMultiSetNode.html +0 -146
  256. package/docs/types/SegmentTreeNodeVal.html +0 -141
  257. package/docs/types/TopologicalStatus.html +0 -141
  258. package/docs/types/TreeMultiSetOptions.html +0 -146
  259. package/docs/types/Turning.html +0 -141
  260. package/docs/types/VertexId.html +0 -141
  261. package/notes/bst.test.ts +0 -181
  262. package/notes/note.md +0 -34
@@ -1,4 +1,4 @@
1
1
  import { BinaryTreeNode } from '../binary-tree';
2
2
  import { AbstractBinaryTreeOptions } from './abstract-binary-tree';
3
- export type RecursiveBinaryTreeNode<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
3
+ export type BinaryTreeNodeNested<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
4
  export type BinaryTreeOptions = AbstractBinaryTreeOptions & {};
@@ -2,7 +2,7 @@ import { BSTNode } from '../binary-tree';
2
2
  import type { BinaryTreeOptions } from './binary-tree';
3
3
  import { BinaryTreeNodeId } from './abstract-binary-tree';
4
4
  export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number;
5
- export type RecursiveBSTNode<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
+ export type BSTNodeNested<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
6
6
  export type BSTOptions = BinaryTreeOptions & {
7
7
  comparator?: BSTComparator;
8
8
  };
@@ -6,4 +6,4 @@ var CP;
6
6
  CP["lt"] = "lt";
7
7
  CP["eq"] = "eq";
8
8
  CP["gt"] = "gt";
9
- })(CP || (exports.CP = CP = {}));
9
+ })(CP = exports.CP || (exports.CP = {}));
@@ -6,4 +6,4 @@ var TopologicalProperty;
6
6
  TopologicalProperty["VAL"] = "VAL";
7
7
  TopologicalProperty["NODE"] = "NODE";
8
8
  TopologicalProperty["ID"] = "ID";
9
- })(TopologicalProperty || (exports.TopologicalProperty = TopologicalProperty = {}));
9
+ })(TopologicalProperty = exports.TopologicalProperty || (exports.TopologicalProperty = {}));
@@ -1,8 +1 @@
1
- export type IdObject = {
2
- id: number;
3
- } & {
4
- [key: string]: any;
5
- };
6
- export type KeyValObject = {
7
- [key: string]: any;
8
- };
1
+ export {};
@@ -1,6 +1,8 @@
1
1
  import { BinaryTreeOptions } from './binary-tree';
2
+ import { RBTreeNode } from '../binary-tree';
2
3
  export declare enum RBColor {
3
4
  RED = "RED",
4
5
  BLACK = "BLACK"
5
6
  }
7
+ export type RBTreeNodeNested<T> = RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
6
8
  export type RBTreeOptions = BinaryTreeOptions & {};
@@ -5,4 +5,4 @@ var RBColor;
5
5
  (function (RBColor) {
6
6
  RBColor["RED"] = "RED";
7
7
  RBColor["BLACK"] = "BLACK";
8
- })(RBColor || (exports.RBColor = RBColor = {}));
8
+ })(RBColor = exports.RBColor || (exports.RBColor = {}));
@@ -1,6 +1,6 @@
1
- import { BSTOptions } from './bst';
2
1
  import { TreeMultiSetNode } from '../binary-tree';
3
- export type RecursiveTreeMultiSetNode<T> = TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
- export type TreeMultiSetOptions = Omit<BSTOptions, 'isDuplicatedVal'> & {
5
- isDuplicatedVal: true;
2
+ import { AVLTreeOptions } from './avl-tree';
3
+ export type TreeMultiSetNodeNested<T> = TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, TreeMultiSetNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
+ export type TreeMultiSetOptions = Omit<AVLTreeOptions, 'isMergeDuplicatedVal'> & {
5
+ isMergeDuplicatedVal: true;
6
6
  };
@@ -5,3 +5,21 @@ export type Thunk = () => ReturnType<ToThunkFn> & {
5
5
  export type TrlFn = (...args: any[]) => any;
6
6
  export type TrlAsyncFn = (...args: any[]) => any;
7
7
  export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
8
+ export type KeyValueObject = {
9
+ [key: string]: any;
10
+ };
11
+ export type KeyValueObjectWithId = {
12
+ [key: string]: any;
13
+ id: string | number | symbol;
14
+ };
15
+ export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
16
+ export type ObjectWithoutId = Omit<KeyValueObject, 'id'>;
17
+ export type ObjectWithNonNumberId = {
18
+ [key: string]: any;
19
+ id: string | boolean | symbol | null | object | undefined;
20
+ };
21
+ export type ObjectWithNumberId = {
22
+ [key: string]: any;
23
+ id: number;
24
+ };
25
+ export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | Function | never;
@@ -7,7 +7,7 @@ export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: nu
7
7
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
8
8
  * @license MIT License
9
9
  */
10
- import type { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
10
+ import type { NonNumberNonObjectButDefined, ObjectWithNonNumberId, ObjectWithNumberId, ObjectWithoutId, Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
11
11
  export declare const THUNK_SYMBOL: unique symbol;
12
12
  export declare const isThunk: (fnOrValue: any) => boolean;
13
13
  export declare const toThunk: (fn: ToThunkFn) => Thunk;
@@ -17,3 +17,8 @@ export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>
17
17
  export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
18
18
  cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
19
19
  };
20
+ export declare function isNonNumberNonObjectButDefined(val: any): val is NonNumberNonObjectButDefined;
21
+ export declare function isObjectWithoutId(val: any): val is ObjectWithoutId;
22
+ export declare function isObjectWithNonNumberId(val: any): val is ObjectWithNonNumberId;
23
+ export declare function isObjectWithNumberId(val: any): val is ObjectWithNumberId;
24
+ export declare function isNumber(val: any): val is number;
@@ -61,7 +61,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
61
61
  return to.concat(ar || Array.prototype.slice.call(from));
62
62
  };
63
63
  Object.defineProperty(exports, "__esModule", { value: true });
64
- exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
64
+ exports.isNumber = exports.isObjectWithNumberId = exports.isObjectWithNonNumberId = exports.isObjectWithoutId = exports.isNonNumberNonObjectButDefined = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
65
65
  var uuidV4 = function () {
66
66
  return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
67
67
  var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
@@ -149,3 +149,85 @@ var trampolineAsync = function (fn) {
149
149
  }, { cont: cont });
150
150
  };
151
151
  exports.trampolineAsync = trampolineAsync;
152
+ // export class AutoPruneMap<K, V> extends Map<K, V> {
153
+ //
154
+ // private _proxySet: Set<V>;
155
+ // get proxySet(): Set<V> {
156
+ // return this._proxySet;
157
+ // }
158
+ //
159
+ // set proxySet(value: Set<V>) {
160
+ // this._proxySet = value;
161
+ // }
162
+ //
163
+ // private _isEmptyArrayAllowed: boolean;
164
+ //
165
+ // get isEmptyArrayAllowed(): boolean {
166
+ // return this._isEmptyArrayAllowed;
167
+ // }
168
+ //
169
+ // set isEmptyArrayAllowed(value: boolean) {
170
+ // this._isEmptyArrayAllowed = value;
171
+ // }
172
+ //
173
+ // constructor(isEmptyArrayAllowed: boolean = false) {
174
+ // super();
175
+ // this._isEmptyArrayAllowed = isEmptyArrayAllowed;
176
+ // this._proxySet = new Set<V>();
177
+ // }
178
+ //
179
+ // set(key: K, value: V): this {
180
+ // if (Array.isArray(value) && !this.proxySet.has(value)) {
181
+ // if(!this.isEmptyArrayAllowed && value.length === 0) return this;
182
+ // value = this.createArrayProxy(value, key);
183
+ // if (!this.proxySet.has(value)) this.proxySet.add(value);
184
+ // }
185
+ // super.set(key, value);
186
+ // return this;
187
+ // }
188
+ //
189
+ // private createArrayProxy(array: V & any[], key: K) {
190
+ // const that = this;
191
+ // const proxyHandler: ProxyHandler<V & any[]> = {
192
+ // set(target: any, property: PropertyKey, value: any): boolean {
193
+ // const result = Reflect.set(target, property, value);
194
+ // that.checkAndDeleteEmptyArray(key);
195
+ // return result;
196
+ // },
197
+ // deleteProperty(target: any, property: PropertyKey): boolean {
198
+ // const result = Reflect.deleteProperty(target, property);
199
+ // that.checkAndDeleteEmptyArray(key);
200
+ // return result;
201
+ // },
202
+ // }
203
+ // return new Proxy(array, proxyHandler);
204
+ // }
205
+ //
206
+ // private checkAndDeleteEmptyArray(key: K): void {
207
+ // const value = this.get(key);
208
+ //
209
+ // if (Array.isArray(value) && value.length === 0) {
210
+ // super.delete(key);
211
+ // }
212
+ // }
213
+ // }
214
+ function isNonNumberNonObjectButDefined(val) {
215
+ return typeof val !== 'number' && typeof val !== 'object' && val !== undefined;
216
+ }
217
+ exports.isNonNumberNonObjectButDefined = isNonNumberNonObjectButDefined;
218
+ function isObjectWithoutId(val) {
219
+ return typeof val === 'object' && !('id' in val);
220
+ }
221
+ exports.isObjectWithoutId = isObjectWithoutId;
222
+ function isObjectWithNonNumberId(val) {
223
+ return typeof val === 'object' && 'id' in val && typeof val.id !== 'number';
224
+ }
225
+ exports.isObjectWithNonNumberId = isObjectWithNonNumberId;
226
+ function isObjectWithNumberId(val) {
227
+ return typeof val === 'object' && 'id' in val && typeof val.id === 'number';
228
+ }
229
+ exports.isObjectWithNumberId = isObjectWithNumberId;
230
+ function isNumber(val) {
231
+ return typeof val === 'number';
232
+ }
233
+ exports.isNumber = isNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.18.6",
3
+ "version": "1.18.8",
4
4
  "description": "Explore our comprehensive Javascript Data Structure / TypeScript Data Structure Library, meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures, such as Binary Tree, AVL Tree, Binary Search Tree (BST), Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Singly Linked List, Hash, CoordinateSet, CoordinateMap, Heap, Doubly Linked List, Priority Queue, Max Priority Queue, Min Priority Queue, Queue, ObjectDeque, ArrayDeque, Stack, and Trie. Each data structure is thoughtfully designed and implemented using TypeScript to provide efficient, reliable, and easy-to-use solutions for your programming needs. Whether you're optimizing algorithms, managing data, or enhancing performance, our TypeScript Data Structure Library is your go-to resource. Elevate your coding experience with these fundamental building blocks for software development.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -62,6 +62,6 @@
62
62
  "jest": "^29.6.2",
63
63
  "ts-jest": "^29.1.1",
64
64
  "typedoc": "^0.24.8",
65
- "typescript": "^5.1.6"
65
+ "typescript": "^4.9.5"
66
66
  }
67
67
  }
@@ -1,3 +0,0 @@
1
- export class AaTree {
2
-
3
- }
@@ -1,288 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- import {BST, BSTNode} from './bst';
9
- import type {AVLTreeDeleted, BinaryTreeNodeId, RecursiveAVLTreeNode} from '../types';
10
- import {IBinaryTreeNode} from '../interfaces';
11
-
12
-
13
- export class AVLTreeNode<T, FAMILY extends AVLTreeNode<T, FAMILY > = RecursiveAVLTreeNode<T>> extends BSTNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
14
-
15
- }
16
-
17
- export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<number>> extends BST<N> {
18
-
19
- override _createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N {
20
- const node = new AVLTreeNode<N['val'], N>(id, val, count);
21
- return node as N;
22
- }
23
-
24
- /**
25
- * The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
26
- * balances the tree.
27
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add or
28
- * update in the AVL tree.
29
- * @param {N | null} val - The `val` parameter represents the value that you want to assign to the node with the given
30
- * `id`. It can be of type `N` (the generic type) or `null`.
31
- * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
32
- * of times the value `val` should be inserted into the AVL tree. If the `count` parameter is not provided, it defaults
33
- * to `1`, indicating that the value should be inserted once.
34
- * @returns The method is returning either an N object or null.
35
- */
36
- override add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null {
37
- const inserted = super.add(id, val, count);
38
- if (inserted) this.balancePath(inserted);
39
- return inserted;
40
- }
41
-
42
- /**
43
- * The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
44
- * then balances the tree if necessary.
45
- * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
46
- * removed from the AVL tree.
47
- * @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean parameter that
48
- * determines whether the left sum of all nodes in the AVL tree should be updated after removing a node. If
49
- * `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
50
- * @returns The method is returning an array of `AVLTreeDeleted<N>` objects.
51
- */
52
- override remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): AVLTreeDeleted<N>[] {
53
- const deletedResults = super.remove(id, isUpdateAllLeftSum);
54
- for (const {needBalanced} of deletedResults) {
55
- if (needBalanced) {
56
- this.balancePath(needBalanced);
57
- }
58
- }
59
- return deletedResults;
60
- }
61
-
62
- /**
63
- * The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
64
- * height of its right subtree.
65
- * @param node - The parameter "node" is of type N, which represents a node in an AVL tree.
66
- * @returns The balance factor of the given AVL tree node.
67
- */
68
- balanceFactor(node: N): number {
69
- if (!node.right) // node has no right subtree
70
- return -node.height;
71
- else if (!node.left) // node has no left subtree
72
- return +node.height;
73
- else
74
- return node.right.height - node.left.height;
75
- }
76
-
77
- /**
78
- * The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.
79
- * @param node - The parameter `node` is an AVLTreeNode object, which represents a node in an AVL tree.
80
- */
81
- updateHeight(node: N): void {
82
- if (!node.left && !node.right) // node is a leaf
83
- node.height = 0;
84
- else if (!node.left) {
85
- // node has no left subtree
86
- const rightHeight = node.right ? node.right.height : 0;
87
- node.height = 1 + rightHeight;
88
- } else if (!node.right) // node has no right subtree
89
- node.height = 1 + node.left.height;
90
- else
91
- node.height = 1 + Math.max(node.right.height, node.left.height);
92
- }
93
-
94
- /**
95
- * The `balancePath` function balances the AVL tree by performing appropriate rotations based on the balance factor of
96
- * each node in the path from the given node to the root.
97
- * @param node - The `node` parameter is an AVLTreeNode object, which represents a node in an AVL tree.
98
- */
99
- balancePath(node: N): void {
100
- const path = this.getPathToRoot(node);
101
- for (let i = path.length - 1; i >= 0; i--) {
102
- const A = path[i];
103
- this.updateHeight(A);
104
- switch (this.balanceFactor(A)) {
105
- case -2:
106
- if (A && A.left) {
107
- if (this.balanceFactor(A.left) <= 0) {
108
- this.balanceLL(A); // Perform LL rotation
109
- } else {
110
- this.balanceLR(A); // Perform LR rotation
111
- }
112
- }
113
- break;
114
- case +2:
115
- if (A && A.right) {
116
- if (this.balanceFactor(A.right) >= 0) {
117
- this.balanceRR(A); // Perform RR rotation
118
- } else {
119
- this.balanceRL(A); // Perform RL rotation
120
- }
121
- }
122
- }
123
- }
124
- }
125
-
126
- /**
127
- * The `balanceLL` function performs a left-left rotation on an AVL tree to balance it.
128
- * @param A - The parameter A is an AVLTreeNode object.
129
- */
130
- balanceLL(A: N): void {
131
- const parentOfA = A.parent;
132
- const B = A.left; // A is left-heavy and B is left-heavy
133
- A.parent = B;
134
- if (B && B.right) {
135
- B.right.parent = A;
136
- }
137
- if (B) B.parent = parentOfA;
138
- if (A === this.root) {
139
- if (B) this._setRoot(B);
140
- } else {
141
- if (parentOfA?.left === A) {
142
- parentOfA.left = B;
143
- } else {
144
- if (parentOfA) parentOfA.right = B;
145
- }
146
- }
147
-
148
- if (B) {
149
- A.left = B.right; // Make T2 the left subtree of A
150
- B.right = A; // Make A the left child of B
151
- }
152
- this.updateHeight(A);
153
- if (B) this.updateHeight(B);
154
- }
155
-
156
- /**
157
- * The `balanceLR` function performs a left-right rotation to balance an AVL tree.
158
- * @param A - A is an AVLTreeNode object.
159
- */
160
- balanceLR(A: N): void {
161
- const parentOfA = A.parent;
162
- const B = A.left; // A is left-heavy
163
- let C = null;
164
- if (B) {
165
- C = B.right;// B is right-heavy
166
- }
167
- if (A) A.parent = C;
168
- if (B) B.parent = C;
169
-
170
- if (C) {
171
- if (C.left) {
172
- C.left.parent = B;
173
- }
174
- if (C.right) {
175
- C.right.parent = A;
176
- }
177
- C.parent = parentOfA;
178
- }
179
-
180
- if (A === this.root) {
181
- if (C) this._setRoot(C);
182
- } else {
183
- if (parentOfA) {
184
- if (parentOfA.left === A) {
185
- parentOfA.left = C;
186
- } else {
187
- parentOfA.right = C;
188
- }
189
- }
190
- }
191
-
192
- if (C) {
193
- A.left = C.right; // Make T3 the left subtree of A
194
- if (B) B.right = C.left; // Make T2 the right subtree of B
195
- C.left = B;
196
- C.right = A;
197
- }
198
-
199
- this.updateHeight(A); // Adjust heights
200
- B && this.updateHeight(B);
201
- C && this.updateHeight(C);
202
- }
203
-
204
- /**
205
- * The `balanceRR` function performs a right-right rotation on an AVL tree to balance it.
206
- * @param A - The parameter A is an AVLTreeNode object.
207
- */
208
- balanceRR(A: N): void {
209
- const parentOfA = A.parent;
210
- const B = A.right; // A is right-heavy and B is right-heavy
211
- A.parent = B;
212
- if (B) {
213
- if (B.left) {
214
- B.left.parent = A;
215
- }
216
- B.parent = parentOfA;
217
- }
218
-
219
- if (A === this.root) {
220
- if (B) this._setRoot(B);
221
- } else {
222
- if (parentOfA) {
223
- if (parentOfA.left === A) {
224
- parentOfA.left = B;
225
- } else {
226
- parentOfA.right = B;
227
- }
228
- }
229
- }
230
-
231
- if (B) {
232
- A.right = B.left; // Make T2 the right subtree of A
233
- B.left = A;
234
- }
235
- this.updateHeight(A);
236
- B && this.updateHeight(B);
237
- }
238
-
239
- /**
240
- * The `balanceRL` function performs a right-left rotation to balance an AVL tree.
241
- * @param A - A is an AVLTreeNode object.
242
- */
243
- balanceRL(A: N): void {
244
- const parentOfA = A.parent;
245
- const B = A.right; // A is right-heavy
246
- let C = null;
247
- if (B) {
248
- C = B.left; // B is left-heavy
249
- }
250
-
251
- A.parent = C;
252
- if (B) B.parent = C;
253
-
254
- if (C) {
255
- if (C.left) {
256
- C.left.parent = A;
257
- }
258
- if (C.right) {
259
- C.right.parent = B;
260
- }
261
- C.parent = parentOfA;
262
- }
263
-
264
-
265
- if (A === this.root) {
266
- if (C) this._setRoot(C);
267
- } else {
268
- if (parentOfA) {
269
- if (parentOfA.left === A) {
270
- parentOfA.left = C;
271
- } else {
272
- parentOfA.right = C;
273
- }
274
- }
275
- }
276
-
277
- if (C) A.right = C.left; // Make T2 the right subtree of A
278
- if (B && C) B.left = C.right; // Make T3 the left subtree of B
279
- if (C) C.left = A;
280
- if (C) C.right = B;
281
-
282
- this.updateHeight(A); // Adjust heights
283
- B && this.updateHeight(B);
284
- C && this.updateHeight(C);
285
- }
286
- }
287
-
288
-
@@ -1,3 +0,0 @@
1
- export class BTree {
2
-
3
- }
@@ -1,78 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export class BinaryIndexedTree {
9
-
10
- /**
11
- * The constructor initializes an array with a specified length and fills it with zeros.
12
- * @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The
13
- * sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array.
14
- * The size of the sum tree array is `n + 1` because
15
- */
16
- constructor(n: number) {
17
- this._sumTree = new Array<number>(n + 1).fill(0);
18
- }
19
-
20
- private _sumTree: number[];
21
-
22
- get sumTree(): number[] {
23
- return this._sumTree;
24
- }
25
-
26
- static lowBit(x: number) {
27
- return x & (-x);
28
- }
29
-
30
- /**
31
- * The update function updates the values in a binary indexed tree by adding a delta value to the specified index and
32
- * its ancestors.
33
- * @param {number} i - The parameter `i` represents the index of the element in the `_sumTree` array that needs to be
34
- * updated.
35
- * @param {number} delta - The "delta" parameter represents the change in value that needs to be added to the element
36
- * at index "i" in the "_sumTree" array.
37
- */
38
- update(i: number, delta: number) {
39
- while (i < this._sumTree.length) {
40
- this._sumTree[i] += delta;
41
- i += BinaryIndexedTree.lowBit(i);
42
- }
43
- }
44
-
45
- /**
46
- * The function calculates the prefix sum of an array using a binary indexed tree.
47
- * @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
48
- * array for which we want to calculate the prefix sum.
49
- * @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
50
- * `i`.
51
- */
52
- getPrefixSum(i: number) {
53
- let sum = 0;
54
- while (i > 0) {
55
- sum += this._sumTree[i];
56
- i -= BinaryIndexedTree.lowBit(i);
57
- }
58
- return sum;
59
- }
60
-
61
- /**
62
- * The function `getRangeSum` calculates the sum of a range of numbers in an array.
63
- * @param {number} start - The start parameter is the starting index of the range for which we want to calculate the
64
- * sum.
65
- * @param {number} end - The "end" parameter represents the ending index of the range for which we want to calculate
66
- * the sum.
67
- * @returns the sum of the elements in the range specified by the start and end indices.
68
- */
69
- getRangeSum(start: number, end: number): number {
70
- if (!(0 <= start && start <= end && end <= this._sumTree.length))
71
- throw 'Index out of bounds';
72
- return this.getPrefixSum(end) - this.getPrefixSum(start);
73
- }
74
-
75
- protected _setSumTree(value: number[]) {
76
- this._sumTree = value;
77
- }
78
- }