red-black-tree-typed 2.1.1 → 2.2.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 (288) hide show
  1. package/dist/cjs/index.cjs +4017 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/cjs-legacy/index.cjs +4019 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -0
  5. package/dist/esm/index.mjs +4008 -0
  6. package/dist/esm/index.mjs.map +1 -0
  7. package/dist/esm-legacy/index.mjs +4010 -0
  8. package/dist/esm-legacy/index.mjs.map +1 -0
  9. package/dist/types/data-structures/base/index.d.ts +2 -1
  10. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +236 -2
  11. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +197 -2
  12. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +345 -2
  13. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
  14. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
  15. package/dist/types/data-structures/binary-tree/bst.d.ts +467 -12
  16. package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
  17. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +262 -3
  18. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
  19. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +244 -2
  20. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +332 -2
  21. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
  22. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
  23. package/dist/types/data-structures/graph/index.d.ts +2 -1
  24. package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
  25. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
  26. package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
  27. package/dist/types/data-structures/hash/index.d.ts +0 -1
  28. package/dist/types/data-structures/heap/heap.d.ts +503 -5
  29. package/dist/types/data-structures/heap/index.d.ts +2 -0
  30. package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
  31. package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
  32. package/dist/types/data-structures/index.d.ts +7 -7
  33. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
  34. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
  35. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
  36. package/dist/types/data-structures/matrix/index.d.ts +1 -1
  37. package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
  38. package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
  39. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
  40. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
  41. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
  42. package/dist/types/data-structures/queue/deque.d.ts +431 -4
  43. package/dist/types/data-structures/queue/queue.d.ts +308 -4
  44. package/dist/types/data-structures/stack/stack.d.ts +306 -2
  45. package/dist/types/data-structures/tree/tree.d.ts +62 -1
  46. package/dist/types/data-structures/trie/trie.d.ts +350 -4
  47. package/dist/types/index.d.ts +15 -2
  48. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +1 -1
  49. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  51. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  52. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  53. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  54. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  55. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  56. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  57. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  58. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  59. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  60. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  61. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  62. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  63. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  64. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  65. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  66. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  67. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  68. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  69. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  70. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  71. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  72. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  73. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  74. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  75. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  76. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  77. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  78. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  79. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  80. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  81. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  82. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  83. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  84. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  85. package/dist/types/types/index.d.ts +3 -0
  86. package/dist/types/types/utils/index.d.ts +2 -0
  87. package/dist/types/types/utils/utils.d.ts +22 -0
  88. package/dist/types/utils/index.d.ts +1 -1
  89. package/dist/types/utils/utils.d.ts +209 -22
  90. package/dist/umd/red-black-tree-typed.js +4012 -0
  91. package/dist/umd/red-black-tree-typed.js.map +1 -0
  92. package/dist/umd/red-black-tree-typed.min.js +13 -0
  93. package/dist/umd/red-black-tree-typed.min.js.map +1 -0
  94. package/package.json +43 -5
  95. package/src/data-structures/binary-tree/avl-tree-counter.ts +106 -15
  96. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
  97. package/src/data-structures/binary-tree/avl-tree.ts +107 -16
  98. package/src/data-structures/binary-tree/binary-tree.ts +4 -4
  99. package/src/data-structures/binary-tree/bst.ts +103 -12
  100. package/src/data-structures/binary-tree/red-black-tree.ts +110 -20
  101. package/src/data-structures/binary-tree/tree-counter.ts +105 -14
  102. package/src/data-structures/binary-tree/tree-multi-map.ts +123 -12
  103. package/src/data-structures/graph/abstract-graph.ts +5 -5
  104. package/src/data-structures/graph/directed-graph.ts +5 -5
  105. package/src/data-structures/graph/undirected-graph.ts +5 -5
  106. package/src/data-structures/heap/heap.ts +5 -5
  107. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  108. package/src/interfaces/binary-tree.ts +1 -1
  109. package/tsconfig.base.json +23 -0
  110. package/tsconfig.json +8 -34
  111. package/tsconfig.test.json +8 -0
  112. package/tsconfig.types.json +15 -0
  113. package/tsup.config.js +28 -0
  114. package/tsup.node.config.js +71 -0
  115. package/dist/common/index.js +0 -28
  116. package/dist/constants/index.js +0 -8
  117. package/dist/data-structures/base/index.d.ts +0 -2
  118. package/dist/data-structures/base/index.js +0 -18
  119. package/dist/data-structures/base/iterable-element-base.js +0 -243
  120. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  121. package/dist/data-structures/base/linear-base.js +0 -415
  122. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  123. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  124. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  125. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  126. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  127. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  128. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  129. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  130. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  131. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  132. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  133. package/dist/data-structures/binary-tree/bst.js +0 -903
  134. package/dist/data-structures/binary-tree/index.js +0 -26
  135. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  136. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  137. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  138. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  139. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  140. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  141. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  142. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  143. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  144. package/dist/data-structures/graph/abstract-graph.js +0 -896
  145. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  146. package/dist/data-structures/graph/directed-graph.js +0 -525
  147. package/dist/data-structures/graph/index.js +0 -20
  148. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  149. package/dist/data-structures/graph/map-graph.js +0 -107
  150. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  151. package/dist/data-structures/graph/undirected-graph.js +0 -424
  152. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  153. package/dist/data-structures/hash/hash-map.js +0 -692
  154. package/dist/data-structures/hash/index.d.ts +0 -1
  155. package/dist/data-structures/hash/index.js +0 -17
  156. package/dist/data-structures/heap/heap.d.ts +0 -503
  157. package/dist/data-structures/heap/heap.js +0 -901
  158. package/dist/data-structures/heap/index.d.ts +0 -3
  159. package/dist/data-structures/heap/index.js +0 -19
  160. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  161. package/dist/data-structures/heap/max-heap.js +0 -40
  162. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  163. package/dist/data-structures/heap/min-heap.js +0 -31
  164. package/dist/data-structures/index.js +0 -28
  165. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  166. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  167. package/dist/data-structures/linked-list/index.js +0 -19
  168. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  169. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  170. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  171. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  172. package/dist/data-structures/matrix/index.js +0 -18
  173. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  174. package/dist/data-structures/matrix/matrix.js +0 -448
  175. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  176. package/dist/data-structures/matrix/navigator.js +0 -111
  177. package/dist/data-structures/priority-queue/index.js +0 -19
  178. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  179. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  180. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  181. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  182. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  183. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  184. package/dist/data-structures/queue/deque.d.ts +0 -431
  185. package/dist/data-structures/queue/deque.js +0 -879
  186. package/dist/data-structures/queue/index.js +0 -18
  187. package/dist/data-structures/queue/queue.d.ts +0 -308
  188. package/dist/data-structures/queue/queue.js +0 -473
  189. package/dist/data-structures/stack/index.js +0 -17
  190. package/dist/data-structures/stack/stack.d.ts +0 -306
  191. package/dist/data-structures/stack/stack.js +0 -401
  192. package/dist/data-structures/tree/index.js +0 -17
  193. package/dist/data-structures/tree/tree.d.ts +0 -62
  194. package/dist/data-structures/tree/tree.js +0 -107
  195. package/dist/data-structures/trie/index.js +0 -17
  196. package/dist/data-structures/trie/trie.d.ts +0 -350
  197. package/dist/data-structures/trie/trie.js +0 -610
  198. package/dist/index.d.ts +0 -16
  199. package/dist/index.js +0 -32
  200. package/dist/interfaces/binary-tree.js +0 -2
  201. package/dist/interfaces/doubly-linked-list.js +0 -2
  202. package/dist/interfaces/graph.js +0 -2
  203. package/dist/interfaces/heap.js +0 -2
  204. package/dist/interfaces/index.js +0 -24
  205. package/dist/interfaces/navigator.js +0 -2
  206. package/dist/interfaces/priority-queue.js +0 -2
  207. package/dist/interfaces/segment-tree.js +0 -2
  208. package/dist/interfaces/singly-linked-list.js +0 -2
  209. package/dist/types/common.js +0 -2
  210. package/dist/types/data-structures/base/base.js +0 -2
  211. package/dist/types/data-structures/base/index.js +0 -17
  212. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  213. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  214. package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
  215. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  216. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
  217. package/dist/types/data-structures/binary-tree/bst.js +0 -2
  218. package/dist/types/data-structures/binary-tree/index.js +0 -25
  219. package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
  220. package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
  221. package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
  222. package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  223. package/dist/types/data-structures/graph/abstract-graph.js +0 -2
  224. package/dist/types/data-structures/graph/directed-graph.js +0 -2
  225. package/dist/types/data-structures/graph/index.js +0 -19
  226. package/dist/types/data-structures/graph/map-graph.js +0 -2
  227. package/dist/types/data-structures/graph/undirected-graph.js +0 -2
  228. package/dist/types/data-structures/hash/hash-map.js +0 -2
  229. package/dist/types/data-structures/hash/index.js +0 -17
  230. package/dist/types/data-structures/heap/heap.js +0 -2
  231. package/dist/types/data-structures/heap/index.js +0 -17
  232. package/dist/types/data-structures/heap/max-heap.js +0 -2
  233. package/dist/types/data-structures/heap/min-heap.js +0 -2
  234. package/dist/types/data-structures/index.js +0 -28
  235. package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  236. package/dist/types/data-structures/linked-list/index.js +0 -19
  237. package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
  238. package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
  239. package/dist/types/data-structures/matrix/index.js +0 -18
  240. package/dist/types/data-structures/matrix/matrix.js +0 -2
  241. package/dist/types/data-structures/matrix/navigator.js +0 -2
  242. package/dist/types/data-structures/priority-queue/index.js +0 -19
  243. package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  244. package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  245. package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
  246. package/dist/types/data-structures/queue/deque.js +0 -2
  247. package/dist/types/data-structures/queue/index.js +0 -18
  248. package/dist/types/data-structures/queue/queue.js +0 -2
  249. package/dist/types/data-structures/stack/index.js +0 -17
  250. package/dist/types/data-structures/stack/stack.js +0 -2
  251. package/dist/types/data-structures/tree/index.js +0 -17
  252. package/dist/types/data-structures/tree/tree.js +0 -2
  253. package/dist/types/data-structures/trie/index.js +0 -17
  254. package/dist/types/data-structures/trie/trie.js +0 -2
  255. package/dist/types/index.js +0 -19
  256. package/dist/types/utils/index.js +0 -18
  257. package/dist/types/utils/utils.js +0 -2
  258. package/dist/types/utils/validate-type.js +0 -2
  259. package/dist/utils/index.d.ts +0 -2
  260. package/dist/utils/index.js +0 -18
  261. package/dist/utils/number.js +0 -24
  262. package/dist/utils/utils.d.ts +0 -209
  263. package/dist/utils/utils.js +0 -353
  264. package/dist/{common → types/common}/index.d.ts +0 -0
  265. package/dist/{constants → types/constants}/index.d.ts +0 -0
  266. package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
  267. package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
  268. package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
  269. package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
  270. package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
  271. package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
  272. package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
  273. package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
  274. package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
  275. package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
  276. package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
  277. package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
  278. package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
  279. package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
  280. package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
  281. package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
  282. /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
  283. /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
  284. /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
  285. /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
  286. /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
  287. /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
  288. /package/dist/{utils → types/utils}/number.d.ts +0 -0
