data-structure-typed 1.18.0 → 1.18.6

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 (290) 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/abstract-binary-tree.d.ts +333 -0
  107. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1455 -0
  108. package/dist/data-structures/binary-tree/avl-tree.d.ts +20 -25
  109. package/dist/data-structures/binary-tree/avl-tree.js +10 -18
  110. package/dist/data-structures/binary-tree/binary-tree.d.ts +18 -345
  111. package/dist/data-structures/binary-tree/binary-tree.js +39 -1444
  112. package/dist/data-structures/binary-tree/bst.d.ts +24 -31
  113. package/dist/data-structures/binary-tree/bst.js +46 -53
  114. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  115. package/dist/data-structures/binary-tree/index.js +1 -0
  116. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
  117. package/dist/data-structures/binary-tree/rb-tree.js +64 -5
  118. package/dist/data-structures/binary-tree/tree-multiset.d.ts +11 -25
  119. package/dist/data-structures/binary-tree/tree-multiset.js +29 -31
  120. package/dist/data-structures/graph/abstract-graph.d.ts +56 -58
  121. package/dist/data-structures/graph/abstract-graph.js +84 -68
  122. package/dist/data-structures/graph/directed-graph.d.ts +124 -95
  123. package/dist/data-structures/graph/directed-graph.js +156 -108
  124. package/dist/data-structures/graph/undirected-graph.d.ts +83 -58
  125. package/dist/data-structures/graph/undirected-graph.js +98 -71
  126. package/dist/data-structures/hash/coordinate-set.d.ts +1 -1
  127. package/dist/data-structures/index.d.ts +1 -0
  128. package/dist/data-structures/index.js +1 -0
  129. package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
  130. package/dist/data-structures/interfaces/abstract-graph.js +2 -0
  131. package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
  132. package/dist/data-structures/interfaces/avl-tree.js +2 -0
  133. package/dist/data-structures/interfaces/binary-tree.d.ts +26 -0
  134. package/dist/data-structures/interfaces/binary-tree.js +2 -0
  135. package/dist/data-structures/interfaces/bst.d.ts +1 -0
  136. package/dist/data-structures/interfaces/bst.js +2 -0
  137. package/dist/data-structures/interfaces/directed-graph.d.ts +9 -0
  138. package/dist/data-structures/interfaces/directed-graph.js +2 -0
  139. package/dist/data-structures/interfaces/doubly-linked-list.d.ts +1 -0
  140. package/dist/data-structures/interfaces/doubly-linked-list.js +2 -0
  141. package/dist/data-structures/interfaces/heap.d.ts +1 -0
  142. package/dist/data-structures/interfaces/heap.js +2 -0
  143. package/dist/data-structures/interfaces/index.d.ts +13 -0
  144. package/dist/data-structures/interfaces/index.js +29 -0
  145. package/dist/data-structures/interfaces/navigator.d.ts +1 -0
  146. package/dist/data-structures/interfaces/navigator.js +2 -0
  147. package/dist/data-structures/interfaces/priority-queue.d.ts +1 -0
  148. package/dist/data-structures/interfaces/priority-queue.js +2 -0
  149. package/dist/data-structures/interfaces/segment-tree.d.ts +1 -0
  150. package/dist/data-structures/interfaces/segment-tree.js +2 -0
  151. package/dist/data-structures/interfaces/singly-linked-list.d.ts +1 -0
  152. package/dist/data-structures/interfaces/singly-linked-list.js +2 -0
  153. package/dist/data-structures/interfaces/tree-multiset.d.ts +1 -0
  154. package/dist/data-structures/interfaces/tree-multiset.js +2 -0
  155. package/dist/data-structures/interfaces/undirected-graph.d.ts +2 -0
  156. package/dist/data-structures/interfaces/undirected-graph.js +2 -0
  157. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  158. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  159. package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
  160. package/dist/data-structures/priority-queue/priority-queue.js +4 -4
  161. package/dist/data-structures/queue/deque.d.ts +5 -5
  162. package/dist/data-structures/queue/deque.js +6 -6
  163. package/dist/data-structures/queue/queue.d.ts +1 -1
  164. package/dist/data-structures/stack/stack.d.ts +1 -1
  165. package/dist/data-structures/types/abstract-binary-tree.d.ts +32 -0
  166. package/dist/data-structures/types/abstract-binary-tree.js +21 -0
  167. package/dist/data-structures/types/abstract-graph.d.ts +1 -20
  168. package/dist/data-structures/types/avl-tree.d.ts +3 -4
  169. package/dist/data-structures/types/binary-tree.d.ts +3 -10
  170. package/dist/data-structures/types/bst.d.ts +10 -4
  171. package/dist/data-structures/types/bst.js +7 -0
  172. package/dist/data-structures/types/directed-graph.d.ts +5 -9
  173. package/dist/data-structures/types/directed-graph.js +7 -0
  174. package/dist/data-structures/types/heap.d.ts +2 -2
  175. package/dist/data-structures/types/helpers.d.ts +8 -0
  176. package/dist/data-structures/types/helpers.js +2 -0
  177. package/dist/data-structures/types/index.d.ts +3 -1
  178. package/dist/data-structures/types/index.js +3 -1
  179. package/dist/data-structures/types/navigator.d.ts +2 -2
  180. package/dist/data-structures/types/priority-queue.d.ts +2 -2
  181. package/dist/data-structures/types/rb-tree.d.ts +6 -0
  182. package/dist/data-structures/types/rb-tree.js +8 -0
  183. package/dist/data-structures/types/tree-multiset.d.ts +5 -4
  184. package/docs/assets/search.js +1 -1
  185. package/docs/classes/AVLTree.html +310 -309
  186. package/docs/classes/AVLTreeNode.html +122 -68
  187. package/docs/classes/AaTree.html +30 -17
  188. package/docs/classes/AbstractBinaryTree.html +2023 -0
  189. package/docs/classes/AbstractBinaryTreeNode.html +491 -0
  190. package/docs/classes/AbstractEdge.html +84 -39
  191. package/docs/classes/AbstractGraph.html +235 -119
  192. package/docs/classes/AbstractVertex.html +87 -35
  193. package/docs/classes/ArrayDeque.html +43 -30
  194. package/docs/classes/BST.html +297 -285
  195. package/docs/classes/BSTNode.html +123 -62
  196. package/docs/classes/BTree.html +30 -17
  197. package/docs/classes/BinaryIndexedTree.html +38 -25
  198. package/docs/classes/BinaryTree.html +596 -589
  199. package/docs/classes/BinaryTreeNode.html +181 -161
  200. package/docs/classes/Character.html +33 -20
  201. package/docs/classes/CoordinateMap.html +38 -25
  202. package/docs/classes/CoordinateSet.html +39 -26
  203. package/docs/classes/Deque.html +63 -50
  204. package/docs/classes/DirectedEdge.html +90 -46
  205. package/docs/classes/DirectedGraph.html +374 -212
  206. package/docs/classes/DirectedVertex.html +79 -41
  207. package/docs/classes/DoublyLinkedList.html +68 -55
  208. package/docs/classes/DoublyLinkedListNode.html +40 -27
  209. package/docs/classes/HashTable.html +30 -17
  210. package/docs/classes/Heap.html +45 -32
  211. package/docs/classes/HeapItem.html +37 -24
  212. package/docs/classes/Matrix2D.html +45 -32
  213. package/docs/classes/MatrixNTI2D.html +33 -20
  214. package/docs/classes/MaxHeap.html +45 -32
  215. package/docs/classes/MaxPriorityQueue.html +83 -65
  216. package/docs/classes/MinHeap.html +45 -32
  217. package/docs/classes/MinPriorityQueue.html +83 -65
  218. package/docs/classes/Navigator.html +40 -27
  219. package/docs/classes/ObjectDeque.html +78 -55
  220. package/docs/classes/Pair.html +30 -17
  221. package/docs/classes/PriorityQueue.html +78 -60
  222. package/docs/classes/Queue.html +45 -32
  223. package/docs/classes/SegmentTree.html +46 -33
  224. package/docs/classes/SegmentTreeNode.html +49 -36
  225. package/docs/classes/SinglyLinkedList.html +65 -52
  226. package/docs/classes/SinglyLinkedListNode.html +37 -24
  227. package/docs/classes/SkipLinkedList.html +30 -17
  228. package/docs/classes/SplayTree.html +30 -17
  229. package/docs/classes/Stack.html +43 -30
  230. package/docs/classes/TreeMap.html +30 -17
  231. package/docs/classes/TreeMultiSet.html +330 -316
  232. package/docs/classes/TreeMultiSetNode.html +450 -0
  233. package/docs/classes/TreeNode.html +45 -32
  234. package/docs/classes/TreeSet.html +30 -17
  235. package/docs/classes/Trie.html +42 -29
  236. package/docs/classes/TrieNode.html +40 -27
  237. package/docs/classes/TwoThreeTree.html +30 -17
  238. package/docs/classes/UndirectedEdge.html +86 -56
  239. package/docs/classes/UndirectedGraph.html +286 -165
  240. package/docs/classes/UndirectedVertex.html +79 -41
  241. package/docs/classes/Vector2D.html +57 -44
  242. package/docs/enums/CP.html +36 -23
  243. package/docs/enums/FamilyPosition.html +48 -35
  244. package/docs/enums/LoopType.html +42 -29
  245. package/docs/{interfaces/PriorityQueueOptions.html → enums/RBColor.html} +52 -55
  246. package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +59 -48
  247. package/docs/index.html +211 -73
  248. package/docs/interfaces/{NavigatorParams.html → IBinaryTree.html} +56 -67
  249. package/docs/interfaces/IBinaryTreeNode.html +396 -0
  250. package/docs/interfaces/IDirectedGraph.html +36 -23
  251. package/docs/interfaces/IGraph.html +134 -93
  252. package/docs/interfaces/{HeapOptions.html → IUNDirectedGraph.html} +38 -57
  253. package/docs/modules.html +57 -31
  254. package/docs/types/{ToThunkFn.html → AVLTreeOptions.html} +35 -27
  255. package/docs/types/AbstractBinaryTreeOptions.html +150 -0
  256. package/docs/types/AbstractRecursiveBinaryTreeNode.html +146 -0
  257. package/docs/types/{ResultsByProperty.html → AbstractResultByProperty.html} +35 -22
  258. package/docs/types/{TreeMultiSetDeletedResult.html → AbstractResultsByProperty.html} +35 -29
  259. package/docs/types/BSTComparator.html +30 -17
  260. package/docs/types/{TrlAsyncFn.html → BSTOptions.html} +36 -31
  261. package/docs/types/BinaryTreeDeletedResult.html +153 -0
  262. package/docs/types/BinaryTreeNodeId.html +30 -17
  263. package/docs/types/BinaryTreeNodePropertyName.html +30 -17
  264. package/docs/types/{BinaryTreeDeleted.html → BinaryTreeOptions.html} +35 -31
  265. package/docs/types/DFSOrderPattern.html +30 -17
  266. package/docs/types/DijkstraResult.html +30 -17
  267. package/docs/types/Direction.html +30 -17
  268. package/docs/types/{SpecifyOptional.html → EdgeId.html} +34 -28
  269. package/docs/types/{TrlFn.html → HeapOptions.html} +45 -24
  270. package/docs/types/IdObject.html +151 -0
  271. package/docs/types/{BSTDeletedResult.html → KeyValObject.html} +36 -30
  272. package/docs/types/NavigatorParams.html +175 -0
  273. package/docs/types/NodeOrPropertyName.html +30 -17
  274. package/docs/types/PriorityQueueComparator.html +30 -17
  275. package/docs/types/PriorityQueueDFSOrderPattern.html +30 -17
  276. package/docs/types/PriorityQueueOptions.html +155 -0
  277. package/docs/types/{Thunk.html → RBTreeOptions.html} +35 -27
  278. package/docs/types/RecursiveAVLTreeNode.html +146 -0
  279. package/docs/types/RecursiveBSTNode.html +146 -0
  280. package/docs/types/RecursiveBinaryTreeNode.html +146 -0
  281. package/docs/types/RecursiveTreeMultiSetNode.html +146 -0
  282. package/docs/types/SegmentTreeNodeVal.html +30 -17
  283. package/docs/types/TopologicalStatus.html +30 -17
  284. package/docs/types/TreeMultiSetOptions.html +146 -0
  285. package/docs/types/Turning.html +30 -17
  286. package/docs/types/VertexId.html +30 -17
  287. package/notes/note.md +8 -1
  288. package/package.json +10 -2
  289. package/docs/classes/RBTree.html +0 -153
  290. package/docs/types/ResultByProperty.html +0 -133
