data-structure-typed 1.18.7 → 1.19.0

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 (269) hide show
  1. package/README.md +208 -419
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +198 -167
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +413 -398
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +24 -16
  5. package/dist/data-structures/binary-tree/avl-tree.js +23 -17
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
  7. package/dist/data-structures/binary-tree/binary-tree.js +12 -27
  8. package/dist/data-structures/binary-tree/bst.d.ts +66 -90
  9. package/dist/data-structures/binary-tree/bst.js +85 -163
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -17
  11. package/dist/data-structures/binary-tree/rb-tree.js +5 -17
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +187 -18
  13. package/dist/data-structures/binary-tree/tree-multiset.js +716 -39
  14. package/dist/data-structures/graph/abstract-graph.d.ts +112 -52
  15. package/dist/data-structures/graph/abstract-graph.js +138 -72
  16. package/dist/data-structures/graph/directed-graph.d.ts +104 -101
  17. package/dist/data-structures/graph/directed-graph.js +134 -129
  18. package/dist/data-structures/graph/undirected-graph.d.ts +66 -65
  19. package/dist/data-structures/graph/undirected-graph.js +107 -106
  20. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +12 -18
  21. package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
  22. package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
  23. package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
  24. package/dist/data-structures/interfaces/bst.d.ts +4 -5
  25. package/dist/data-structures/interfaces/rb-tree.d.ts +2 -3
  26. package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
  27. package/dist/data-structures/tree/tree.d.ts +1 -4
  28. package/dist/data-structures/tree/tree.js +1 -12
  29. package/dist/data-structures/types/abstract-binary-tree.d.ts +10 -6
  30. package/dist/data-structures/types/abstract-binary-tree.js +9 -5
  31. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  32. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  33. package/dist/data-structures/types/bst.d.ts +1 -1
  34. package/dist/data-structures/types/bst.js +1 -1
  35. package/dist/data-structures/types/directed-graph.js +1 -1
  36. package/dist/data-structures/types/helpers.d.ts +1 -8
  37. package/dist/data-structures/types/rb-tree.d.ts +2 -0
  38. package/dist/data-structures/types/rb-tree.js +1 -1
  39. package/dist/data-structures/types/tree-multiset.d.ts +5 -5
  40. package/dist/utils/index.d.ts +1 -0
  41. package/dist/utils/index.js +1 -0
  42. package/dist/utils/types/index.d.ts +1 -0
  43. package/dist/utils/types/index.js +1 -0
  44. package/dist/utils/types/validate-type.d.ts +19 -0
  45. package/dist/utils/types/validate-type.js +2 -0
  46. package/dist/utils/utils.d.ts +2 -2
  47. package/dist/utils/utils.js +0 -62
  48. package/dist/utils/validate-type.d.ts +45 -0
  49. package/dist/utils/validate-type.js +58 -0
  50. package/package.json +5 -2
  51. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  52. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  53. package/backup/recursive-type/src/assets/logo.png +0 -0
  54. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  55. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
  56. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
  57. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
  58. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
  59. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
  60. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
  61. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  62. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  63. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  64. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
  65. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
  66. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
  67. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
  68. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
  69. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  70. package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
  71. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
  72. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  73. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  74. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  75. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  76. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  77. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  78. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  79. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  80. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  81. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  82. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  83. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  84. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  85. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  86. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
  87. package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
  88. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
  89. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
  90. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
  91. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
  92. package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
  93. package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
  94. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
  95. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
  96. package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
  97. package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
  98. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
  99. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
  100. package/backup/recursive-type/src/data-structures/index.ts +0 -15
  101. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
  102. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
  103. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
  104. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
  105. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
  106. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
  107. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
  108. package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
  109. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
  110. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
  111. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
  112. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
  113. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
  114. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
  115. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  116. package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
  117. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
  118. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
  119. package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
  120. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
  121. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
  122. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
  123. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
  124. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
  125. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
  126. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
  127. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
  128. package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
  129. package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
  130. package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
  131. package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
  132. package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
  133. package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
  134. package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
  135. package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
  136. package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
  137. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
  138. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
  139. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
  140. package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
  141. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
  142. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
  143. package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
  144. package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
  145. package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
  146. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
  147. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
  148. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
  149. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
  150. package/backup/recursive-type/src/index.ts +0 -1
  151. package/backup/recursive-type/src/utils/index.ts +0 -2
  152. package/backup/recursive-type/src/utils/types/index.ts +0 -1
  153. package/backup/recursive-type/src/utils/types/utils.ts +0 -6
  154. package/backup/recursive-type/src/utils/utils.ts +0 -78
  155. package/docs/.nojekyll +0 -1
  156. package/docs/assets/highlight.css +0 -92
  157. package/docs/assets/main.js +0 -58
  158. package/docs/assets/search.js +0 -1
  159. package/docs/assets/style.css +0 -1367
  160. package/docs/classes/AVLTree.html +0 -2451
  161. package/docs/classes/AVLTreeNode.html +0 -499
  162. package/docs/classes/AaTree.html +0 -172
  163. package/docs/classes/AbstractBinaryTree.html +0 -2118
  164. package/docs/classes/AbstractBinaryTreeNode.html +0 -524
  165. package/docs/classes/AbstractEdge.html +0 -295
  166. package/docs/classes/AbstractGraph.html +0 -1043
  167. package/docs/classes/AbstractVertex.html +0 -258
  168. package/docs/classes/ArrayDeque.html +0 -439
  169. package/docs/classes/BST.html +0 -2297
  170. package/docs/classes/BSTNode.html +0 -503
  171. package/docs/classes/BTree.html +0 -172
  172. package/docs/classes/BinaryIndexedTree.html +0 -341
  173. package/docs/classes/BinaryTree.html +0 -2133
  174. package/docs/classes/BinaryTreeNode.html +0 -501
  175. package/docs/classes/Character.html +0 -220
  176. package/docs/classes/CoordinateMap.html +0 -483
  177. package/docs/classes/CoordinateSet.html +0 -444
  178. package/docs/classes/Deque.html +0 -975
  179. package/docs/classes/DirectedEdge.html +0 -366
  180. package/docs/classes/DirectedGraph.html +0 -1443
  181. package/docs/classes/DirectedVertex.html +0 -254
  182. package/docs/classes/DoublyLinkedList.html +0 -968
  183. package/docs/classes/DoublyLinkedListNode.html +0 -297
  184. package/docs/classes/HashTable.html +0 -172
  185. package/docs/classes/Heap.html +0 -423
  186. package/docs/classes/HeapItem.html +0 -255
  187. package/docs/classes/Matrix2D.html +0 -502
  188. package/docs/classes/MatrixNTI2D.html +0 -240
  189. package/docs/classes/MaxHeap.html +0 -436
  190. package/docs/classes/MaxPriorityQueue.html +0 -836
  191. package/docs/classes/MinHeap.html +0 -437
  192. package/docs/classes/MinPriorityQueue.html +0 -838
  193. package/docs/classes/Navigator.html +0 -313
  194. package/docs/classes/ObjectDeque.html +0 -455
  195. package/docs/classes/Pair.html +0 -172
  196. package/docs/classes/PriorityQueue.html +0 -760
  197. package/docs/classes/Queue.html +0 -392
  198. package/docs/classes/RBTree.html +0 -2388
  199. package/docs/classes/RBTreeNode.html +0 -516
  200. package/docs/classes/SegmentTree.html +0 -434
  201. package/docs/classes/SegmentTreeNode.html +0 -357
  202. package/docs/classes/SinglyLinkedList.html +0 -788
  203. package/docs/classes/SinglyLinkedListNode.html +0 -270
  204. package/docs/classes/SkipLinkedList.html +0 -172
  205. package/docs/classes/SplayTree.html +0 -172
  206. package/docs/classes/Stack.html +0 -368
  207. package/docs/classes/TreeMap.html +0 -172
  208. package/docs/classes/TreeMultiSet.html +0 -2297
  209. package/docs/classes/TreeMultiSetNode.html +0 -499
  210. package/docs/classes/TreeNode.html +0 -343
  211. package/docs/classes/TreeSet.html +0 -172
  212. package/docs/classes/Trie.html +0 -372
  213. package/docs/classes/TrieNode.html +0 -280
  214. package/docs/classes/TwoThreeTree.html +0 -172
  215. package/docs/classes/UndirectedEdge.html +0 -337
  216. package/docs/classes/UndirectedGraph.html +0 -1210
  217. package/docs/classes/UndirectedVertex.html +0 -254
  218. package/docs/classes/Vector2D.html +0 -805
  219. package/docs/enums/CP.html +0 -181
  220. package/docs/enums/FamilyPosition.html +0 -181
  221. package/docs/enums/LoopType.html +0 -182
  222. package/docs/enums/RBColor.html +0 -174
  223. package/docs/enums/TopologicalProperty.html +0 -181
  224. package/docs/index.html +0 -645
  225. package/docs/interfaces/IAVLTree.html +0 -1378
  226. package/docs/interfaces/IAVLTreeNode.html +0 -405
  227. package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
  228. package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
  229. package/docs/interfaces/IAbstractGraph.html +0 -433
  230. package/docs/interfaces/IBST.html +0 -1271
  231. package/docs/interfaces/IBSTNode.html +0 -408
  232. package/docs/interfaces/IDirectedGraph.html +0 -572
  233. package/docs/interfaces/IUNDirectedGraph.html +0 -465
  234. package/docs/modules.html +0 -262
  235. package/docs/types/AVLTreeOptions.html +0 -150
  236. package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
  237. package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
  238. package/docs/types/AbstractBinaryTreeOptions.html +0 -156
  239. package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
  240. package/docs/types/BSTComparator.html +0 -162
  241. package/docs/types/BSTOptions.html +0 -152
  242. package/docs/types/BinaryTreeDeletedResult.html +0 -159
  243. package/docs/types/BinaryTreeNodeId.html +0 -147
  244. package/docs/types/BinaryTreeNodePropertyName.html +0 -147
  245. package/docs/types/BinaryTreeOptions.html +0 -150
  246. package/docs/types/DFSOrderPattern.html +0 -147
  247. package/docs/types/DijkstraResult.html +0 -167
  248. package/docs/types/Direction.html +0 -147
  249. package/docs/types/EdgeId.html +0 -147
  250. package/docs/types/HeapOptions.html +0 -168
  251. package/docs/types/IdObject.html +0 -157
  252. package/docs/types/KeyValObject.html +0 -152
  253. package/docs/types/NavigatorParams.html +0 -181
  254. package/docs/types/NodeOrPropertyName.html +0 -147
  255. package/docs/types/PriorityQueueComparator.html +0 -167
  256. package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
  257. package/docs/types/PriorityQueueOptions.html +0 -161
  258. package/docs/types/RBTreeOptions.html +0 -150
  259. package/docs/types/RecursiveAVLTreeNode.html +0 -152
  260. package/docs/types/RecursiveBSTNode.html +0 -152
  261. package/docs/types/RecursiveBinaryTreeNode.html +0 -152
  262. package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
  263. package/docs/types/SegmentTreeNodeVal.html +0 -147
  264. package/docs/types/TopologicalStatus.html +0 -147
  265. package/docs/types/TreeMultiSetOptions.html +0 -152
  266. package/docs/types/Turning.html +0 -147
  267. package/docs/types/VertexId.html +0 -147
  268. package/notes/bst.test.ts +0 -181
  269. package/notes/note.md +0 -34
