data-structure-typed 1.17.4 → 1.18.5

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 (293) hide show
  1. package/README.md +193 -66
  2. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  3. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  4. package/backup/recursive-type/src/assets/logo.png +0 -0
  5. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  6. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +3 -0
  7. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +288 -0
  8. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +3 -0
  9. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
  10. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +1502 -0
  11. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +503 -0
  12. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  13. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  14. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  15. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +11 -0
  16. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +110 -0
  17. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +243 -0
  18. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +3 -0
  19. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +55 -0
  20. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +3 -0
  21. package/backup/recursive-type/src/data-structures/diagrams/README.md +5 -0
  22. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +985 -0
  23. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  24. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  25. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  26. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  27. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  28. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  29. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  30. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  31. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  32. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  33. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  34. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  35. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  36. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  37. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +478 -0
  38. package/backup/recursive-type/src/data-structures/graph/index.ts +3 -0
  39. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +293 -0
  40. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +67 -0
  41. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +56 -0
  42. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +3 -0
  43. package/backup/recursive-type/src/data-structures/hash/index.ts +6 -0
  44. package/backup/recursive-type/src/data-structures/hash/pair.ts +3 -0
  45. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +3 -0
  46. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +3 -0
  47. package/backup/recursive-type/src/data-structures/heap/heap.ts +176 -0
  48. package/backup/recursive-type/src/data-structures/heap/index.ts +3 -0
  49. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +31 -0
  50. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +34 -0
  51. package/backup/recursive-type/src/data-structures/index.ts +15 -0
  52. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +42 -0
  53. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +1 -0
  54. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +56 -0
  55. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +1 -0
  56. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +15 -0
  57. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
  58. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +1 -0
  59. package/backup/recursive-type/src/data-structures/interfaces/index.ts +13 -0
  60. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +1 -0
  61. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +1 -0
  62. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +1 -0
  63. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +1 -0
  64. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +1 -0
  65. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +3 -0
  66. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
  67. package/backup/recursive-type/src/data-structures/linked-list/index.ts +3 -0
  68. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +490 -0
  69. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  70. package/backup/recursive-type/src/data-structures/matrix/index.ts +4 -0
  71. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +27 -0
  72. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +208 -0
  73. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +122 -0
  74. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +316 -0
  75. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +3 -0
  76. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
  77. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
  78. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +354 -0
  79. package/backup/recursive-type/src/data-structures/queue/deque.ts +251 -0
  80. package/backup/recursive-type/src/data-structures/queue/index.ts +2 -0
  81. package/backup/recursive-type/src/data-structures/queue/queue.ts +120 -0
  82. package/backup/recursive-type/src/data-structures/stack/index.ts +1 -0
  83. package/backup/recursive-type/src/data-structures/stack/stack.ts +98 -0
  84. package/backup/recursive-type/src/data-structures/tree/index.ts +1 -0
  85. package/backup/recursive-type/src/data-structures/tree/tree.ts +80 -0
  86. package/backup/recursive-type/src/data-structures/trie/index.ts +1 -0
  87. package/backup/recursive-type/src/data-structures/trie/trie.ts +227 -0
  88. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +5 -0
  89. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +8 -0
  90. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +10 -0
  91. package/backup/recursive-type/src/data-structures/types/bst.ts +6 -0
  92. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +8 -0
  93. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +1 -0
  94. package/backup/recursive-type/src/data-structures/types/heap.ts +5 -0
  95. package/backup/recursive-type/src/data-structures/types/index.ts +12 -0
  96. package/backup/recursive-type/src/data-structures/types/navigator.ts +13 -0
  97. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +9 -0
  98. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +1 -0
  99. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +1 -0
  100. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +1 -0
  101. package/backup/recursive-type/src/index.ts +1 -0
  102. package/backup/recursive-type/src/utils/index.ts +2 -0
  103. package/backup/recursive-type/src/utils/types/index.ts +1 -0
  104. package/backup/recursive-type/src/utils/types/utils.ts +6 -0
  105. package/backup/recursive-type/src/utils/utils.ts +78 -0
  106. package/dist/data-structures/binary-tree/avl-tree.d.ts +19 -25
  107. package/dist/data-structures/binary-tree/avl-tree.js +12 -20
  108. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -1
  109. package/dist/data-structures/binary-tree/binary-indexed-tree.js +10 -0
  110. package/dist/data-structures/binary-tree/binary-tree.d.ts +135 -161
  111. package/dist/data-structures/binary-tree/binary-tree.js +192 -164
  112. package/dist/data-structures/binary-tree/bst.d.ts +21 -21
  113. package/dist/data-structures/binary-tree/bst.js +33 -36
  114. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
  115. package/dist/data-structures/binary-tree/rb-tree.js +68 -5
  116. package/dist/data-structures/binary-tree/segment-tree.d.ts +17 -39
  117. package/dist/data-structures/binary-tree/segment-tree.js +34 -47
  118. package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -8
  119. package/dist/data-structures/binary-tree/tree-multiset.js +7 -6
  120. package/dist/data-structures/graph/abstract-graph.d.ts +56 -71
  121. package/dist/data-structures/graph/abstract-graph.js +87 -92
  122. package/dist/data-structures/graph/directed-graph.d.ts +128 -105
  123. package/dist/data-structures/graph/directed-graph.js +161 -121
  124. package/dist/data-structures/graph/undirected-graph.d.ts +81 -62
  125. package/dist/data-structures/graph/undirected-graph.js +99 -78
  126. package/dist/data-structures/hash/coordinate-map.d.ts +1 -5
  127. package/dist/data-structures/hash/coordinate-map.js +3 -9
  128. package/dist/data-structures/hash/coordinate-set.d.ts +2 -6
  129. package/dist/data-structures/hash/coordinate-set.js +3 -9
  130. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  131. package/dist/data-structures/hash/hash-table.js +7 -0
  132. package/dist/data-structures/hash/pair.d.ts +2 -1
  133. package/dist/data-structures/hash/pair.js +7 -0
  134. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  135. package/dist/data-structures/hash/tree-map.js +7 -0
  136. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  137. package/dist/data-structures/hash/tree-set.js +7 -0
  138. package/dist/data-structures/heap/heap.d.ts +0 -14
  139. package/dist/data-structures/heap/heap.js +3 -27
  140. package/dist/data-structures/index.d.ts +1 -0
  141. package/dist/data-structures/index.js +1 -0
  142. package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
  143. package/dist/data-structures/interfaces/abstract-graph.js +2 -0
  144. package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
  145. package/dist/data-structures/interfaces/avl-tree.js +2 -0
  146. package/dist/data-structures/interfaces/binary-tree.d.ts +27 -0
  147. package/dist/data-structures/interfaces/binary-tree.js +2 -0
  148. package/dist/data-structures/interfaces/bst.d.ts +1 -0
  149. package/dist/data-structures/interfaces/bst.js +2 -0
  150. package/dist/data-structures/interfaces/directed-graph.d.ts +9 -0
  151. package/dist/data-structures/interfaces/directed-graph.js +2 -0
  152. package/dist/data-structures/interfaces/doubly-linked-list.d.ts +1 -0
  153. package/dist/data-structures/interfaces/doubly-linked-list.js +2 -0
  154. package/dist/data-structures/interfaces/heap.d.ts +1 -0
  155. package/dist/data-structures/interfaces/heap.js +2 -0
  156. package/dist/data-structures/interfaces/index.d.ts +13 -0
  157. package/dist/data-structures/interfaces/index.js +29 -0
  158. package/dist/data-structures/interfaces/navigator.d.ts +1 -0
  159. package/dist/data-structures/interfaces/navigator.js +2 -0
  160. package/dist/data-structures/interfaces/priority-queue.d.ts +1 -0
  161. package/dist/data-structures/interfaces/priority-queue.js +2 -0
  162. package/dist/data-structures/interfaces/segment-tree.d.ts +1 -0
  163. package/dist/data-structures/interfaces/segment-tree.js +2 -0
  164. package/dist/data-structures/interfaces/singly-linked-list.d.ts +1 -0
  165. package/dist/data-structures/interfaces/singly-linked-list.js +2 -0
  166. package/dist/data-structures/interfaces/tree-multiset.d.ts +1 -0
  167. package/dist/data-structures/interfaces/tree-multiset.js +2 -0
  168. package/dist/data-structures/interfaces/undirected-graph.d.ts +2 -0
  169. package/dist/data-structures/interfaces/undirected-graph.js +2 -0
  170. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -3
  171. package/dist/data-structures/linked-list/doubly-linked-list.js +12 -18
  172. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -2
  173. package/dist/data-structures/linked-list/singly-linked-list.js +12 -15
  174. package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
  175. package/dist/data-structures/priority-queue/priority-queue.js +4 -4
  176. package/dist/data-structures/queue/deque.d.ts +5 -5
  177. package/dist/data-structures/queue/deque.js +6 -6
  178. package/dist/data-structures/queue/queue.d.ts +1 -1
  179. package/dist/data-structures/stack/stack.d.ts +1 -1
  180. package/dist/data-structures/tree/tree.d.ts +12 -4
  181. package/dist/data-structures/tree/tree.js +44 -12
  182. package/dist/data-structures/trie/trie.d.ts +3 -3
  183. package/dist/data-structures/trie/trie.js +10 -10
  184. package/dist/data-structures/types/abstract-graph.d.ts +1 -20
  185. package/dist/data-structures/types/avl-tree.d.ts +5 -4
  186. package/dist/data-structures/types/binary-tree.d.ts +6 -5
  187. package/dist/data-structures/types/bst.d.ts +4 -3
  188. package/dist/data-structures/types/directed-graph.d.ts +5 -9
  189. package/dist/data-structures/types/directed-graph.js +7 -0
  190. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -1
  191. package/dist/data-structures/types/heap.d.ts +2 -2
  192. package/dist/data-structures/types/index.d.ts +0 -1
  193. package/dist/data-structures/types/index.js +0 -1
  194. package/dist/data-structures/types/navigator.d.ts +2 -2
  195. package/dist/data-structures/types/priority-queue.d.ts +2 -2
  196. package/dist/data-structures/types/tree-multiset.d.ts +3 -4
  197. package/docs/assets/search.js +1 -1
  198. package/docs/classes/AVLTree.html +552 -405
  199. package/docs/classes/AVLTreeNode.html +107 -242
  200. package/docs/classes/AaTree.html +18 -13
  201. package/docs/classes/AbstractEdge.html +77 -68
  202. package/docs/classes/AbstractGraph.html +223 -115
  203. package/docs/classes/AbstractVertex.html +71 -45
  204. package/docs/classes/ArrayDeque.html +31 -26
  205. package/docs/classes/BST.html +543 -391
  206. package/docs/classes/BSTNode.html +107 -236
  207. package/docs/classes/BTree.html +18 -13
  208. package/docs/classes/BinaryIndexedTree.html +56 -21
  209. package/docs/classes/BinaryTree.html +564 -355
  210. package/docs/classes/BinaryTreeNode.html +146 -199
  211. package/docs/classes/Character.html +21 -16
  212. package/docs/classes/CoordinateMap.html +49 -52
  213. package/docs/classes/CoordinateSet.html +50 -53
  214. package/docs/classes/Deque.html +51 -68
  215. package/docs/classes/DirectedEdge.html +98 -103
  216. package/docs/classes/DirectedGraph.html +449 -210
  217. package/docs/classes/DirectedVertex.html +63 -52
  218. package/docs/classes/DoublyLinkedList.html +56 -71
  219. package/docs/classes/DoublyLinkedListNode.html +28 -23
  220. package/docs/classes/HashTable.html +155 -0
  221. package/docs/classes/Heap.html +33 -109
  222. package/docs/classes/HeapItem.html +25 -20
  223. package/docs/classes/Matrix2D.html +33 -28
  224. package/docs/classes/MatrixNTI2D.html +21 -16
  225. package/docs/classes/MaxHeap.html +33 -114
  226. package/docs/classes/MaxPriorityQueue.html +71 -61
  227. package/docs/classes/MinHeap.html +33 -114
  228. package/docs/classes/MinPriorityQueue.html +71 -61
  229. package/docs/classes/Navigator.html +28 -23
  230. package/docs/classes/ObjectDeque.html +66 -51
  231. package/docs/classes/{RBTree.html → Pair.html} +25 -20
  232. package/docs/classes/PriorityQueue.html +66 -56
  233. package/docs/classes/Queue.html +33 -28
  234. package/docs/classes/SegmentTree.html +129 -57
  235. package/docs/classes/SegmentTreeNode.html +62 -140
  236. package/docs/classes/SinglyLinkedList.html +53 -58
  237. package/docs/classes/SinglyLinkedListNode.html +25 -20
  238. package/docs/classes/SkipLinkedList.html +18 -13
  239. package/docs/classes/SplayTree.html +18 -13
  240. package/docs/classes/Stack.html +31 -26
  241. package/docs/classes/TreeMap.html +155 -0
  242. package/docs/classes/TreeMultiSet.html +541 -388
  243. package/docs/classes/TreeNode.html +125 -35
  244. package/docs/classes/TreeSet.html +155 -0
  245. package/docs/classes/Trie.html +30 -25
  246. package/docs/classes/TrieNode.html +33 -28
  247. package/docs/classes/TwoThreeTree.html +18 -13
  248. package/docs/classes/UndirectedEdge.html +87 -80
  249. package/docs/classes/UndirectedGraph.html +356 -178
  250. package/docs/classes/UndirectedVertex.html +63 -52
  251. package/docs/classes/Vector2D.html +45 -40
  252. package/docs/enums/CP.html +21 -16
  253. package/docs/enums/FamilyPosition.html +21 -16
  254. package/docs/enums/LoopType.html +20 -15
  255. package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +47 -44
  256. package/docs/index.html +203 -69
  257. package/docs/interfaces/{PriorityQueueOptions.html → IBinaryTree.html} +49 -40
  258. package/docs/interfaces/IBinaryTreeNode.html +383 -0
  259. package/docs/interfaces/IDirectedGraph.html +24 -19
  260. package/docs/interfaces/IGraph.html +122 -89
  261. package/docs/interfaces/{HeapOptions.html → IUNDirectedGraph.html} +26 -53
  262. package/docs/modules.html +33 -23
  263. package/docs/types/{ToThunkFn.html → AVLTreeDeleted.html} +31 -22
  264. package/docs/types/BSTComparator.html +18 -13
  265. package/docs/types/BSTDeletedResult.html +23 -18
  266. package/docs/types/BinaryTreeDeleted.html +23 -18
  267. package/docs/types/BinaryTreeNodeId.html +18 -13
  268. package/docs/types/BinaryTreeNodePropertyName.html +18 -13
  269. package/docs/types/DFSOrderPattern.html +18 -13
  270. package/docs/types/DijkstraResult.html +18 -13
  271. package/docs/types/Direction.html +18 -13
  272. package/docs/types/{DoublyLinkedListGetBy.html → EdgeId.html} +22 -17
  273. package/docs/types/{TrlFn.html → HeapOptions.html} +33 -20
  274. package/docs/types/{TrlAsyncFn.html → NavigatorParams.html} +46 -20
  275. package/docs/types/NodeOrPropertyName.html +18 -13
  276. package/docs/types/PriorityQueueComparator.html +18 -13
  277. package/docs/types/PriorityQueueDFSOrderPattern.html +18 -13
  278. package/docs/types/{SpecifyOptional.html → PriorityQueueOptions.html} +32 -20
  279. package/docs/types/RecursiveAVLTreeNode.html +135 -0
  280. package/docs/types/RecursiveBSTNode.html +135 -0
  281. package/docs/types/RecursiveBinaryTreeNode.html +135 -0
  282. package/docs/types/ResultByProperty.html +21 -16
  283. package/docs/types/ResultsByProperty.html +21 -16
  284. package/docs/types/SegmentTreeNodeVal.html +18 -13
  285. package/docs/types/TopologicalStatus.html +18 -13
  286. package/docs/types/TreeMultiSetDeletedResult.html +23 -18
  287. package/docs/types/Turning.html +18 -13
  288. package/docs/types/VertexId.html +18 -13
  289. package/notes/note.md +12 -1
  290. package/package.json +11 -3
  291. package/tsconfig.json +2 -2
  292. package/docs/interfaces/NavigatorParams.html +0 -197
  293. package/docs/types/Thunk.html +0 -133