@@ -5,49 +5,42 @@
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';
9
- import { BinaryTree, BinaryTreeNode, LoopType } from './binary-tree';
10
- export declare enum CP {
11
- lt = -1,
12
- eq = 0,
13
- gt = 1
8
+ import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, RecursiveBSTNode } from '../types';
9
+ import { BinaryTreeDeletedResult, BSTOptions, CP } from '../types';
10
+ import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
+ import { IBinaryTree, IBinaryTreeNode } from '../interfaces';
12
+ export declare class BSTNode<T, FAMILY extends BSTNode<T, FAMILY> = RecursiveBSTNode<T>> extends BinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
14
13
  }
15
- export declare class BSTNode<T> extends BinaryTreeNode<T> {
16
- clone(): BSTNode<T>;
17
- }
18
- export declare class BST<T> extends BinaryTree<T> {
14
+ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BinaryTree<N> implements IBinaryTree<N> {
19
15
  /**
20
16
  * The constructor function accepts an optional options object and sets the comparator property if provided.
21
17
  * @param [options] - An optional object that can contain the following properties:
22
18
  */
23
- constructor(options?: {
24
- comparator?: BSTComparator;
25
- loopType?: LoopType;
26
- });
27
- createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
19
+ constructor(options?: BSTOptions);
20
+ _createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
28
21
  /**
29
22
  * The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
30
23
  * the ID matches, and returns the inserted node.
31
24
  * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
32
25
  * 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`.
26
+ * @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
27
+ * be of type `N` (the generic type) or `null`.
35
28
  * @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
36
29
  * the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
37
30
  * inserted once.
38
- * @returns The method `add` returns a `BSTNode<T>` object or `null`.
31
+ * @returns The method `add` returns a `N` object or `null`.
39
32
  */
40
- add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
33
+ add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
41
34
  /**
42
35
  * 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.
36
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
37
+ * generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
45
38
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
46
39
  * specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
47
40
  * `'id'`.
48
- * @returns The method is returning a BSTNode<T> object or null.
41
+ * @returns The method is returning a N object or null.
49
42
  */
50
- get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BSTNode<T> | null;
43
+ get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
51
44
  /**
52
45
  * The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
53
46
  * leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
@@ -65,23 +58,23 @@ export declare class BST<T> extends BinaryTree<T> {
65
58
  * @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
66
59
  * set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
67
60
  * 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.
61
+ * @returns an array of `BSTDeletedResult<N>` objects.
69
62
  */
70
- remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<T>[];
63
+ remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
71
64
  /**
72
65
  * The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
73
66
  * 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.
67
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
68
+ * generic type `N`. It represents the property value that you want to search for in the binary search tree.
76
69
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
77
70
  * specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
78
71
  * `'id'`.
79
72
  * @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
80
73
  * nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
81
74
  * to false or not provided, the function will return all nodes that match the given nodeProperty.
82
- * @returns an array of BSTNode<T> objects.
75
+ * @returns an array of N objects.
83
76
  */
84
- getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): BSTNode<T>[];
77
+ getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
85
78
  /**
86
79
  * The `lesserSum` function calculates the sum of a specified property in all nodes with an ID less than a given ID in
87
80
  * a binary search tree.
@@ -96,7 +89,7 @@ export declare class BST<T> extends BinaryTree<T> {
96
89
  /**
97
90
  * The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
98
91
  * 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
92
+ * @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
100
93
  * contains properties such as `id` and `count`.
101
94
  * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
102
95
  * each node should be increased.
@@ -105,7 +98,7 @@ export declare class BST<T> extends BinaryTree<T> {
105
98
  * defaults to 'id'.
106
99
  * @returns a boolean value.
107
100
  */
108
- allGreaterNodesAdd(node: BSTNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
101
+ allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
109
102
  /**
110
103
  * The `balance` function takes a sorted array of nodes and builds a balanced binary search tree using either a
111
104
  * recursive or iterative approach.
@@ -31,22 +31,14 @@ var __read = (this && this.__read) || function (o, n) {
31
31
  return ar;
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.BST = exports.BSTNode = exports.CP = void 0;
34
+ exports.BST = exports.BSTNode = void 0;
35
+ var types_1 = require("../types");
35
36
  var binary_tree_1 = require("./binary-tree");
36
- var CP;
37
- (function (CP) {
38
- CP[CP["lt"] = -1] = "lt";
39
- CP[CP["eq"] = 0] = "eq";
40
- CP[CP["gt"] = 1] = "gt";
41
- })(CP || (exports.CP = CP = {}));
42
37
  var BSTNode = /** @class */ (function (_super) {
43
38
  __extends(BSTNode, _super);
44
39
  function BSTNode() {
45
40
  return _super !== null && _super.apply(this, arguments) || this;
46
41
  }
47
- BSTNode.prototype.clone = function () {
48
- return new BSTNode(this.id, this.val, this.count);
49
- };
50
42
  return BSTNode;
51
43
  }(binary_tree_1.BinaryTreeNode));
52
44
  exports.BSTNode = BSTNode;
@@ -67,25 +59,26 @@ var BST = /** @class */ (function (_super) {
67
59
  }
68
60
  return _this;
69
61
  }
70
- BST.prototype.createNode = function (id, val, count) {
71
- return val !== null ? new BSTNode(id, val, count) : null;
62
+ BST.prototype._createNode = function (id, val, count) {
63
+ var node = val !== null ? new BSTNode(id, val, count) : null;
64
+ return node;
72
65
  };
73
66
  /**
74
67
  * The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
75
68
  * the ID matches, and returns the inserted node.
76
69
  * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
77
70
  * 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`.
71
+ * @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
72
+ * be of type `N` (the generic type) or `null`.
80
73
  * @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
81
74
  * the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
82
75
  * inserted once.
83
- * @returns The method `add` returns a `BSTNode<T>` object or `null`.
76
+ * @returns The method `add` returns a `N` object or `null`.
84
77
  */
85
78
  BST.prototype.add = function (id, val, count) {
86
79
  if (count === void 0) { count = 1; }
87
80
  var inserted = null;
88
- var newNode = this.createNode(id, val, count);
81
+ var newNode = this._createNode(id, val, count);
89
82
  if (this.root === null) {
90
83
  this._setRoot(newNode);
91
84
  this._setSize(this.size + 1);
@@ -97,7 +90,7 @@ var BST = /** @class */ (function (_super) {
97
90
  var traversing = true;
98
91
  while (traversing) {
99
92
  if (cur !== null && newNode !== null) {
100
- if (this._compare(cur.id, id) === CP.eq) {
93
+ if (this._compare(cur.id, id) === types_1.CP.eq) {
101
94
  if (newNode) {
102
95
  cur.count += newNode.count;
103
96
  this._setCount(this.count + newNode.count);
@@ -107,12 +100,12 @@ var BST = /** @class */ (function (_super) {
107
100
  traversing = false;
108
101
  inserted = cur;
109
102
  }
110
- else if (this._compare(cur.id, id) === CP.gt) {
103
+ else if (this._compare(cur.id, id) === types_1.CP.gt) {
111
104
  // Traverse left of the node
112
105
  if (cur.left === undefined) {
113
106
  if (newNode) {
114
107
  newNode.parent = cur;
115
- newNode.familyPosition = binary_tree_1.FamilyPosition.left;
108
+ newNode.familyPosition = types_1.FamilyPosition.LEFT;
116
109
  }
117
110
  //Add to the left of the current node
118
111
  cur.left = newNode;
@@ -127,12 +120,12 @@ var BST = /** @class */ (function (_super) {
127
120
  cur = cur.left;
128
121
  }
129
122
  }
130
- else if (this._compare(cur.id, id) === CP.lt) {
123
+ else if (this._compare(cur.id, id) === types_1.CP.lt) {
131
124
  // Traverse right of the node
132
125
  if (cur.right === undefined) {
133
126
  if (newNode) {
134
127
  newNode.parent = cur;
135
- newNode.familyPosition = binary_tree_1.FamilyPosition.right;
128
+ newNode.familyPosition = types_1.FamilyPosition.RIGHT;
136
129
  }
137
130
  //Add to the right of the current node
138
131
  cur.right = newNode;
@@ -157,12 +150,12 @@ var BST = /** @class */ (function (_super) {
157
150
  };
158
151
  /**
159
152
  * The `get` function returns the first node in a binary search tree that matches the given property value or name.
160
- * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
161
- * generic type `T`. It represents the value of the property that you want to search for in the binary search tree.
153
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
154
+ * generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
162
155
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
163
156
  * specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
164
157
  * `'id'`.
165
- * @returns The method is returning a BSTNode<T> object or null.
158
+ * @returns The method is returning a N object or null.
166
159
  */
167
160
  BST.prototype.get = function (nodeProperty, propertyName) {
168
161
  var _a;
@@ -179,9 +172,9 @@ var BST = /** @class */ (function (_super) {
179
172
  */
180
173
  BST.prototype.lastKey = function () {
181
174
  var _a, _b, _c, _d, _e, _f;
182
- if (this._compare(0, 1) === CP.lt)
175
+ if (this._compare(0, 1) === types_1.CP.lt)
183
176
  return (_b = (_a = this.getRightMost()) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 0;
184
- else if (this._compare(0, 1) === CP.gt)
177
+ else if (this._compare(0, 1) === types_1.CP.gt)
185
178
  return (_d = (_c = this.getLeftMost()) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : 0;
186
179
  else
187
180
  return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : 0;
@@ -194,7 +187,7 @@ var BST = /** @class */ (function (_super) {
194
187
  * @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
195
188
  * set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
196
189
  * set to false or not provided, the count of the node will be taken into account and the
197
- * @returns an array of `BSTDeletedResult<T>` objects.
190
+ * @returns an array of `BSTDeletedResult<N>` objects.
198
191
  */
199
192
  BST.prototype.remove = function (id, ignoreCount) {
200
193
  var bstDeletedResult = [];
@@ -217,10 +210,10 @@ var BST = /** @class */ (function (_super) {
217
210
  }
218
211
  else {
219
212
  switch (curr.familyPosition) {
220
- case binary_tree_1.FamilyPosition.left:
213
+ case types_1.FamilyPosition.LEFT:
221
214
  parent.left = curr.right;
222
215
  break;
223
- case binary_tree_1.FamilyPosition.right:
216
+ case types_1.FamilyPosition.RIGHT:
224
217
  parent.right = curr.right;
225
218
  break;
226
219
  }
@@ -250,15 +243,15 @@ var BST = /** @class */ (function (_super) {
250
243
  /**
251
244
  * The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
252
245
  * option to specify the property name and whether to return only one node.
253
- * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
254
- * generic type `T`. It represents the property value that you want to search for in the binary search tree.
246
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
247
+ * generic type `N`. It represents the property value that you want to search for in the binary search tree.
255
248
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
256
249
  * specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
257
250
  * `'id'`.
258
251
  * @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
259
252
  * nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
260
253
  * to false or not provided, the function will return all nodes that match the given nodeProperty.
261
- * @returns an array of BSTNode<T> objects.
254
+ * @returns an array of N objects.
262
255
  */
263
256
  BST.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
264
257
  var _this = this;
@@ -266,16 +259,16 @@ var BST = /** @class */ (function (_super) {
266
259
  if (!this.root)
267
260
  return [];
268
261
  var result = [];
269
- if (this.loopType === binary_tree_1.LoopType.recursive) {
262
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
270
263
  var _traverse_1 = function (cur) {
271
264
  if (_this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
272
265
  return;
273
266
  if (!cur.left && !cur.right)
274
267
  return;
275
268
  if (propertyName === 'id') {
276
- if (_this._compare(cur.id, nodeProperty) === CP.gt)
269
+ if (_this._compare(cur.id, nodeProperty) === types_1.CP.gt)
277
270
  cur.left && _traverse_1(cur.left);
278
- if (_this._compare(cur.id, nodeProperty) === CP.lt)
271
+ if (_this._compare(cur.id, nodeProperty) === types_1.CP.lt)
279
272
  cur.right && _traverse_1(cur.right);
280
273
  }
281
274
  else {
@@ -293,9 +286,9 @@ var BST = /** @class */ (function (_super) {
293
286
  if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
294
287
  return result;
295
288
  if (propertyName === 'id') {
296
- if (this._compare(cur.id, nodeProperty) === CP.gt)
289
+ if (this._compare(cur.id, nodeProperty) === types_1.CP.gt)
297
290
  cur.left && queue.push(cur.left);
298
- if (this._compare(cur.id, nodeProperty) === CP.lt)
291
+ if (this._compare(cur.id, nodeProperty) === types_1.CP.lt)
299
292
  cur.right && queue.push(cur.right);
300
293
  }
301
294
  else {
@@ -339,15 +332,15 @@ var BST = /** @class */ (function (_super) {
339
332
  return needSum;
340
333
  };
341
334
  var sum = 0;
342
- if (this.loopType === binary_tree_1.LoopType.recursive) {
335
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
343
336
  var _traverse_2 = function (cur) {
344
337
  var compared = _this._compare(cur.id, id);
345
- if (compared === CP.eq) {
338
+ if (compared === types_1.CP.eq) {
346
339
  if (cur.right)
347
340
  sum += _this.subTreeSum(cur.right, propertyName);
348
341
  return;
349
342
  }
350
- else if (compared === CP.lt) {
343
+ else if (compared === types_1.CP.lt) {
351
344
  if (cur.left)
352
345
  sum += _this.subTreeSum(cur.left, propertyName);
353
346
  sum += getSumByPropertyName(cur);
@@ -371,12 +364,12 @@ var BST = /** @class */ (function (_super) {
371
364
  var cur = queue.shift();
372
365
  if (cur) {
373
366
  var compared = this._compare(cur.id, id);
374
- if (compared === CP.eq) {
367
+ if (compared === types_1.CP.eq) {
375
368
  if (cur.right)
376
369
  sum += this.subTreeSum(cur.right, propertyName);
377
370
  return sum;
378
371
  }
379
- else if (compared === CP.lt) { // todo maybe a bug
372
+ else if (compared === types_1.CP.lt) { // todo maybe a bug
380
373
  if (cur.left)
381
374
  sum += this.subTreeSum(cur.left, propertyName);
382
375
  sum += getSumByPropertyName(cur);
@@ -399,7 +392,7 @@ var BST = /** @class */ (function (_super) {
399
392
  /**
400
393
  * The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
401
394
  * that have a greater value than a given node.
402
- * @param node - The `node` parameter is of type `BSTNode<T>`, which represents a node in a binary search tree. It
395
+ * @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
403
396
  * contains properties such as `id` and `count`.
404
397
  * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
405
398
  * each node should be increased.
@@ -426,15 +419,15 @@ var BST = /** @class */ (function (_super) {
426
419
  break;
427
420
  }
428
421
  };
429
- if (this.loopType === binary_tree_1.LoopType.recursive) {
422
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
430
423
  var _traverse_3 = function (cur) {
431
424
  var compared = _this._compare(cur.id, node.id);
432
425
  _sumByPropertyName(cur);
433
426
  if (!cur.left && !cur.right)
434
427
  return;
435
- if (cur.left && compared === CP.gt)
428
+ if (cur.left && compared === types_1.CP.gt)
436
429
  _traverse_3(cur.left);
437
- else if (cur.right && compared === CP.gt)
430
+ else if (cur.right && compared === types_1.CP.gt)
438
431
  _traverse_3(cur.right);
439
432
  };
440
433
  _traverse_3(this.root);
@@ -447,9 +440,9 @@ var BST = /** @class */ (function (_super) {
447
440
  if (cur) {
448
441
  var compared = this._compare(cur.id, node.id);
449
442
  _sumByPropertyName(cur);
450
- if (cur.left && compared === CP.gt)
443
+ if (cur.left && compared === types_1.CP.gt)
451
444
  queue.push(cur.left);
452
- else if (cur.right && compared === CP.gt)
445
+ else if (cur.right && compared === types_1.CP.gt)
453
446
  queue.push(cur.right);
454
447
  }
455
448
  }
@@ -467,7 +460,7 @@ var BST = /** @class */ (function (_super) {
467
460
  this.clear();
468
461
  if (sorted.length < 1)
469
462
  return false;
470
- if (this.loopType === binary_tree_1.LoopType.recursive) {
463
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
471
464
  var buildBalanceBST_1 = function (l, r) {
472
465
  if (l > r)
473
466
  return;
@@ -508,7 +501,7 @@ var BST = /** @class */ (function (_super) {
508
501
  if (!this.root)
509
502
  return true;
510
503
  var balanced = true;
511
- if (this.loopType === binary_tree_1.LoopType.recursive) {
504
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
512
505
  var _height_1 = function (cur) {
513
506
  if (!cur)
514
507
  return 0;
@@ -560,11 +553,11 @@ var BST = /** @class */ (function (_super) {
560
553
  BST.prototype._compare = function (a, b) {
561
554
  var compared = this._comparator(a, b);
562
555
  if (compared > 0)
563
- return CP.gt;
556
+ return types_1.CP.gt;
564
557
  else if (compared < 0)
565
- return CP.lt;
558
+ return types_1.CP.lt;
566
559
  else
567
- return CP.eq;
560
+ return types_1.CP.eq;
568
561
  };
569
562
  return BST;
570
563
  }(binary_tree_1.BinaryTree));
@@ -1,3 +1,4 @@
1
+ export * from './abstract-binary-tree';
1
2
  export * from './binary-tree';
2
3
  export * from './bst';
3
4
  export * from './binary-indexed-tree';
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./abstract-binary-tree"), exports);
17
18
  __exportStar(require("./binary-tree"), exports);
18
19
  __exportStar(require("./bst"), exports);
19
20
  __exportStar(require("./binary-indexed-tree"), exports);
@@ -1,2 +1 @@
1
- export declare class RBTree {
2
- }
1
+ export {};
@@ -1,9 +1,68 @@
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 types_1 = require("../types");
20
+ var RBNode = /** @class */ (function (_super) {
21
+ __extends(RBNode, _super);
22
+ // override createNode(id: BinaryTreeNodeId, val: T | null, count?: number): RBNode<T> | null {
23
+ // return val !== null ? new RBNode<T>(id, val, count) : null;
24
+ // }
25
+ function RBNode(id, val, count) {
26
+ var _this = _super.call(this, id, val, count) || this;
27
+ _this._color = types_1.RBColor.RED;
28
+ return _this;
6
29
  }
30
+ Object.defineProperty(RBNode.prototype, "color", {
31
+ get: function () {
32
+ return this._color;
33
+ },
34
+ set: function (value) {
35
+ this._color = value;
36
+ },
37
+ enumerable: false,
38
+ configurable: true
39
+ });
40
+ return RBNode;
41
+ }(binary_tree_1.BinaryTreeNode));
42
+ var RBTree = /** @class */ (function (_super) {
43
+ __extends(RBTree, _super);
44
+ function RBTree(options) {
45
+ return _super.call(this, options) || this;
46
+ }
47
+ // override _createNode(id: BinaryTreeNodeId, val: N | null, count?: number): RBNode<N> | null {
48
+ // return val !== null ? new RBNode<N>(id, val, count) : null;
49
+ // }
50
+ // private override _root: BinaryTreeNode<N> | null = null;
51
+ //
52
+ // override get root(): BinaryTreeNode<N> | null {
53
+ // return this._root;
54
+ // }
55
+ RBTree.prototype.insert = function (id, val) {
56
+ };
57
+ RBTree.prototype.leftRotate = function (node) {
58
+ };
59
+ RBTree.prototype.rightRotate = function (node) {
60
+ };
61
+ RBTree.prototype.insertFixup = function (node) {
62
+ };
63
+ RBTree.prototype.deleteFixup = function (node) {
64
+ };
65
+ RBTree.prototype.transplant = function (u, v) {
66
+ };
7
67
  return RBTree;
8
- }());
9
- exports.RBTree = RBTree;
68
+ }(binary_tree_1.BinaryTree));
@@ -6,37 +6,23 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { BinaryTreeNodeId, TreeMultiSetDeletedResult } from '../types';
10
- export declare class TreeMultiSet<T> extends BST<T> {
9
+ import type { BinaryTreeNodeId, RecursiveTreeMultiSetNode, TreeMultiSetOptions } from '../types';
10
+ import { IBinaryTree, IBinaryTreeNode } from '../interfaces';
11
+ export declare class TreeMultiSetNode<T, FAMILY extends TreeMultiSetNode<T, FAMILY> = RecursiveTreeMultiSetNode<T>> extends BSTNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
12
+ }
13
+ /**
14
+ * The only distinction between a TreeMultiSet and a BST lies in the ability of the former to store duplicate nodes through the utilization of counters.
15
+ */
16
+ export declare class TreeMultiSet<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BST<N> implements IBinaryTree<N> {
17
+ constructor(options?: TreeMultiSetOptions);
11
18
  /**
12
19
  * The function creates a new BSTNode with the given id, value, and count.
13
20
  * @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
14
21
  * 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.
22
+ * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.
16
23
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
17
24
  * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
18
25
  * @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
19
26
  */
20
- createNode(id: BinaryTreeNodeId, val: T, count?: number): BSTNode<T>;
21
- /**
22
- * The function overrides the add method of the BinarySearchTree class in TypeScript.
23
- * @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`.
26
- * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
27
- * 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
- */
30
- add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
31
- /**
32
- * The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
33
- * method.
34
- * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
35
- * removed from the tree.
36
- * @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean value that
37
- * determines whether to update the left sum of all nodes in the tree after removing a node. If `isUpdateAllLeftSum` is
38
- * set to `true`, the left sum of all nodes will be recalculated. If it
39
- * @returns The method is returning an array of TreeMultiSetDeletedResult objects.
40
- */
41
- remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<T>[];
27
+ _createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N;
42
28
  }
@@ -14,8 +14,19 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.TreeMultiSet = void 0;
29
+ exports.TreeMultiSet = exports.TreeMultiSetNode = void 0;
19
30
  /**
20
31
  * data-structure-typed
21
32
  *
@@ -24,47 +35,34 @@ exports.TreeMultiSet = void 0;
24
35
  * @license MIT License
25
36
  */
26
37
  var bst_1 = require("./bst");
38
+ var TreeMultiSetNode = /** @class */ (function (_super) {
39
+ __extends(TreeMultiSetNode, _super);
40
+ function TreeMultiSetNode() {
41
+ return _super !== null && _super.apply(this, arguments) || this;
42
+ }
43
+ return TreeMultiSetNode;
44
+ }(bst_1.BSTNode));
45
+ exports.TreeMultiSetNode = TreeMultiSetNode;
46
+ /**
47
+ * The only distinction between a TreeMultiSet and a BST lies in the ability of the former to store duplicate nodes through the utilization of counters.
48
+ */
27
49
  var TreeMultiSet = /** @class */ (function (_super) {
28
50
  __extends(TreeMultiSet, _super);
29
- function TreeMultiSet() {
30
- return _super !== null && _super.apply(this, arguments) || this;
51
+ function TreeMultiSet(options) {
52
+ return _super.call(this, __assign(__assign({}, options), { isDuplicatedVal: true })) || this;
31
53
  }
32
54
  /**
33
55
  * The function creates a new BSTNode with the given id, value, and count.
34
56
  * @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
35
57
  * distinguish one node from another in the tree.
36
- * @param {T} val - The `val` parameter represents the value that will be stored in the binary search tree node.
58
+ * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.
37
59
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
38
60
  * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
39
61
  * @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
40
62
  */
41
- TreeMultiSet.prototype.createNode = function (id, val, count) {
42
- return new bst_1.BSTNode(id, val, count);
43
- };
44
- /**
45
- * The function overrides the add method of the BinarySearchTree class in TypeScript.
46
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
47
- * @param {T | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
48
- * can be of type `T` (the generic type) or `null`.
49
- * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
50
- * of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
51
- * @returns The `add` method is returning a `BSTNode<T>` object or `null`.
52
- */
53
- TreeMultiSet.prototype.add = function (id, val, count) {
54
- return _super.prototype.add.call(this, id, val, count);
55
- };
56
- /**
57
- * The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
58
- * method.
59
- * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
60
- * removed from the tree.
61
- * @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean value that
62
- * determines whether to update the left sum of all nodes in the tree after removing a node. If `isUpdateAllLeftSum` is
63
- * set to `true`, the left sum of all nodes will be recalculated. If it
64
- * @returns The method is returning an array of TreeMultiSetDeletedResult objects.
65
- */
66
- TreeMultiSet.prototype.remove = function (id, isUpdateAllLeftSum) {
67
- return _super.prototype.remove.call(this, id, isUpdateAllLeftSum);
63
+ TreeMultiSet.prototype._createNode = function (id, val, count) {
64
+ var node = new TreeMultiSetNode(id, val, count);
65
+ return node;
68
66
  };
69
67
  return TreeMultiSet;
70
68
  }(bst_1.BST));