@@ -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
- 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;
1
+ import { TreeMultisetNode } from '../binary-tree';
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
  };
@@ -1,2 +1,3 @@
1
1
  export * from './utils';
2
2
  export * from './types';
3
+ export * from './validate-type';
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./utils"), exports);
18
18
  __exportStar(require("./types"), exports);
19
+ __exportStar(require("./validate-type"), exports);
@@ -1 +1,2 @@
1
1
  export * from './utils';
2
+ export * from './validate-type';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./utils"), exports);
18
+ __exportStar(require("./validate-type"), exports);
@@ -0,0 +1,19 @@
1
+ export type KeyValueObject = {
2
+ [key: string]: any;
3
+ };
4
+ export type KeyValueObjectWithId = {
5
+ [key: string]: any;
6
+ id: string | number | symbol;
7
+ };
8
+ export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
9
+ export type ObjectWithoutId = Omit<KeyValueObject, 'id'>;
10
+ export type ObjectWithNonNumberId = {
11
+ [key: string]: any;
12
+ id: string | boolean | symbol | null | object | undefined;
13
+ };
14
+ export type ObjectWithNumberId = {
15
+ [key: string]: any;
16
+ id: number;
17
+ };
18
+ export type RestrictValById = NonNumberNonObjectButDefined | ObjectWithoutId | ObjectWithNonNumberId | ObjectWithNumberId;
19
+ export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | Function | never;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,3 @@
1
- export declare const uuidV4: () => string;
2
- export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean) => T[];
3
1
  /**
4
2
  * data-structure-typed
5
3
  *
@@ -8,6 +6,8 @@ export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: nu
8
6
  * @license MIT License
9
7
  */
