avl-tree-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 +3859 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +3852 -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 +15 -3
  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/avl-tree-typed.js +3852 -0
  87. package/dist/umd/avl-tree-typed.js.map +1 -0
  88. package/dist/umd/avl-tree-typed.min.js +13 -0
  89. package/dist/umd/avl-tree-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 -15
  192. package/dist/index.js +0 -31
  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 -23
  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,473 +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.LinkedListQueue = exports.Queue = void 0;
11
- const linked_list_1 = require("../linked-list");
12
- const linear_base_1 = require("../base/linear-base");
13
- /**
14
- * Array-backed queue with amortized O(1) enqueue/dequeue via an offset pointer and optional auto-compaction.
15
- * @remarks Time O(1), Space O(1)
16
- * @template E
17
- * @template R
18
- * 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.
19
- * 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).
20
- * 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.
21
- * 4. Task Scheduling: Managing the order of task execution in operating systems or applications.
22
- * 5. Data Buffering: Acting as a buffer for data packets in network communication.
23
- * 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store elements that are to be visited.
24
- * 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
25
- * @example
26
- * // Sliding Window using Queue
27
- * const nums = [2, 3, 4, 1, 5];
28
- * const k = 2;
29
- * const queue = new Queue<number>();
30
- *
31
- * let maxSum = 0;
32
- * let currentSum = 0;
33
- *
34
- * nums.forEach(num => {
35
- * queue.push(num);
36
- * currentSum += num;
37
- *
38
- * if (queue.length > k) {
39
- * currentSum -= queue.shift()!;
40
- * }
41
- *
42
- * if (queue.length === k) {
43
- * maxSum = Math.max(maxSum, currentSum);
44
- * }
45
- * });
46
- *
47
- * console.log(maxSum); // 7
48
- * @example
49
- * // Breadth-First Search (BFS) using Queue
50
- * const graph: { [key in number]: number[] } = {
51
- * 1: [2, 3],
52
- * 2: [4, 5],
53
- * 3: [],
54
- * 4: [],
55
- * 5: []
56
- * };
57
- *
58
- * const queue = new Queue<number>();
59
- * const visited: number[] = [];
60
- *
61
- * queue.push(1);
62
- *
63
- * while (!queue.isEmpty()) {
64
- * const node = queue.shift()!;
65
- * if (!visited.includes(node)) {
66
- * visited.push(node);
67
- * graph[node].forEach(neighbor => queue.push(neighbor));
68
- * }
69
- * }
70
- *
71
- * console.log(visited); // [1, 2, 3, 4, 5]
72
- */
73
- class Queue extends linear_base_1.LinearBase {
74
- /**
75
- * Create a Queue and optionally bulk-insert elements.
76
- * @remarks Time O(N), Space O(N)
77
- * @param [elements] - Iterable of elements (or raw records if toElementFn is set).
78
- * @param [options] - Options such as toElementFn, maxLen, and autoCompactRatio.
79
- * @returns New Queue instance.
80
- */
81
- constructor(elements = [], options) {
82
- super(options);
83
- this._elements = [];
84
- this._offset = 0;
85
- this._autoCompactRatio = 0.5;
86
- if (options) {
87
- const { autoCompactRatio = 0.5 } = options;
88
- this._autoCompactRatio = autoCompactRatio;
89
- }
90
- this.pushMany(elements);
91
- }
92
- /**
93
- * Get the underlying array buffer.
94
- * @remarks Time O(1), Space O(1)
95
- * @returns Backing array of elements.
96
- */
97
- get elements() {
98
- return this._elements;
99
- }
100
- /**
101
- * Get the current start offset into the array.
102
- * @remarks Time O(1), Space O(1)
103
- * @returns Zero-based offset.
104
- */
105
- get offset() {
106
- return this._offset;
107
- }
108
- /**
109
- * Get the compaction threshold (offset/size).
110
- * @remarks Time O(1), Space O(1)
111
- * @returns Auto-compaction ratio in (0,1].
112
- */
113
- get autoCompactRatio() {
114
- return this._autoCompactRatio;
115
- }
116
- /**
117
- * Set the compaction threshold.
118
- * @remarks Time O(1), Space O(1)
119
- * @param value - New ratio; compacts when offset/size exceeds this value.
120
- * @returns void
121
- */
122
- set autoCompactRatio(value) {
123
- this._autoCompactRatio = value;
124
- }
125
- /**
126
- * Get the number of elements currently in the queue.
127
- * @remarks Time O(1), Space O(1)
128
- * @returns Current length.
129
- */
130
- get length() {
131
- return this.elements.length - this._offset;
132
- }
133
- /**
134
- * Get the first element (front) without removing it.
135
- * @remarks Time O(1), Space O(1)
136
- * @returns Front element or undefined.
137
- */
138
- get first() {
139
- return this.length > 0 ? this.elements[this._offset] : undefined;
140
- }
141
- /**
142
- * Get the last element (back) without removing it.
143
- * @remarks Time O(1), Space O(1)
144
- * @returns Back element or undefined.
145
- */
146
- get last() {
147
- return this.length > 0 ? this.elements[this.elements.length - 1] : undefined;
148
- }
149
- /**
150
- * Create a queue from an array of elements.
151
- * @remarks Time O(N), Space O(N)
152
- * @template E
153
- * @param elements - Array of elements to enqueue in order.
154
- * @returns A new queue populated from the array.
155
- */
156
- static fromArray(elements) {
157
- return new Queue(elements);
158
- }
159
- /**
160
- * Check whether the queue is empty.
161
- * @remarks Time O(1), Space O(1)
162
- * @returns True if length is 0.
163
- */
164
- isEmpty() {
165
- return this.length === 0;
166
- }
167
- /**
168
- * Enqueue one element at the back.
169
- * @remarks Time O(1), Space O(1)
170
- * @param element - Element to enqueue.
171
- * @returns True on success.
172
- */
173
- push(element) {
174
- this.elements.push(element);
175
- if (this._maxLen > 0 && this.length > this._maxLen)
176
- this.shift();
177
- return true;
178
- }
179
- /**
180
- * Enqueue many elements from an iterable.
181
- * @remarks Time O(N), Space O(1)
182
- * @param elements - Iterable of elements (or raw records if toElementFn is set).
183
- * @returns Array of per-element success flags.
184
- */
185
- pushMany(elements) {
186
- const ans = [];
187
- for (const el of elements) {
188
- if (this.toElementFn)
189
- ans.push(this.push(this.toElementFn(el)));
190
- else
191
- ans.push(this.push(el));
192
- }
193
- return ans;
194
- }
195
- /**
196
- * Dequeue one element from the front (amortized via offset).
197
- * @remarks Time O(1) amortized, Space O(1)
198
- * @returns Removed element or undefined.
199
- */
200
- shift() {
201
- if (this.length === 0)
202
- return undefined;
203
- const first = this.first;
204
- this._offset += 1;
205
- if (this.elements.length > 0 && this.offset / this.elements.length > this.autoCompactRatio)
206
- this.compact();
207
- return first;
208
- }
209
- /**
210
- * Delete the first occurrence of a specific element.
211
- * @remarks Time O(N), Space O(1)
212
- * @param element - Element to remove (strict equality via Object.is).
213
- * @returns True if an element was removed.
214
- */
215
- delete(element) {
216
- for (let i = this._offset; i < this.elements.length; i++) {
217
- if (Object.is(this.elements[i], element)) {
218
- this.elements.splice(i, 1);
219
- return true;
220
- }
221
- }
222
- return false;
223
- }
224
- /**
225
- * Get the element at a given logical index.
226
- * @remarks Time O(1), Space O(1)
227
- * @param index - Zero-based index from the front.
228
- * @returns Element or undefined.
229
- */
230
- at(index) {
231
- if (index < 0 || index >= this.length)
232
- return undefined;
233
- return this._elements[this._offset + index];
234
- }
235
- /**
236
- * Delete the element at a given index.
237
- * @remarks Time O(N), Space O(1)
238
- * @param index - Zero-based index from the front.
239
- * @returns Removed element or undefined.
240
- */
241
- deleteAt(index) {
242
- if (index < 0 || index >= this.length)
243
- return undefined;
244
- const gi = this._offset + index;
245
- const [deleted] = this.elements.splice(gi, 1);
246
- return deleted;
247
- }
248
- /**
249
- * Insert a new element at a given index.
250
- * @remarks Time O(N), Space O(1)
251
- * @param index - Zero-based index from the front.
252
- * @param newElement - Element to insert.
253
- * @returns True if inserted.
254
- */
255
- addAt(index, newElement) {
256
- if (index < 0 || index > this.length)
257
- return false;
258
- this._elements.splice(this._offset + index, 0, newElement);
259
- return true;
260
- }
261
- /**
262
- * Replace the element at a given index.
263
- * @remarks Time O(1), Space O(1)
264
- * @param index - Zero-based index from the front.
265
- * @param newElement - New element to set.
266
- * @returns True if updated.
267
- */
268
- setAt(index, newElement) {
269
- if (index < 0 || index >= this.length)
270
- return false;
271
- this._elements[this._offset + index] = newElement;
272
- return true;
273
- }
274
- /**
275
- * Reverse the queue in-place by compacting then reversing.
276
- * @remarks Time O(N), Space O(N)
277
- * @returns This queue.
278
- */
279
- reverse() {
280
- this._elements = this.elements.slice(this._offset).reverse();
281
- this._offset = 0;
282
- return this;
283
- }
284
- /**
285
- * Remove all elements and reset offset.
286
- * @remarks Time O(1), Space O(1)
287
- * @returns void
288
- */
289
- clear() {
290
- this._elements = [];
291
- this._offset = 0;
292
- }
293
- /**
294
- * Compact storage by discarding consumed head elements.
295
- * @remarks Time O(N), Space O(N)
296
- * @returns True when compaction performed.
297
- */
298
- compact() {
299
- this._elements = this.elements.slice(this._offset);
300
- this._offset = 0;
301
- return true;
302
- }
303
- /**
304
- * Remove and/or insert elements at a position (array-like).
305
- * @remarks Time O(N + M), Space O(M)
306
- * @param start - Start index (clamped to [0, length]).
307
- * @param [deleteCount] - Number of elements to remove (default 0).
308
- * @param [items] - Elements to insert after `start`.
309
- * @returns A new queue containing the removed elements (typed as `this`).
310
- */
311
- splice(start, deleteCount = 0, ...items) {
312
- start = Math.max(0, Math.min(start, this.length));
313
- deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
314
- const gi = this._offset + start;
315
- const removedArray = this._elements.splice(gi, deleteCount, ...items);
316
- if (this.elements.length > 0 && this.offset / this.elements.length > this.autoCompactRatio)
317
- this.compact();
318
- const removed = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
319
- removed._setAutoCompactRatio(this._autoCompactRatio);
320
- removed.pushMany(removedArray);
321
- return removed;
322
- }
323
- /**
324
- * Deep clone this queue and its parameters.
325
- * @remarks Time O(N), Space O(N)
326
- * @returns A new queue with the same content and options.
327
- */
328
- clone() {
329
- const out = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
330
- out._setAutoCompactRatio(this._autoCompactRatio);
331
- for (let i = this._offset; i < this.elements.length; i++)
332
- out.push(this.elements[i]);
333
- return out;
334
- }
335
- /**
336
- * Filter elements into a new queue of the same class.
337
- * @remarks Time O(N), Space O(N)
338
- * @param predicate - Predicate (element, index, queue) → boolean to keep element.
339
- * @param [thisArg] - Value for `this` inside the predicate.
340
- * @returns A new queue with kept elements.
341
- */
342
- filter(predicate, thisArg) {
343
- const out = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
344
- out._setAutoCompactRatio(this._autoCompactRatio);
345
- let index = 0;
346
- for (const v of this) {
347
- if (predicate.call(thisArg, v, index, this))
348
- out.push(v);
349
- index++;
350
- }
351
- return out;
352
- }
353
- /**
354
- * Map each element to a new element in a possibly different-typed queue.
355
- * @remarks Time O(N), Space O(N)
356
- * @template EM
357
- * @template RM
358
- * @param callback - Mapping function (element, index, queue) → newElement.
359
- * @param [options] - Options for the output queue (e.g., toElementFn, maxLen, autoCompactRatio).
360
- * @param [thisArg] - Value for `this` inside the callback.
361
- * @returns A new Queue with mapped elements.
362
- */
363
- map(callback, options, thisArg) {
364
- var _a, _b;
365
- const out = new this.constructor([], {
366
- toElementFn: options === null || options === void 0 ? void 0 : options.toElementFn,
367
- maxLen: (_a = options === null || options === void 0 ? void 0 : options.maxLen) !== null && _a !== void 0 ? _a : this._maxLen,
368
- autoCompactRatio: (_b = options === null || options === void 0 ? void 0 : options.autoCompactRatio) !== null && _b !== void 0 ? _b : this._autoCompactRatio
369
- });
370
- let index = 0;
371
- for (const v of this)
372
- out.push(thisArg === undefined ? callback(v, index++, this) : callback.call(thisArg, v, index++, this));
373
- return out;
374
- }
375
- /**
376
- * Map each element to a new value of the same type.
377
- * @remarks Time O(N), Space O(N)
378
- * @param callback - Mapping function (element, index, queue) → element.
379
- * @param [thisArg] - Value for `this` inside the callback.
380
- * @returns A new queue with mapped elements (same element type).
381
- */
382
- mapSame(callback, thisArg) {
383
- var _a;
384
- const Ctor = this.constructor;
385
- const out = new Ctor([], {
386
- toElementFn: this.toElementFn,
387
- maxLen: this._maxLen,
388
- autoCompactRatio: this._autoCompactRatio
389
- });
390
- (_a = out._setAutoCompactRatio) === null || _a === void 0 ? void 0 : _a.call(out, this._autoCompactRatio);
391
- let index = 0;
392
- for (const v of this) {
393
- const mv = thisArg === undefined ? callback(v, index++, this) : callback.call(thisArg, v, index++, this);
394
- out.push(mv);
395
- }
396
- return out;
397
- }
398
- /**
399
- * (Protected) Set the internal auto-compaction ratio.
400
- * @remarks Time O(1), Space O(1)
401
- * @param value - New ratio to assign.
402
- * @returns void
403
- */
404
- _setAutoCompactRatio(value) {
405
- this._autoCompactRatio = value;
406
- }
407
- /**
408
- * (Protected) Iterate elements from front to back.
409
- * @remarks Time O(N), Space O(1)
410
- * @returns Iterator of E.
411
- */
412
- *_getIterator() {
413
- for (let i = this._offset; i < this.elements.length; i++)
414
- yield this.elements[i];
415
- }
416
- /**
417
- * (Protected) Iterate elements from back to front.
418
- * @remarks Time O(N), Space O(1)
419
- * @returns Iterator of E.
420
- */
421
- *_getReverseIterator() {
422
- for (let i = this.length - 1; i >= 0; i--) {
423
- const cur = this.at(i);
424
- if (cur !== undefined)
425
- yield cur;
426
- }
427
- }
428
- /**
429
- * (Protected) Create an empty instance of the same concrete class.
430
- * @remarks Time O(1), Space O(1)
431
- * @param [options] - Options forwarded to the constructor.
432
- * @returns An empty like-kind queue instance.
433
- */
434
- _createInstance(options) {
435
- const Ctor = this.constructor;
436
- return new Ctor([], options);
437
- }
438
- /**
439
- * (Protected) Create a like-kind queue and seed it from an iterable.
440
- * @remarks Time O(N), Space O(N)
441
- * @template EM
442
- * @template RM
443
- * @param [elements] - Iterable used to seed the new queue.
444
- * @param [options] - Options forwarded to the constructor.
445
- * @returns A like-kind Queue instance.
446
- */
447
- _createLike(elements = [], options) {
448
- const Ctor = this.constructor;
449
- return new Ctor(elements, options);
450
- }
451
- }
452
- exports.Queue = Queue;
453
- /**
454
- * Queue implemented over a singly linked list; preserves head/tail operations with linear scans for queries.
455
- * @remarks Time O(1), Space O(1)
456
- * @template E
457
- * @template R
458
- * @example examples will be generated by unit test
459
- */
460
- class LinkedListQueue extends linked_list_1.SinglyLinkedList {
461
- /**
462
- * Deep clone this linked-list-based queue.
463
- * @remarks Time O(N), Space O(N)
464
- * @returns A new queue with the same sequence of elements.
465
- */
466
- clone() {
467
- const out = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
468
- for (const v of this)
469
- out.push(v);
470
- return out;
471
- }
472
- }
473
- exports.LinkedListQueue = LinkedListQueue;
@@ -1,17 +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("./stack"), exports);