data-structure-typed 0.8.18 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +690 -2
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -18
  8. package/dist/data-structures/binary-tree/avl-tree.js +110 -37
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +40 -2
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +44 -2
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -138
  12. package/dist/data-structures/binary-tree/binary-tree.js +27 -979
  13. package/dist/data-structures/binary-tree/bst.d.ts +118 -28
  14. package/dist/data-structures/binary-tree/bst.js +162 -124
  15. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  16. package/dist/data-structures/binary-tree/index.js +1 -0
  17. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  18. package/dist/data-structures/binary-tree/rb-tree.js +40 -2
  19. package/dist/data-structures/binary-tree/segment-tree.d.ts +63 -13
  20. package/dist/data-structures/binary-tree/segment-tree.js +80 -17
  21. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -10
  22. package/dist/data-structures/binary-tree/tree-multiset.js +682 -9
  23. package/dist/data-structures/graph/abstract-graph.d.ts +270 -64
  24. package/dist/data-structures/graph/abstract-graph.js +365 -92
  25. package/dist/data-structures/graph/directed-graph.d.ts +175 -26
  26. package/dist/data-structures/graph/directed-graph.js +249 -95
  27. package/dist/data-structures/graph/index.d.ts +1 -0
  28. package/dist/data-structures/graph/index.js +1 -0
  29. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  30. package/dist/data-structures/graph/map-graph.js +111 -0
  31. package/dist/data-structures/graph/undirected-graph.d.ts +111 -8
  32. package/dist/data-structures/graph/undirected-graph.js +154 -44
  33. package/dist/data-structures/hash/coordinate-map.d.ts +39 -2
  34. package/dist/data-structures/hash/coordinate-map.js +44 -3
  35. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  36. package/dist/data-structures/hash/coordinate-set.js +34 -0
  37. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  38. package/dist/data-structures/hash/hash-table.js +4 -0
  39. package/dist/data-structures/hash/index.d.ts +5 -0
  40. package/dist/data-structures/hash/index.js +5 -0
  41. package/dist/data-structures/hash/pair.d.ts +2 -1
  42. package/dist/data-structures/hash/pair.js +4 -0
  43. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  44. package/dist/data-structures/hash/tree-map.js +4 -0
  45. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-set.js +4 -0
  47. package/dist/data-structures/heap/heap.d.ts +62 -51
  48. package/dist/data-structures/heap/heap.js +106 -63
  49. package/dist/data-structures/heap/max-heap.d.ts +13 -4
  50. package/dist/data-structures/heap/max-heap.js +10 -2
  51. package/dist/data-structures/heap/min-heap.d.ts +14 -4
  52. package/dist/data-structures/heap/min-heap.js +11 -2
  53. package/dist/data-structures/index.d.ts +1 -0
  54. package/dist/data-structures/index.js +1 -0
  55. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -57
  56. package/dist/data-structures/linked-list/doubly-linked-list.js +461 -194
  57. package/dist/data-structures/linked-list/index.d.ts +1 -0
  58. package/dist/data-structures/linked-list/index.js +1 -0
  59. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -319
  60. package/dist/data-structures/linked-list/singly-linked-list.js +338 -557
  61. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  62. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  63. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  64. package/dist/data-structures/matrix/matrix.js +14 -0
  65. package/dist/data-structures/matrix/matrix2d.d.ts +87 -4
  66. package/dist/data-structures/matrix/matrix2d.js +91 -8
  67. package/dist/data-structures/matrix/navigator.d.ts +37 -16
  68. package/dist/data-structures/matrix/navigator.js +28 -0
  69. package/dist/data-structures/matrix/vector2d.d.ts +156 -29
  70. package/dist/data-structures/matrix/vector2d.js +184 -55
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -1
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +28 -4
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -1
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +29 -4
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +166 -22
  76. package/dist/data-structures/priority-queue/priority-queue.js +219 -75
  77. package/dist/data-structures/queue/deque.d.ts +141 -13
  78. package/dist/data-structures/queue/deque.js +151 -7
  79. package/dist/data-structures/queue/queue.d.ts +68 -42
  80. package/dist/data-structures/queue/queue.js +95 -51
  81. package/dist/data-structures/stack/stack.d.ts +30 -36
  82. package/dist/data-structures/stack/stack.js +31 -37
  83. package/dist/data-structures/tree/index.d.ts +1 -0
  84. package/dist/data-structures/tree/index.js +17 -0
  85. package/dist/data-structures/tree/tree.d.ts +14 -0
  86. package/dist/{types/utils.js → data-structures/tree/tree.js} +26 -19
  87. package/dist/data-structures/trie/trie.d.ts +39 -6
  88. package/dist/data-structures/trie/trie.js +81 -12
  89. package/dist/index.d.ts +3 -0
  90. package/dist/index.js +3 -0
  91. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  92. package/dist/interfaces/abstract-binary-tree.js +2 -0
  93. package/dist/interfaces/abstract-graph.d.ts +17 -0
  94. package/dist/interfaces/abstract-graph.js +2 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/avl-tree.js +2 -0
  97. package/dist/interfaces/binary-tree.d.ts +6 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/bst.d.ts +17 -0
  100. package/dist/interfaces/bst.js +2 -0
  101. package/dist/interfaces/directed-graph.d.ts +12 -0
  102. package/dist/interfaces/directed-graph.js +2 -0
  103. package/dist/interfaces/doubly-linked-list.js +2 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +15 -0
  106. package/dist/interfaces/index.js +31 -0
  107. package/dist/interfaces/navigator.js +2 -0
  108. package/dist/interfaces/priority-queue.js +2 -0
  109. package/dist/interfaces/rb-tree.d.ts +8 -0
  110. package/dist/interfaces/rb-tree.js +2 -0
  111. package/dist/interfaces/segment-tree.js +2 -0
  112. package/dist/interfaces/singly-linked-list.js +2 -0
  113. package/dist/interfaces/tree-multiset.d.ts +7 -0
  114. package/dist/interfaces/tree-multiset.js +2 -0
  115. package/dist/interfaces/undirected-graph.d.ts +5 -0
  116. package/dist/interfaces/undirected-graph.js +2 -0
  117. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  118. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  119. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  120. package/dist/types/data-structures/abstract-graph.js +2 -0
  121. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  122. package/dist/types/data-structures/avl-tree.js +2 -0
  123. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  124. package/dist/types/data-structures/binary-tree.js +2 -0
  125. package/dist/types/data-structures/bst.d.ts +13 -0
  126. package/dist/types/data-structures/bst.js +9 -0
  127. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  128. package/dist/types/data-structures/directed-graph.js +9 -0
  129. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  130. package/dist/types/data-structures/heap.d.ts +3 -0
  131. package/dist/types/data-structures/heap.js +2 -0
  132. package/dist/types/data-structures/index.d.ts +13 -7
  133. package/dist/types/data-structures/index.js +31 -0
  134. package/dist/types/data-structures/map-graph.d.ts +1 -0
  135. package/dist/types/data-structures/map-graph.js +2 -0
  136. package/dist/types/data-structures/navigator.d.ts +14 -0
  137. package/dist/types/data-structures/navigator.js +2 -0
  138. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  139. package/dist/types/data-structures/priority-queue.js +2 -0
  140. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  141. package/dist/types/data-structures/rb-tree.js +8 -0
  142. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  143. package/dist/types/data-structures/segment-tree.js +2 -0
  144. package/dist/types/data-structures/singly-linked-list.js +2 -0
  145. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  146. package/dist/types/data-structures/tree-multiset.js +2 -0
  147. package/dist/types/helpers.d.ts +1 -0
  148. package/dist/types/helpers.js +2 -0
  149. package/dist/types/index.d.ts +2 -0
  150. package/dist/types/index.js +2 -0
  151. package/dist/types/utils/index.d.ts +2 -0
  152. package/dist/types/utils/index.js +18 -0
  153. package/dist/types/utils/utils.d.ts +7 -0
  154. package/dist/types/utils/utils.js +2 -0
  155. package/dist/types/utils/validate-type.d.ts +19 -0
  156. package/dist/types/utils/validate-type.js +2 -0
  157. package/dist/utils/index.js +17 -0
  158. package/dist/utils/utils.d.ts +19 -0
  159. package/dist/{data-structures/trampoline.js → utils/utils.js} +26 -12
  160. package/package.json +106 -55
  161. package/.idea/data-structure-typed.iml +0 -12
  162. package/.idea/modules.xml +0 -8
  163. package/.idea/vcs.xml +0 -6
  164. package/dist/data-structures/trampoline.d.ts +0 -25
  165. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  166. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  167. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  168. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  169. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  170. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  171. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  172. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  173. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  174. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  175. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  176. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  177. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  178. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  179. package/dist/types/data-structures/graph/index.d.ts +0 -3
  180. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  181. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  182. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  183. package/dist/types/data-structures/hash/index.d.ts +0 -1
  184. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  185. package/dist/types/data-structures/heap/index.d.ts +0 -3
  186. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  187. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  188. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  189. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  190. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  191. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  192. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  193. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  194. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  195. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  196. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  197. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  198. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  199. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  200. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  201. package/dist/types/data-structures/queue/index.d.ts +0 -1
  202. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  203. package/dist/types/data-structures/stack/index.d.ts +0 -1
  204. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  205. package/dist/types/data-structures/trampoline.d.ts +0 -25
  206. package/dist/types/data-structures/trie/index.d.ts +0 -1
  207. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  208. package/dist/types/types/utils.d.ts +0 -46
  209. package/dist/types/utils.d.ts +0 -46
  210. package/dist/utils.d.ts +0 -122
  211. package/dist/utils.js +0 -569
  212. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  213. package/src/data-structures/binary-tree/avl-tree.ts +0 -232
  214. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  215. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  216. package/src/data-structures/binary-tree/binary-tree.ts +0 -1088
  217. package/src/data-structures/binary-tree/bst.ts +0 -404
  218. package/src/data-structures/binary-tree/index.ts +0 -11
  219. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  220. package/src/data-structures/binary-tree/segment-tree.ts +0 -164
  221. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  222. package/src/data-structures/binary-tree/tree-multiset.ts +0 -21
  223. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  224. package/src/data-structures/graph/abstract-graph.ts +0 -789
  225. package/src/data-structures/graph/directed-graph.ts +0 -322
  226. package/src/data-structures/graph/index.ts +0 -3
  227. package/src/data-structures/graph/undirected-graph.ts +0 -154
  228. package/src/data-structures/hash/coordinate-map.ts +0 -24
  229. package/src/data-structures/hash/coordinate-set.ts +0 -20
  230. package/src/data-structures/hash/hash-table.ts +0 -1
  231. package/src/data-structures/hash/index.ts +0 -1
  232. package/src/data-structures/heap/heap.ts +0 -136
  233. package/src/data-structures/heap/index.ts +0 -3
  234. package/src/data-structures/heap/max-heap.ts +0 -22
  235. package/src/data-structures/heap/min-heap.ts +0 -24
  236. package/src/data-structures/index.ts +0 -11
  237. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -258
  238. package/src/data-structures/linked-list/index.ts +0 -2
  239. package/src/data-structures/linked-list/singly-linked-list.ts +0 -750
  240. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  241. package/src/data-structures/matrix/index.ts +0 -4
  242. package/src/data-structures/matrix/matrix.ts +0 -13
  243. package/src/data-structures/matrix/matrix2d.ts +0 -125
  244. package/src/data-structures/matrix/navigator.ts +0 -99
  245. package/src/data-structures/matrix/vector2d.ts +0 -189
  246. package/src/data-structures/priority-queue/index.ts +0 -3
  247. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -12
  248. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -12
  249. package/src/data-structures/priority-queue/priority-queue.ts +0 -208
  250. package/src/data-structures/queue/deque.ts +0 -139
  251. package/src/data-structures/queue/index.ts +0 -2
  252. package/src/data-structures/queue/queue.ts +0 -123
  253. package/src/data-structures/stack/index.ts +0 -1
  254. package/src/data-structures/stack/stack.ts +0 -104
  255. package/src/data-structures/trampoline.ts +0 -91
  256. package/src/data-structures/trie/index.ts +0 -1
  257. package/src/data-structures/trie/trie.ts +0 -153
  258. package/src/index.ts +0 -1
  259. package/src/types/index.ts +0 -1
  260. package/src/types/patches/index.d.ts +0 -0
  261. package/src/types/utils.ts +0 -158
  262. package/src/utils.ts +0 -605
  263. package/tsconfig.json +0 -53
  264. /package/dist/{types/data-structures/hash/hash-table.d.ts → interfaces/doubly-linked-list.d.ts} +0 -0
  265. /package/dist/{types/data-structures/hash/pair.d.ts → interfaces/heap.d.ts} +0 -0
  266. /package/dist/{types/data-structures/hash/tree-map.d.ts → interfaces/navigator.d.ts} +0 -0
  267. /package/dist/{types/data-structures/hash/tree-set.d.ts → interfaces/priority-queue.d.ts} +0 -0
  268. /package/dist/{types/data-structures/linked-list/skip-linked-list.d.ts → interfaces/segment-tree.d.ts} +0 -0
  269. /package/{src/data-structures/hash/pair.ts → dist/interfaces/singly-linked-list.d.ts} +0 -0
  270. /package/{src/data-structures/hash/tree-map.ts → dist/types/data-structures/doubly-linked-list.d.ts} +0 -0
  271. /package/{src/data-structures/hash/tree-set.ts → dist/types/data-structures/singly-linked-list.d.ts} +0 -0
  272. /package/dist/{types/types → utils}/index.d.ts +0 -0
