tree-set-typed 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/.eslintrc.js +61 -0
  2. package/.prettierignore +6 -0
  3. package/.prettierrc.js +16 -0
  4. package/LICENSE +21 -0
  5. package/README.md +482 -0
  6. package/coverage/clover.xml +13 -0
  7. package/coverage/coverage-final.json +96 -0
  8. package/coverage/coverage-summary.json +60 -0
  9. package/coverage/lcov-report/base.css +403 -0
  10. package/coverage/lcov-report/block-navigation.js +87 -0
  11. package/coverage/lcov-report/favicon.png +0 -0
  12. package/coverage/lcov-report/index.html +119 -0
  13. package/coverage/lcov-report/index.ts.html +109 -0
  14. package/coverage/lcov-report/prettify.css +1 -0
  15. package/coverage/lcov-report/prettify.js +2 -0
  16. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  17. package/coverage/lcov-report/sorter.js +206 -0
  18. package/coverage/lcov.info +14 -0
  19. package/dist/cjs/index.cjs +12 -0
  20. package/dist/cjs/index.cjs.map +1 -0
  21. package/dist/cjs-legacy/index.cjs +12 -0
  22. package/dist/cjs-legacy/index.cjs.map +1 -0
  23. package/dist/esm/index.mjs +3 -0
  24. package/dist/esm/index.mjs.map +1 -0
  25. package/dist/esm-legacy/index.mjs +3 -0
  26. package/dist/esm-legacy/index.mjs.map +1 -0
  27. package/dist/types/common/index.d.ts +12 -0
  28. package/dist/types/constants/index.d.ts +4 -0
  29. package/dist/types/data-structures/base/index.d.ts +2 -0
  30. package/dist/types/data-structures/base/iterable-element-base.d.ts +219 -0
  31. package/dist/types/data-structures/base/iterable-entry-base.d.ts +150 -0
  32. package/dist/types/data-structures/base/linear-base.d.ts +335 -0
  33. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +236 -0
  34. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +197 -0
  35. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +440 -0
  36. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -0
  37. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +807 -0
  38. package/dist/types/data-structures/binary-tree/bst.d.ts +645 -0
  39. package/dist/types/data-structures/binary-tree/index.d.ts +10 -0
  40. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +312 -0
  41. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -0
  42. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +243 -0
  43. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +333 -0
  44. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -0
  45. package/dist/types/data-structures/graph/directed-graph.d.ts +332 -0
  46. package/dist/types/data-structures/graph/index.d.ts +4 -0
  47. package/dist/types/data-structures/graph/map-graph.d.ts +78 -0
  48. package/dist/types/data-structures/graph/undirected-graph.d.ts +347 -0
  49. package/dist/types/data-structures/hash/hash-map.d.ts +428 -0
  50. package/dist/types/data-structures/hash/index.d.ts +1 -0
  51. package/dist/types/data-structures/heap/heap.d.ts +552 -0
  52. package/dist/types/data-structures/heap/index.d.ts +3 -0
  53. package/dist/types/data-structures/heap/max-heap.d.ts +32 -0
  54. package/dist/types/data-structures/heap/min-heap.d.ts +33 -0
  55. package/dist/types/data-structures/index.d.ts +12 -0
  56. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +437 -0
  57. package/dist/types/data-structures/linked-list/index.d.ts +3 -0
  58. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +567 -0
  59. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -0
  60. package/dist/types/data-structures/matrix/index.d.ts +2 -0
  61. package/dist/types/data-structures/matrix/matrix.d.ts +168 -0
  62. package/dist/types/data-structures/matrix/navigator.d.ts +55 -0
  63. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  64. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -0
  65. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -0
  66. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -0
  67. package/dist/types/data-structures/queue/deque.d.ts +459 -0
  68. package/dist/types/data-structures/queue/index.d.ts +2 -0
  69. package/dist/types/data-structures/queue/queue.d.ts +364 -0
  70. package/dist/types/data-structures/stack/index.d.ts +1 -0
  71. package/dist/types/data-structures/stack/stack.d.ts +324 -0
  72. package/dist/types/data-structures/tree/index.d.ts +1 -0
  73. package/dist/types/data-structures/tree/tree.d.ts +62 -0
  74. package/dist/types/data-structures/trie/index.d.ts +1 -0
  75. package/dist/types/data-structures/trie/trie.d.ts +412 -0
  76. package/dist/types/index.d.ts +23 -0
  77. package/dist/types/interfaces/binary-tree.d.ts +60 -0
  78. package/dist/types/interfaces/doubly-linked-list.d.ts +1 -0
  79. package/dist/types/interfaces/graph.d.ts +21 -0
  80. package/dist/types/interfaces/heap.d.ts +1 -0
  81. package/dist/types/interfaces/index.d.ts +8 -0
  82. package/dist/types/interfaces/navigator.d.ts +1 -0
  83. package/dist/types/interfaces/priority-queue.d.ts +1 -0
  84. package/dist/types/interfaces/segment-tree.d.ts +1 -0
  85. package/dist/types/interfaces/singly-linked-list.d.ts +1 -0
  86. package/dist/types/types/common.d.ts +15 -0
  87. package/dist/types/types/data-structures/base/base.d.ts +13 -0
  88. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  89. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  90. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  91. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  92. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  93. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  94. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  95. package/dist/types/types/data-structures/binary-tree/index.d.ts +9 -0
  96. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  97. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  98. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  99. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  100. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  101. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  102. package/dist/types/types/data-structures/graph/index.d.ts +3 -0
  103. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  104. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  105. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  106. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  107. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  108. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  109. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  110. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  111. package/dist/types/types/data-structures/index.d.ts +12 -0
  112. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  113. package/dist/types/types/data-structures/linked-list/index.d.ts +3 -0
  114. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  115. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  116. package/dist/types/types/data-structures/matrix/index.d.ts +2 -0
  117. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  118. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  119. package/dist/types/types/data-structures/priority-queue/index.d.ts +3 -0
  120. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  121. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  122. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  123. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  124. package/dist/types/types/data-structures/queue/index.d.ts +2 -0
  125. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  126. package/dist/types/types/data-structures/stack/index.d.ts +1 -0
  127. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  128. package/dist/types/types/data-structures/tree/index.d.ts +1 -0
  129. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  130. package/dist/types/types/data-structures/trie/index.d.ts +1 -0
  131. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  132. package/dist/types/types/index.d.ts +3 -0
  133. package/dist/types/types/utils/index.d.ts +2 -0
  134. package/dist/types/types/utils/utils.d.ts +22 -0
  135. package/dist/types/types/utils/validate-type.d.ts +19 -0
  136. package/dist/types/utils/index.d.ts +2 -0
  137. package/dist/types/utils/number.d.ts +14 -0
  138. package/dist/types/utils/utils.d.ts +209 -0
  139. package/dist/umd/red-black-tree-typed.js +14578 -0
  140. package/dist/umd/red-black-tree-typed.js.map +1 -0
  141. package/dist/umd/red-black-tree-typed.min.js +44 -0
  142. package/dist/umd/red-black-tree-typed.min.js.map +1 -0
  143. package/docs/.nojekyll +1 -0
  144. package/docs/assets/highlight.css +92 -0
  145. package/docs/assets/main.js +59 -0
  146. package/docs/assets/navigation.js +1 -0
  147. package/docs/assets/search.js +1 -0
  148. package/docs/assets/style.css +1383 -0
  149. package/docs/classes/AVLTree.html +2046 -0
  150. package/docs/classes/AVLTreeNode.html +263 -0
  151. package/docs/index.html +523 -0
  152. package/docs/modules.html +45 -0
  153. package/jest.config.js +8 -0
  154. package/package.json +113 -0
  155. package/src/common/index.ts +23 -0
  156. package/src/constants/index.ts +4 -0
  157. package/src/data-structures/base/index.ts +2 -0
  158. package/src/data-structures/base/iterable-element-base.ts +352 -0
  159. package/src/data-structures/base/iterable-entry-base.ts +246 -0
  160. package/src/data-structures/base/linear-base.ts +643 -0
  161. package/src/data-structures/binary-tree/avl-tree-counter.ts +539 -0
  162. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +438 -0
  163. package/src/data-structures/binary-tree/avl-tree.ts +840 -0
  164. package/src/data-structures/binary-tree/binary-indexed-tree.ts +331 -0
  165. package/src/data-structures/binary-tree/binary-tree.ts +2492 -0
  166. package/src/data-structures/binary-tree/bst.ts +2024 -0
  167. package/src/data-structures/binary-tree/index.ts +10 -0
  168. package/src/data-structures/binary-tree/red-black-tree.ts +767 -0
  169. package/src/data-structures/binary-tree/segment-tree.ts +324 -0
  170. package/src/data-structures/binary-tree/tree-counter.ts +575 -0
  171. package/src/data-structures/binary-tree/tree-multi-map.ts +549 -0
  172. package/src/data-structures/graph/abstract-graph.ts +1081 -0
  173. package/src/data-structures/graph/directed-graph.ts +715 -0
  174. package/src/data-structures/graph/index.ts +4 -0
  175. package/src/data-structures/graph/map-graph.ts +132 -0
  176. package/src/data-structures/graph/undirected-graph.ts +626 -0
  177. package/src/data-structures/hash/hash-map.ts +813 -0
  178. package/src/data-structures/hash/index.ts +1 -0
  179. package/src/data-structures/heap/heap.ts +1020 -0
  180. package/src/data-structures/heap/index.ts +3 -0
  181. package/src/data-structures/heap/max-heap.ts +47 -0
  182. package/src/data-structures/heap/min-heap.ts +36 -0
  183. package/src/data-structures/index.ts +12 -0
  184. package/src/data-structures/linked-list/doubly-linked-list.ts +876 -0
  185. package/src/data-structures/linked-list/index.ts +3 -0
  186. package/src/data-structures/linked-list/singly-linked-list.ts +1050 -0
  187. package/src/data-structures/linked-list/skip-linked-list.ts +173 -0
  188. package/src/data-structures/matrix/index.ts +2 -0
  189. package/src/data-structures/matrix/matrix.ts +491 -0
  190. package/src/data-structures/matrix/navigator.ts +124 -0
  191. package/src/data-structures/priority-queue/index.ts +3 -0
  192. package/src/data-structures/priority-queue/max-priority-queue.ts +42 -0
  193. package/src/data-structures/priority-queue/min-priority-queue.ts +29 -0
  194. package/src/data-structures/priority-queue/priority-queue.ts +19 -0
  195. package/src/data-structures/queue/deque.ts +1001 -0
  196. package/src/data-structures/queue/index.ts +2 -0
  197. package/src/data-structures/queue/queue.ts +592 -0
  198. package/src/data-structures/stack/index.ts +1 -0
  199. package/src/data-structures/stack/stack.ts +469 -0
  200. package/src/data-structures/tree/index.ts +1 -0
  201. package/src/data-structures/tree/tree.ts +115 -0
  202. package/src/data-structures/trie/index.ts +1 -0
  203. package/src/data-structures/trie/trie.ts +756 -0
  204. package/src/index.ts +24 -0
  205. package/src/interfaces/binary-tree.ts +252 -0
  206. package/src/interfaces/doubly-linked-list.ts +1 -0
  207. package/src/interfaces/graph.ts +44 -0
  208. package/src/interfaces/heap.ts +1 -0
  209. package/src/interfaces/index.ts +8 -0
  210. package/src/interfaces/navigator.ts +1 -0
  211. package/src/interfaces/priority-queue.ts +1 -0
  212. package/src/interfaces/segment-tree.ts +1 -0
  213. package/src/interfaces/singly-linked-list.ts +1 -0
  214. package/src/types/common.ts +25 -0
  215. package/src/types/data-structures/base/base.ts +34 -0
  216. package/src/types/data-structures/base/index.ts +1 -0
  217. package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
  218. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -0
  219. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -0
  220. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  221. package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
  222. package/src/types/data-structures/binary-tree/bst.ts +19 -0
  223. package/src/types/data-structures/binary-tree/index.ts +9 -0
  224. package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
  225. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
  226. package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
  227. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -0
  228. package/src/types/data-structures/graph/abstract-graph.ts +18 -0
  229. package/src/types/data-structures/graph/directed-graph.ts +2 -0
  230. package/src/types/data-structures/graph/index.ts +3 -0
  231. package/src/types/data-structures/graph/map-graph.ts +1 -0
  232. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  233. package/src/types/data-structures/hash/hash-map.ts +19 -0
  234. package/src/types/data-structures/hash/index.ts +3 -0
  235. package/src/types/data-structures/heap/heap.ts +6 -0
  236. package/src/types/data-structures/heap/index.ts +1 -0
  237. package/src/types/data-structures/heap/max-heap.ts +1 -0
  238. package/src/types/data-structures/heap/min-heap.ts +1 -0
  239. package/src/types/data-structures/index.ts +12 -0
  240. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -0
  241. package/src/types/data-structures/linked-list/index.ts +3 -0
  242. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -0
  243. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  244. package/src/types/data-structures/matrix/index.ts +2 -0
  245. package/src/types/data-structures/matrix/matrix.ts +7 -0
  246. package/src/types/data-structures/matrix/navigator.ts +14 -0
  247. package/src/types/data-structures/priority-queue/index.ts +3 -0
  248. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  249. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  250. package/src/types/data-structures/priority-queue/priority-queue.ts +3 -0
  251. package/src/types/data-structures/queue/deque.ts +5 -0
  252. package/src/types/data-structures/queue/index.ts +2 -0
  253. package/src/types/data-structures/queue/queue.ts +5 -0
  254. package/src/types/data-structures/stack/index.ts +1 -0
  255. package/src/types/data-structures/stack/stack.ts +3 -0
  256. package/src/types/data-structures/tree/index.ts +1 -0
  257. package/src/types/data-structures/tree/tree.ts +1 -0
  258. package/src/types/data-structures/trie/index.ts +1 -0
  259. package/src/types/data-structures/trie/trie.ts +3 -0
  260. package/src/types/index.ts +3 -0
  261. package/src/types/utils/index.ts +2 -0
  262. package/src/types/utils/utils.ts +33 -0
  263. package/src/types/utils/validate-type.ts +35 -0
  264. package/src/utils/index.ts +2 -0
  265. package/src/utils/number.ts +22 -0
  266. package/src/utils/utils.ts +350 -0
  267. package/test/index.test.ts +111 -0
  268. package/tsconfig.base.json +23 -0
  269. package/tsconfig.json +12 -0
  270. package/tsconfig.test.json +8 -0
  271. package/tsconfig.types.json +15 -0
  272. package/tsup.config.js +28 -0
  273. package/tsup.node.config.js +71 -0
