min-heap-typed 2.1.1 → 2.1.2

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 (281) hide show
  1. package/dist/cjs/index.cjs +987 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +980 -0
  4. package/dist/esm/index.mjs.map +1 -0
  5. package/dist/types/data-structures/base/index.d.ts +2 -1
  6. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
  7. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
  8. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
  9. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
  10. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
  11. package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
  12. package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
  17. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
  18. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
  19. package/dist/types/data-structures/graph/index.d.ts +2 -1
  20. package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
  21. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
  22. package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
  23. package/dist/types/data-structures/hash/index.d.ts +0 -1
  24. package/dist/types/data-structures/heap/heap.d.ts +503 -5
  25. package/dist/types/data-structures/heap/index.d.ts +2 -0
  26. package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
  27. package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
  28. package/dist/types/data-structures/index.d.ts +7 -7
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
  32. package/dist/types/data-structures/matrix/index.d.ts +1 -1
  33. package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
  34. package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
  35. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
  36. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
  37. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
  38. package/dist/types/data-structures/queue/deque.d.ts +431 -4
  39. package/dist/types/data-structures/queue/queue.d.ts +308 -4
  40. package/dist/types/data-structures/stack/stack.d.ts +306 -2
  41. package/dist/types/data-structures/tree/tree.d.ts +62 -1
  42. package/dist/types/data-structures/trie/trie.d.ts +350 -4
  43. package/dist/types/index.d.ts +13 -2
  44. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +1 -1
  45. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  46. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  47. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  48. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  49. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  51. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  52. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  53. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  54. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  55. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  56. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  57. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  58. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  59. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  60. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  61. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  62. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  63. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  64. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  65. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  66. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  67. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  68. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  69. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  70. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  71. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  72. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  73. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  74. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  75. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  76. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  77. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  78. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  79. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  80. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  81. package/dist/types/types/index.d.ts +3 -0
  82. package/dist/types/types/utils/index.d.ts +2 -0
  83. package/dist/types/types/utils/utils.d.ts +22 -0
  84. package/dist/types/utils/index.d.ts +1 -1
  85. package/dist/types/utils/utils.d.ts +209 -22
  86. package/dist/umd/max-heap-typed.js +992 -0
  87. package/dist/umd/max-heap-typed.js.map +1 -0
  88. package/dist/umd/max-heap-typed.min.js +16 -0
  89. package/dist/umd/max-heap-typed.min.js.map +1 -0
  90. package/package.json +25 -5
  91. package/src/data-structures/binary-tree/avl-tree-counter.ts +4 -4
  92. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  93. package/src/data-structures/binary-tree/avl-tree.ts +2 -2
  94. package/src/data-structures/binary-tree/binary-tree.ts +4 -4
  95. package/src/data-structures/binary-tree/bst.ts +1 -1
  96. package/src/data-structures/binary-tree/red-black-tree.ts +2 -2
  97. package/src/data-structures/binary-tree/tree-counter.ts +4 -4
  98. package/src/data-structures/binary-tree/tree-multi-map.ts +1 -1
  99. package/src/data-structures/heap/heap.ts +5 -5
  100. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  101. package/src/interfaces/binary-tree.ts +1 -1
  102. package/tsconfig.base.json +23 -0
  103. package/tsconfig.json +8 -34
  104. package/tsconfig.test.json +8 -0
  105. package/tsconfig.types.json +15 -0
  106. package/tsup.config.js +28 -0
  107. package/tsup.node.config.js +37 -0
  108. package/dist/common/index.js +0 -28
  109. package/dist/constants/index.js +0 -8
  110. package/dist/data-structures/base/index.d.ts +0 -2
  111. package/dist/data-structures/base/index.js +0 -18
  112. package/dist/data-structures/base/iterable-element-base.js +0 -243
  113. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  114. package/dist/data-structures/base/linear-base.js +0 -415
  115. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  116. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  117. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  118. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  119. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  120. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  121. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  122. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  123. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  124. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  125. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  126. package/dist/data-structures/binary-tree/bst.js +0 -903
  127. package/dist/data-structures/binary-tree/index.js +0 -26
  128. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  129. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  130. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  131. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  132. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  133. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  134. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  135. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  136. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  137. package/dist/data-structures/graph/abstract-graph.js +0 -896
  138. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  139. package/dist/data-structures/graph/directed-graph.js +0 -525
  140. package/dist/data-structures/graph/index.js +0 -20
  141. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  142. package/dist/data-structures/graph/map-graph.js +0 -107
  143. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  144. package/dist/data-structures/graph/undirected-graph.js +0 -424
  145. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  146. package/dist/data-structures/hash/hash-map.js +0 -692
  147. package/dist/data-structures/hash/index.d.ts +0 -1
  148. package/dist/data-structures/hash/index.js +0 -17
  149. package/dist/data-structures/heap/heap.d.ts +0 -503
  150. package/dist/data-structures/heap/heap.js +0 -901
  151. package/dist/data-structures/heap/index.d.ts +0 -3
  152. package/dist/data-structures/heap/index.js +0 -19
  153. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  154. package/dist/data-structures/heap/max-heap.js +0 -40
  155. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  156. package/dist/data-structures/heap/min-heap.js +0 -31
  157. package/dist/data-structures/index.js +0 -28
  158. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  159. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  160. package/dist/data-structures/linked-list/index.js +0 -19
  161. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  162. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  163. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  164. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  165. package/dist/data-structures/matrix/index.js +0 -18
  166. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  167. package/dist/data-structures/matrix/matrix.js +0 -448
  168. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  169. package/dist/data-structures/matrix/navigator.js +0 -111
  170. package/dist/data-structures/priority-queue/index.js +0 -19
  171. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  172. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  173. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  174. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  175. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  176. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  177. package/dist/data-structures/queue/deque.d.ts +0 -431
  178. package/dist/data-structures/queue/deque.js +0 -879
  179. package/dist/data-structures/queue/index.js +0 -18
  180. package/dist/data-structures/queue/queue.d.ts +0 -308
  181. package/dist/data-structures/queue/queue.js +0 -473
  182. package/dist/data-structures/stack/index.js +0 -17
  183. package/dist/data-structures/stack/stack.d.ts +0 -306
  184. package/dist/data-structures/stack/stack.js +0 -401
  185. package/dist/data-structures/tree/index.js +0 -17
  186. package/dist/data-structures/tree/tree.d.ts +0 -62
  187. package/dist/data-structures/tree/tree.js +0 -107
  188. package/dist/data-structures/trie/index.js +0 -17
  189. package/dist/data-structures/trie/trie.d.ts +0 -350
  190. package/dist/data-structures/trie/trie.js +0 -610
  191. package/dist/index.d.ts +0 -14
  192. package/dist/index.js +0 -30
  193. package/dist/interfaces/binary-tree.js +0 -2
  194. package/dist/interfaces/doubly-linked-list.js +0 -2
  195. package/dist/interfaces/graph.js +0 -2
  196. package/dist/interfaces/heap.js +0 -2
  197. package/dist/interfaces/index.js +0 -24
  198. package/dist/interfaces/navigator.js +0 -2
  199. package/dist/interfaces/priority-queue.js +0 -2
  200. package/dist/interfaces/segment-tree.js +0 -2
  201. package/dist/interfaces/singly-linked-list.js +0 -2
  202. package/dist/types/common.js +0 -2
  203. package/dist/types/data-structures/base/base.js +0 -2
  204. package/dist/types/data-structures/base/index.js +0 -17
  205. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  206. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  207. package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
  208. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  209. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
  210. package/dist/types/data-structures/binary-tree/bst.js +0 -2
  211. package/dist/types/data-structures/binary-tree/index.js +0 -25
  212. package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
  213. package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
  214. package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
  215. package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  216. package/dist/types/data-structures/graph/abstract-graph.js +0 -2
  217. package/dist/types/data-structures/graph/directed-graph.js +0 -2
  218. package/dist/types/data-structures/graph/index.js +0 -19
  219. package/dist/types/data-structures/graph/map-graph.js +0 -2
  220. package/dist/types/data-structures/graph/undirected-graph.js +0 -2
  221. package/dist/types/data-structures/hash/hash-map.js +0 -2
  222. package/dist/types/data-structures/hash/index.js +0 -17
  223. package/dist/types/data-structures/heap/heap.js +0 -2
  224. package/dist/types/data-structures/heap/index.js +0 -17
  225. package/dist/types/data-structures/heap/max-heap.js +0 -2
  226. package/dist/types/data-structures/heap/min-heap.js +0 -2
  227. package/dist/types/data-structures/index.js +0 -28
  228. package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  229. package/dist/types/data-structures/linked-list/index.js +0 -19
  230. package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
  231. package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
  232. package/dist/types/data-structures/matrix/index.js +0 -18
  233. package/dist/types/data-structures/matrix/matrix.js +0 -2
  234. package/dist/types/data-structures/matrix/navigator.js +0 -2
  235. package/dist/types/data-structures/priority-queue/index.js +0 -19
  236. package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  237. package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  238. package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
  239. package/dist/types/data-structures/queue/deque.js +0 -2
  240. package/dist/types/data-structures/queue/index.js +0 -18
  241. package/dist/types/data-structures/queue/queue.js +0 -2
  242. package/dist/types/data-structures/stack/index.js +0 -17
  243. package/dist/types/data-structures/stack/stack.js +0 -2
  244. package/dist/types/data-structures/tree/index.js +0 -17
  245. package/dist/types/data-structures/tree/tree.js +0 -2
  246. package/dist/types/data-structures/trie/index.js +0 -17
  247. package/dist/types/data-structures/trie/trie.js +0 -2
  248. package/dist/types/index.js +0 -19
  249. package/dist/types/utils/index.js +0 -18
  250. package/dist/types/utils/utils.js +0 -2
  251. package/dist/types/utils/validate-type.js +0 -2
  252. package/dist/utils/index.d.ts +0 -2
  253. package/dist/utils/index.js +0 -18
  254. package/dist/utils/number.js +0 -24
  255. package/dist/utils/utils.d.ts +0 -209
  256. package/dist/utils/utils.js +0 -353
  257. package/dist/{common → types/common}/index.d.ts +0 -0
  258. package/dist/{constants → types/constants}/index.d.ts +0 -0
  259. package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
  260. package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
  261. package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
  262. package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
  263. package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
  264. package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
  265. package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
  266. package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
  267. package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
  268. package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
  269. package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
  270. package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
  271. package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
  272. package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
  273. package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
  274. package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
  275. /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
  276. /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
  277. /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
  278. /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
  279. /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
  280. /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
  281. /package/dist/{utils → types/utils}/number.d.ts +0 -0