10
8
  import type { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
9
+ export declare const uuidV4: () => string;
10
+ export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean) => T[];
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;
@@ -149,65 +149,3 @@ 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
- // }
@@ -0,0 +1,45 @@
1
+ import { z } from 'zod';
2
+ import { NonNumberNonObjectButDefined, ObjectWithNonNumberId, ObjectWithNumberId, ObjectWithoutId } from './types';
3
+ export declare const nonNumberNonObjectButDefinedSchema: z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodAny]>>;
4
+ export declare const keyValueObjectSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
5
+ export declare const objectWithoutIdSchema: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>, Record<string, unknown>>;
6
+ export declare const keyValueObjectWithIdSchema: z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
7
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodAny]>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ id?: any;
10
+ }, {
11
+ id?: any;
12
+ }>>;
13
+ export declare const objectWithNonNumberIdSchema: z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
14
+ id: z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodAny, z.ZodAny, z.ZodUndefined]>>;
15
+ }, "strip", z.ZodTypeAny, {
16
+ id?: any;
17
+ }, {
18
+ id?: any;
19
+ }>>;
20
+ export declare const objectWithNumberIdSchema: z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
21
+ id: z.ZodNumber;
22
+ }, "strip", z.ZodTypeAny, {
23
+ id: number;
24
+ }, {
25
+ id: number;
26
+ }>>;
27
+ export declare const binaryTreeNodeValWithId: z.ZodUnion<[z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodAny]>>, z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>, Record<string, unknown>>, z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
28
+ id: z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodAny, z.ZodAny, z.ZodUndefined]>>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ id?: any;
31
+ }, {
32
+ id?: any;
33
+ }>>, z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
34
+ id: z.ZodNumber;
35
+ }, "strip", z.ZodTypeAny, {
36
+ id: number;
37
+ }, {
38
+ id: number;
39
+ }>>]>;
40
+ export declare function parseBySchema(schema: z.Schema, val: any): boolean;
41
+ export declare function isNonNumberNonObjectButDefined(val: any): val is NonNumberNonObjectButDefined;
42
+ export declare function isObjectWithoutId(val: any): val is ObjectWithoutId;
43
+ export declare function isObjectWithNonNumberId(val: any): val is ObjectWithNonNumberId;
44
+ export declare function isObjectWithNumberId(val: any): val is ObjectWithNumberId;
45
+ export declare function isNumber(val: any): val is number;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNumber = exports.isObjectWithNumberId = exports.isObjectWithNonNumberId = exports.isObjectWithoutId = exports.isNonNumberNonObjectButDefined = exports.parseBySchema = exports.binaryTreeNodeValWithId = exports.objectWithNumberIdSchema = exports.objectWithNonNumberIdSchema = exports.keyValueObjectWithIdSchema = exports.objectWithoutIdSchema = exports.keyValueObjectSchema = exports.nonNumberNonObjectButDefinedSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ exports.nonNumberNonObjectButDefinedSchema = zod_1.z.union([zod_1.z.string(),
6
+ zod_1.z.boolean(), zod_1.z.any()])
7
+ .nullable();
8
+ exports.keyValueObjectSchema = zod_1.z.record(zod_1.z.unknown());
9
+ exports.objectWithoutIdSchema = exports.keyValueObjectSchema.refine(function (obj) { return !('id' in obj); }, {
10
+ message: 'Object cannot contain the \'id\' field',
11
+ });
12
+ exports.keyValueObjectWithIdSchema = zod_1.z.record(zod_1.z.any()).and(zod_1.z.object({
13
+ id: zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.any()])
14
+ }));
15
+ exports.objectWithNonNumberIdSchema = zod_1.z.record(zod_1.z.any()).and(zod_1.z.object({
16
+ id: zod_1.z
17
+ .union([zod_1.z.string(), zod_1.z.boolean(), zod_1.z.any(), zod_1.z.any(), zod_1.z.undefined()])
18
+ .nullable()
19
+ }));
20
+ exports.objectWithNumberIdSchema = zod_1.z.record(zod_1.z.any()).and(zod_1.z.object({
21
+ id: zod_1.z.number()
22
+ }));
23
+ exports.binaryTreeNodeValWithId = zod_1.z.union([
24
+ exports.nonNumberNonObjectButDefinedSchema,
25
+ exports.objectWithoutIdSchema,
26
+ exports.objectWithNonNumberIdSchema,
27
+ exports.objectWithNumberIdSchema
28
+ ]);
29
+ function parseBySchema(schema, val) {
30
+ try {
31
+ schema.parse(val);
32
+ return true;
33
+ }
34
+ catch (error) {
35
+ return false;
36
+ }
37
+ }
38
+ exports.parseBySchema = parseBySchema;
39
+ function isNonNumberNonObjectButDefined(val) {
40
+ return parseBySchema(exports.nonNumberNonObjectButDefinedSchema, val);
41
+ }
42
+ exports.isNonNumberNonObjectButDefined = isNonNumberNonObjectButDefined;
43
+ function isObjectWithoutId(val) {
44
+ return parseBySchema(exports.objectWithoutIdSchema, val);
45
+ }
46
+ exports.isObjectWithoutId = isObjectWithoutId;
47
+ function isObjectWithNonNumberId(val) {
48
+ return parseBySchema(exports.objectWithNonNumberIdSchema, val);
49
+ }
50
+ exports.isObjectWithNonNumberId = isObjectWithNonNumberId;
51
+ function isObjectWithNumberId(val) {
52
+ return parseBySchema(exports.objectWithNonNumberIdSchema, val);
53
+ }
54
+ exports.isObjectWithNumberId = isObjectWithNumberId;
55
+ function isNumber(val) {
56
+ return typeof val === 'number';
57
+ }
58
+ exports.isNumber = isNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.18.7",
3
+ "version": "1.19.0",
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,9 @@
62
62
  "jest": "^29.6.2",
63
63
  "ts-jest": "^29.1.1",
64
64
  "typedoc": "^0.24.8",
65
- "typescript": "^5.1.5"
65
+ "typescript": "^4.9.5"
66
+ },
67
+ "dependencies": {
68
+ "zod": "^3.22.2"
66
69
  }
67
70
  }
@@ -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
- }