min-heap-typed 2.1.0 → 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 +3 -3
  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 +8 -11
  92. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
  93. package/src/data-structures/binary-tree/avl-tree.ts +6 -8
  94. package/src/data-structures/binary-tree/binary-tree.ts +13 -15
  95. package/src/data-structures/binary-tree/bst.ts +6 -11
  96. package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
  97. package/src/data-structures/binary-tree/tree-counter.ts +8 -13
  98. package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
  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 +3 -3
  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,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./queue"), exports);
18
- __exportStar(require("./deque"), exports);
@@ -1,308 +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 { ElementCallback, LinearBaseOptions, QueueOptions } from '../../types';
9
- import { SinglyLinkedList } from '../linked-list';
10
- import { LinearBase } from '../base/linear-base';
11
- /**
12
- * Array-backed queue with amortized O(1) enqueue/dequeue via an offset pointer and optional auto-compaction.
13
- * @remarks Time O(1), Space O(1)
14
- * @template E
15
- * @template R
16
- * 1. First In, First Out (FIFO): The core feature of a queue is its first in, first out nature. The element added to the queue first will be the one to be removed first.
17
- * 2. Operations: The main operations include enqueue (adding an element to the end of the queue) and dequeue (removing and returning the element at the front of the queue). Typically, there is also a peek operation (looking at the front element without removing it).
18
- * 3. Uses: Queues are commonly used to manage a series of tasks or elements that need to be processed in order. For example, managing task queues in a multi-threaded environment, or in algorithms for data structures like trees and graphs for breadth-first search.
19
- * 4. Task Scheduling: Managing the order of task execution in operating systems or applications.
20
- * 5. Data Buffering: Acting as a buffer for data packets in network communication.
21
- * 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store elements that are to be visited.
22
- * 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
23
- * @example
24
- * // Sliding Window using Queue
25
- * const nums = [2, 3, 4, 1, 5];
26
- * const k = 2;
27
- * const queue = new Queue<number>();
28
- *
29
- * let maxSum = 0;
30
- * let currentSum = 0;
31
- *
32
- * nums.forEach(num => {
33
- * queue.push(num);
34
- * currentSum += num;
35
- *
36
- * if (queue.length > k) {
37
- * currentSum -= queue.shift()!;
38
- * }
39
- *
40
- * if (queue.length === k) {
41
- * maxSum = Math.max(maxSum, currentSum);
42
- * }
43
- * });
44
- *
45
- * console.log(maxSum); // 7
46
- * @example
47
- * // Breadth-First Search (BFS) using Queue
48
- * const graph: { [key in number]: number[] } = {
49
- * 1: [2, 3],
50
- * 2: [4, 5],
51
- * 3: [],
52
- * 4: [],
53
- * 5: []
54
- * };
55
- *
56
- * const queue = new Queue<number>();
57
- * const visited: number[] = [];
58
- *
59
- * queue.push(1);
60
- *
61
- * while (!queue.isEmpty()) {
62
- * const node = queue.shift()!;
63
- * if (!visited.includes(node)) {
64
- * visited.push(node);
65
- * graph[node].forEach(neighbor => queue.push(neighbor));
66
- * }
67
- * }
68
- *
69
- * console.log(visited); // [1, 2, 3, 4, 5]
70
- */
71
- export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
72
- /**
73
- * Create a Queue and optionally bulk-insert elements.
74
- * @remarks Time O(N), Space O(N)
75
- * @param [elements] - Iterable of elements (or raw records if toElementFn is set).
76
- * @param [options] - Options such as toElementFn, maxLen, and autoCompactRatio.
77
- * @returns New Queue instance.
78
- */
79
- constructor(elements?: Iterable<E> | Iterable<R>, options?: QueueOptions<E, R>);
80
- protected _elements: E[];
81
- /**
82
- * Get the underlying array buffer.
83
- * @remarks Time O(1), Space O(1)
84
- * @returns Backing array of elements.
85
- */
86
- get elements(): E[];
87
- protected _offset: number;
88
- /**
89
- * Get the current start offset into the array.
90
- * @remarks Time O(1), Space O(1)
91
- * @returns Zero-based offset.
92
- */
93
- get offset(): number;
94
- protected _autoCompactRatio: number;
95
- /**
96
- * Get the compaction threshold (offset/size).
97
- * @remarks Time O(1), Space O(1)
98
- * @returns Auto-compaction ratio in (0,1].
99
- */
100
- get autoCompactRatio(): number;
101
- /**
102
- * Set the compaction threshold.
103
- * @remarks Time O(1), Space O(1)
104
- * @param value - New ratio; compacts when offset/size exceeds this value.
105
- * @returns void
106
- */
107
- set autoCompactRatio(value: number);
108
- /**
109
- * Get the number of elements currently in the queue.
110
- * @remarks Time O(1), Space O(1)
111
- * @returns Current length.
112
- */
113
- get length(): number;
114
- /**
115
- * Get the first element (front) without removing it.
116
- * @remarks Time O(1), Space O(1)
117
- * @returns Front element or undefined.
118
- */
119
- get first(): E | undefined;
120
- /**
121
- * Get the last element (back) without removing it.
122
- * @remarks Time O(1), Space O(1)
123
- * @returns Back element or undefined.
124
- */
125
- get last(): E | undefined;
126
- /**
127
- * Create a queue from an array of elements.
128
- * @remarks Time O(N), Space O(N)
129
- * @template E
130
- * @param elements - Array of elements to enqueue in order.
131
- * @returns A new queue populated from the array.
132
- */
133
- static fromArray<E>(elements: E[]): Queue<E>;
134
- /**
135
- * Check whether the queue is empty.
136
- * @remarks Time O(1), Space O(1)
137
- * @returns True if length is 0.
138
- */
139
- isEmpty(): boolean;
140
- /**
141
- * Enqueue one element at the back.
142
- * @remarks Time O(1), Space O(1)
143
- * @param element - Element to enqueue.
144
- * @returns True on success.
145
- */
146
- push(element: E): boolean;
147
- /**
148
- * Enqueue many elements from an iterable.
149
- * @remarks Time O(N), Space O(1)
150
- * @param elements - Iterable of elements (or raw records if toElementFn is set).
151
- * @returns Array of per-element success flags.
152
- */
153
- pushMany(elements: Iterable<E> | Iterable<R>): boolean[];
154
- /**
155
- * Dequeue one element from the front (amortized via offset).
156
- * @remarks Time O(1) amortized, Space O(1)
157
- * @returns Removed element or undefined.
158
- */
159
- shift(): E | undefined;
160
- /**
161
- * Delete the first occurrence of a specific element.
162
- * @remarks Time O(N), Space O(1)
163
- * @param element - Element to remove (strict equality via Object.is).
164
- * @returns True if an element was removed.
165
- */
166
- delete(element: E): boolean;
167
- /**
168
- * Get the element at a given logical index.
169
- * @remarks Time O(1), Space O(1)
170
- * @param index - Zero-based index from the front.
171
- * @returns Element or undefined.
172
- */
173
- at(index: number): E | undefined;
174
- /**
175
- * Delete the element at a given index.
176
- * @remarks Time O(N), Space O(1)
177
- * @param index - Zero-based index from the front.
178
- * @returns Removed element or undefined.
179
- */
180
- deleteAt(index: number): E | undefined;
181
- /**
182
- * Insert a new element at a given index.
183
- * @remarks Time O(N), Space O(1)
184
- * @param index - Zero-based index from the front.
185
- * @param newElement - Element to insert.
186
- * @returns True if inserted.
187
- */
188
- addAt(index: number, newElement: E): boolean;
189
- /**
190
- * Replace the element at a given index.
191
- * @remarks Time O(1), Space O(1)
192
- * @param index - Zero-based index from the front.
193
- * @param newElement - New element to set.
194
- * @returns True if updated.
195
- */
196
- setAt(index: number, newElement: E): boolean;
197
- /**
198
- * Reverse the queue in-place by compacting then reversing.
199
- * @remarks Time O(N), Space O(N)
200
- * @returns This queue.
201
- */
202
- reverse(): this;
203
- /**
204
- * Remove all elements and reset offset.
205
- * @remarks Time O(1), Space O(1)
206
- * @returns void
207
- */
208
- clear(): void;
209
- /**
210
- * Compact storage by discarding consumed head elements.
211
- * @remarks Time O(N), Space O(N)
212
- * @returns True when compaction performed.
213
- */
214
- compact(): boolean;
215
- /**
216
- * Remove and/or insert elements at a position (array-like).
217
- * @remarks Time O(N + M), Space O(M)
218
- * @param start - Start index (clamped to [0, length]).
219
- * @param [deleteCount] - Number of elements to remove (default 0).
220
- * @param [items] - Elements to insert after `start`.
221
- * @returns A new queue containing the removed elements (typed as `this`).
222
- */
223
- splice(start: number, deleteCount?: number, ...items: E[]): this;
224
- /**
225
- * Deep clone this queue and its parameters.
226
- * @remarks Time O(N), Space O(N)
227
- * @returns A new queue with the same content and options.
228
- */
229
- clone(): this;
230
- /**
231
- * Filter elements into a new queue of the same class.
232
- * @remarks Time O(N), Space O(N)
233
- * @param predicate - Predicate (element, index, queue) → boolean to keep element.
234
- * @param [thisArg] - Value for `this` inside the predicate.
235
- * @returns A new queue with kept elements.
236
- */
237
- filter(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): this;
238
- /**
239
- * Map each element to a new element in a possibly different-typed queue.
240
- * @remarks Time O(N), Space O(N)
241
- * @template EM
242
- * @template RM
243
- * @param callback - Mapping function (element, index, queue) → newElement.
244
- * @param [options] - Options for the output queue (e.g., toElementFn, maxLen, autoCompactRatio).
245
- * @param [thisArg] - Value for `this` inside the callback.
246
- * @returns A new Queue with mapped elements.
247
- */
248
- map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: QueueOptions<EM, RM>, thisArg?: unknown): Queue<EM, RM>;
249
- /**
250
- * Map each element to a new value of the same type.
251
- * @remarks Time O(N), Space O(N)
252
- * @param callback - Mapping function (element, index, queue) → element.
253
- * @param [thisArg] - Value for `this` inside the callback.
254
- * @returns A new queue with mapped elements (same element type).
255
- */
256
- mapSame(callback: ElementCallback<E, R, E>, thisArg?: unknown): this;
257
- /**
258
- * (Protected) Set the internal auto-compaction ratio.
259
- * @remarks Time O(1), Space O(1)
260
- * @param value - New ratio to assign.
261
- * @returns void
262
- */
263
- protected _setAutoCompactRatio(value: number): void;
264
- /**
265
- * (Protected) Iterate elements from front to back.
266
- * @remarks Time O(N), Space O(1)
267
- * @returns Iterator of E.
268
- */
269
- protected _getIterator(): IterableIterator<E>;
270
- /**
271
- * (Protected) Iterate elements from back to front.
272
- * @remarks Time O(N), Space O(1)
273
- * @returns Iterator of E.
274
- */
275
- protected _getReverseIterator(): IterableIterator<E>;
276
- /**
277
- * (Protected) Create an empty instance of the same concrete class.
278
- * @remarks Time O(1), Space O(1)
279
- * @param [options] - Options forwarded to the constructor.
280
- * @returns An empty like-kind queue instance.
281
- */
282
- protected _createInstance(options?: LinearBaseOptions<E, R>): this;
283
- /**
284
- * (Protected) Create a like-kind queue and seed it from an iterable.
285
- * @remarks Time O(N), Space O(N)
286
- * @template EM
287
- * @template RM
288
- * @param [elements] - Iterable used to seed the new queue.
289
- * @param [options] - Options forwarded to the constructor.
290
- * @returns A like-kind Queue instance.
291
- */
292
- protected _createLike<EM = E, RM = R>(elements?: Iterable<EM> | Iterable<RM>, options?: QueueOptions<EM, RM>): Queue<EM, RM>;
293
- }
294
- /**
295
- * Queue implemented over a singly linked list; preserves head/tail operations with linear scans for queries.
296
- * @remarks Time O(1), Space O(1)
297
- * @template E
298
- * @template R
299
- * @example examples will be generated by unit test
300
- */
301
- export declare class LinkedListQueue<E = any, R = any> extends SinglyLinkedList<E, R> {
302
- /**
303
- * Deep clone this linked-list-based queue.
304
- * @remarks Time O(N), Space O(N)
305
- * @returns A new queue with the same sequence of elements.
306
- */
307
- clone(): this;
308
- }