@@ -1,297 +0,0 @@
1
- "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Pablo Zeng
6
- * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
7
- * @license MIT License
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.SegmentTree = exports.SegmentTreeNode = void 0;
11
- class SegmentTreeNode {
12
- /**
13
- * The constructor initializes the properties of a SegmentTreeNode object.
14
- * @param {number} start - The `start` parameter represents the starting index of the segment covered
15
- * by this node in a segment tree.
16
- * @param {number} end - The `end` parameter represents the end index of the segment covered by this
17
- * node in a segment tree.
18
- * @param {number} sum - The `sum` parameter represents the sum of the values in the range covered by
19
- * the segment tree node.
20
- * @param {SegmentTreeNodeVal | undefined} [value] - The `value` parameter is an optional parameter
21
- * of type `SegmentTreeNodeVal`. It represents the value associated with the segment tree node.
22
- */
23
- constructor(start, end, sum, value) {
24
- this._start = 0;
25
- this._end = 0;
26
- this._value = undefined;
27
- this._sum = 0;
28
- this._left = undefined;
29
- this._right = undefined;
30
- this._start = start;
31
- this._end = end;
32
- this._sum = sum;
33
- this._value = value || undefined;
34
- }
35
- /**
36
- * The function returns the value of the protected variable _start.
37
- * @returns The start value, which is of type number.
38
- */
39
- get start() {
40
- return this._start;
41
- }
42
- /**
43
- * The above function sets the value of the "start" property.
44
- * @param {number} value - The value parameter is of type number.
45
- */
46
- set start(value) {
47
- this._start = value;
48
- }
49
- /**
50
- * The function returns the value of the protected variable `_end`.
51
- * @returns The value of the protected property `_end`.
52
- */
53
- get end() {
54
- return this._end;
55
- }
56
- /**
57
- * The above function sets the value of the "end" property.
58
- * @param {number} value - The value parameter is a number that represents the new value for the end
59
- * property.
60
- */
61
- set end(value) {
62
- this._end = value;
63
- }
64
- /**
65
- * The function returns the value of a segment tree node.
66
- * @returns The value being returned is either a `SegmentTreeNodeVal` object or `undefined`.
67
- */
68
- get value() {
69
- return this._value;
70
- }
71
- /**
72
- * The function sets the value of a segment tree node.
73
- * @param {SegmentTreeNodeVal | undefined} value - The `value` parameter is of type
74
- * `SegmentTreeNodeVal` or `undefined`.
75
- */
76
- set value(value) {
77
- this._value = value;
78
- }
79
- /**
80
- * The function returns the value of the sum property.
81
- * @returns The method is returning the value of the variable `_sum`.
82
- */
83
- get sum() {
84
- return this._sum;
85
- }
86
- /**
87
- * The above function sets the value of the sum property.
88
- * @param {number} value - The parameter "value" is of type "number".
89
- */
90
- set sum(value) {
91
- this._sum = value;
92
- }
93
- /**
94
- * The function returns the left child of a segment tree node.
95
- * @returns The `left` property of the `SegmentTreeNode` object is being returned. It is of type
96
- * `SegmentTreeNode` or `undefined`.
97
- */
98
- get left() {
99
- return this._left;
100
- }
101
- /**
102
- * The function sets the value of the left property of a SegmentTreeNode object.
103
- * @param {SegmentTreeNode | undefined} value - The value parameter is of type SegmentTreeNode or
104
- * undefined.
105
- */
106
- set left(value) {
107
- this._left = value;
108
- }
109
- /**
110
- * The function returns the right child of a segment tree node.
111
- * @returns The `getRight()` method is returning a value of type `SegmentTreeNode` or `undefined`.
112
- */
113
- get right() {
114
- return this._right;
115
- }
116
- /**
117
- * The function sets the right child of a segment tree node.
118
- * @param {SegmentTreeNode | undefined} value - The `value` parameter is of type `SegmentTreeNode |
119
- * undefined`. This means that it can accept either a `SegmentTreeNode` object or `undefined` as its
120
- * value.
121
- */
122
- set right(value) {
123
- this._right = value;
124
- }
125
- }
126
- exports.SegmentTreeNode = SegmentTreeNode;
127
- class SegmentTree {
128
- /**
129
- * The constructor initializes the values, start, end, and root properties of an object.
130
- * @param {number[]} values - An array of numbers that will be used to build a binary search tree.
131
- * @param {number} [start] - The `start` parameter is the index of the first element in the `values` array that should
132
- * be included in the range. If no value is provided for `start`, it defaults to 0, which means the range starts from
133
- * the beginning of the array.
134
- * @param {number} [end] - The "end" parameter is the index of the last element in the "values" array that should be
135
- * included in the range. If not provided, it defaults to the index of the last element in the "values" array.
136
- */
137
- constructor(values, start, end) {
138
- this._values = [];
139
- this._start = 0;
140
- start = start || 0;
141
- end = end || values.length - 1;
142
- this._values = values;
143
- this._start = start;
144
- this._end = end;
145
- if (values.length > 0) {
146
- this._root = this.build(start, end);
147
- }
148
- else {
149
- this._root = undefined;
150
- this._values = [];
151
- }
152
- }
153
- /**
154
- * The function returns an array of numbers.
155
- * @returns An array of numbers is being returned.
156
- */
157
- get values() {
158
- return this._values;
159
- }
160
- /**
161
- * The function returns the value of the protected variable _start.
162
- * @returns The start value, which is of type number.
163
- */
164
- get start() {
165
- return this._start;
166
- }
167
- /**
168
- * The function returns the value of the protected variable `_end`.
169
- * @returns The value of the protected property `_end`.
170
- */
171
- get end() {
172
- return this._end;
173
- }
174
- /**
175
- * The function returns the root node of a segment tree.
176
- * @returns The `root` property of the class `SegmentTreeNode` or `undefined` if it is not defined.
177
- */
178
- get root() {
179
- return this._root;
180
- }
181
- /**
182
- * The build function creates a segment tree by recursively dividing the given range into smaller segments and assigning
183
- * the sum of values to each segment.
184
- * @param {number} start - The `start` parameter represents the starting index of the segment or range for which we are
185
- * building the segment tree.
186
- * @param {number} end - The "end" parameter represents the ending index of the segment or range for which we want to
187
- * build a segment tree.
188
- * @returns a SegmentTreeNode object.
189
- */
190
- build(start, end) {
191
- if (start > end) {
192
- return new SegmentTreeNode(start, end, 0);
193
- }
194
- if (start === end)
195
- return new SegmentTreeNode(start, end, this._values[start]);
196
- const mid = start + Math.floor((end - start) / 2);
197
- const left = this.build(start, mid);
198
- const right = this.build(mid + 1, end);
199
- const cur = new SegmentTreeNode(start, end, left.sum + right.sum);
200
- cur.left = left;
201
- cur.right = right;
202
- return cur;
203
- }
204
- /**
205
- * The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.
206
- * @param {number} index - The index parameter represents the index of the node in the segment tree that needs to be
207
- * updated.
208
- * @param {number} sum - The `sum` parameter represents the new value that should be assigned to the `sum` property of
209
- * the `SegmentTreeNode` at the specified `index`.
210
- * @param {SegmentTreeNodeVal} [value] - The `value` parameter is an optional value that can be assigned to the `value`
211
- * property of the `SegmentTreeNode` object. It is not currently used in the code, but you can uncomment the line `//
212
- * cur.value = value;` and pass a value for `value` in the
213
- * @returns The function does not return anything.
214
- */
215
- updateNode(index, sum, value) {
216
- const root = this.root || undefined;
217
- if (!root) {
218
- return;
219
- }
220
- const dfs = (cur, index, sum, value) => {
221
- if (cur.start === cur.end && cur.start === index) {
222
- cur.sum = sum;
223
- if (value !== undefined)
224
- cur.value = value;
225
- return;
226
- }
227
- const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
228
- if (index <= mid) {
229
- if (cur.left) {
230
- dfs(cur.left, index, sum, value);
231
- }
232
- }
233
- else {
234
- if (cur.right) {
235
- dfs(cur.right, index, sum, value);
236
- }
237
- }
238
- if (cur.left && cur.right) {
239
- cur.sum = cur.left.sum + cur.right.sum;
240
- }
241
- };
242
- dfs(root, index, sum, value);
243
- }
244
- /**
245
- * The function `querySumByRange` calculates the sum of values within a given range in a segment tree.
246
- * @param {number} indexA - The starting index of the range for which you want to calculate the sum.
247
- * @param {number} indexB - The parameter `indexB` represents the ending index of the range for which you want to
248
- * calculate the sum.
249
- * @returns The function `querySumByRange` returns a number.
250
- */
251
- querySumByRange(indexA, indexB) {
252
- const root = this.root || undefined;
253
- if (!root) {
254
- return 0;
255
- }
256
- if (indexA < 0 || indexB >= this.values.length || indexA > indexB) {
257
- return NaN;
258
- }
259
- const dfs = (cur, i, j) => {
260
- if (i <= cur.start && j >= cur.end) {
261
- // The range [i, j] completely covers the current node's range [cur.start, cur.end]
262
- return cur.sum;
263
- }
264
- const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
265
- if (j <= mid) {
266
- if (cur.left) {
267
- return dfs(cur.left, i, j);
268
- }
269
- else {
270
- return NaN;
271
- }
272
- }
273
- else if (i > mid) {
274
- if (cur.right) {
275
- return dfs(cur.right, i, j);
276
- }
277
- else {
278
- return NaN;
279
- }
280
- }
281
- else {
282
- // Query both left and right subtrees
283
- let leftSum = 0;
284
- let rightSum = 0;
285
- if (cur.left) {
286
- leftSum = dfs(cur.left, i, mid);
287
- }
288
- if (cur.right) {
289
- rightSum = dfs(cur.right, mid + 1, j);
290
- }
291
- return leftSum + rightSum;
292
- }
293
- };
294
- return dfs(root, indexA, indexB);
295
- }
296
- }
297
- exports.SegmentTree = SegmentTree;
@@ -1,190 +0,0 @@
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 type { BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
9
- import { BSTOptions } from '../../types';
10
- import { BSTNode } from './bst';
11
- import { IBinaryTree } from '../../interfaces';
12
- import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
13
- /**
14
- * RB-tree node with an extra 'count' field; keeps parent/child links.
15
- * @remarks Time O(1), Space O(1)
16
- * @template K
17
- * @template V
18
- */
19
- export declare class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<K, V> {
20
- parent?: TreeCounterNode<K, V>;
21
- /**
22
- * Create a tree counter node.
23
- * @remarks Time O(1), Space O(1)
24
- * @param key - Key of the node.
25
- * @param [value] - Value associated with the key (ignored in map mode).
26
- * @param [count] - Initial count for this node (default 1).
27
- * @param color - Initial color ('RED' or 'BLACK').
28
- * @returns New TreeCounterNode instance.
29
- */
30
- constructor(key: K, value?: V, count?: number, color?: RBTNColor);
31
- _left?: TreeCounterNode<K, V> | null | undefined;
32
- /**
33
- * Get the left child pointer.
34
- * @remarks Time O(1), Space O(1)
35
- * @returns Left child node, or null/undefined.
36
- */
37
- get left(): TreeCounterNode<K, V> | null | undefined;
38
- /**
39
- * Set the left child and update its parent pointer.
40
- * @remarks Time O(1), Space O(1)
41
- * @param v - New left child node, or null/undefined.
42
- * @returns void
43
- */
44
- set left(v: TreeCounterNode<K, V> | null | undefined);
45
- _right?: TreeCounterNode<K, V> | null | undefined;
46
- /**
47
- * Get the right child pointer.
48
- * @remarks Time O(1), Space O(1)
49
- * @returns Right child node, or null/undefined.
50
- */
51
- get right(): TreeCounterNode<K, V> | null | undefined;
52
- /**
53
- * Set the right child and update its parent pointer.
54
- * @remarks Time O(1), Space O(1)
55
- * @param v - New right child node, or null/undefined.
56
- * @returns void
57
- */
58
- set right(v: TreeCounterNode<K, V> | null | undefined);
59
- }
60
- /**
61
- * Red-Black Tree–based counter map (key → value with per-node count). Supports O(log N) updates and map-like mode.
62
- * @remarks Time O(1), Space O(1)
63
- * @template K
64
- * @template V
65
- * @template R
66
- */
67
- export declare class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R> implements IBinaryTree<K, V, R> {
68
- /**
69
- * Create a TreeCounter and optionally bulk-insert items.
70
- * @remarks Time O(N log N), Space O(N)
71
- * @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
72
- * @param [options] - Options for TreeCounter (comparator, reverse, map mode).
73
- * @returns New TreeCounter instance.
74
- */
75
- constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: TreeCounterOptions<K, V, R>);
76
- protected _count: number;
77
- /**
78
- * Get the total aggregate count across all nodes.
79
- * @remarks Time O(1), Space O(1)
80
- * @returns Total count.
81
- */
82
- get count(): number;
83
- /**
84
- * Compute the total count by traversing the tree (sums node.count).
85
- * @remarks Time O(N), Space O(H)
86
- * @returns Total count recomputed from nodes.
87
- */
88
- getComputedCount(): number;
89
- _createNode(key: K, value?: V, color?: RBTNColor, count?: number): TreeCounterNode<K, V>;
90
- /**
91
- * Type guard: check whether the input is a TreeCounterNode.
92
- * @remarks Time O(1), Space O(1)
93
- * @returns True if the value is a TreeCounterNode.
94
- */
95
- isNode(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is TreeCounterNode<K, V>;
96
- /**
97
- * Insert or increment a node and update aggregate count.
98
- * @remarks Time O(log N), Space O(1)
99
- * @param keyNodeOrEntry - Key, node, or [key, value] entry to insert.
100
- * @param [value] - Value when a bare key is provided (ignored in map mode).
101
- * @param [count] - How much to increase the node's count (default 1).
102
- * @returns True if inserted/updated; false if ignored.
103
- */
104
- add(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): boolean;
105
- /**
106
- * Delete a node (or decrement its count) and rebalance if needed.
107
- * @remarks Time O(log N), Space O(1)
108
- * @param keyNodeOrEntry - Key, node, or [key, value] entry identifying the node.
109
- * @param [ignoreCount] - If true, remove the node regardless of its count.
110
- * @returns Array of deletion results including deleted node and a rebalance hint when present.
111
- */
112
- delete(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, ignoreCount?: boolean): BinaryTreeDeleteResult<TreeCounterNode<K, V>>[];
113
- /**
114
- * Remove all nodes and reset aggregate counters.
115
- * @remarks Time O(N), Space O(1)
116
- * @returns void
117
- */
118
- clear(): void;
119
- /**
120
- * Rebuild the tree into a perfectly balanced form using in-order nodes.
121
- * @remarks Time O(N), Space O(N)
122
- * @param [iterationType] - Traversal style to use when constructing the balanced tree.
123
- * @returns True if rebalancing succeeded (tree not empty).
124
- */
125
- perfectlyBalance(iterationType?: IterationType): boolean;
126
- /**
127
- * Create a new TreeCounter by mapping each [key, value] entry.
128
- * @remarks Time O(N log N), Space O(N)
129
- * @template MK
130
- * @template MV
131
- * @template MR
132
- * @param callback - Function mapping (key, value, index, tree) → [newKey, newValue].
133
- * @param [options] - Options for the output tree.
134
- * @param [thisArg] - Value for `this` inside the callback.
135
- * @returns A new TreeCounter with mapped entries.
136
- */
137
- map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): TreeCounter<MK, MV, MR>;
138
- /**
139
- * Deep copy this tree, preserving map mode and aggregate counts.
140
- * @remarks Time O(N), Space O(N)
141
- * @returns A deep copy of this tree.
142
- */
143
- clone(): this;
144
- /**
145
- * (Protected) Create an empty instance of the same concrete class.
146
- * @remarks Time O(1), Space O(1)
147
- * @template TK
148
- * @template TV
149
- * @template TR
150
- * @param [options] - Optional constructor options for the like-kind instance.
151
- * @returns An empty like-kind instance.
152
- */
153
- protected _createInstance<TK = K, TV = V, TR = R>(options?: Partial<BSTOptions<TK, TV, TR>>): this;
154
- /**
155
- * (Protected) Create a like-kind instance and seed it from an iterable.
156
- * @remarks Time O(N log N), Space O(N)
157
- * @template TK
158
- * @template TV
159
- * @template TR
160
- * @param iter - Iterable used to seed the new tree.
161
- * @param [options] - Options merged with the current snapshot.
162
- * @returns A like-kind TreeCounter built from the iterable.
163
- */
164
- protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK | BSTNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<BSTOptions<TK, TV, TR>>): TreeCounter<TK, TV, TR>;
165
- /**
166
- * (Protected) Normalize input into a node plus its effective value and count.
167
- * @remarks Time O(1), Space O(1)
168
- * @param keyNodeOrEntry - Key, node, or [key, value] entry.
169
- * @param [value] - Value used when a bare key is provided.
170
- * @param [count] - Count increment to apply (default 1).
171
- * @returns Tuple [node, value] where node may be undefined.
172
- */
173
- protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): [TreeCounterNode<K, V> | undefined, V | undefined];
174
- /**
175
- * (Protected) Swap keys/values/counters between the source and destination nodes.
176
- * @remarks Time O(1), Space O(1)
177
- * @param srcNode - Source node (or key) whose properties will be moved.
178
- * @param destNode - Destination node (or key) to receive properties.
179
- * @returns Destination node after swap, or undefined.
180
- */
181
- protected _swapProperties(srcNode: BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>, destNode: BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>): TreeCounterNode<K, V> | undefined;
182
- /**
183
- * (Protected) Replace one node by another and adjust counters accordingly.
184
- * @remarks Time O(1), Space O(1)
185
- * @param oldNode - Node being replaced.
186
- * @param newNode - Replacement node.
187
- * @returns The new node after replacement.
188
- */
189
- protected _replaceNode(oldNode: TreeCounterNode<K, V>, newNode: TreeCounterNode<K, V>): TreeCounterNode<K, V>;
190
- }