@@ -1,21 +1,88 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
1
8
  import { BST, BSTNode } from './bst';
2
- import { BinaryTreeNodeId } from './binary-tree';
3
- export interface AVLTreeDeleted<T> {
4
- deleted: AVLTreeNode<T> | null;
5
- needBalanced: AVLTreeNode<T> | null;
9
+ import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId } from '../../types';
10
+ import { IAVLTree, IAVLTreeNode } from '../../interfaces';
11
+ export declare class AVLTreeNode<T = any, NEIGHBOR extends AVLTreeNode<T, NEIGHBOR> = AVLTreeNodeNested<T>> extends BSTNode<T, NEIGHBOR> implements IAVLTreeNode<T, NEIGHBOR> {
12
+ constructor(id: BinaryTreeNodeId, val?: T);
6
13
  }
7
- export declare class AVLTreeNode<T> extends BSTNode<T> {
8
- clone(): AVLTreeNode<T>;
9
- }
10
- export declare class AVLTree<T> extends BST<T> {
11
- createNode(id: BinaryTreeNodeId, val: T, count?: number): AVLTreeNode<T>;
12
- put(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null;
13
- remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): AVLTreeDeleted<T>[];
14
- balanceFactor(node: AVLTreeNode<T>): number;
15
- updateHeight(node: AVLTreeNode<T>): void;
16
- balancePath(node: AVLTreeNode<T>): void;
17
- balanceLL(A: AVLTreeNode<T>): void;
18
- balanceLR(A: AVLTreeNode<T>): void;
19
- balanceRR(A: AVLTreeNode<T>): void;
20
- balanceRL(A: AVLTreeNode<T>): void;
14
+ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends BST<N> implements IAVLTree<N> {
15
+ /**
16
+ * This is a constructor function for an AVL tree data structure in TypeScript.
17
+ * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
18
+ * constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
19
+ * options.
20
+ */
21
+ constructor(options?: AVLTreeOptions);
22
+ /**
23
+ * The function creates a new AVL tree node with the given id and value.
24
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
25
+ * identify each node in the tree.
26
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
27
+ * that will be stored in the node.
28
+ * @returns a new AVLTreeNode object with the specified id and value.
29
+ */
30
+ createNode(id: BinaryTreeNodeId, val?: N['val']): N;
31
+ /**
32
+ * The function overrides the add method of a binary tree node and balances the tree after inserting a new node.
33
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add.
34
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It is of type
35
+ * `N['val']`, which means it should be of the same type as the `val` property of the nodes in the binary tree.
36
+ * @returns The method is returning the inserted node, or null or undefined if the insertion was not successful.
37
+ */
38
+ add(id: BinaryTreeNodeId, val?: N['val']): N | null | undefined;
39
+ /**
40
+ * The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
41
+ * then balances the tree if necessary.
42
+ * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
43
+ * removed from the AVL tree.
44
+ * @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean parameter that
45
+ * determines whether the left sum of all nodes in the AVL tree should be updated after removing a node. If
46
+ * `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
47
+ * @returns The method is returning an array of `AVLTreeDeleted<N>` objects.
48
+ */
49
+ remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): BinaryTreeDeletedResult<N>[];
50
+ /**
51
+ * The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
52
+ * height of its right subtree.
53
+ * @param node - The parameter "node" is of type N, which represents a node in an AVL tree.
54
+ * @returns The balance factor of the given AVL tree node.
55
+ */
56
+ protected _balanceFactor(node: N): number;
57
+ /**
58
+ * The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.
59
+ * @param node - The parameter `node` is an AVLTreeNode object, which represents a node in an AVL tree.
60
+ */
61
+ protected _updateHeight(node: N): void;
62
+ /**
63
+ * The `_balancePath` function balances the AVL tree by performing appropriate rotations based on the balance factor of
64
+ * each node in the path from the given node to the root.
65
+ * @param node - The `node` parameter is an AVLTreeNode object, which represents a node in an AVL tree.
66
+ */
67
+ protected _balancePath(node: N): void;
68
+ /**
69
+ * The `_balanceLL` function performs a left-left rotation on an AVL tree to balance it.
70
+ * @param A - The parameter A is an AVLTreeNode object.
71
+ */
72
+ protected _balanceLL(A: N): void;
73
+ /**
74
+ * The `_balanceLR` function performs a left-right rotation to balance an AVL tree.
75
+ * @param A - A is an AVLTreeNode object.
76
+ */
77
+ protected _balanceLR(A: N): void;
78
+ /**
79
+ * The `_balanceRR` function performs a right-right rotation on an AVL tree to balance it.
80
+ * @param A - The parameter A is an AVLTreeNode object.
81
+ */
82
+ protected _balanceRR(A: N): void;
83
+ /**
84
+ * The `_balanceRL` function performs a right-left rotation to balance an AVL tree.
85
+ * @param A - A is an AVLTreeNode object.
86
+ */
87
+ protected _balanceRL(A: N): void;
21
88
  }
