doubly-linked-list-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 +1299 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +1294 -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 +11 -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/doubly-linked-list-typed.js +1302 -0
  87. package/dist/umd/doubly-linked-list-typed.js.map +1 -0
  88. package/dist/umd/doubly-linked-list-typed.min.js +9 -0
  89. package/dist/umd/doubly-linked-list-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 -12
  192. package/dist/index.js +0 -28
  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,174 +0,0 @@
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
- }
@@ -1,294 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BinaryIndexedTree = void 0;
4
- /**
5
- * data-structure-typed
6
- *
7
- * @author Pablo Zeng
8
- * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
9
- * @license MIT License
10
- */
11
- const utils_1 = require("../../utils");
12
- /**
13
- *
14
- */
15
- class BinaryIndexedTree {
16
- /**
17
- * The constructor initializes the properties of an object, including default frequency, maximum
18
- * value, a freqMap data structure, the most significant bit, and the count of negative frequencies.
19
- * @param - - `frequency`: The default frequency value. It is optional and has a default
20
- * value of 0.
21
- */
22
- constructor({ frequency = 0, max }) {
23
- this._freq = frequency;
24
- this._max = max;
25
- this._freqMap = { 0: 0 };
26
- this._msb = (0, utils_1.getMSB)(max);
27
- this._negativeCount = frequency < 0 ? max : 0;
28
- }
29
- /**
30
- * The function returns the frequency map of numbers.
31
- * @returns The `_freqMap` property, which is a record with number keys and number values, is being
32
- * returned.
33
- */
34
- get freqMap() {
35
- return this._freqMap;
36
- }
37
- /**
38
- * The function returns the value of the _msb property.
39
- * @returns The `_msb` property of the object.
40
- */
41
- get msb() {
42
- return this._msb;
43
- }
44
- /**
45
- * The function returns the value of the _negativeCount property.
46
- * @returns The method is returning the value of the variable `_negativeCount`, which is of type
47
- * `number`.
48
- */
49
- get negativeCount() {
50
- return this._negativeCount;
51
- }
52
- /**
53
- * The above function returns the value of the protected variable `_freq`.
54
- * @returns The frequency value stored in the protected variable `_freq`.
55
- */
56
- get freq() {
57
- return this._freq;
58
- }
59
- /**
60
- * The above function returns the maximum value.
61
- * @returns The maximum value stored in the variable `_max`.
62
- */
63
- get max() {
64
- return this._max;
65
- }
66
- /**
67
- * The function "readSingle" reads a single number from a specified index.
68
- * @param {number} index - The `index` parameter is a number that represents the index of an element in a
69
- * collection or array.
70
- * @returns a number.
71
- */
72
- readSingle(index) {
73
- this._checkIndex(index);
74
- return this._readSingle(index);
75
- }
76
- /**
77
- * The "update" function updates the value at a given index by adding a delta and triggers a callback
78
- * to notify of the change.
79
- * @param {number} position - The `index` parameter represents the index of the element that needs to be
80
- * updated in the data structure.
81
- * @param {number} change - The "delta" parameter represents the change in value that needs to be
82
- * applied to the frequency at the specified index.
83
- */
84
- update(position, change) {
85
- this._checkIndex(position);
86
- const freqCur = this._readSingle(position);
87
- this._update(position, change);
88
- this._updateNegativeCount(freqCur, freqCur + change);
89
- }
90
- /**
91
- * The function "writeSingle" checks the index and writes a single value with a given frequency.
92
- * @param {number} index - The `index` parameter is a number that represents the index of an element. It
93
- * is used to identify the specific element that needs to be written.
94
- * @param {number} freq - The `freq` parameter represents the frequency value that needs to be
95
- * written.
96
- */
97
- writeSingle(index, freq) {
98
- this._checkIndex(index);
99
- this._writeSingle(index, freq);
100
- }
101
- /**
102
- * The read function takes a count parameter, checks if it is an integer, and returns the result of
103
- * calling the _read function with the count parameter clamped between 0 and the maximum value.
104
- * @param {number} count - The `count` parameter is a number that represents the number of items to
105
- * read.
106
- * @returns a number.
107
- */
108
- read(count) {
109
- if (!Number.isInteger(count)) {
110
- throw new Error('Invalid count');
111
- }
112
- return this._read(Math.max(Math.min(count, this.max), 0));
113
- }
114
- /**
115
- * The function returns the lower bound of a non-descending sequence that sums up to a given number.
116
- * @param {number} sum - The `sum` parameter is a number that represents the target sum that we want
117
- * to find in the sequence.
118
- * @returns The lowerBound function is returning a number.
119
- */
120
- lowerBound(sum) {
121
- if (this.negativeCount > 0) {
122
- throw new Error('Sequence is not non-descending');
123
- }
124
- return this._binarySearch(sum, (x, y) => x < y);
125
- }
126
- /**
127
- * The upperBound function returns the index of the first element in a sequence that is greater than
128
- * or equal to a given sum.
129
- * @param {number} sum - The "sum" parameter is a number that represents the target sum that we want
130
- * to find in the sequence.
131
- * @returns The upperBound function is returning a number.
132
- */
133
- upperBound(sum) {
134
- if (this.negativeCount > 0) {
135
- throw new Error('Must not be descending');
136
- }
137
- return this._binarySearch(sum, (x, y) => x <= y);
138
- }
139
- /**
140
- * The function calculates the prefix sum of an array using a binary indexed tree.
141
- * @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
142
- * array for which we want to calculate the prefix sum.
143
- * @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
144
- * `i`.
145
- */
146
- getPrefixSum(i) {
147
- this._checkIndex(i);
148
- i++; // Convert to 1-based index
149
- let sum = 0;
150
- while (i > 0) {
151
- sum += this._getFrequency(i);
152
- i -= i & -i;
153
- }
154
- return sum;
155
- }
156
- /**
157
- * The function returns the value of a specific index in a freqMap data structure, or a default value if
158
- * the index is not found.
159
- * @param {number} index - The `index` parameter is a number that represents the index of a node in a
160
- * freqMap data structure.
161
- * @returns a number.
162
- */
163
- _getFrequency(index) {
164
- if (index in this.freqMap) {
165
- return this.freqMap[index];
166
- }
167
- return this.freq * (index & -index);
168
- }
169
- /**
170
- * The function _updateFrequency adds a delta value to the element at the specified index in the freqMap array.
171
- * @param {number} index - The index parameter is a number that represents the index of the freqMap
172
- * element that needs to be updated.
173
- * @param {number} delta - The `delta` parameter represents the change in value that needs to be
174
- * added to the freqMap at the specified `index`.
175
- */
176
- _updateFrequency(index, delta) {
177
- this.freqMap[index] = this._getFrequency(index) + delta;
178
- }
179
- /**
180
- * The function checks if the given index is valid and within the range.
181
- * @param {number} index - The parameter "index" is of type number and represents the index value
182
- * that needs to be checked.
183
- */
184
- _checkIndex(index) {
185
- if (!Number.isInteger(index)) {
186
- throw new Error('Invalid index: Index must be an integer.');
187
- }
188
- if (index < 0 || index >= this.max) {
189
- throw new Error('Index out of range: Index must be within the range [0, this.max).');
190
- }
191
- }
192
- /**
193
- * The function calculates the sum of elements in an array up to a given index using a binary indexed
194
- * freqMap.
195
- * @param {number} index - The `index` parameter is a number that represents the index of an element in a
196
- * data structure.
197
- * @returns a number.
198
- */
199
- _readSingle(index) {
200
- index = index + 1;
201
- let sum = this._getFrequency(index);
202
- const z = index - (index & -index);
203
- index--;
204
- while (index !== z) {
205
- sum -= this._getFrequency(index);
206
- index -= index & -index;
207
- }
208
- return sum;
209
- }
210
- /**
211
- * The function `_updateNegativeCount` updates a counter based on changes in frequency values.
212
- * @param {number} freqCur - The current frequency value.
213
- * @param {number} freqNew - The freqNew parameter represents the new frequency value.
214
- */
215
- _updateNegativeCount(freqCur, freqNew) {
216
- if (freqCur < 0 && freqNew >= 0) {
217
- this._negativeCount--;
218
- }
219
- else if (freqCur >= 0 && freqNew < 0) {
220
- this._negativeCount++;
221
- }
222
- }
223
- /**
224
- * The `_update` function updates the values in a binary indexed freqMap starting from a given index and
225
- * propagating the changes to its parent nodes.
226
- * @param {number} index - The `index` parameter is a number that represents the index of the element in
227
- * the data structure that needs to be updated.
228
- * @param {number} delta - The `delta` parameter represents the change in value that needs to be
229
- * applied to the elements in the data structure.
230
- */
231
- _update(index, delta) {
232
- index = index + 1;
233
- while (index <= this.max) {
234
- this._updateFrequency(index, delta);
235
- index += index & -index;
236
- }
237
- }
238
- /**
239
- * The `_writeSingle` function updates the frequency at a specific index and triggers a callback if
240
- * the frequency has changed.
241
- * @param {number} index - The `index` parameter is a number that represents the index of the element
242
- * being modified or accessed.
243
- * @param {number} freq - The `freq` parameter represents the new frequency value that needs to be
244
- * written to the specified index `index`.
245
- */
246
- _writeSingle(index, freq) {
247
- const freqCur = this._readSingle(index);
248
- this._update(index, freq - freqCur);
249
- this._updateNegativeCount(freqCur, freq);
250
- }
251
- /**
252
- * The `_read` function calculates the sum of values in a binary freqMap up to a given count.
253
- * @param {number} count - The `count` parameter is a number that represents the number of elements
254
- * to read from the freqMap.
255
- * @returns the sum of the values obtained from calling the `_getFrequency` method for each index in the
256
- * range from `count` to 1.
257
- */
258
- _read(count) {
259
- let index = count;
260
- let sum = 0;
261
- while (index) {
262
- sum += this._getFrequency(index);
263
- index -= index & -index;
264
- }
265
- return sum;
266
- }
267
- /**
268
- * The function `_binarySearch` performs a binary search to find the largest number that satisfies a given
269
- * condition.
270
- * @param {number} sum - The sum parameter is a number that represents the target sum value.
271
- * @param before - The `before` parameter is a function that takes two numbers `x` and `y` as
272
- * arguments and returns a boolean value. It is used to determine if `x` is less than or equal to
273
- * `y`. The purpose of this function is to compare two numbers and determine their order.
274
- * @returns the value of the variable "left".
275
- */
276
- _binarySearch(sum, before) {
277
- let left = 0;
278
- let right = this.msb << 1;
279
- let sumT = sum;
280
- while (right > left + 1) {
281
- const middle = (left + right) >> 1;
282
- const sumM = this._getFrequency(middle);
283
- if (middle <= this.max && before(sumM, sumT)) {
284
- sumT -= sumM;
285
- left = middle;
286
- }
287
- else {
288
- right = middle;
289
- }
290
- }
291
- return left;
292
- }
293
- }
294
- exports.BinaryIndexedTree = BinaryIndexedTree;