@@ -0,0 +1,459 @@
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 { DequeOptions, ElementCallback, IterableElementBaseOptions, IterableWithSizeOrLength, LinearBaseOptions } from '../../types';
9
+ import { LinearBase } from '../base/linear-base';
10
+ /**
11
+ * Deque implemented with circular buckets allowing O(1) amortized push/pop at both ends.
12
+ * @remarks Time O(1), Space O(1)
13
+ * @template E
14
+ * @template R
15
+ * 1. Operations at Both Ends: Supports adding and removing elements at both the front and back of the queue. This allows it to be used as a stack (last in, first out) and a queue (first in, first out).
16
+ * 2. Efficient Random Access: Being based on an array, it offers fast random access capability, allowing constant time access to any element.
17
+ * 3. Continuous Memory Allocation: Since it is based on an array, all elements are stored contiguously in memory, which can bring cache friendliness and efficient memory access.
18
+ * 4. Efficiency: Adding and removing elements at both ends of a deque is usually very fast. However, when the dynamic array needs to expand, it may involve copying the entire array to a larger one, and this operation has a time complexity of O(n).
19
+ * 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
20
+ * @example
21
+ * // basic Deque creation and push/pop operations
22
+ * // Create a simple Deque with initial values
23
+ * const deque = new Deque([1, 2, 3, 4, 5]);
24
+ *
25
+ * // Verify the deque maintains insertion order
26
+ * console.log([...deque]); // [1, 2, 3, 4, 5];
27
+ *
28
+ * // Check length
29
+ * console.log(deque.length); // 5;
30
+ *
31
+ * // Push to the end
32
+ * deque.push(6);
33
+ * console.log(deque.length); // 6;
34
+ *
35
+ * // Pop from the end
36
+ * const last = deque.pop();
37
+ * console.log(last); // 6;
38
+ * @example
39
+ * // Deque shift and unshift operations
40
+ * const deque = new Deque<number>([20, 30, 40]);
41
+ *
42
+ * // Unshift adds to the front
43
+ * deque.unshift(10);
44
+ * console.log([...deque]); // [10, 20, 30, 40];
45
+ *
46
+ * // Shift removes from the front (O(1) complexity!)
47
+ * const first = deque.shift();
48
+ * console.log(first); // 10;
49
+ *
50
+ * // Verify remaining elements
51
+ * console.log([...deque]); // [20, 30, 40];
52
+ * console.log(deque.length); // 3;
53
+ * @example
54
+ * // Deque peek at both ends
55
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
56
+ *
57
+ * // Get first element without removing
58
+ * const first = deque.at(0);
59
+ * console.log(first); // 10;
60
+ *
61
+ * // Get last element without removing
62
+ * const last = deque.at(deque.length - 1);
63
+ * console.log(last); // 50;
64
+ *
65
+ * // Length unchanged
66
+ * console.log(deque.length); // 5;
67
+ * @example
68
+ * // Deque for...of iteration and reverse
69
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
70
+ *
71
+ * // Iterate forward
72
+ * const forward: string[] = [];
73
+ * for (const item of deque) {
74
+ * forward.push(item);
75
+ * }
76
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
77
+ *
78
+ * // Reverse the deque
79
+ * deque.reverse();
80
+ * const backward: string[] = [];
81
+ * for (const item of deque) {
82
+ * backward.push(item);
83
+ * }
84
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
85
+ * @example
86
+ * // Deque as sliding window for stream processing
87
+ * interface DataPoint {
88
+ * timestamp: number;
89
+ * value: number;
90
+ * sensor: string;
91
+ * }
92
+ *
93
+ * // Create a deque-based sliding window for real-time data aggregation
94
+ * const windowSize = 3;
95
+ * const dataWindow = new Deque<DataPoint>();
96
+ *
97
+ * // Simulate incoming sensor data stream
98
+ * const incomingData: DataPoint[] = [
99
+ * { timestamp: 1000, value: 25.5, sensor: 'temp-01' },
100
+ * { timestamp: 1100, value: 26.2, sensor: 'temp-01' },
101
+ * { timestamp: 1200, value: 25.8, sensor: 'temp-01' },
102
+ * { timestamp: 1300, value: 27.1, sensor: 'temp-01' },
103
+ * { timestamp: 1400, value: 26.9, sensor: 'temp-01' }
104
+ * ];
105
+ *
106
+ * const windowResults: Array<{ avgValue: number; windowSize: number }> = [];
107
+ *
108
+ * for (const dataPoint of incomingData) {
109
+ * // Add new data to the end
110
+ * dataWindow.push(dataPoint);
111
+ *
112
+ * // Remove oldest data when window exceeds size (O(1) from front)
113
+ * if (dataWindow.length > windowSize) {
114
+ * dataWindow.shift();
115
+ * }
116
+ *
117
+ * // Calculate average of current window
118
+ * let sum = 0;
119
+ * for (const point of dataWindow) {
120
+ * sum += point.value;
121
+ * }
122
+ * const avg = sum / dataWindow.length;
123
+ *
124
+ * windowResults.push({
125
+ * avgValue: Math.round(avg * 10) / 10,
126
+ * windowSize: dataWindow.length
127
+ * });
128
+ * }
129
+ *
130
+ * // Verify sliding window behavior
131
+ * console.log(windowResults.length); // 5;
132
+ * console.log(windowResults[0].windowSize); // 1; // First window has 1 element
133
+ * console.log(windowResults[2].windowSize); // 3; // Windows are at max size from 3rd onwards
134
+ * console.log(windowResults[4].windowSize); // 3; // Last window still has 3 elements
135
+ * console.log(dataWindow.length); // 3;
136
+ */
137
+ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
138
+ protected _equals: (a: E, b: E) => boolean;
139
+ /**
140
+ * Create a Deque and optionally bulk-insert elements.
141
+ * @remarks Time O(N), Space O(N)
142
+ * @param [elements] - Iterable (or iterable-like) of elements/records to insert.
143
+ * @param [options] - Options such as bucketSize, toElementFn, and maxLen.
144
+ * @returns New Deque instance.
145
+ */
146
+ constructor(elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>, options?: DequeOptions<E, R>);
147
+ protected _bucketSize: number;
148
+ /**
149
+ * Get the current bucket size.
150
+ * @remarks Time O(1), Space O(1)
151
+ * @returns Bucket capacity per bucket.
152
+ */
153
+ get bucketSize(): number;
154
+ protected _bucketFirst: number;
155
+ /**
156
+ * Get the index of the first bucket in use.
157
+ * @remarks Time O(1), Space O(1)
158
+ * @returns Zero-based bucket index.
159
+ */
160
+ get bucketFirst(): number;
161
+ protected _firstInBucket: number;
162
+ /**
163
+ * Get the index inside the first bucket.
164
+ * @remarks Time O(1), Space O(1)
165
+ * @returns Zero-based index within the first bucket.
166
+ */
167
+ get firstInBucket(): number;
168
+ protected _bucketLast: number;
169
+ /**
170
+ * Get the index of the last bucket in use.
171
+ * @remarks Time O(1), Space O(1)
172
+ * @returns Zero-based bucket index.
173
+ */
174
+ get bucketLast(): number;
175
+ protected _lastInBucket: number;
176
+ /**
177
+ * Get the index inside the last bucket.
178
+ * @remarks Time O(1), Space O(1)
179
+ * @returns Zero-based index within the last bucket.
180
+ */
181
+ get lastInBucket(): number;
182
+ protected _bucketCount: number;
183
+ /**
184
+ * Get the number of buckets allocated.
185
+ * @remarks Time O(1), Space O(1)
186
+ * @returns Bucket count.
187
+ */
188
+ get bucketCount(): number;
189
+ protected _buckets: E[][];
190
+ /**
191
+ * Get the internal buckets array.
192
+ * @remarks Time O(1), Space O(1)
193
+ * @returns Array of buckets storing values.
194
+ */
195
+ get buckets(): E[][];
196
+ protected _length: number;
197
+ /**
198
+ * Get the number of elements in the deque.
199
+ * @remarks Time O(1), Space O(1)
200
+ * @returns Current length.
201
+ */
202
+ get length(): number;
203
+ /**
204
+ * Get the first element without removing it.
205
+ * @remarks Time O(1), Space O(1)
206
+ * @returns First element or undefined.
207
+ */
208
+ get first(): E | undefined;
209
+ /**
210
+ * Get the last element without removing it.
211
+ * @remarks Time O(1), Space O(1)
212
+ * @returns Last element or undefined.
213
+ */
214
+ get last(): E | undefined;
215
+ /**
216
+ * Create a Deque from an array of elements.
217
+ * @remarks Time O(N), Space O(N)
218
+ * @template E
219
+ * @template R
220
+ * @param this - Constructor (subclass) to instantiate.
221
+ * @param data - Array of elements to insert in order.
222
+ * @param [options] - Options forwarded to the constructor.
223
+ * @returns A new Deque populated from the array.
224
+ */
225
+ static fromArray<E, R = any>(this: new (elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>, options?: DequeOptions<E, R>) => any, data: E[], options?: DequeOptions<E, R>): any;
226
+ /**
227
+ * Append one element at the back.
228
+ * @remarks Time O(1) amortized, Space O(1)
229
+ * @param element - Element to append.
230
+ * @returns True when appended.
231
+ */
232
+ push(element: E): boolean;
233
+ /**
234
+ * Remove and return the last element.
235
+ * @remarks Time O(1), Space O(1)
236
+ * @returns Removed element or undefined.
237
+ */
238
+ pop(): E | undefined;
239
+ /**
240
+ * Remove and return the first element.
241
+ * @remarks Time O(1) amortized, Space O(1)
242
+ * @returns Removed element or undefined.
243
+ */
244
+ shift(): E | undefined;
245
+ /**
246
+ * Prepend one element at the front.
247
+ * @remarks Time O(1) amortized, Space O(1)
248
+ * @param element - Element to prepend.
249
+ * @returns True when prepended.
250
+ */
251
+ unshift(element: E): boolean;
252
+ /**
253
+ * Append a sequence of elements.
254
+ * @remarks Time O(N), Space O(1)
255
+ * @param elements - Iterable (or iterable-like) of elements/records.
256
+ * @returns Array of per-element success flags.
257
+ */
258
+ pushMany(elements: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
259
+ /**
260
+ * Prepend a sequence of elements.
261
+ * @remarks Time O(N), Space O(1)
262
+ * @param [elements] - Iterable (or iterable-like) of elements/records.
263
+ * @returns Array of per-element success flags.
264
+ */
265
+ unshiftMany(elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
266
+ /**
267
+ * Check whether the deque is empty.
268
+ * @remarks Time O(1), Space O(1)
269
+ * @returns True if length is 0.
270
+ */
271
+ isEmpty(): boolean;
272
+ /**
273
+ * Remove all elements and reset structure.
274
+ * @remarks Time O(1), Space O(1)
275
+ * @returns void
276
+ */
277
+ clear(): void;
278
+ /**
279
+ * Get the element at a given position.
280
+ * @remarks Time O(1), Space O(1)
281
+ * @param pos - Zero-based position from the front.
282
+ * @returns Element or undefined.
283
+ */
284
+ at(pos: number): E | undefined;
285
+ /**
286
+ * Replace the element at a given position.
287
+ * @remarks Time O(1), Space O(1)
288
+ * @param pos - Zero-based position from the front.
289
+ * @param element - New element value.
290
+ * @returns True if updated.
291
+ */
292
+ setAt(pos: number, element: E): boolean;
293
+ /**
294
+ * Insert repeated copies of an element at a position.
295
+ * @remarks Time O(N), Space O(1)
296
+ * @param pos - Zero-based position from the front.
297
+ * @param element - Element to insert.
298
+ * @param [num] - Number of times to insert (default 1).
299
+ * @returns True if inserted.
300
+ */
301
+ addAt(pos: number, element: E, num?: number): boolean;
302
+ /**
303
+ * Cut the deque to keep items up to index; optionally mutate in-place.
304
+ * @remarks Time O(N), Space O(1)
305
+ * @param pos - Last index to keep.
306
+ * @param [isCutSelf] - When true, mutate this deque; otherwise return a new deque.
307
+ * @returns This deque if in-place; otherwise a new deque of the prefix.
308
+ */
309
+ cut(pos: number, isCutSelf?: boolean): Deque<E>;
310
+ /**
311
+ * Remove and/or insert elements at a position (array-like behavior).
312
+ * @remarks Time O(N + M), Space O(M)
313
+ * @param start - Start index (clamped to [0, length]).
314
+ * @param [deleteCount] - Number of elements to remove (default: length - start).
315
+ * @param [items] - Elements to insert after `start`.
316
+ * @returns A new deque containing the removed elements (typed as `this`).
317
+ */
318
+ splice(start: number, deleteCount?: number, ...items: E[]): this;
319
+ /**
320
+ * Cut the deque to keep items from index onward; optionally mutate in-place.
321
+ * @remarks Time O(N), Space O(1)
322
+ * @param pos - First index to keep.
323
+ * @param [isCutSelf] - When true, mutate this deque; otherwise return a new deque.
324
+ * @returns This deque if in-place; otherwise a new deque of the suffix.
325
+ */
326
+ cutRest(pos: number, isCutSelf?: boolean): Deque<E>;
327
+ /**
328
+ * Delete the element at a given position.
329
+ * @remarks Time O(N), Space O(1)
330
+ * @param pos - Zero-based position from the front.
331
+ * @returns Removed element or undefined.
332
+ */
333
+ deleteAt(pos: number): E | undefined;
334
+ /**
335
+ * Delete the first occurrence of a value.
336
+ * @remarks Time O(N), Space O(1)
337
+ * @param element - Element to remove (using the configured equality).
338
+ * @returns True if an element was removed.
339
+ */
340
+ delete(element: E): boolean;
341
+ /**
342
+ * Delete the first element matching a predicate.
343
+ * @remarks Time O(N), Space O(1)
344
+ * @param predicate - Function (value, index, deque) → boolean.
345
+ * @returns True if a match was removed.
346
+ */
347
+ deleteWhere(predicate: (value: E, index: number, deque: this) => boolean): boolean;
348
+ /**
349
+ * Set the equality comparator used by delete operations.
350
+ * @remarks Time O(1), Space O(1)
351
+ * @param equals - Equality predicate (a, b) → boolean.
352
+ * @returns This deque.
353
+ */
354
+ setEquality(equals: (a: E, b: E) => boolean): this;
355
+ /**
356
+ * Reverse the deque by reversing buckets and pointers.
357
+ * @remarks Time O(N), Space O(N)
358
+ * @returns This deque.
359
+ */
360
+ reverse(): this;
361
+ /**
362
+ * Deduplicate consecutive equal elements in-place.
363
+ * @remarks Time O(N), Space O(1)
364
+ * @returns This deque.
365
+ */
366
+ unique(): this;
367
+ /**
368
+ * Trim unused buckets to fit exactly the active range.
369
+ * @remarks Time O(N), Space O(1)
370
+ * @returns void
371
+ */
372
+ shrinkToFit(): void;
373
+ /**
374
+ * Deep clone this deque, preserving options.
375
+ * @remarks Time O(N), Space O(N)
376
+ * @returns A new deque with the same content and options.
377
+ */
378
+ clone(): this;
379
+ /**
380
+ * Filter elements into a new deque of the same class.
381
+ * @remarks Time O(N), Space O(N)
382
+ * @param predicate - Predicate (value, index, deque) → boolean to keep element.
383
+ * @param [thisArg] - Value for `this` inside the predicate.
384
+ * @returns A new deque with kept elements.
385
+ */
386
+ filter(predicate: ElementCallback<E, R, boolean>, thisArg?: any): this;
387
+ /**
388
+ * Map elements into a new deque of the same element type.
389
+ * @remarks Time O(N), Space O(N)
390
+ * @param callback - Mapping function (value, index, deque) → newValue.
391
+ * @param [thisArg] - Value for `this` inside the callback.
392
+ * @returns A new deque with mapped values.
393
+ */
394
+ mapSame(callback: ElementCallback<E, R, E>, thisArg?: any): this;
395
+ /**
396
+ * Map elements into a new deque (possibly different element type).
397
+ * @remarks Time O(N), Space O(N)
398
+ * @template EM
399
+ * @template RM
400
+ * @param callback - Mapping function (value, index, deque) → newElement.
401
+ * @param [options] - Options for the output deque (e.g., bucketSize, toElementFn, maxLen).
402
+ * @param [thisArg] - Value for `this` inside the callback.
403
+ * @returns A new Deque with mapped elements.
404
+ */
405
+ map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: IterableElementBaseOptions<EM, RM>, thisArg?: any): Deque<EM, RM>;
406
+ /**
407
+ * (Protected) Set the internal bucket size.
408
+ * @remarks Time O(1), Space O(1)
409
+ * @param size - Bucket capacity to assign.
410
+ * @returns void
411
+ */
412
+ protected _setBucketSize(size: number): void;
413
+ /**
414
+ * (Protected) Iterate elements from front to back.
415
+ * @remarks Time O(N), Space O(1)
416
+ * @returns Iterator of elements.
417
+ */
418
+ protected _getIterator(): IterableIterator<E>;
419
+ /**
420
+ * (Protected) Reallocate buckets to make room near the ends.
421
+ * @remarks Time O(N), Space O(N)
422
+ * @param [needBucketNum] - How many extra buckets to add; defaults to half of current.
423
+ * @returns void
424
+ */
425
+ protected _reallocate(needBucketNum?: number): void;
426
+ /**
427
+ * (Protected) Translate a logical position to bucket/offset.
428
+ * @remarks Time O(1), Space O(1)
429
+ * @param pos - Zero-based position.
430
+ * @returns An object containing bucketIndex and indexInBucket.
431
+ */
432
+ protected _getBucketAndPosition(pos: number): {
433
+ bucketIndex: number;
434
+ indexInBucket: number;
435
+ };
436
+ /**
437
+ * (Protected) Create an empty instance of the same concrete class.
438
+ * @remarks Time O(1), Space O(1)
439
+ * @param [options] - Options forwarded to the constructor.
440
+ * @returns An empty like-kind deque instance.
441
+ */
442
+ protected _createInstance(options?: LinearBaseOptions<E, R>): this;
443
+ /**
444
+ * (Protected) Create a like-kind deque seeded by elements.
445
+ * @remarks Time O(N), Space O(N)
446
+ * @template T
447
+ * @template RR
448
+ * @param [elements] - Iterable used to seed the new deque.
449
+ * @param [options] - Options forwarded to the constructor.
450
+ * @returns A like-kind Deque instance.
451
+ */
452
+ protected _createLike<T = E, RR = R>(elements?: IterableWithSizeOrLength<T> | IterableWithSizeOrLength<RR>, options?: DequeOptions<T, RR>): any;
453
+ /**
454
+ * (Protected) Iterate elements from back to front.
455
+ * @remarks Time O(N), Space O(1)
456
+ * @returns Iterator of elements.
457
+ */
458
+ protected _getReverseIterator(): IterableIterator<E>;
459
+ }
@@ -0,0 +1,2 @@
1
+ export * from './queue';
2
+ export * from './deque';