@@ -1,33 +1,81 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AVLTree = exports.AVLTreeNode = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  const bst_1 = require("./bst");
5
12
  class AVLTreeNode extends bst_1.BSTNode {
6
- clone() {
7
- return new AVLTreeNode(this.id, this.val, this.count);
13
+ constructor(id, val) {
14
+ super(id, val);
8
15
  }
9
16
  }
10
17
  exports.AVLTreeNode = AVLTreeNode;
11
18
  class AVLTree extends bst_1.BST {
12
- createNode(id, val, count) {
13
- return new AVLTreeNode(id, val, count);
19
+ /**
20
+ * This is a constructor function for an AVL tree data structure in TypeScript.
21
+ * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
22
+ * constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
23
+ * options.
24
+ */
25
+ constructor(options) {
26
+ super(options);
14
27
  }
15
- put(id, val, count) {
16
- const inserted = super.put(id, val, count);
28
+ /**
29
+ * The function creates a new AVL tree node with the given id and value.
30
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
31
+ * identify each node in the tree.
32
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
33
+ * that will be stored in the node.
34
+ * @returns a new AVLTreeNode object with the specified id and value.
35
+ */
36
+ createNode(id, val) {
37
+ return new AVLTreeNode(id, val);
38
+ }
39
+ /**
40
+ * The function overrides the add method of a binary tree node and balances the tree after inserting a new node.
41
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add.
42
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It is of type
43
+ * `N['val']`, which means it should be of the same type as the `val` property of the nodes in the binary tree.
44
+ * @returns The method is returning the inserted node, or null or undefined if the insertion was not successful.
45
+ */
46
+ add(id, val) {
47
+ // TODO support node as a param
48
+ const inserted = super.add(id, val);
17
49
  if (inserted)
18
- this.balancePath(inserted);
50
+ this._balancePath(inserted);
19
51
  return inserted;
20
52
  }
53
+ /**
54
+ * The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
55
+ * then balances the tree if necessary.
56
+ * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
57
+ * removed from the AVL tree.
58
+ * @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean parameter that
59
+ * determines whether the left sum of all nodes in the AVL tree should be updated after removing a node. If
60
+ * `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
61
+ * @returns The method is returning an array of `AVLTreeDeleted<N>` objects.
62
+ */
21
63
  remove(id, isUpdateAllLeftSum) {
22
64
  const deletedResults = super.remove(id, isUpdateAllLeftSum);
23
65
  for (const { needBalanced } of deletedResults) {
24
66
  if (needBalanced) {
25
- this.balancePath(needBalanced);
67
+ this._balancePath(needBalanced);
26
68
  }
27
69
  }
28
70
  return deletedResults;
29
71
  }
30
- balanceFactor(node) {
72
+ /**
73
+ * The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
74
+ * height of its right subtree.
75
+ * @param node - The parameter "node" is of type N, which represents a node in an AVL tree.
76
+ * @returns The balance factor of the given AVL tree node.
77
+ */
78
+ _balanceFactor(node) {
31
79
  if (!node.right) // node has no right subtree
32
80
  return -node.height;
33
81
  else if (!node.left) // node has no left subtree
@@ -35,7 +83,11 @@ class AVLTree extends bst_1.BST {
35
83
  else
36
84
  return node.right.height - node.left.height;
37
85
  }
38
- updateHeight(node) {
86
+ /**
87
+ * The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.
88
+ * @param node - The parameter `node` is an AVLTreeNode object, which represents a node in an AVL tree.
89
+ */
90
+ _updateHeight(node) {
39
91
  if (!node.left && !node.right) // node is a leaf
40
92
  node.height = 0;
41
93
  else if (!node.left) {
@@ -48,35 +100,44 @@ class AVLTree extends bst_1.BST {
48
100
  else
49
101
  node.height = 1 + Math.max(node.right.height, node.left.height);
50
102
  }
51
- balancePath(node) {
103
+ /**
104
+ * The `_balancePath` function balances the AVL tree by performing appropriate rotations based on the balance factor of
105
+ * each node in the path from the given node to the root.
106
+ * @param node - The `node` parameter is an AVLTreeNode object, which represents a node in an AVL tree.
107
+ */
108
+ _balancePath(node) {
52
109
  const path = this.getPathToRoot(node);
53
110
  for (let i = path.length - 1; i >= 0; i--) {
54
111
  const A = path[i];
55
- this.updateHeight(A);
56
- switch (this.balanceFactor(A)) {
112
+ this._updateHeight(A);
113
+ switch (this._balanceFactor(A)) {
57
114
  case -2:
58
115
  if (A && A.left) {
59
- if (this.balanceFactor(A.left) <= 0) {
60
- this.balanceLL(A); // Perform LL rotation
116
+ if (this._balanceFactor(A.left) <= 0) {
117
+ this._balanceLL(A); // Perform LL rotation
61
118
  }
62
119
  else {
63
- this.balanceLR(A); // Perform LR rotation
120
+ this._balanceLR(A); // Perform LR rotation
64
121
  }
65
122
  }
66
123
  break;
67
124
  case +2:
68
125
  if (A && A.right) {
69
- if (this.balanceFactor(A.right) >= 0) {
70
- this.balanceRR(A); // Perform RR rotation
126
+ if (this._balanceFactor(A.right) >= 0) {
127
+ this._balanceRR(A); // Perform RR rotation
71
128
  }
72
129
  else {
73
- this.balanceRL(A); // Perform RL rotation
130
+ this._balanceRL(A); // Perform RL rotation
74
131
  }
75
132
  }
76
133
  }
77
134
  }
78
135
  }
79
- balanceLL(A) {
136
+ /**
137
+ * The `_balanceLL` function performs a left-left rotation on an AVL tree to balance it.
138
+ * @param A - The parameter A is an AVLTreeNode object.
139
+ */
140
+ _balanceLL(A) {
80
141
  const parentOfA = A.parent;
81
142
  const B = A.left; // A is left-heavy and B is left-heavy
82
143
  A.parent = B;
@@ -87,7 +148,7 @@ class AVLTree extends bst_1.BST {
87
148
  B.parent = parentOfA;
88
149
  if (A === this.root) {
89
150
  if (B)
90
- this.root = B;
151
+ this._setRoot(B);
91
152
  }
92
153
  else {
93
154
  if ((parentOfA === null || parentOfA === void 0 ? void 0 : parentOfA.left) === A) {
@@ -102,11 +163,15 @@ class AVLTree extends bst_1.BST {
102
163
  A.left = B.right; // Make T2 the left subtree of A
103
164
  B.right = A; // Make A the left child of B
104
165
  }
105
- this.updateHeight(A);
166
+ this._updateHeight(A);
106
167
  if (B)
107
- this.updateHeight(B);
168
+ this._updateHeight(B);
108
169
  }
109
- balanceLR(A) {
170
+ /**
171
+ * The `_balanceLR` function performs a left-right rotation to balance an AVL tree.
172
+ * @param A - A is an AVLTreeNode object.
173
+ */
174
+ _balanceLR(A) {
110
175
  const parentOfA = A.parent;
111
176
  const B = A.left; // A is left-heavy
112
177
  let C = null;
@@ -128,7 +193,7 @@ class AVLTree extends bst_1.BST {
128
193
  }
129
194
  if (A === this.root) {
130
195
  if (C)
131
- this.root = C;
196
+ this._setRoot(C);
132
197
  }
133
198
  else {
134
199
  if (parentOfA) {
@@ -147,11 +212,15 @@ class AVLTree extends bst_1.BST {
147
212
  C.left = B;
148
213
  C.right = A;
149
214
  }
150
- this.updateHeight(A); // Adjust heights
151
- B && this.updateHeight(B);
152
- C && this.updateHeight(C);
215
+ this._updateHeight(A); // Adjust heights
216
+ B && this._updateHeight(B);
217
+ C && this._updateHeight(C);
153
218
  }
154
- balanceRR(A) {
219
+ /**
220
+ * The `_balanceRR` function performs a right-right rotation on an AVL tree to balance it.
221
+ * @param A - The parameter A is an AVLTreeNode object.
222
+ */
223
+ _balanceRR(A) {
155
224
  const parentOfA = A.parent;
156
225
  const B = A.right; // A is right-heavy and B is right-heavy
157
226
  A.parent = B;
@@ -163,7 +232,7 @@ class AVLTree extends bst_1.BST {
163
232
  }
164
233
  if (A === this.root) {
165
234
  if (B)
166
- this.root = B;
235
+ this._setRoot(B);
167
236
  }
168
237
  else {
169
238
  if (parentOfA) {
@@ -179,10 +248,14 @@ class AVLTree extends bst_1.BST {
179
248
  A.right = B.left; // Make T2 the right subtree of A
180
249
  B.left = A;
181
250
  }
182
- this.updateHeight(A);
183
- B && this.updateHeight(B);
251
+ this._updateHeight(A);
252
+ B && this._updateHeight(B);
184
253
  }
185
- balanceRL(A) {
254
+ /**
255
+ * The `_balanceRL` function performs a right-left rotation to balance an AVL tree.
256
+ * @param A - A is an AVLTreeNode object.
257
+ */
258
+ _balanceRL(A) {
186
259
  const parentOfA = A.parent;
187
260
  const B = A.right; // A is right-heavy
188
261
  let C = null;
@@ -203,7 +276,7 @@ class AVLTree extends bst_1.BST {
203
276
  }
204
277
  if (A === this.root) {
205
278
  if (C)
206
- this.root = C;
279
+ this._setRoot(C);
207
280
  }
208
281
  else {
209
282
  if (parentOfA) {
@@ -223,9 +296,9 @@ class AVLTree extends bst_1.BST {
223
296
  C.left = A;
224
297
  if (C)
225
298
  C.right = B;
226
- this.updateHeight(A); // Adjust heights
227
- B && this.updateHeight(B);
228
- C && this.updateHeight(C);
299
+ this._updateHeight(A); // Adjust heights
300
+ B && this._updateHeight(B);
301
+ C && this._updateHeight(C);
229
302
  }
230
303
  }
231
304
  exports.AVLTree = AVLTree;
@@ -1,8 +1,46 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
1
8
  export declare class BinaryIndexedTree {
2
- private readonly _sumTree;
9
+ /**
10
+ * The constructor initializes an array with a specified length and fills it with zeros.
11
+ * @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The
12
+ * sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array.
13
+ * The size of the sum tree array is `n + 1` because
14
+ */
3
15
  constructor(n: number);
16
+ private _sumTree;
17
+ get sumTree(): number[];
18
+ static lowBit(x: number): number;
19
+ /**
20
+ * The update function updates the values in a binary indexed tree by adding a delta value to the specified index and
21
+ * its ancestors.
22
+ * @param {number} i - The parameter `i` represents the index of the element in the `_sumTree` array that needs to be
23
+ * updated.
24
+ * @param {number} delta - The "delta" parameter represents the change in value that needs to be added to the element
25
+ * at index "i" in the "_sumTree" array.
26
+ */
4
27
  update(i: number, delta: number): void;
28
+ /**
29
+ * The function calculates the prefix sum of an array using a binary indexed tree.
30
+ * @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
31
+ * array for which we want to calculate the prefix sum.
32
+ * @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
33
+ * `i`.
34
+ */
5
35
  getPrefixSum(i: number): number;
36
+ /**
37
+ * The function `getRangeSum` calculates the sum of a range of numbers in an array.
38
+ * @param {number} start - The start parameter is the starting index of the range for which we want to calculate the
39
+ * sum.
40
+ * @param {number} end - The "end" parameter represents the ending index of the range for which we want to calculate
41
+ * the sum.
42
+ * @returns the sum of the elements in the range specified by the start and end indices.
43
+ */
6
44
  getRangeSum(start: number, end: number): number;
7
- static lowBit(x: number): number;
45
+ protected _setSumTree(value: number[]): void;
8
46
  }
@@ -1,16 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BinaryIndexedTree = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  class BinaryIndexedTree {
12
+ /**
13
+ * The constructor initializes an array with a specified length and fills it with zeros.
14
+ * @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The
15
+ * sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array.
16
+ * The size of the sum tree array is `n + 1` because
17
+ */
5
18
  constructor(n) {
6
19
  this._sumTree = new Array(n + 1).fill(0);
7
20
  }
21
+ get sumTree() {
22
+ return this._sumTree;
23
+ }
24
+ static lowBit(x) {
25
+ return x & (-x);
26
+ }
27
+ /**
28
+ * The update function updates the values in a binary indexed tree by adding a delta value to the specified index and
29
+ * its ancestors.
30
+ * @param {number} i - The parameter `i` represents the index of the element in the `_sumTree` array that needs to be
31
+ * updated.
32
+ * @param {number} delta - The "delta" parameter represents the change in value that needs to be added to the element
33
+ * at index "i" in the "_sumTree" array.
34
+ */
8
35
  update(i, delta) {
9
36
  while (i < this._sumTree.length) {
10
37
  this._sumTree[i] += delta;
11
38
  i += BinaryIndexedTree.lowBit(i);
12
39
  }
13
40
  }
41
+ /**
42
+ * The function calculates the prefix sum of an array using a binary indexed tree.
43
+ * @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
44
+ * array for which we want to calculate the prefix sum.
45
+ * @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
46
+ * `i`.
47
+ */
14
48
  getPrefixSum(i) {
15
49
  let sum = 0;
16
50
  while (i > 0) {
@@ -19,13 +53,21 @@ class BinaryIndexedTree {
19
53
  }
20
54
  return sum;
21
55
  }
56
+ /**
57
+ * The function `getRangeSum` calculates the sum of a range of numbers in an array.
58
+ * @param {number} start - The start parameter is the starting index of the range for which we want to calculate the
59
+ * sum.
60
+ * @param {number} end - The "end" parameter represents the ending index of the range for which we want to calculate
61
+ * the sum.
62
+ * @returns the sum of the elements in the range specified by the start and end indices.
63
+ */
22
64
  getRangeSum(start, end) {
23
65
  if (!(0 <= start && start <= end && end <= this._sumTree.length))
24
66
  throw 'Index out of bounds';
25
67
  return this.getPrefixSum(end) - this.getPrefixSum(start);
26
68
  }
27
- static lowBit(x) {
28
- return x & (-x);
69
+ _setSumTree(value) {
70
+ this._sumTree = value;
29
71
  }
30
72
  }
31
73
  exports.BinaryIndexedTree = BinaryIndexedTree;
@@ -1,140 +1,31 @@
1
- export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
2
- export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
3
- export type DFSOrderPattern = 'in' | 'pre' | 'post';
4
- export type BinaryTreeNodeId = number;
5
- export type BinaryTreeDeleted<T> = {
6
- deleted: BinaryTreeNode<T> | null | undefined;
7
- needBalanced: BinaryTreeNode<T> | null;
8
- };
9
- export type ResultByProperty<T> = T | BinaryTreeNode<T> | number | BinaryTreeNodeId;
10
- export type ResultsByProperty<T> = ResultByProperty<T>[];
11
- export interface BinaryTreeNodeObj<T> {
12
- id: BinaryTreeNodeId;
13
- val: T;
14
- count?: number;
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { BinaryTreeNodeId, BinaryTreeNodeNested, BinaryTreeOptions } from '../../types';
9
+ import { AbstractBinaryTree, AbstractBinaryTreeNode } from './abstract-binary-tree';
10
+ import { IBinaryTree, IBinaryTreeNode } from '../../interfaces';
11
+ export declare class BinaryTreeNode<T = any, NEIGHBOR extends BinaryTreeNode<T, NEIGHBOR> = BinaryTreeNodeNested<T>> extends AbstractBinaryTreeNode<T, NEIGHBOR> implements IBinaryTreeNode<T, NEIGHBOR> {
12
+ constructor(id: BinaryTreeNodeId, val?: T);
15
13
  }
16
- export declare enum FamilyPosition {
17
- root = 0,
18
- left = 1,
19
- right = 2
20
- }
21
- export declare enum LoopType {
22
- iterative = 1,
23
- recursive = 2
24
- }
25
- export declare class BinaryTreeNode<T> {
26
- protected _id: BinaryTreeNodeId;
27
- get id(): BinaryTreeNodeId;
28
- set id(v: BinaryTreeNodeId);
29
- protected _val: T;
30
- get val(): T;
31
- set val(v: T);
32
- protected _left?: BinaryTreeNode<T> | null;
33
- get left(): BinaryTreeNode<T> | null | undefined;
34
- set left(v: BinaryTreeNode<T> | null | undefined);
35
- protected _right?: BinaryTreeNode<T> | null;
36
- get right(): BinaryTreeNode<T> | null | undefined;
37
- set right(v: BinaryTreeNode<T> | null | undefined);
38
- protected _parent: BinaryTreeNode<T> | null | undefined;
39
- get parent(): BinaryTreeNode<T> | null | undefined;
40
- set parent(v: BinaryTreeNode<T> | null | undefined);
41
- protected _familyPosition: FamilyPosition;
42
- get familyPosition(): FamilyPosition;
43
- set familyPosition(v: FamilyPosition);
44
- protected _count: number;
45
- get count(): number;
46
- set count(v: number);
47
- protected _height: number;
48
- get height(): number;
49
- set height(v: number);
50
- constructor(id: BinaryTreeNodeId, val: T, count?: number);
51
- swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T>;
52
- clone(): BinaryTreeNode<T>;
53
- }
54
- export declare class BinaryTree<T> {
55
- protected _root: BinaryTreeNode<T> | null;
56
- get root(): BinaryTreeNode<T> | null;
57
- protected set root(v: BinaryTreeNode<T> | null);
58
- protected _size: number;
59
- get size(): number;
60
- protected set size(v: number);
61
- protected _count: number;
62
- get count(): number;
63
- protected set count(v: number);
64
- private readonly _autoIncrementId;
65
- private _maxId;
66
- private readonly _isDuplicatedVal;
67
- protected _loopType: LoopType;
68
- protected _visitedId: BinaryTreeNodeId[];
69
- protected _visitedVal: Array<T>;
70
- protected _visitedNode: BinaryTreeNode<T>[];
71
- protected _visitedCount: number[];
72
- protected _visitedLeftSum: number[];
73
- protected _resetResults(): void;
74
- constructor(options?: {
75
- loopType?: LoopType;
76
- autoIncrementId?: boolean;
77
- isDuplicatedVal?: boolean;
78
- });
79
- createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BinaryTreeNode<T> | null;
80
- clear(): void;
81
- isEmpty(): boolean;
82
- insertTo({ newNode, parent }: {
83
- newNode: BinaryTreeNode<T> | null;
84
- parent: BinaryTreeNode<T>;
85
- }): BinaryTreeNode<T> | null | undefined;
86
- put(id: BinaryTreeNodeId, val: T, count?: number): BinaryTreeNode<T> | null | undefined;
87
- insertMany(data: T[] | BinaryTreeNode<T>[]): (BinaryTreeNode<T> | null | undefined)[];
88
- fill(data: T[] | BinaryTreeNode<T>[]): boolean;
89
- remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeleted<T>[];
90
- getDepth(node: BinaryTreeNode<T>): number;
91
- getHeight(beginRoot?: BinaryTreeNode<T> | null): number;
92
- getMinHeight(beginRoot?: BinaryTreeNode<T> | null): number;
93
- isBalanced(beginRoot?: BinaryTreeNode<T> | null): boolean;
94
- getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): (BinaryTreeNode<T> | null | undefined)[];
95
- has(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): boolean;
96
- get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BinaryTreeNode<T> | null;
97
- getPathToRoot(node: BinaryTreeNode<T>): BinaryTreeNode<T>[];
98
- protected _pushByPropertyNameStopOrNot(cur: BinaryTreeNode<T>, result: (BinaryTreeNode<T> | null | undefined)[], nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
99
- protected _accumulatedByPropertyName(node: BinaryTreeNode<T>, nodeOrPropertyName?: NodeOrPropertyName): void;
100
- protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): ResultsByProperty<T>;
101
- getLeftMost(): BinaryTreeNode<T> | null;
102
- getLeftMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
103
- getRightMost(): BinaryTreeNode<T> | null;
104
- getRightMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
105
- isBST(node?: BinaryTreeNode<T> | null): boolean;
106
- getSubTreeSizeAndCount(subTreeRoot: BinaryTreeNode<T> | null | undefined): [number, number];
107
- subTreeSum(subTreeRoot: BinaryTreeNode<T>, propertyName?: BinaryTreeNodePropertyName): number;
108
- subTreeAdd(subTreeRoot: BinaryTreeNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
109
- BFS(): BinaryTreeNodeId[];
110
- BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
111
- BFS(nodeOrPropertyName: 'val'): T[];
112
- BFS(nodeOrPropertyName: 'node'): BinaryTreeNode<T>[];
113
- BFS(nodeOrPropertyName: 'count'): number[];
114
- DFS(): BinaryTreeNodeId[];
115
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
116
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
117
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
118
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
119
- DFSIterative(): BinaryTreeNodeId[];
120
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
121
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
122
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
123
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
124
- levelIterative(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[];
125
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
126
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[];
127
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
128
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[];
129
- listLevels(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[][];
130
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
131
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[][];
132
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[][];
133
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[][];
134
- getPredecessor(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
135
- morris(): BinaryTreeNodeId[];
136
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
137
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
138
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
139
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
14
+ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode> extends AbstractBinaryTree<N> implements IBinaryTree<N> {
15
+ /**
16
+ * This is a constructor function for a binary tree class that takes an optional options parameter.
17
+ * @param {BinaryTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
18
+ * constructor of the `BinaryTree` class. It allows you to customize the behavior of the binary tree by providing
19
+ * different configuration options.
20
+ */
21
+ constructor(options?: BinaryTreeOptions);
22
+ /**
23
+ * The function creates a new binary tree node with an optional value.
24
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
25
+ * `BinaryTreeNodeId`, which represents the unique identifier for each node in the binary tree.
26
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
27
+ * stored in the node.
28
+ * @returns a new instance of a BinaryTreeNode with the specified id and value.
29
+ */
30
+ createNode(id: BinaryTreeNodeId, val?: N['val']): N;
140
31
  }