@@ -5,17 +5,17 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult } from '../types';
8
+ import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult, RecursiveBSTNode } from '../types';
9
9
  import { BinaryTree, BinaryTreeNode, LoopType } from './binary-tree';
10
+ import { IBinaryTree, IBinaryTreeNode } from '../interfaces';
10
11
  export declare enum CP {
11
12
  lt = -1,
12
13
  eq = 0,
13
14
  gt = 1
14
15
  }
15
- export declare class BSTNode<T> extends BinaryTreeNode<T> {
16
- clone(): BSTNode<T>;
16
+ export declare class BSTNode<T, FAMILY extends BSTNode<T, FAMILY> = RecursiveBSTNode<T>> extends BinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
17
17
  }
18
- export declare class BST<T> extends BinaryTree<T> {
18
+ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BinaryTree<N> implements IBinaryTree<N> {
19
19
  /**
20
20
  * The constructor function accepts an optional options object and sets the comparator property if provided.
21
21
  * @param [options] - An optional object that can contain the following properties:
@@ -24,30 +24,30 @@ export declare class BST<T> extends BinaryTree<T> {
24
24
  comparator?: BSTComparator;
25
25
  loopType?: LoopType;
26
26
  });
27
- createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
27
+ _createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
28
28
  /**
29
29
  * The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
30
30
  * the ID matches, and returns the inserted node.
31
31
  * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
32
32
  * determine the position of the node in the binary search tree.
33
- * @param {T | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
34
- * be of type `T` (the generic type) or `null`.
33
+ * @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
34
+ * be of type `N` (the generic type) or `null`.
35
35
  * @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
36
36
  * the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
37
37
  * inserted once.
38
- * @returns The method `add` returns a `BSTNode<T>` object or `null`.
38
+ * @returns The method `add` returns a `N` object or `null`.
39
39
  */
40
- add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
40
+ add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
41
41
  /**
42
42
  * The `get` function returns the first node in a binary search tree that matches the given property value or name.
43
- * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
44
- * generic type `T`. It represents the value of the property that you want to search for in the binary search tree.
43
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
44
+ * generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
45
45
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
46
46
  * specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
47
47
  * `'id'`.
48
- * @returns The method is returning a BSTNode<T> object or null.
48
+ * @returns The method is returning a N object or null.
49
49
  */
50
- get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BSTNode<T> | null;
50
+ get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
51
51
  /**
52
52
  * The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
53
53
  * leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
@@ -65,23 +65,23 @@ export declare class BST<T> extends BinaryTree<T> {
65
65
  * @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
66
66
  * set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
67
67
  * set to false or not provided, the count of the node will be taken into account and the
68
- * @returns an array of `BSTDeletedResult<T>` objects.
68
+ * @returns an array of `BSTDeletedResult<N>` objects.
69
69
  */
70
- remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<T>[];
70
+ remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<N>[];
71
71
  /**
72
72
  * The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
73
73
  * option to specify the property name and whether to return only one node.
74
- * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
75
- * generic type `T`. It represents the property value that you want to search for in the binary search tree.
74
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
75
+ * generic type `N`. It represents the property value that you want to search for in the binary search tree.
76
76
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
77
77
  * specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
78
78
  * `'id'`.
79
79
  * @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
80
80
  * nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
81
81
  * to false or not provided, the function will return all nodes that match the given nodeProperty.
82
- * @returns an array of BSTNode<T> objects.
82
+ * @returns an array of N objects.
83
83
  */
84
- getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): BSTNode<T>[];
84
+ getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
85
85
  /**
86
86
  * The `lesserSum` function calculates the sum of a specified property in all nodes with an ID less than a given ID in
87
87
  * a binary search tree.
@@ -96,7 +96,7 @@ export declare class BST<T> extends BinaryTree<T> {
96
96
  /**
97
97
  * The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
98
98
  * that have a greater value than a given node.
99
- * @param node - The `node` parameter is of type `BSTNode<T>`, which represents a node in a binary search tree. It
99
+ * @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
100
100
  * contains properties such as `id` and `count`.
101
101
  * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
102
102
  * each node should be increased.
@@ -105,7 +105,7 @@ export declare class BST<T> extends BinaryTree<T> {
105
105
  * defaults to 'id'.
106
106
  * @returns a boolean value.
107
107
  */
108
- allGreaterNodesAdd(node: BSTNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
108
+ allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
109
109
  /**
110
110
  * The `balance` function takes a sorted array of nodes and builds a balanced binary search tree using either a
111
111
  * recursive or iterative approach.
@@ -38,15 +38,12 @@ var CP;
38
38
  CP[CP["lt"] = -1] = "lt";
39
39
  CP[CP["eq"] = 0] = "eq";
40
40
  CP[CP["gt"] = 1] = "gt";
41
- })(CP = exports.CP || (exports.CP = {}));
41
+ })(CP || (exports.CP = CP = {}));
42
42
  var BSTNode = /** @class */ (function (_super) {
43
43
  __extends(BSTNode, _super);
44
44
  function BSTNode() {
45
45
  return _super !== null && _super.apply(this, arguments) || this;
46
46
  }
47
- BSTNode.prototype.clone = function () {
48
- return new BSTNode(this.id, this.val, this.count);
49
- };
50
47
  return BSTNode;
51
48
  }(binary_tree_1.BinaryTreeNode));
52
49
  exports.BSTNode = BSTNode;
@@ -67,30 +64,30 @@ var BST = /** @class */ (function (_super) {
67
64
  }
68
65
  return _this;
69
66
  }
70
- BST.prototype.createNode = function (id, val, count) {
71
- return val !== null ? new BSTNode(id, val, count) : null;
67
+ BST.prototype._createNode = function (id, val, count) {
68
+ var node = val !== null ? new BSTNode(id, val, count) : null;
69
+ return node;
72
70
  };
73
71
  /**
74
72
  * The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
75
73
  * the ID matches, and returns the inserted node.
76
74
  * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
77
75
  * determine the position of the node in the binary search tree.
78
- * @param {T | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
79
- * be of type `T` (the generic type) or `null`.
76
+ * @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
77
+ * be of type `N` (the generic type) or `null`.
80
78
  * @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
81
79
  * the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
82
80
  * inserted once.
83
- * @returns The method `add` returns a `BSTNode<T>` object or `null`.
81
+ * @returns The method `add` returns a `N` object or `null`.
84
82
  */
85
83
  BST.prototype.add = function (id, val, count) {
86
- var _a;
87
84
  if (count === void 0) { count = 1; }
88
85
  var inserted = null;
89
- var newNode = this.createNode(id, val, count);
86
+ var newNode = this._createNode(id, val, count);
90
87
  if (this.root === null) {
91
- this.root = newNode;
92
- this.size++;
93
- this.count += (_a = newNode === null || newNode === void 0 ? void 0 : newNode.count) !== null && _a !== void 0 ? _a : 1;
88
+ this._setRoot(newNode);
89
+ this._setSize(this.size + 1);
90
+ this._setCount(this.count + count);
94
91
  inserted = (this.root);
95
92
  }
96
93
  else {
@@ -101,7 +98,7 @@ var BST = /** @class */ (function (_super) {
101
98
  if (this._compare(cur.id, id) === CP.eq) {
102
99
  if (newNode) {
103
100
  cur.count += newNode.count;
104
- this.count += newNode.count;
101
+ this._setCount(this.count + newNode.count);
105
102
  cur.val = newNode.val;
106
103
  }
107
104
  //Duplicates are not accepted.
@@ -117,8 +114,8 @@ var BST = /** @class */ (function (_super) {
117
114
  }
118
115
  //Add to the left of the current node
119
116
  cur.left = newNode;
120
- this.size++;
121
- this.count += newNode.count;
117
+ this._setSize(this.size + 1);
118
+ this._setCount(this.count + newNode.count);
122
119
  traversing = false;
123
120
  inserted = cur.left;
124
121
  }
@@ -137,8 +134,8 @@ var BST = /** @class */ (function (_super) {
137
134
  }
138
135
  //Add to the right of the current node
139
136
  cur.right = newNode;
140
- this.size++;
141
- this.count += newNode.count;
137
+ this._setSize(this.size + 1);
138
+ this._setCount(this.count + newNode.count);
142
139
  traversing = false;
143
140
  inserted = (cur.right);
144
141
  }
@@ -158,12 +155,12 @@ var BST = /** @class */ (function (_super) {
158
155
  };
159
156
  /**
160
157
  * The `get` function returns the first node in a binary search tree that matches the given property value or name.
161
- * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
162
- * generic type `T`. It represents the value of the property that you want to search for in the binary search tree.
158
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
159
+ * generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
163
160
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
164
161
  * specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
165
162
  * `'id'`.
166
- * @returns The method is returning a BSTNode<T> object or null.
163
+ * @returns The method is returning a N object or null.
167
164
  */
168
165
  BST.prototype.get = function (nodeProperty, propertyName) {
169
166
  var _a;
@@ -195,7 +192,7 @@ var BST = /** @class */ (function (_super) {
195
192
  * @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
196
193
  * set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
197
194
  * set to false or not provided, the count of the node will be taken into account and the
198
- * @returns an array of `BSTDeletedResult<T>` objects.
195
+ * @returns an array of `BSTDeletedResult<N>` objects.
199
196
  */
200
197
  BST.prototype.remove = function (id, ignoreCount) {
201
198
  var bstDeletedResult = [];
@@ -208,13 +205,13 @@ var BST = /** @class */ (function (_super) {
208
205
  var needBalanced = null, orgCurrent = curr;
209
206
  if (curr.count > 1 && !ignoreCount) {
210
207
  curr.count--;
211
- this.count--;
208
+ this._setCount(this.count - 1);
212
209
  }
213
210
  else {
214
211
  if (!curr.left) {
215
212
  if (!parent) {
216
213
  if (curr.right !== undefined)
217
- this.root = curr.right;
214
+ this._setRoot(curr.right);
218
215
  }
219
216
  else {
220
217
  switch (curr.familyPosition) {
@@ -242,8 +239,8 @@ var BST = /** @class */ (function (_super) {
242
239
  }
243
240
  }
244
241
  }
245
- this.size--;
246
- this.count -= curr.count;
242
+ this._setSize(this.size - 1);
243
+ this._setCount(this.count - curr.count);
247
244
  }
248
245
  bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
249
246
  return bstDeletedResult;
@@ -251,15 +248,15 @@ var BST = /** @class */ (function (_super) {
251
248
  /**
252
249
  * The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
253
250
  * option to specify the property name and whether to return only one node.
254
- * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
255
- * generic type `T`. It represents the property value that you want to search for in the binary search tree.
251
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
252
+ * generic type `N`. It represents the property value that you want to search for in the binary search tree.
256
253
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
257
254
  * specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
258
255
  * `'id'`.
259
256
  * @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
260
257
  * nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
261
258
  * to false or not provided, the function will return all nodes that match the given nodeProperty.
262
- * @returns an array of BSTNode<T> objects.
259
+ * @returns an array of N objects.
263
260
  */
264
261
  BST.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
265
262
  var _this = this;
@@ -267,7 +264,7 @@ var BST = /** @class */ (function (_super) {
267
264
  if (!this.root)
268
265
  return [];
269
266
  var result = [];
270
- if (this._loopType === binary_tree_1.LoopType.recursive) {
267
+ if (this.loopType === binary_tree_1.LoopType.recursive) {
271
268
  var _traverse_1 = function (cur) {
272
269
  if (_this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
273
270
  return;
@@ -340,7 +337,7 @@ var BST = /** @class */ (function (_super) {
340
337
  return needSum;
341
338
  };
342
339
  var sum = 0;
343
- if (this._loopType === binary_tree_1.LoopType.recursive) {
340
+ if (this.loopType === binary_tree_1.LoopType.recursive) {
344
341
  var _traverse_2 = function (cur) {
345
342
  var compared = _this._compare(cur.id, id);
346
343
  if (compared === CP.eq) {
@@ -400,7 +397,7 @@ var BST = /** @class */ (function (_super) {
400
397
  /**
401
398
  * The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
402
399
  * that have a greater value than a given node.
403
- * @param node - The `node` parameter is of type `BSTNode<T>`, which represents a node in a binary search tree. It
400
+ * @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
404
401
  * contains properties such as `id` and `count`.
405
402
  * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
406
403
  * each node should be increased.
@@ -427,7 +424,7 @@ var BST = /** @class */ (function (_super) {
427
424
  break;
428
425
  }
429
426
  };
430
- if (this._loopType === binary_tree_1.LoopType.recursive) {
427
+ if (this.loopType === binary_tree_1.LoopType.recursive) {
431
428
  var _traverse_3 = function (cur) {
432
429
  var compared = _this._compare(cur.id, node.id);
433
430
  _sumByPropertyName(cur);
@@ -468,7 +465,7 @@ var BST = /** @class */ (function (_super) {
468
465
  this.clear();
469
466
  if (sorted.length < 1)
470
467
  return false;
471
- if (this._loopType === binary_tree_1.LoopType.recursive) {
468
+ if (this.loopType === binary_tree_1.LoopType.recursive) {
472
469
  var buildBalanceBST_1 = function (l, r) {
473
470
  if (l > r)
474
471
  return;
@@ -509,7 +506,7 @@ var BST = /** @class */ (function (_super) {
509
506
  if (!this.root)
510
507
  return true;
511
508
  var balanced = true;
512
- if (this._loopType === binary_tree_1.LoopType.recursive) {
509
+ if (this.loopType === binary_tree_1.LoopType.recursive) {
513
510
  var _height_1 = function (cur) {
514
511
  if (!cur)
515
512
  return 0;
@@ -1,2 +1 @@
1
- export declare class RBTree {
2
- }
1
+ export {};
@@ -1,9 +1,72 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RBTree = void 0;
4
- var RBTree = /** @class */ (function () {
5
- function RBTree() {
18
+ var binary_tree_1 = require("./binary-tree");
19
+ var RBColor;
20
+ (function (RBColor) {
21
+ RBColor[RBColor["Red"] = 0] = "Red";
22
+ RBColor[RBColor["Black"] = 1] = "Black";
23
+ })(RBColor || (RBColor = {}));
24
+ var RBNode = /** @class */ (function (_super) {
25
+ __extends(RBNode, _super);
26
+ // override createNode(id: BinaryTreeNodeId, val: T | null, count?: number): RBNode<T> | null {
27
+ // return val !== null ? new RBNode<T>(id, val, count) : null;
28
+ // }
29
+ function RBNode(id, val, count) {
30
+ var _this = _super.call(this, id, val, count) || this;
31
+ _this._color = RBColor.Red;
32
+ return _this;
6
33
  }
34
+ Object.defineProperty(RBNode.prototype, "color", {
35
+ get: function () {
36
+ return this._color;
37
+ },
38
+ set: function (value) {
39
+ this._color = value;
40
+ },
41
+ enumerable: false,
42
+ configurable: true
43
+ });
44
+ return RBNode;
45
+ }(binary_tree_1.BinaryTreeNode));
46
+ var RBTree = /** @class */ (function (_super) {
47
+ __extends(RBTree, _super);
48
+ function RBTree(options) {
49
+ return _super.call(this, options) || this;
50
+ }
51
+ // override _createNode(id: BinaryTreeNodeId, val: N | null, count?: number): RBNode<N> | null {
52
+ // return val !== null ? new RBNode<N>(id, val, count) : null;
53
+ // }
54
+ // private override _root: BinaryTreeNode<N> | null = null;
55
+ //
56
+ // override get root(): BinaryTreeNode<N> | null {
57
+ // return this._root;
58
+ // }
59
+ RBTree.prototype.insert = function (id, val) {
60
+ };
61
+ RBTree.prototype.leftRotate = function (node) {
62
+ };
63
+ RBTree.prototype.rightRotate = function (node) {
64
+ };
65
+ RBTree.prototype.insertFixup = function (node) {
66
+ };
67
+ RBTree.prototype.deleteFixup = function (node) {
68
+ };
69
+ RBTree.prototype.transplant = function (u, v) {
70
+ };
7
71
  return RBTree;
8
- }());
9
- exports.RBTree = RBTree;
72
+ }(binary_tree_1.BinaryTree));
@@ -8,53 +8,26 @@
8
8
  import type { SegmentTreeNodeVal } from '../types';
9
9
  export declare class SegmentTreeNode {
10
10
  constructor(start: number, end: number, sum: number, val?: SegmentTreeNodeVal | null);
11
- protected _start: number;
11
+ private _start;
12
12
  get start(): number;
13
13
  set start(v: number);
14
- protected _end: number;
14
+ private _end;
15
15
  get end(): number;
16
16
  set end(v: number);
17
- protected _val: SegmentTreeNodeVal | null;
17
+ private _val;
18
18
  get val(): SegmentTreeNodeVal | null;
19
19
  set val(v: SegmentTreeNodeVal | null);
20
- protected _sum: number;
20
+ private _sum;
21
21
  get sum(): number;
22
22
  set sum(v: number);
23
- protected _left: SegmentTreeNode | null;
23
+ private _left;
24
24
  get left(): SegmentTreeNode | null;
25
25
  set left(v: SegmentTreeNode | null);
26
- protected _right: SegmentTreeNode | null;
26
+ private _right;
27
27
  get right(): SegmentTreeNode | null;
28
28
  set right(v: SegmentTreeNode | null);
29
- /**
30
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
31
- */
32
- getStart(): number;
33
- /**
34
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
35
- */
36
- getEnd(): number;
37
- /**
38
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
39
- */
40
- getVal(): SegmentTreeNodeVal | null;
41
- /**
42
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
43
- */
44
- getSum(): number;
45
- /**
46
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
47
- */
48
- getLeft(): SegmentTreeNode | null;
49
- /**
50
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
51
- */
52
- getRight(): SegmentTreeNode | null;
53
29
  }
54
30
  export declare class SegmentTree {
55
- protected _values: number[];
56
- protected _start: number;
57
- protected _end: number;
58
31
  /**
59
32
  * The constructor initializes the values, start, end, and root properties of an object.
60
33
  * @param {number[]} values - An array of numbers that will be used to build a binary search tree.
@@ -65,13 +38,14 @@ export declare class SegmentTree {
65
38
  * included in the range. If not provided, it defaults to the index of the last element in the "values" array.
66
39
  */
67
40
  constructor(values: number[], start?: number, end?: number);
68
- protected _root: SegmentTreeNode | null;
41
+ private _values;
42
+ get values(): number[];
43
+ private _start;
44
+ get start(): number;
45
+ private _end;
46
+ get end(): number;
47
+ private _root;
69
48
  get root(): SegmentTreeNode | null;
70
- set root(v: SegmentTreeNode | null);
71
- /**
72
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
73
- */
74
- getRoot(): SegmentTreeNode | null;
75
49
  /**
76
50
  * The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
77
51
  * for each segment.
@@ -102,4 +76,8 @@ export declare class SegmentTree {
102
76
  * @returns The function `querySumByRange` returns a number.
103
77
  */
104
78
  querySumByRange(indexA: number, indexB: number): number;
79
+ protected _setValues(value: number[]): void;
80
+ protected _setStart(value: number): void;
81
+ protected _setEnd(value: number): void;
82
+ protected _setRoot(v: SegmentTreeNode | null): void;
105
83
  }
@@ -81,42 +81,6 @@ var SegmentTreeNode = /** @class */ (function () {
81
81
  enumerable: false,
82
82
  configurable: true
83
83
  });
84
- /**
85
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
86
- */
87
- SegmentTreeNode.prototype.getStart = function () {
88
- return this._start;
89
- };
90
- /**
91
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
92
- */
93
- SegmentTreeNode.prototype.getEnd = function () {
94
- return this._end;
95
- };
96
- /**
97
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
98
- */
99
- SegmentTreeNode.prototype.getVal = function () {
100
- return this._val;
101
- };
102
- /**
103
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
104
- */
105
- SegmentTreeNode.prototype.getSum = function () {
106
- return this._sum;
107
- };
108
- /**
109
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
110
- */
111
- SegmentTreeNode.prototype.getLeft = function () {
112
- return this._left;
113
- };
114
- /**
115
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
116
- */
117
- SegmentTreeNode.prototype.getRight = function () {
118
- return this._right;
119
- };
120
84
  return SegmentTreeNode;
121
85
  }());
122
86
  exports.SegmentTreeNode = SegmentTreeNode;
@@ -140,22 +104,34 @@ var SegmentTree = /** @class */ (function () {
140
104
  this._end = end;
141
105
  this._root = this.build(start, end);
142
106
  }
107
+ Object.defineProperty(SegmentTree.prototype, "values", {
108
+ get: function () {
109
+ return this._values;
110
+ },
111
+ enumerable: false,
112
+ configurable: true
113
+ });
114
+ Object.defineProperty(SegmentTree.prototype, "start", {
115
+ get: function () {
116
+ return this._start;
117
+ },
118
+ enumerable: false,
119
+ configurable: true
120
+ });
121
+ Object.defineProperty(SegmentTree.prototype, "end", {
122
+ get: function () {
123
+ return this._end;
124
+ },
125
+ enumerable: false,
126
+ configurable: true
127
+ });
143
128
  Object.defineProperty(SegmentTree.prototype, "root", {
144
129
  get: function () {
145
130
  return this._root;
146
131
  },
147
- set: function (v) {
148
- this._root = v;
149
- },
150
132
  enumerable: false,
151
133
  configurable: true
152
134
  });
153
- /**
154
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
155
- */
156
- SegmentTree.prototype.getRoot = function () {
157
- return this._root;
158
- };
159
135
  /**
160
136
  * The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
161
137
  * for each segment.
@@ -166,9 +142,8 @@ var SegmentTree = /** @class */ (function () {
166
142
  * @returns a SegmentTreeNode object.
167
143
  */
168
144
  SegmentTree.prototype.build = function (start, end) {
169
- if (start === end) {
145
+ if (start === end)
170
146
  return new SegmentTreeNode(start, end, this._values[start]);
171
- }
172
147
  var mid = start + Math.floor((end - start) / 2);
173
148
  var left = this.build(start, mid);
174
149
  var right = this.build(mid + 1, end);
@@ -264,6 +239,18 @@ var SegmentTree = /** @class */ (function () {
264
239
  };
265
240
  return dfs(root, indexA, indexB);
266
241
  };
242
+ SegmentTree.prototype._setValues = function (value) {
243
+ this._values = value;
244
+ };
245
+ SegmentTree.prototype._setStart = function (value) {
246
+ this._start = value;
247
+ };
248
+ SegmentTree.prototype._setEnd = function (value) {
249
+ this._end = value;
250
+ };
251
+ SegmentTree.prototype._setRoot = function (v) {
252
+ this._root = v;
253
+ };
267
254
  return SegmentTree;
268
255
  }());
269
256
  exports.SegmentTree = SegmentTree;
@@ -7,27 +7,28 @@
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
9
  import type { BinaryTreeNodeId, TreeMultiSetDeletedResult } from '../types';
10
- export declare class TreeMultiSet<T> extends BST<T> {
10
+ import { IBinaryTree } from '../interfaces';
11
+ export declare class TreeMultiSet<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BST<N> implements IBinaryTree<N> {
11
12
  /**
12
13
  * The function creates a new BSTNode with the given id, value, and count.
13
14
  * @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
14
15
  * distinguish one node from another in the tree.
15
- * @param {T} val - The `val` parameter represents the value that will be stored in the binary search tree node.
16
+ * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.
16
17
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
17
18
  * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
18
19
  * @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
19
20
  */
20
- createNode(id: BinaryTreeNodeId, val: T, count?: number): BSTNode<T>;
21
+ _createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N;
21
22
  /**
22
23
  * The function overrides the add method of the BinarySearchTree class in TypeScript.
23
24
  * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
24
- * @param {T | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
25
- * can be of type `T` (the generic type) or `null`.
25
+ * @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
26
+ * can be of type `N` (the generic type) or `null`.
26
27
  * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
27
28
  * of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
28
- * @returns The `add` method is returning a `BSTNode<T>` object or `null`.
29
+ * @returns The `add` method is returning a `BSTNode<N>` object or `null`.
29
30
  */
30
- add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
31
+ add(id: BinaryTreeNodeId, val: N | null, count?: number): N | null;
31
32
  /**
32
33
  * The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
33
34
  * method.
@@ -38,5 +39,5 @@ export declare class TreeMultiSet<T> extends BST<T> {
38
39
  * set to `true`, the left sum of all nodes will be recalculated. If it
39
40
  * @returns The method is returning an array of TreeMultiSetDeletedResult objects.
40
41
  */
41
- remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<T>[];
42
+ remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<N>[];
42
43
  }