@@ -1,2 +1,345 @@
1
- import { BSTOptions } from './bst';
2
- export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import { BST } from './bst';
9
+ import type { AVLTreeOptions, BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, FamilyPosition, IterationType, RBTNColor } from '../../types';
10
+ import { BSTOptions } from '../../types';
11
+ import { IBinaryTree } from '../../interfaces';
12
+ /**
13
+ * Represents a Node in an AVL (Adelson-Velsky and Landis) Tree.
14
+ * It extends a BSTNode and ensures the 'height' property is maintained.
15
+ *
16
+ * @template K - The type of the key.
17
+ * @template V - The type of the value.
18
+ */
19
+ export declare class AVLTreeNode<K = any, V = any> {
20
+ key: K;
21
+ value?: V;
22
+ parent?: AVLTreeNode<K, V>;
23
+ /**
24
+ * Creates an instance of AVLTreeNode.
25
+ * @remarks Time O(1), Space O(1)
26
+ *
27
+ * @param key - The key of the node.
28
+ * @param [value] - The value associated with the key.
29
+ */
30
+ constructor(key: K, value?: V);
31
+ _left?: AVLTreeNode<K, V> | null | undefined;
32
+ /**
33
+ * Gets the left child of the node.
34
+ * @remarks Time O(1), Space O(1)
35
+ *
36
+ * @returns The left child.
37
+ */
38
+ get left(): AVLTreeNode<K, V> | null | undefined;
39
+ /**
40
+ * Sets the left child of the node and updates its parent reference.
41
+ * @remarks Time O(1), Space O(1)
42
+ *
43
+ * @param v - The node to set as the left child.
44
+ */
45
+ set left(v: AVLTreeNode<K, V> | null | undefined);
46
+ _right?: AVLTreeNode<K, V> | null | undefined;
47
+ /**
48
+ * Gets the right child of the node.
49
+ * @remarks Time O(1), Space O(1)
50
+ *
51
+ * @returns The right child.
52
+ */
53
+ get right(): AVLTreeNode<K, V> | null | undefined;
54
+ /**
55
+ * Sets the right child of the node and updates its parent reference.
56
+ * @remarks Time O(1), Space O(1)
57
+ *
58
+ * @param v - The node to set as the right child.
59
+ */
60
+ set right(v: AVLTreeNode<K, V> | null | undefined);
61
+ _height: number;
62
+ /**
63
+ * Gets the height of the node (used in self-balancing trees).
64
+ * @remarks Time O(1), Space O(1)
65
+ *
66
+ * @returns The height.
67
+ */
68
+ get height(): number;
69
+ /**
70
+ * Sets the height of the node.
71
+ * @remarks Time O(1), Space O(1)
72
+ *
73
+ * @param value - The new height.
74
+ */
75
+ set height(value: number);
76
+ _color: RBTNColor;
77
+ /**
78
+ * Gets the color of the node (used in Red-Black trees).
79
+ * @remarks Time O(1), Space O(1)
80
+ *
81
+ * @returns The node's color.
82
+ */
83
+ get color(): RBTNColor;
84
+ /**
85
+ * Sets the color of the node.
86
+ * @remarks Time O(1), Space O(1)
87
+ *
88
+ * @param value - The new color.
89
+ */
90
+ set color(value: RBTNColor);
91
+ _count: number;
92
+ /**
93
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
94
+ * @remarks Time O(1), Space O(1)
95
+ *
96
+ * @returns The subtree node count.
97
+ */
98
+ get count(): number;
99
+ /**
100
+ * Sets the count of nodes in the subtree.
101
+ * @remarks Time O(1), Space O(1)
102
+ *
103
+ * @param value - The new count.
104
+ */
105
+ set count(value: number);
106
+ /**
107
+ * Gets the position of the node relative to its parent.
108
+ * @remarks Time O(1), Space O(1)
109
+ *
110
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
111
+ */
112
+ get familyPosition(): FamilyPosition;
113
+ }
114
+ /**
115
+ * Represents a self-balancing AVL (Adelson-Velsky and Landis) Tree.
116
+ * This tree extends BST and performs rotations on add/delete to maintain balance.
117
+ *
118
+ * @template K - The type of the key.
119
+ * @template V - The type of the value.
120
+ * @template R - The type of the raw data object (if using `toEntryFn`).
121
+ *
122
+ * 1. Height-Balanced: Each node's left and right subtrees differ in height by no more than one.
123
+ * 2. Automatic Rebalancing: AVL trees rebalance themselves automatically during insertions and deletions.
124
+ * 3. Rotations for Balancing: Utilizes rotations (single or double) to maintain balance after updates.
125
+ * 4. Order Preservation: Maintains the binary search tree property where left child values are less than the parent, and right child values are greater.
126
+ * 5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
127
+ * 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
128
+ * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.@example
129
+ * // Find elements in a range
130
+ * // In interval queries, AVL trees, with their strictly balanced structure and lower height, offer better query efficiency, making them ideal for frequent and high-performance interval queries. In contrast, Red-Black trees, with lower update costs, are more suitable for scenarios involving frequent insertions and deletions where the requirements for interval queries are less demanding.
131
+ * type Datum = { timestamp: Date; temperature: number };
132
+ * // Fixed dataset of CPU temperature readings
133
+ * const cpuData: Datum[] = [
134
+ * { timestamp: new Date('2024-12-02T00:00:00'), temperature: 55.1 },
135
+ * { timestamp: new Date('2024-12-02T00:01:00'), temperature: 56.3 },
136
+ * { timestamp: new Date('2024-12-02T00:02:00'), temperature: 54.8 },
137
+ * { timestamp: new Date('2024-12-02T00:03:00'), temperature: 57.2 },
138
+ * { timestamp: new Date('2024-12-02T00:04:00'), temperature: 58.0 },
139
+ * { timestamp: new Date('2024-12-02T00:05:00'), temperature: 59.4 },
140
+ * { timestamp: new Date('2024-12-02T00:06:00'), temperature: 60.1 },
141
+ * { timestamp: new Date('2024-12-02T00:07:00'), temperature: 61.3 },
142
+ * { timestamp: new Date('2024-12-02T00:08:00'), temperature: 62.0 },
143
+ * { timestamp: new Date('2024-12-02T00:09:00'), temperature: 63.5 },
144
+ * { timestamp: new Date('2024-12-02T00:10:00'), temperature: 64.0 },
145
+ * { timestamp: new Date('2024-12-02T00:11:00'), temperature: 62.8 },
146
+ * { timestamp: new Date('2024-12-02T00:12:00'), temperature: 61.5 },
147
+ * { timestamp: new Date('2024-12-02T00:13:00'), temperature: 60.2 },
148
+ * { timestamp: new Date('2024-12-02T00:14:00'), temperature: 59.8 },
149
+ * { timestamp: new Date('2024-12-02T00:15:00'), temperature: 58.6 },
150
+ * { timestamp: new Date('2024-12-02T00:16:00'), temperature: 57.4 },
151
+ * { timestamp: new Date('2024-12-02T00:17:00'), temperature: 56.2 },
152
+ * { timestamp: new Date('2024-12-02T00:18:00'), temperature: 55.7 },
153
+ * { timestamp: new Date('2024-12-02T00:19:00'), temperature: 54.5 },
154
+ * { timestamp: new Date('2024-12-02T00:20:00'), temperature: 53.2 },
155
+ * { timestamp: new Date('2024-12-02T00:21:00'), temperature: 52.8 },
156
+ * { timestamp: new Date('2024-12-02T00:22:00'), temperature: 51.9 },
157
+ * { timestamp: new Date('2024-12-02T00:23:00'), temperature: 50.5 },
158
+ * { timestamp: new Date('2024-12-02T00:24:00'), temperature: 49.8 },
159
+ * { timestamp: new Date('2024-12-02T00:25:00'), temperature: 48.7 },
160
+ * { timestamp: new Date('2024-12-02T00:26:00'), temperature: 47.5 },
161
+ * { timestamp: new Date('2024-12-02T00:27:00'), temperature: 46.3 },
162
+ * { timestamp: new Date('2024-12-02T00:28:00'), temperature: 45.9 },
163
+ * { timestamp: new Date('2024-12-02T00:29:00'), temperature: 45.0 }
164
+ * ];
165
+ *
166
+ * // Create an AVL tree to store CPU temperature data
167
+ * const cpuTemperatureTree = new AVLTree<Date, number, Datum>(cpuData, {
168
+ * toEntryFn: ({ timestamp, temperature }) => [timestamp, temperature]
169
+ * });
170
+ *
171
+ * // Query a specific time range (e.g., from 00:05 to 00:15)
172
+ * const rangeStart = new Date('2024-12-02T00:05:00');
173
+ * const rangeEnd = new Date('2024-12-02T00:15:00');
174
+ * const rangeResults = cpuTemperatureTree.rangeSearch([rangeStart, rangeEnd], node => ({
175
+ * minute: node ? node.key.getMinutes() : 0,
176
+ * temperature: cpuTemperatureTree.get(node ? node.key : undefined)
177
+ * }));
178
+ *
179
+ * console.log(rangeResults); // [
180
+ * // { minute: 5, temperature: 59.4 },
181
+ * // { minute: 6, temperature: 60.1 },
182
+ * // { minute: 7, temperature: 61.3 },
183
+ * // { minute: 8, temperature: 62 },
184
+ * // { minute: 9, temperature: 63.5 },
185
+ * // { minute: 10, temperature: 64 },
186
+ * // { minute: 11, temperature: 62.8 },
187
+ * // { minute: 12, temperature: 61.5 },
188
+ * // { minute: 13, temperature: 60.2 },
189
+ * // { minute: 14, temperature: 59.8 },
190
+ * // { minute: 15, temperature: 58.6 }
191
+ * // ]
192
+ */
193
+ export declare class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements IBinaryTree<K, V, R> {
194
+ /**
195
+ * Creates an instance of AVLTree.
196
+ * @remarks Time O(N log N) (from `addMany` with balanced add). Space O(N).
197
+ *
198
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
199
+ * @param [options] - Configuration options for the AVL tree.
200
+ */
201
+ constructor(keysNodesEntriesOrRaws?: Iterable<K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: AVLTreeOptions<K, V, R>);
202
+ /**
203
+ * (Protected) Creates a new AVL tree node.
204
+ * @remarks Time O(1), Space O(1)
205
+ *
206
+ * @param key - The key for the new node.
207
+ * @param [value] - The value for the new node.
208
+ * @returns The newly created AVLTreeNode.
209
+ */
210
+ createNode(key: K, value?: V): AVLTreeNode<K, V>;
211
+ /**
212
+ * Checks if the given item is an `AVLTreeNode` instance.
213
+ * @remarks Time O(1), Space O(1)
214
+ *
215
+ * @param keyNodeOrEntry - The item to check.
216
+ * @returns True if it's an AVLTreeNode, false otherwise.
217
+ */
218
+ isNode(keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is AVLTreeNode<K, V>;
219
+ /**
220
+ * Adds a new node to the AVL tree and balances the tree path.
221
+ * @remarks Time O(log N) (O(H) for BST add + O(H) for `_balancePath`). Space O(H) for path/recursion.
222
+ *
223
+ * @param keyNodeOrEntry - The key, node, or entry to add.
224
+ * @param [value] - The value, if providing just a key.
225
+ * @returns True if the addition was successful, false otherwise.
226
+ */
227
+ add(keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
228
+ /**
229
+ * Deletes a node from the AVL tree and re-balances the tree.
230
+ * @remarks Time O(log N) (O(H) for BST delete + O(H) for `_balancePath`). Space O(H) for path/recursion.
231
+ *
232
+ * @param keyNodeOrEntry - The node to delete.
233
+ * @returns An array containing deletion results.
234
+ */
235
+ delete(keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): BinaryTreeDeleteResult<AVLTreeNode<K, V>>[];
236
+ /**
237
+ * Rebuilds the tree to be perfectly balanced.
238
+ * @remarks AVL trees are already height-balanced, but this makes them *perfectly* balanced (minimal height and all leaves at N or N-1).
239
+ * Time O(N) (O(N) for DFS, O(N) for sorted build). Space O(N) for node array and recursion stack.
240
+ *
241
+ * @param [iterationType=this.iterationType] - The traversal method for the initial node export.
242
+ * @returns True if successful, false if the tree was empty.
243
+ */
244
+ perfectlyBalance(iterationType?: IterationType): boolean;
245
+ /**
246
+ * Creates a new AVLTree by mapping each [key, value] pair.
247
+ * @remarks Time O(N log N) (O(N) iteration + O(log M) `add` for each item into the new tree). Space O(N) for the new tree.
248
+ *
249
+ * @template MK - New key type.
250
+ * @template MV - New value type.
251
+ * @template MR - New raw type.
252
+ * @param callback - A function to map each [key, value] pair.
253
+ * @param [options] - Options for the new AVLTree.
254
+ * @param [thisArg] - `this` context for the callback.
255
+ * @returns A new, mapped AVLTree.
256
+ */
257
+ map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): AVLTree<MK, MV, MR>;
258
+ /**
259
+ * (Protected) Creates a new, empty instance of the same AVLTree constructor.
260
+ * @remarks Time O(1)
261
+ *
262
+ * @template TK, TV, TR - Generic types for the new instance.
263
+ * @param [options] - Options for the new tree.
264
+ * @returns A new, empty tree.
265
+ */
266
+ protected _createInstance<TK = K, TV = V, TR = R>(options?: Partial<BSTOptions<TK, TV, TR>>): this;
267
+ /**
268
+ * (Protected) Creates a new instance of the same AVLTree constructor, potentially with different generic types.
269
+ * @remarks Time O(N log N) (from constructor) due to processing the iterable.
270
+ *
271
+ * @template TK, TV, TR - Generic types for the new instance.
272
+ * @param [iter=[]] - An iterable to populate the new tree.
273
+ * @param [options] - Options for the new tree.
274
+ * @returns A new AVLTree.
275
+ */
276
+ protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK | AVLTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<BSTOptions<TK, TV, TR>>): AVLTree<TK, TV, TR>;
277
+ /**
278
+ * (Protected) Swaps properties of two nodes, including height.
279
+ * @remarks Time O(H) (due to `ensureNode`), but O(1) if nodes are passed directly.
280
+ *
281
+ * @param srcNode - The source node.
282
+ * @param destNode - The destination node.
283
+ * @returns The `destNode` (now holding `srcNode`'s properties).
284
+ */
285
+ protected _swapProperties(srcNode: BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>, destNode: BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>): AVLTreeNode<K, V> | undefined;
286
+ /**
287
+ * (Protected) Calculates the balance factor (height(right) - height(left)).
288
+ * @remarks Time O(1) (assumes heights are stored).
289
+ *
290
+ * @param node - The node to check.
291
+ * @returns The balance factor (positive if right-heavy, negative if left-heavy).
292
+ */
293
+ protected _balanceFactor(node: AVLTreeNode<K, V>): number;
294
+ /**
295
+ * (Protected) Recalculates and updates the height of a node based on its children's heights.
296
+ * @remarks Time O(1) (assumes children's heights are correct).
297
+ *
298
+ * @param node - The node to update.
299
+ */
300
+ protected _updateHeight(node: AVLTreeNode<K, V>): void;
301
+ /**
302
+ * (Protected) Performs a Left-Left (LL) rotation (a single right rotation).
303
+ * @remarks Time O(1), Space O(1)
304
+ *
305
+ * @param A - The unbalanced node (root of the unbalanced subtree).
306
+ */
307
+ protected _balanceLL(A: AVLTreeNode<K, V>): void;
308
+ /**
309
+ * (Protected) Performs a Left-Right (LR) double rotation.
310
+ * @remarks Time O(1), Space O(1)
311
+ *
312
+ * @param A - The unbalanced node (root of the unbalanced subtree).
313
+ */
314
+ protected _balanceLR(A: AVLTreeNode<K, V>): void;
315
+ /**
316
+ * (Protected) Performs a Right-Right (RR) rotation (a single left rotation).
317
+ * @remarks Time O(1), Space O(1)
318
+ *
319
+ * @param A - The unbalanced node (root of the unbalanced subtree).
320
+ */
321
+ protected _balanceRR(A: AVLTreeNode<K, V>): void;
322
+ /**
323
+ * (Protected) Performs a Right-Left (RL) double rotation.
324
+ * @remarks Time O(1), Space O(1)
325
+ *
326
+ * @param A - The unbalanced node (root of the unbalanced subtree).
327
+ */
328
+ protected _balanceRL(A: AVLTreeNode<K, V>): void;
329
+ /**
330
+ * (Protected) Traverses up the tree from the specified node, updating heights and performing rotations as needed.
331
+ * @remarks Time O(log N) (O(H)), as it traverses the path to root. Space O(H) for the path array.
332
+ *
333
+ * @param node - The node to start balancing from (e.g., the newly inserted node or parent of the deleted node).
334
+ */
335
+ protected _balancePath(node: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): void;
336
+ /**
337
+ * (Protected) Replaces a node, ensuring height is copied.
338
+ * @remarks Time O(1)
339
+ *
340
+ * @param oldNode - The node to be replaced.
341
+ * @param newNode - The node to insert.
342
+ * @returns The `newNode`.
343
+ */
344
+ protected _replaceNode(oldNode: AVLTreeNode<K, V>, newNode: AVLTreeNode<K, V>): AVLTreeNode<K, V>;
345
+ }
@@ -1 +1,174 @@
1
- export {};
1
+ /**
2
+ *
3
+ */
4
+ export declare class BinaryIndexedTree {
5
+ protected readonly _freq: number;
6
+ protected readonly _max: number;
7
+ /**
8
+ * The constructor initializes the properties of an object, including default frequency, maximum
9
+ * value, a freqMap data structure, the most significant bit, and the count of negative frequencies.
10
+ * @param - - `frequency`: The default frequency value. It is optional and has a default
11
+ * value of 0.
12
+ */
13
+ constructor({ frequency, max }: {
14
+ frequency?: number;
15
+ max: number;
16
+ });
17
+ protected _freqMap: Record<number, number>;
18
+ /**
19
+ * The function returns the frequency map of numbers.
20
+ * @returns The `_freqMap` property, which is a record with number keys and number values, is being
21
+ * returned.
22
+ */
23
+ get freqMap(): Record<number, number>;
24
+ protected _msb: number;
25
+ /**
26
+ * The function returns the value of the _msb property.
27
+ * @returns The `_msb` property of the object.
28
+ */
29
+ get msb(): number;
30
+ protected _negativeCount: number;
31
+ /**
32
+ * The function returns the value of the _negativeCount property.
33
+ * @returns The method is returning the value of the variable `_negativeCount`, which is of type
34
+ * `number`.
35
+ */
36
+ get negativeCount(): number;
37
+ /**
38
+ * The above function returns the value of the protected variable `_freq`.
39
+ * @returns The frequency value stored in the protected variable `_freq`.
40
+ */
41
+ get freq(): number;
42
+ /**
43
+ * The above function returns the maximum value.
44
+ * @returns The maximum value stored in the variable `_max`.
45
+ */
46
+ get max(): number;
47
+ /**
48
+ * The function "readSingle" reads a single number from a specified index.
49
+ * @param {number} index - The `index` parameter is a number that represents the index of an element in a
50
+ * collection or array.
51
+ * @returns a number.
52
+ */
53
+ readSingle(index: number): number;
54
+ /**
55
+ * The "update" function updates the value at a given index by adding a delta and triggers a callback
56
+ * to notify of the change.
57
+ * @param {number} position - The `index` parameter represents the index of the element that needs to be
58
+ * updated in the data structure.
59
+ * @param {number} change - The "delta" parameter represents the change in value that needs to be
60
+ * applied to the frequency at the specified index.
61
+ */
62
+ update(position: number, change: number): void;
63
+ /**
64
+ * The function "writeSingle" checks the index and writes a single value with a given frequency.
65
+ * @param {number} index - The `index` parameter is a number that represents the index of an element. It
66
+ * is used to identify the specific element that needs to be written.
67
+ * @param {number} freq - The `freq` parameter represents the frequency value that needs to be
68
+ * written.
69
+ */
70
+ writeSingle(index: number, freq: number): void;
71
+ /**
72
+ * The read function takes a count parameter, checks if it is an integer, and returns the result of
73
+ * calling the _read function with the count parameter clamped between 0 and the maximum value.
74
+ * @param {number} count - The `count` parameter is a number that represents the number of items to
75
+ * read.
76
+ * @returns a number.
77
+ */
78
+ read(count: number): number;
79
+ /**
80
+ * The function returns the lower bound of a non-descending sequence that sums up to a given number.
81
+ * @param {number} sum - The `sum` parameter is a number that represents the target sum that we want
82
+ * to find in the sequence.
83
+ * @returns The lowerBound function is returning a number.
84
+ */
85
+ lowerBound(sum: number): number;
86
+ /**
87
+ * The upperBound function returns the index of the first element in a sequence that is greater than
88
+ * or equal to a given sum.
89
+ * @param {number} sum - The "sum" parameter is a number that represents the target sum that we want
90
+ * to find in the sequence.
91
+ * @returns The upperBound function is returning a number.
92
+ */
93
+ upperBound(sum: number): number;
94
+ /**
95
+ * The function calculates the prefix sum of an array using a binary indexed tree.
96
+ * @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
97
+ * array for which we want to calculate the prefix sum.
98
+ * @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
99
+ * `i`.
100
+ */
101
+ getPrefixSum(i: number): number;
102
+ /**
103
+ * The function returns the value of a specific index in a freqMap data structure, or a default value if
104
+ * the index is not found.
105
+ * @param {number} index - The `index` parameter is a number that represents the index of a node in a
106
+ * freqMap data structure.
107
+ * @returns a number.
108
+ */
109
+ protected _getFrequency(index: number): number;
110
+ /**
111
+ * The function _updateFrequency adds a delta value to the element at the specified index in the freqMap array.
112
+ * @param {number} index - The index parameter is a number that represents the index of the freqMap
113
+ * element that needs to be updated.
114
+ * @param {number} delta - The `delta` parameter represents the change in value that needs to be
115
+ * added to the freqMap at the specified `index`.
116
+ */
117
+ protected _updateFrequency(index: number, delta: number): void;
118
+ /**
119
+ * The function checks if the given index is valid and within the range.
120
+ * @param {number} index - The parameter "index" is of type number and represents the index value
121
+ * that needs to be checked.
122
+ */
123
+ protected _checkIndex(index: number): void;
124
+ /**
125
+ * The function calculates the sum of elements in an array up to a given index using a binary indexed
126
+ * freqMap.
127
+ * @param {number} index - The `index` parameter is a number that represents the index of an element in a
128
+ * data structure.
129
+ * @returns a number.
130
+ */
131
+ protected _readSingle(index: number): number;
132
+ /**
133
+ * The function `_updateNegativeCount` updates a counter based on changes in frequency values.
134
+ * @param {number} freqCur - The current frequency value.
135
+ * @param {number} freqNew - The freqNew parameter represents the new frequency value.
136
+ */
137
+ protected _updateNegativeCount(freqCur: number, freqNew: number): void;
138
+ /**
139
+ * The `_update` function updates the values in a binary indexed freqMap starting from a given index and
140
+ * propagating the changes to its parent nodes.
141
+ * @param {number} index - The `index` parameter is a number that represents the index of the element in
142
+ * the data structure that needs to be updated.
143
+ * @param {number} delta - The `delta` parameter represents the change in value that needs to be
144
+ * applied to the elements in the data structure.
145
+ */
146
+ protected _update(index: number, delta: number): void;
147
+ /**
148
+ * The `_writeSingle` function updates the frequency at a specific index and triggers a callback if
149
+ * the frequency has changed.
150
+ * @param {number} index - The `index` parameter is a number that represents the index of the element
151
+ * being modified or accessed.
152
+ * @param {number} freq - The `freq` parameter represents the new frequency value that needs to be
153
+ * written to the specified index `index`.
154
+ */
155
+ protected _writeSingle(index: number, freq: number): void;
156
+ /**
157
+ * The `_read` function calculates the sum of values in a binary freqMap up to a given count.
158
+ * @param {number} count - The `count` parameter is a number that represents the number of elements
159
+ * to read from the freqMap.
160
+ * @returns the sum of the values obtained from calling the `_getFrequency` method for each index in the
161
+ * range from `count` to 1.
162
+ */
163
+ protected _read(count: number): number;
164
+ /**
165
+ * The function `_binarySearch` performs a binary search to find the largest number that satisfies a given
166
+ * condition.
167
+ * @param {number} sum - The sum parameter is a number that represents the target sum value.
168
+ * @param before - The `before` parameter is a function that takes two numbers `x` and `y` as
169
+ * arguments and returns a boolean value. It is used to determine if `x` is less than or equal to
170
+ * `y`. The purpose of this function is to compare two numbers and determine their order.
171
+ * @returns the value of the variable "left".
172
+ */
173
+ protected _binarySearch(sum: number, before: (x: number, y: number) => boolean): number;
174
+ }